File indexing completed on 2025-08-03 08:20:33
0001 #include <string.h>
0002 #include <stdio.h>
0003 #include <iostream>
0004 #include <iomanip>
0005
0006 #include "eventReceiverClient.h"
0007 #include "Event.h"
0008
0009 #ifdef HAVE_GETOPT_H
0010 #include "getopt.h"
0011 #endif
0012
0013 using namespace std;
0014
0015
0016 void exitmsg()
0017 {
0018 cout << " usage: eventClient [-t <timeout in s> -v ] event_nr [hostname] " << endl;
0019 exit(1);
0020 }
0021
0022
0023 void exithelp()
0024 {
0025
0026 cout << std::endl;
0027 cout << "eventClient receives events from the eventServer process" << std::endl;
0028 cout << " usage: eventClient [-t <timeout in s> -v ] event_nr [hostname] " << endl;
0029 cout << std::endl;
0030 cout << " List of options: " << std::endl;
0031 cout << " -p <port number> (default 8080)" << std::endl;
0032 cout << " -t <s> timeout" << std::endl;
0033 cout << " -v verbose" << std::endl;
0034 exit(0);
0035 }
0036
0037
0038
0039
0040 int
0041 main(int argc, char *argv[])
0042 {
0043 int ThePort = 8080;
0044
0045 int verbosity = 0;
0046 int timeout = 0;
0047
0048 int c;
0049
0050 while ((c = getopt(argc, argv, "t:p:v")) != EOF)
0051 switch (c)
0052 {
0053 case 't':
0054 if ( !sscanf(optarg, "%d", &timeout) ) exitmsg();
0055 break;
0056
0057 case 'p':
0058 if ( !sscanf(optarg, "%d", &ThePort) ) exitmsg();
0059 break;
0060
0061 case 'v':
0062 verbosity++;
0063 break;
0064
0065 case 'h':
0066 exithelp();
0067 break;
0068 }
0069
0070 if ( optind >= argc) exitmsg();
0071
0072
0073 int evtnr = atoi(argv[optind]);
0074
0075 string host;
0076 if ( argc > optind+1)
0077 {
0078 host = argv[optind+1];
0079 }
0080 else
0081 {
0082 host = "localhost";
0083 }
0084
0085 eventReceiverClient *erc = new eventReceiverClient(host,0,ThePort);
0086 if ( erc->getStatus())
0087 {
0088 delete erc;
0089 return 1;
0090 }
0091
0092 if (timeout) erc->setUserTimeout(timeout);
0093
0094 erc->setVerbosity(verbosity);
0095
0096 Event *e = erc->getEvent(evtnr);
0097 if (e)
0098 {
0099 e->identify();
0100 delete e;
0101 }
0102 else
0103 {
0104 cout << "event " << evtnr << " not received, timeout = "<< erc->hadTimeout() << endl;
0105 }
0106 delete erc;
0107
0108 return 0;
0109 }