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

ddscomm.cc

Go to the documentation of this file.
00001 #include <cstdlib>
00002 #include <unistd.h>
00003 #include "TROOT.h"
00004 #include "TSystem.h"
00005 #include "MessageService/MsgService.h"
00006 #include "Dispatcher/DDS.h"
00007 #include "Dispatcher/DDSClient.h"
00008 #include "Dispatcher/DDSPSStatus.h"
00009 
00010 TROOT root("ddscomm","MINOS Data Dispatcher System communications");
00011 CVSID("$Id: ddscomm.cc,v 1.9 2009/02/28 21:46:12 gmieg Exp $");
00012 
00014 //                                                                          //
00015 // Data Dispatcher System communications program.  This program uses        //
00016 // the DDSClient class to communicate with the ddsparentserver.             //
00017 //                                                                          //
00018 // S. Kasahara  8/2001                                                      //
00019 //                                                                          //
00020 // usage:  ddscomm -i<host ip> -p<port #> -s -r                             //
00021 // -i: ip address of ddsparentserver (default is local host ip)             //
00022 // -p: port # ddsparentserver listens on (default is DDS::kPort)            //
00023 // -s: shutdown ddsparentserver                                             //
00024 // -r: ddsparentserver report status                                        //
00025 // -h: print usage message                                                  //
00026 //                                                                          //
00027 // Notes:  Currently supports 3 communication messages:                     //
00028 //         ddscomm                                                          //
00029 //           - prints abbreviated ddsparentserver status                    //
00030 //         ddscomm -r                                                       //
00031 //           - prints full ddsparentserver status report                    //
00032 //         ddscomm -s                                                       //
00033 //           - shuts down dispatcher parent server.                         //
00034 //             This command must be issued on the same host as the          //
00035 //             dispatcher parent server.                                    //
00036 //                                                                          //
00037 //         Options -p and -i may be specified with any communication        //
00038 //         message.                                                         //
00039 //                                                                          //
00041 
00042 int main(int argc, char **argv) {
00043 
00044   MsgStream& ms = MSGSTREAM("DDS",Msg::kInfo);
00045 
00046   // Determine host name of current machine, default port #, default msg type
00047   const char* hostname = gSystem -> HostName();  
00048   Int_t port = DDS::kPort;
00049   DDS::EMessageType msgrequest = DDS::kStatus;
00050 
00051   gROOT -> SetBatch(kTRUE);
00052 
00053   // Process the command line arguments
00054   int c;
00055   bool isreport = false;
00056   while ((c = getopt(argc,argv,"i:p:srh")) != -1) {
00057     switch (c) {
00058     case 'i':
00059       hostname = optarg;
00060       break;
00061     case 'p':
00062       port = atoi(optarg);
00063       break;
00064     case 's':
00065       msgrequest = DDS::kShutdown;
00066       break;
00067     case 'r':
00068       msgrequest = DDS::kStatus;
00069       isreport = true;
00070       break;
00071     case 'h':
00072       fprintf(stderr,"usage: %s -i<host ip> -p<port #> -r -s\n",argv[0]);
00073       fprintf(stderr," -i: ip address of ddsparentserver (default is local ip)\n");
00074       fprintf(stderr," -p: port # ddsparentserver listens on (default is %i)\n",DDS::kPort);
00075       fprintf(stderr," -r: report full status of ddsparentserver\n");
00076       fprintf(stderr," -s: shutdown ddsparentserver\n");
00077       fprintf(stderr," -h: print this message\n");
00078       fprintf(stderr,"no opt: prints brief status of ddsparentserver\n");
00079       exit(0);
00080       break;
00081     default:
00082       fprintf(stderr,"unknown command line option:%c\n",(char)optopt);
00083       exit(1);
00084       break;
00085     }
00086   }
00087 
00088   int retstat=0;
00089   DDSClient* ddsclient = 0;
00090   if (msgrequest != DDS::kMessageUnknown) {
00091 
00092     const DDSPSStatus* psstatus = 0;
00093     switch (msgrequest) {
00094     
00095     case DDS::kShutdown:
00096       ms << "Sending shutdown message to parent server on host " 
00097          << hostname << " port " << port << "." << endl;
00098       // Need to fix how this is done
00099       ddsclient = new DDSClient(hostname,port,msgrequest);
00100       delete ddsclient;
00101       break;
00102 
00103     case DDS::kStatus:
00104       if ( isreport ) {
00105         ms << "Request full status report from parent server on host " 
00106            << hostname << " port " << port << "." << endl;
00107       }
00108       else {
00109         ms << "Request abbreviated status of parent server on host "
00110            << hostname << " port " << port << "." << endl;
00111       }
00112 
00113       ddsclient = new DDSClient(hostname,port,msgrequest);
00114       ms << "ddsparentserver " << hostname << " port " 
00115          << port << " status " << DDS::AsString(ddsclient->GetStatus()) 
00116          << endl;
00117       psstatus = ddsclient->GetPSStatus();
00118       if ( psstatus && isreport ) psstatus -> Print();
00119        
00120       if ( ddsclient->GetStatus() != DDS::kOk ) {
00121         retstat = 1;
00122       }
00123       delete ddsclient;
00124       
00125       break;
00126 
00127     default:
00128       break;
00129 
00130     }// end of msgrequest switch
00131   }
00132 
00133   return retstat;
00134 
00135 }

Generated on Mon Nov 23 05:26:36 2009 for loon by  doxygen 1.3.9.1