wiki:Old/Documentation/OTG/FuncSpec/OtrMainProgram

Version 3 (modified by root, 19 years ago) ( diff )

Name changed from OTG/FuncSpec/OtrMainProgram to Documentation/OTG/FuncSpec/OtrMainProgram

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);
  gate->configGate(otr1,sin);
  gate->init();
  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;
    exit(-1);
  }

  return 0;
}

Explanation

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.

Discussion

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.

Note: See TracWiki for help on using the wiki.