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
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00041
00042 int main(int argc, char **argv) {
00043
00044 MsgStream& ms = MSGSTREAM("DDS",Msg::kInfo);
00045
00046
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
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
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 }
00131 }
00132
00133 return retstat;
00134
00135 }