Version 1 (modified by 19 years ago) ( diff ) | ,
---|
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.
- First an OrbitApp object is createdd to handle all OML-related stuff.
- Parsing user command-line input to determine
- protocol type
- debug mode is used or not. and if yes, the log file path.
- Create Gate based on the "protocol type"
- Init the OML-related object.
- Conduct 2nd-tier parse to get all detail parameters of Gate such as receiving port.
- Init Gate
- Create a seperate thread to let Gate start receiving packets.
- An eternal while loop is actting 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.