Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ddsparentserver.cc

Go to the documentation of this file.
00001 #include <cstdlib>
00002 #include <unistd.h>
00003 #include "TROOT.h"
00004 #include "MessageService/Msg.h"
00005 #include "MessageService/MsgService.h"
00006 #include "Dispatcher/DDSParentServer.h"
00007 
00008 TROOT root("ddsparentserver","MINOS Data Dispatcher System ddsparentserver");
00009 CVSID("$Id: ddsparentserver.cc,v 1.7 2009/02/28 21:46:12 gmieg Exp $");
00010 
00012 //                                                                          //
00013 // Data Dispatcher System parentserver program.  This program uses the      //
00014 // DDSParentServer class and drives the parent server portion of the        //
00015 // dispatcher system.                                                       //
00016 //                                                                          //
00017 // usage: ddsparentserver -p<port #> -m<max no. of clients> -l<loglevel>    //
00018 //                        -t<maxinactive>                                   //
00019 // -p: port number assigned to listening socket (default = 9090)            //
00020 // -m: maximum number of concurrent clients allowed (default = 10)          //
00021 // -l: loglevel at which to print messages (default = Info)                 //
00022 // -t: inactive client time limit (sec) before child server will disconnect //
00023 //     (def = 21600)                                                        //
00024 // -h: print usage message                                                  //
00026 
00027 int main(int argc, char **argv) {
00028 
00029   Int_t port = 9090;
00030   Int_t maxchild = 10;
00031   Int_t maxinactive = 21600;
00032   Int_t logLevel = Msg::GetLevelCode("Info");
00033  
00034   gROOT -> SetBatch(kTRUE);
00035 
00036   // Process the command line arguments
00037   int c;
00038   while ((c = getopt(argc,argv,"p:m:l:t:h")) != -1) {
00039     switch (c) {
00040     case 'p':
00041       port = atoi(optarg);
00042       break;
00043     case 'm':
00044       maxchild = atoi(optarg);
00045       break;
00046     case 'l':
00047       logLevel = Msg::GetLevelCode(optarg);
00048       if ( logLevel < Msg::kMinLogLevel ) {
00049         fprintf(stderr,
00050                 "-l (loglevel) option has invalid argument %s.\n",optarg);
00051         fprintf(stderr,"   valid arguments are:");
00052         fprintf(stderr," %s",Msg::LevelAsString(Msg::kMinLogLevel));
00053         for (int i = Msg::kMinLogLevel+1;
00054                  i < (Msg::kNLogLevel+Msg::kMinLogLevel); i++) {
00055           if ( strcmp("Unknown?!",Msg::LevelAsString(i)) ) 
00056              fprintf(stderr,", %s",Msg::LevelAsString(i));
00057         }
00058         fprintf(stderr,"\n");
00059         exit(1);
00060       }
00061       break;
00062     case 't':
00063       maxinactive = atoi(optarg);
00064       break;
00065     case 'h':
00066       fprintf(stdout,"usage: %s -p<port#> -m<max no. clients> -l<loglevel> -t<maxinactive>\n",argv[0]);
00067       fprintf(stdout," -p: port number to listen on (default=%i)\n",DDS::kPort);
00068       fprintf(stdout," -m: maximum number of concurrent clients (default = 10)\n");
00069       fprintf(stdout,
00070               " -l: loglevel at which to print messages (default=Info).\n");
00071       fprintf(stdout,"     valid arguments are:");
00072       fprintf(stdout," %s",Msg::LevelAsString(Msg::kMinLogLevel));
00073       for (int i = Msg::kMinLogLevel+1;
00074                i < (Msg::kNLogLevel+Msg::kMinLogLevel); i++) {
00075         if ( strcmp("Unknown?!",Msg::LevelAsString(i)) ) 
00076           fprintf(stdout,", %s",Msg::LevelAsString(i));
00077       }
00078       fprintf(stdout,"\n");
00079       fprintf(stdout,
00080       " -t: inactive client time limit(sec) before child server will disconnect\n");
00081       fprintf(stdout," -h: print this message\n");
00082       exit(0);
00083       break;
00084     default:
00085       fprintf(stderr,"unknown command line option: %c\n",(char)optopt);
00086       exit(1);
00087       break; 
00088     }
00089   }
00090 
00091   MsgService::Instance() -> GetStream("DDS") -> SetLogLevel(logLevel);
00092   // require time stamping for all log levels above this
00093   for (int i = logLevel; i < Msg::kNLogLevel; i++) {
00094     MsgService::Instance() -> GetStream("DDS")->AddFormat(i,Msg::kTime);
00095   }
00096 
00097 // Create a DDSParentServer object attached to port 9090 
00098   DDSParentServer *ps =new DDSParentServer(port,maxchild,logLevel,maxinactive);
00099   if (! ps->IsValid() ) {
00100     // Error in creation of parent server
00101     MSG("DDS",Msg::kFatal) 
00102     << "PS: Error in creation of parent server. Program terminating." <<endl;
00103     return 1;
00104   }
00105 
00106 // Print some information about the parent server socket
00107   MSG("DDS",Msg::kInfo)
00108         << "PS: Successfully opened parent server listening socket." << endl;
00109   MSG("DDS",Msg::kInfo) << ps << endl;
00110 
00111 // Run the main loop to listen for and process client connections
00112 // The parent server will stay in this loop until it receives a 
00113 // DDS::kShutdown message from a connected client 
00114   ps -> Run();
00115 
00116 // Print final stats from the parent server socket
00117   MSG("DDS",Msg::kInfo)<<"PS: Shutdown message received by parent server."
00118                        << endl; 
00119   MSG("DDS",Msg::kInfo)<< ps << endl;;
00120 
00121 // delete parent server socket
00122   delete ps;
00123 
00124   return 0;
00125 
00126 }
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 

Generated on Mon Feb 15 11:06:36 2010 for loon by  doxygen 1.3.9.1