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"
11 // Static initialization.
12 Options
*Options::instance_
= 0;
15 Options::print_usage_and_die ()
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")));
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
),
30 max_queue_size_ (MAX_QUEUE_SIZE
),
33 char *timeout
= ACE_OS::getenv ("TIMEOUT");
36 this->timeout_
= Options::DEFAULT_TIMEOUT
;
38 this->timeout_
= ACE_OS::atoi (timeout
);
44 if (Options::instance_
== 0)
45 ACE_NEW_RETURN (Options::instance_
, Options
, 0);
47 return Options::instance_
;
51 Options::timeout () const
53 return this->timeout_
;
57 Options::connection_id ()
59 return this->connection_id_
;
63 Options::max_queue_size () const
65 return this->max_queue_size_
;
69 Options::consumer_acceptor_port () const
71 return this->consumer_acceptor_port_
;
75 Options::supplier_acceptor_port () const
77 return this->supplier_acceptor_port_
;
81 Options::consumer_connector_port () const
83 return this->consumer_connector_port_
;
87 Options::supplier_connector_port () const
89 return this->supplier_connector_port_
;
93 Options::connector_host () const
95 return this->connector_host_
;
99 Options::enabled (int option
) const
101 return ACE_BIT_ENABLED (this->options_
, option
);
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; )
115 // Become an Acceptor.
117 for (ACE_TCHAR
*flag
= ACE_OS::strtok (get_opt
.opt_arg (),
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);
142 // Become a Connector.
144 for (ACE_TCHAR
*flag
= ACE_OS::strtok (get_opt
.opt_arg (),
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);
168 this->connection_id_
= ACE_OS::atoi (get_opt
.opt_arg ());
173 this->connector_host_
= get_opt
.opt_arg ();
178 this->max_queue_size_
= ACE_OS::atoi (get_opt
.opt_arg ());
183 this->timeout_
= ACE_OS::atoi (get_opt
.opt_arg ());
188 ACE_SET_BITS (this->options_
, Options::VERBOSE
);
192 this->print_usage_and_die ();