Orbit > OTG > Function Specifications > Understanding OTR Main Program

Tha main() fucntion in otg.cpp is given as below:

int main(int argc, const char * argv[])
  OrbitApp * otr1 = new OTRApp();

  try {       
  pthread_t thread1;
  char *protocol_name = "udp";
  char *debuglog_name = NULL;
  parseOptionsPhase1(argc, argv, &protocol_name, &debuglog_name);
  Gate* gate = createGate(protocol_name);
  //create dummy sink 
  Sink *sin =  new DummySink();
  otr1->init(&argc, argv, debuglog_name);
  parseOptionsPhase2(argc, argv, gate);
  if ( pthread_create( &thread1, NULL,create_receive_thread, (void*)gate) != 0 )
         throw "Create Thread Failed...";  
  char msg[MAX_INPUT_SIZE];
  while (1) {
        cin.getline(msg, MAX_INPUT_SIZE );
        parseRuntimeOptions(msg, gate, thread1, otr1);

  }catch ( const char *reason ) {
    cerr << "Exception:" << reason << endl;

  return 0;


As can be seen, this is a very clean and short program. I explain it in detail.

  1. First an OrbitApp object is created to handle all OML-related stuff.
  2. Parsing user command-line input to determine
    1. protocol type
    2. debug mode is used or not. and if yes, the log file path.
  3. Create Gate based on the "protocol type"
  4. Init the OML-related object.
  5. Conduct 2nd-tier parse to get all detail parameters of Gate such as receiving port.
  6. Init Gate
  7. Create a separate thread to let Gate start receiving packets.
  8. An eternal while loop is acting as the continuing main thread to handle run-time user inputs.


It is possible to have multiple gates in one OTR application. More gates listening to more ports and we could create more threads. But it seems there is no need to do this. Users care more than lower-layer link performance than have multiple competitive applications running on one single port.

Last modified 14 years ago Last modified on Feb 27, 2006, 8:45:06 PM
Note: See TracWiki for help on using the wiki.