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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
// $Id$
#define ACE_BUILD_SVC_DLL
#include "ace/Get_Opt.h"
#include "Options.h"
ACE_RCSID(Peer, Options, "$Id$")
// Static initialization.
Options *Options::instance_ = 0;
void
Options::print_usage_and_die (void)
{
ACE_DEBUG ((LM_DEBUG, "%n [-a {C|S}:acceptor-port] [-c {C|S}:connector-port] [-C connection-id] [-h gateway-host] [-q max-queue-size] [-t timeout] [-v]\n"));
}
Options::Options (void)
: options_ (0),
supplier_acceptor_port_ (DEFAULT_PEER_SUPPLIER_PORT),
consumer_acceptor_port_ (DEFAULT_PEER_CONSUMER_PORT),
supplier_connector_port_ (DEFAULT_GATEWAY_SUPPLIER_PORT),
consumer_connector_port_ (DEFAULT_GATEWAY_CONSUMER_PORT),
connector_host_ (ACE_DEFAULT_SERVER_HOST),
timeout_ (0),
max_queue_size_ (MAX_QUEUE_SIZE),
connection_id_ (0)
{
char *timeout = ACE_OS::getenv ("TIMEOUT");
if (timeout == 0)
this->timeout_ = Options::DEFAULT_TIMEOUT;
else
this->timeout_ = ACE_OS::atoi (timeout);
}
Options *
Options::instance (void)
{
if (Options::instance_ == 0)
ACE_NEW_RETURN (Options::instance_, Options, 0);
return Options::instance_;
}
long
Options::timeout (void) const
{
return this->timeout_;
}
CONNECTION_ID &
Options::connection_id (void)
{
return this->connection_id_;
}
long
Options::max_queue_size (void) const
{
return this->max_queue_size_;
}
u_short
Options::consumer_acceptor_port (void) const
{
return this->consumer_acceptor_port_;
}
u_short
Options::supplier_acceptor_port (void) const
{
return this->supplier_acceptor_port_;
}
u_short
Options::consumer_connector_port (void) const
{
return this->consumer_connector_port_;
}
u_short
Options::supplier_connector_port (void) const
{
return this->supplier_connector_port_;
}
const char *
Options::connector_host (void) const
{
return this->connector_host_;
}
int
Options::enabled (int option) const
{
return ACE_BIT_ENABLED (this->options_, option);
}
void
Options::parse_args (int argc, char *argv[])
{
ACE_Get_Opt get_opt (argc, argv, "a:c:C:h:m:t:v", 0);
for (int c; (c = get_opt ()) != -1; )
{
switch (c)
{
case 'a':
{
// Become an Acceptor.
for (char *flag = ACE_OS::strtok (get_opt.optarg, "|");
flag != 0;
flag = ACE_OS::strtok (0, "|"))
if (ACE_OS::strncasecmp (flag, "C", 1) == 0)
{
ACE_SET_BITS (this->options_,
Options::CONSUMER_ACCEPTOR);
if (ACE_OS::strlen (flag) > 1)
// Set the Consumer Acceptor port number.
this->consumer_acceptor_port_ = ACE_OS::atoi (flag + 2);
}
else if (ACE_OS::strncasecmp (flag, "S", 1) == 0)
{
ACE_SET_BITS (this->options_,
Options::SUPPLIER_ACCEPTOR);
if (ACE_OS::strlen (flag) > 1)
// Set the Supplier Acceptor port number.
this->supplier_acceptor_port_ = ACE_OS::atoi (flag + 2);
}
}
break;
/* NOTREACHED */
case 'c':
{
// Become a Connector.
for (char *flag = ACE_OS::strtok (get_opt.optarg, "|");
flag != 0;
flag = ACE_OS::strtok (0, "|"))
if (ACE_OS::strncasecmp (flag, "C", 1) == 0)
{
ACE_SET_BITS (this->options_,
Options::CONSUMER_CONNECTOR);
if (ACE_OS::strlen (flag) > 1)
// Set the Consumer Connector port number.
this->consumer_connector_port_ = ACE_OS::atoi (flag + 2);
}
else if (ACE_OS::strncasecmp (flag, "S", 1) == 0)
{
ACE_SET_BITS (this->options_,
Options::SUPPLIER_CONNECTOR);
if (ACE_OS::strlen (flag) > 1)
// Set the Supplier Connector port number.
this->supplier_connector_port_ = ACE_OS::atoi (flag + 2);
}
}
break;
/* NOTREACHED */
case 'C':
this->connection_id_ = ACE_OS::atoi (get_opt.optarg);
break;
/* NOTREACHED */
case 'h':
// connector host
this->connector_host_ = get_opt.optarg;
break;
/* NOTREACHED */
case 'm':
// max queue size.
this->max_queue_size_ = ACE_OS::atoi (get_opt.optarg);
break;
/* NOTREACHED */
case 't':
// Timeout
this->timeout_ = ACE_OS::atoi (get_opt.optarg);
break;
/* NOTREACHED */
case 'v':
// Verbose mode.
ACE_SET_BITS (this->options_, Options::VERBOSE);
break;
/* NOTREACHED */
default:
this->print_usage_and_die ();
/* NOTREACHED */
}
}
}
|