ddsparentserver.cc File Reference

#include <cstdlib>
#include <unistd.h>
#include "TROOT.h"
#include "MessageService/Msg.h"
#include "MessageService/MsgService.h"
#include "Dispatcher/DDSParentServer.h"

Go to the source code of this file.

Functions

TROOT root ("ddsparentserver","MINOS Data Dispatcher System ddsparentserver")
 CVSID ("$Id: ddsparentserver.cc,v 1.7 2009/02/28 21:46:12 gmieg Exp $")
int main (int argc, char **argv)

Function Documentation

CVSID ( "$Id: ddsparentserver.  cc,
v 1.7 2009/02/28 21:46:12 gmieg Exp $"   
)
int main ( int  argc,
char **  argv 
)

Definition at line 27 of file ddsparentserver.cc.

References exit(), Msg::GetLevelCode(), MsgService::Instance(), DDSParentServer::IsValid(), Msg::kFatal, Msg::kInfo, Msg::kMinLogLevel, Msg::kNLogLevel, DDS::kPort, Msg::kTime, Msg::LevelAsString(), MSG, port, and Dbi::SetLogLevel().

00027                                 {
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 }

TROOT root ( "ddsparentserver"  ,
"MINOS Data Dispatcher System ddsparentserver"   
)

Generated on 15 Jul 2018 for loon by  doxygen 1.6.1