00001
00002
00003 #include "orbsvcs/Event/EC_Gateway_IIOP_Factory.h"
00004 #include "orbsvcs/Event/ECG_Defaults.h"
00005 #include "orbsvcs/Event_Utilities.h"
00006 #include "orbsvcs/Time_Utilities.h"
00007
00008 #include "ace/Dynamic_Service.h"
00009 #include "ace/Arg_Shifter.h"
00010
00011 #include "orbsvcs/Event/ECG_ConsumerEC_Control.h"
00012 #include "orbsvcs/Event/ECG_Reactive_ConsumerEC_Control.h"
00013 #include "orbsvcs/Event/ECG_Reconnect_ConsumerEC_Control.h"
00014 #include "orbsvcs/Event/EC_Gateway_IIOP.h"
00015 #include "ace/OS_NS_strings.h"
00016
00017 #if !defined (__ACE_INLINE__)
00018 #include "orbsvcs/Event/EC_Gateway_IIOP_Factory.i"
00019 #endif
00020
00021 ACE_RCSID (Event,
00022 EC_Gateway_IIOP_Factory,
00023 "EC_Gateway_IIOP_Factory.cpp,v 1.14 2006/03/14 06:14:25 jtc Exp")
00024
00025 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00026
00027 int
00028 TAO_EC_Gateway_IIOP_Factory::init_svcs (void)
00029 {
00030 return ACE_Service_Config::static_svcs ()->
00031 insert (&ace_svc_desc_TAO_EC_Gateway_IIOP_Factory);
00032 }
00033
00034 TAO_EC_Gateway_IIOP_Factory::TAO_EC_Gateway_IIOP_Factory (void)
00035 : orbid_ (TAO_ECG_DEFAULT_IIOP_ORB_ID),
00036 consumer_ec_control_ (TAO_ECG_DEFAULT_IIOP_CONSUMEREC_CONTROL),
00037 consumer_ec_control_period_ (TAO_ECG_DEFAULT_IIOP_CONSUMEREC_CONTROL_PERIOD),
00038 consumer_ec_control_timeout_ (TAO_ECG_DEFAULT_IIOP_CONSUMEREC_CONTROL_TIMEOUT),
00039 use_ttl_ (TAO_ECG_DEFAULT_IIOP_USE_TTL),
00040 use_consumer_proxy_map_ (TAO_ECG_DEFAULT_IIOP_USE_CONSUMER_PROXY_MAP)
00041 {
00042 }
00043
00044 TAO_EC_Gateway_IIOP_Factory::~TAO_EC_Gateway_IIOP_Factory (void)
00045 {
00046 }
00047
00048 int
00049 TAO_EC_Gateway_IIOP_Factory::fini (void)
00050 {
00051 return 0;
00052 }
00053
00054 int
00055 TAO_EC_Gateway_IIOP_Factory::init (int argc, char* argv[])
00056 {
00057 int result = 0;
00058
00059 ACE_Arg_Shifter arg_shifter (argc, argv);
00060
00061 while (arg_shifter.is_anything_left ())
00062 {
00063 const char *arg = arg_shifter.get_current ();
00064
00065 if (ACE_OS::strcasecmp (arg, ACE_TEXT("-ECGIIOPConsumerECControl")) == 0)
00066 {
00067 arg_shifter.consume_arg ();
00068
00069 if (arg_shifter.is_parameter_next ())
00070 {
00071 const ACE_TCHAR* opt = arg_shifter.get_current ();
00072 if (ACE_OS::strcasecmp (opt, ACE_TEXT("null")) == 0)
00073 this->consumer_ec_control_ = 0;
00074 else if (ACE_OS::strcasecmp (opt, ACE_TEXT("reactive")) == 0)
00075 this->consumer_ec_control_ = 1;
00076 else if (ACE_OS::strcasecmp (opt, ACE_TEXT("reconnect")) == 0)
00077 this->consumer_ec_control_ = 2;
00078 else
00079 this->unsupported_option_value ("-ECGIIOPConsumerECControl", opt);
00080 arg_shifter.consume_arg ();
00081 }
00082 }
00083
00084 else if (ACE_OS::strcasecmp (arg, ACE_TEXT("-ECGIIOPConsumerECControlPeriod")) == 0)
00085 {
00086 arg_shifter.consume_arg ();
00087
00088 if (arg_shifter.is_parameter_next ())
00089 {
00090 const ACE_TCHAR* opt = arg_shifter.get_current ();
00091 this->consumer_ec_control_period_ = ACE_OS::atoi (opt);
00092 arg_shifter.consume_arg ();
00093 }
00094 }
00095
00096 else if (ACE_OS::strcasecmp (arg, ACE_TEXT("-ECGIIOPConsumerECControlTimeout")) == 0)
00097 {
00098 arg_shifter.consume_arg ();
00099
00100 if (arg_shifter.is_parameter_next ())
00101 {
00102 const ACE_TCHAR* opt = arg_shifter.get_current ();
00103 unsigned long timeout = ACE_OS::strtoul(opt, 0, 10);
00104 this->consumer_ec_control_timeout_.usec(timeout);
00105 arg_shifter.consume_arg ();
00106 }
00107 }
00108
00109 else if (ACE_OS::strcasecmp (arg, ACE_TEXT("-ECGIIOPUseORBId")) == 0)
00110 {
00111 arg_shifter.consume_arg ();
00112
00113 if (arg_shifter.is_parameter_next ())
00114 {
00115
00116 this->orbid_ = ACE_TEXT_ALWAYS_CHAR(arg_shifter.get_current ());
00117 arg_shifter.consume_arg ();
00118 }
00119 }
00120
00121 else if (ACE_OS::strcasecmp (arg, ACE_TEXT("-ECGIIOPUseTTL")) == 0)
00122 {
00123 arg_shifter.consume_arg ();
00124
00125 if (arg_shifter.is_parameter_next ())
00126 {
00127 const ACE_TCHAR* opt = arg_shifter.get_current ();
00128 this->use_ttl_ = ACE_OS::atoi (opt);
00129 arg_shifter.consume_arg ();
00130 }
00131 }
00132
00133 else if (ACE_OS::strcasecmp (arg, ACE_TEXT("-ECGIIOPUseConsumerProxyMap")) == 0)
00134 {
00135 arg_shifter.consume_arg ();
00136
00137 if (arg_shifter.is_parameter_next ())
00138 {
00139 const ACE_TCHAR* opt = arg_shifter.get_current ();
00140 this->use_consumer_proxy_map_ = ACE_OS::atoi (opt);
00141 arg_shifter.consume_arg ();
00142 }
00143 }
00144
00145 else
00146 {
00147 arg_shifter.ignore_arg ();
00148 ACE_DEBUG ((LM_WARNING,
00149 "Ignoring <%s> option "
00150 "during initialization.\n",
00151 arg));
00152 result = -1;
00153 }
00154 }
00155
00156 return result;
00157 }
00158
00159 void
00160 TAO_EC_Gateway_IIOP_Factory::unsupported_option_value (const char * option_name,
00161 const char * option_value)
00162 {
00163 ACE_ERROR ((LM_ERROR,
00164 "EC_Gateway_IIOP_Factory -"
00165 "Unsupported <%s> option value: <%s>. "
00166 "Ignoring this option - using defaults instead.\n",
00167 option_name,
00168 option_value));
00169 }
00170
00171 TAO_ECG_ConsumerEC_Control*
00172 TAO_EC_Gateway_IIOP_Factory::create_consumerec_control (TAO_EC_Gateway_IIOP* gateway)
00173 {
00174 if (this->consumer_ec_control_ == 0)
00175 return new TAO_ECG_ConsumerEC_Control ();
00176 else if (this->consumer_ec_control_ == 1)
00177 {
00178 int argc = 0;
00179 char **argv = 0;
00180 CORBA::ORB_var orb =
00181 CORBA::ORB_init (argc, argv, this->orbid_.c_str ());
00182 ACE_Time_Value rate (0, this->consumer_ec_control_period_);
00183 return new TAO_ECG_Reactive_ConsumerEC_Control (rate, consumer_ec_control_timeout_, gateway, orb.in ());
00184 }
00185 else if (this->consumer_ec_control_ == 2)
00186 {
00187 int argc = 0;
00188 char **argv = 0;
00189 CORBA::ORB_var orb =
00190 CORBA::ORB_init (argc, argv, this->orbid_.c_str ());
00191 ACE_Time_Value rate (0, this->consumer_ec_control_period_);
00192 return new TAO_ECG_Reconnect_ConsumerEC_Control (rate, consumer_ec_control_timeout_, gateway, orb.in ());
00193 }
00194 return 0;
00195 }
00196
00197 void
00198 TAO_EC_Gateway_IIOP_Factory::destroy_consumerec_control (
00199 TAO_ECG_ConsumerEC_Control* x)
00200 {
00201 delete x;
00202 }
00203
00204 TAO_END_VERSIONED_NAMESPACE_DECL
00205
00206 ACE_STATIC_SVC_DEFINE (TAO_EC_Gateway_IIOP_Factory,
00207 ACE_TEXT ("EC_Gateway_IIOP_Factory"),
00208 ACE_SVC_OBJ_T,
00209 &ACE_SVC_NAME (TAO_EC_Gateway_IIOP_Factory),
00210 ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00211 0)
00212 ACE_FACTORY_DEFINE (TAO_RTEvent_Serv, TAO_EC_Gateway_IIOP_Factory)