-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy patheventClient.cc
109 lines (83 loc) · 1.84 KB
/
eventClient.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include "eventReceiverClient.h"
#include "Event.h"
#ifdef HAVE_GETOPT_H
#include "getopt.h"
#endif
using namespace std;
void exitmsg()
{
cout << " usage: eventClient [-t <timeout in s> -v ] event_nr [hostname] " << endl;
exit(1);
}
void exithelp()
{
cout << std::endl;
cout << "eventClient receives events from the eventServer process" << std::endl;
cout << " usage: eventClient [-t <timeout in s> -v ] event_nr [hostname] " << endl;
cout << std::endl;
cout << " List of options: " << std::endl;
cout << " -p <port number> (default 8080)" << std::endl;
cout << " -t <s> timeout" << std::endl;
cout << " -v verbose" << std::endl;
exit(0);
}
// Driver code
int
main(int argc, char *argv[])
{
int ThePort = 8080;
int verbosity = 0;
int timeout = 0;
int c;
while ((c = getopt(argc, argv, "t:p:v")) != EOF)
switch (c)
{
case 't':
if ( !sscanf(optarg, "%d", &timeout) ) exitmsg();
break;
case 'p':
if ( !sscanf(optarg, "%d", &ThePort) ) exitmsg();
break;
case 'v': // verbose
verbosity++;
break;
case 'h':
exithelp();
break;
}
if ( optind >= argc) exitmsg();
int evtnr = atoi(argv[optind]);
string host;
if ( argc > optind+1)
{
host = argv[optind+1];
}
else
{
host = "localhost";
}
eventReceiverClient *erc = new eventReceiverClient(host,0,ThePort);
if ( erc->getStatus())
{
delete erc;
return 1;
}
if (timeout) erc->setUserTimeout(timeout);
erc->setVerbosity(verbosity);
Event *e = erc->getEvent(evtnr);
if (e)
{
e->identify();
delete e;
}
else
{
cout << "event " << evtnr << " not received, timeout = "<< erc->hadTimeout() << endl;
}
delete erc;
return 0;
}