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
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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
00093 for (int i = logLevel; i < Msg::kNLogLevel; i++) {
00094 MsgService::Instance() -> GetStream("DDS")->AddFormat(i,Msg::kTime);
00095 }
00096
00097
00098 DDSParentServer *ps =new DDSParentServer(port,maxchild,logLevel,maxinactive);
00099 if (! ps->IsValid() ) {
00100
00101 MSG("DDS",Msg::kFatal)
00102 << "PS: Error in creation of parent server. Program terminating." <<endl;
00103 return 1;
00104 }
00105
00106
00107 MSG("DDS",Msg::kInfo)
00108 << "PS: Successfully opened parent server listening socket." << endl;
00109 MSG("DDS",Msg::kInfo) << ps << endl;
00110
00111
00112
00113
00114 ps -> Run();
00115
00116
00117 MSG("DDS",Msg::kInfo)<<"PS: Shutdown message received by parent server."
00118 << endl;
00119 MSG("DDS",Msg::kInfo)<< ps << endl;;
00120
00121
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