(continued)
I will introduce several aspects related to xApps in following posts:
(1) xApp framework introduction
(2) HOW-TO: manually build xApps based on Gerrit sources
(3) HOW-TO: introduce policy types and policy instances
(4) HOW-TO: delete xApps and re-deploy xApps
Let's begin with 'xApp framework'( which will be abbreviated as XFW). XFW is implemented in three different programming languages: Go, C++ and Python. I will focus on Cpp version.
Xapp is simply a subclass of Messenger, and it provides the Run method to execute the main message loop.
// part of xapp.hpp
class Xapp : public Messenger {
public:
Xapp( char* listen_port, bool wait4rt ); // builder
void Run( int nthreads ); // message listen driver
};
// part of xapp.cpp
/*
If wait4table is true, then the construction of the object does not
complete until the underlying transport has a new copy of the route
table.
If port is nil, then the default port is used (4560).
*/
Xapp::Xapp( char* port, bool wait4table ) : Messenger( port, wait4table ) {
// nothing to do; all handled in Messenger constructor
}
Below is a typical xapp implementation: you create an Xapp instance, add message callbacks and call Run.
// part of ts_xapp.cpp
extern int main( int argc, char** argv ) {
int nthreads = 1;
char* port = (char *) "4560";
xfw = std::unique_ptr<Xapp>( new Xapp( port, true ) );
xfw->Add_msg_cb( 20010, policy_callback, NULL );
xfw->Add_msg_cb( 30002, prediction_callback, NULL );
xfw->Run( nthreads );
}
Let's take a look at the su