Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / ACE / apps / Gateway / Peer / Options.cpp
blob8874d671051dd8784f59040e37dbcd70a45b0a15
1 #define ACE_BUILD_SVC_DLL
3 #include "ace/Get_Opt.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/OS_NS_stdlib.h"
6 #include "ace/OS_NS_strings.h"
7 #include "ace/OS_NS_string.h"
8 #include "ace/OS_Memory.h"
9 #include "Options.h"
11 // Static initialization.
12 Options *Options::instance_ = 0;
14 void
15 Options::print_usage_and_die ()
17 ACE_DEBUG ((LM_DEBUG,
18 ACE_TEXT ("%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")));
19 ACE_OS::exit (1);
22 Options::Options ()
23 : options_ (0),
24 supplier_acceptor_port_ (DEFAULT_PEER_SUPPLIER_PORT),
25 consumer_acceptor_port_ (DEFAULT_PEER_CONSUMER_PORT),
26 supplier_connector_port_ (DEFAULT_GATEWAY_SUPPLIER_PORT),
27 consumer_connector_port_ (DEFAULT_GATEWAY_CONSUMER_PORT),
28 connector_host_ (ACE_DEFAULT_SERVER_HOST),
29 timeout_ (0),
30 max_queue_size_ (MAX_QUEUE_SIZE),
31 connection_id_ (0)
33 char *timeout = ACE_OS::getenv ("TIMEOUT");
35 if (timeout == 0)
36 this->timeout_ = Options::DEFAULT_TIMEOUT;
37 else
38 this->timeout_ = ACE_OS::atoi (timeout);
41 Options *
42 Options::instance ()
44 if (Options::instance_ == 0)
45 ACE_NEW_RETURN (Options::instance_, Options, 0);
47 return Options::instance_;
50 long
51 Options::timeout () const
53 return this->timeout_;
56 CONNECTION_ID &
57 Options::connection_id ()
59 return this->connection_id_;
62 long
63 Options::max_queue_size () const
65 return this->max_queue_size_;
68 u_short
69 Options::consumer_acceptor_port () const
71 return this->consumer_acceptor_port_;
74 u_short
75 Options::supplier_acceptor_port () const
77 return this->supplier_acceptor_port_;
80 u_short
81 Options::consumer_connector_port () const
83 return this->consumer_connector_port_;
86 u_short
87 Options::supplier_connector_port () const
89 return this->supplier_connector_port_;
92 const ACE_TCHAR *
93 Options::connector_host () const
95 return this->connector_host_;
98 int
99 Options::enabled (int option) const
101 return ACE_BIT_ENABLED (this->options_, option);
104 void
105 Options::parse_args (int argc, ACE_TCHAR *argv[])
107 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("a:c:C:h:m:t:v"), 0);
109 for (int c; (c = get_opt ()) != -1; )
111 switch (c)
113 case 'a':
115 // Become an Acceptor.
117 for (ACE_TCHAR *flag = ACE_OS::strtok (get_opt.opt_arg (),
118 ACE_TEXT ("|"));
119 flag != 0;
120 flag = ACE_OS::strtok (0, ACE_TEXT ("|")))
121 if (ACE_OS::strncasecmp (flag, ACE_TEXT ("C"), 1) == 0)
123 ACE_SET_BITS (this->options_,
124 Options::CONSUMER_ACCEPTOR);
125 if (ACE_OS::strlen (flag) > 1)
126 // Set the Consumer Acceptor port number.
127 this->consumer_acceptor_port_ = ACE_OS::atoi (flag + 2);
129 else if (ACE_OS::strncasecmp (flag, ACE_TEXT ("S"), 1) == 0)
131 ACE_SET_BITS (this->options_,
132 Options::SUPPLIER_ACCEPTOR);
133 if (ACE_OS::strlen (flag) > 1)
134 // Set the Supplier Acceptor port number.
135 this->supplier_acceptor_port_ = ACE_OS::atoi (flag + 2);
138 break;
139 /* NOTREACHED */
140 case 'c':
142 // Become a Connector.
144 for (ACE_TCHAR *flag = ACE_OS::strtok (get_opt.opt_arg (),
145 ACE_TEXT ("|"));
146 flag != 0;
147 flag = ACE_OS::strtok (0, ACE_TEXT ("|")))
148 if (ACE_OS::strncasecmp (flag, ACE_TEXT ("C"), 1) == 0)
150 ACE_SET_BITS (this->options_,
151 Options::CONSUMER_CONNECTOR);
152 if (ACE_OS::strlen (flag) > 1)
153 // Set the Consumer Connector port number.
154 this->consumer_connector_port_ = ACE_OS::atoi (flag + 2);
156 else if (ACE_OS::strncasecmp (flag, ACE_TEXT ("S"), 1) == 0)
158 ACE_SET_BITS (this->options_,
159 Options::SUPPLIER_CONNECTOR);
160 if (ACE_OS::strlen (flag) > 1)
161 // Set the Supplier Connector port number.
162 this->supplier_connector_port_ = ACE_OS::atoi (flag + 2);
165 break;
166 /* NOTREACHED */
167 case 'C':
168 this->connection_id_ = ACE_OS::atoi (get_opt.opt_arg ());
169 break;
170 /* NOTREACHED */
171 case 'h':
172 // connector host
173 this->connector_host_ = get_opt.opt_arg ();
174 break;
175 /* NOTREACHED */
176 case 'm':
177 // max queue size.
178 this->max_queue_size_ = ACE_OS::atoi (get_opt.opt_arg ());
179 break;
180 /* NOTREACHED */
181 case 't':
182 // Timeout
183 this->timeout_ = ACE_OS::atoi (get_opt.opt_arg ());
184 break;
185 /* NOTREACHED */
186 case 'v':
187 // Verbose mode.
188 ACE_SET_BITS (this->options_, Options::VERBOSE);
189 break;
190 /* NOTREACHED */
191 default:
192 this->print_usage_and_die ();
193 /* NOTREACHED */