#include <CEC_Event_Loader.h>
Inheritance diagram for TAO_CEC_Event_Loader:
Public Member Functions | |
TAO_CEC_Event_Loader (void) | |
Constructor. | |
~TAO_CEC_Event_Loader (void) | |
Destructor. | |
Derived from ACE_Service_Object | |
virtual int | init (int argc, ACE_TCHAR *argv[]) |
virtual int | fini (void) |
Derived from TAO_Object_Loader | |
virtual CORBA::Object_ptr | create_object (CORBA::ORB_ptr orb, int argc, ACE_TCHAR *argv[]) throw (CORBA::SystemException) |
Protected Attributes | |
CORBA::ORB_var | orb_ |
Keep a pointer to the underlying ORB. | |
int | terminate_flag_ |
Flag to control the event loop. | |
TAO_CEC_EventChannel_Attributes * | attributes_ |
Attributes used to configure the Event Service properties. | |
TAO_CEC_Factory * | factory_ |
Factory used to configure the Event Service strategies. | |
TAO_CEC_EventChannel * | ec_impl_ |
The Event Service implementation class. | |
CosNaming::NamingContext_var | naming_context_ |
Naming Context needed if '-x' option is passed. | |
int | bind_to_naming_service_ |
Flag to check if '-x' option is passed. | |
CosNaming::Name | channel_name_ |
The name used when binding to the NamingService. | |
Private Member Functions | |
TAO_CEC_Event_Loader (const TAO_CEC_Event_Loader &) | |
TAO_CEC_Event_Loader & | operator= (const TAO_CEC_Event_Loader &) |
Definition at line 39 of file CEC_Event_Loader.h.
|
Constructor.
Definition at line 37 of file CEC_Event_Loader.cpp.
00037 : 00038 attributes_ (0) 00039 , factory_ (0) 00040 , ec_impl_ (0) 00041 #if defined (TAO_HAS_TYPED_EVENT_CHANNEL) 00042 , typed_attributes_ (0) 00043 , typed_ec_impl_ (0) 00044 #endif /* TAO_HAS_TYPED_EVENT_CHANNEL */ 00045 { 00046 // Constructor 00047 } |
|
Destructor.
Definition at line 49 of file CEC_Event_Loader.cpp.
00050 {
00051 // Destructor
00052 }
|
|
|
|
Implements TAO_Object_Loader. Definition at line 86 of file CEC_Event_Loader.cpp. References CORBA::Object::_nil(), ACE_ANY_EXCEPTION, ACE_CATCHANY, ACE_DEBUG, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_PRINT_EXCEPTION, ACE_TCHAR, ACE_TEXT, ACE_TEXT_ALWAYS_CHAR, ACE_TRY, ACE_TRY_CHECK, ACE_OS::fclose(), ACE_OS::fopen(), ACE_OS::fprintf(), CORBA::is_nil(), LM_DEBUG, CORBA::string_dup(), TAO_CEC_EventChannel, TAO_CEC_TypedEventChannel, and TAO_debug_level. Referenced by init().
00091 { 00092 ACE_TRY 00093 { 00094 // **************************************************************** 00095 00096 // @@ Some ideas for improvement (not that you have to implement 00097 // them): 00098 // - Receive a child POA name from the command line, and create 00099 // all the objects in that child POA (easier to destroy stuff 00100 // that way). 00101 // - Receive an option to register the Event Service with the 00102 // _tao_add_to_IOR_table() stuff.. 00103 00104 // Parse the options, check if we should bind with the naming 00105 // service and under what name... 00106 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("n:o:p:xrtd")); 00107 int opt; 00108 const ACE_TCHAR *service_name = ACE_TEXT("CosEventService"); 00109 const ACE_TCHAR *ior_file = 0; 00110 const ACE_TCHAR *pid_file = 0; 00111 this->bind_to_naming_service_ = 1; 00112 int use_rebind = 0; 00113 00114 #if defined (TAO_HAS_TYPED_EVENT_CHANNEL) 00115 // Flag to create a typed event channel 00116 int typed_ec = 0; 00117 // Flag to destroy the event channel on shutdown 00118 int destroy = 0; 00119 #endif /* TAO_HAS_TYPED_EVENT_CHANNEL */ 00120 00121 while ((opt = get_opt ()) != EOF) 00122 { 00123 switch (opt) 00124 { 00125 case 'n': 00126 service_name = get_opt.opt_arg (); 00127 break; 00128 00129 case 'o': 00130 ior_file = get_opt.opt_arg (); 00131 break; 00132 00133 case 'p': 00134 pid_file = get_opt.opt_arg (); 00135 break; 00136 00137 case 'x': 00138 this->bind_to_naming_service_ = 0; 00139 break; 00140 00141 case 'r': 00142 use_rebind = 1; 00143 break; 00144 00145 #if defined (TAO_HAS_TYPED_EVENT_CHANNEL) 00146 case 't': 00147 typed_ec = 1; 00148 break; 00149 00150 case 'd': 00151 destroy = 1; 00152 break; 00153 #endif /* TAO_HAS_TYPED_EVENT_CHANNEL */ 00154 00155 case '?': 00156 default: 00157 #if defined (TAO_HAS_TYPED_EVENT_CHANNEL) 00158 ACE_DEBUG ((LM_DEBUG, 00159 ACE_TEXT ("Usage: %s ") 00160 ACE_TEXT ("-n service_name ") 00161 ACE_TEXT ("-o ior_file_name ") 00162 ACE_TEXT ("-p pid_file_name ") 00163 ACE_TEXT ("-x [disable naming service bind]") 00164 ACE_TEXT ("-r [rebind, no AlreadyBound failures] ") 00165 ACE_TEXT ("-t [enable typed event channel]") 00166 ACE_TEXT ("-d [destroy typed event channelon shutdown] ") 00167 ACE_TEXT ("\n"), 00168 argv[0])); 00169 #else 00170 ACE_DEBUG ((LM_DEBUG, 00171 ACE_TEXT ("Usage: %s ") 00172 ACE_TEXT ("-n service_name ") 00173 ACE_TEXT ("-o ior_file_name ") 00174 ACE_TEXT ("-p pid_file_name ") 00175 ACE_TEXT ("-x [disable naming service bind] ") 00176 ACE_TEXT ("-r [rebind, no AlreadyBound failures] ") 00177 ACE_TEXT ("\n"), 00178 argv[0])); 00179 #endif /* TAO_HAS_TYPED_EVENT_CHANNEL */ 00180 return CORBA::Object::_nil (); 00181 } 00182 } 00183 00184 // *************************************************************** 00185 00186 // POA initialization and activation ... 00187 CORBA::Object_var object = 00188 orb->resolve_initial_references ("RootPOA" ACE_ENV_ARG_PARAMETER); 00189 ACE_TRY_CHECK; 00190 PortableServer::POA_var poa = 00191 PortableServer::POA::_narrow (object.in () ACE_ENV_ARG_PARAMETER); 00192 ACE_TRY_CHECK; 00193 PortableServer::POAManager_var poa_manager = 00194 poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); 00195 ACE_TRY_CHECK; 00196 poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); 00197 ACE_TRY_CHECK; 00198 00199 00200 // **************************************************************** 00201 00202 // Control the event loop 00203 this->terminate_flag_ = 0; 00204 00205 #if defined (TAO_HAS_TYPED_EVENT_CHANNEL) 00206 if (!typed_ec) 00207 { 00208 #endif /* TAO_HAS_TYPED_EVENT_CHANNEL */ 00209 00210 // Create and activate the event service 00211 this->attributes_ = new TAO_CEC_EventChannel_Attributes(poa.in (), 00212 poa.in ()); 00213 this->factory_ = 0; 00214 00215 this->ec_impl_ = new TAO_CEC_EventChannel (*this->attributes_, 00216 this->factory_, 00217 this->terminate_flag_); 00218 00219 this->ec_impl_->activate (ACE_ENV_SINGLE_ARG_PARAMETER); 00220 ACE_TRY_CHECK; 00221 00222 CosEventChannelAdmin::EventChannel_var event_channel = 00223 this->ec_impl_->_this (ACE_ENV_SINGLE_ARG_PARAMETER); 00224 ACE_TRY_CHECK; 00225 00226 if (ior_file != 0) 00227 { 00228 CORBA::String_var ior = 00229 orb->object_to_string (event_channel.in () ACE_ENV_ARG_PARAMETER); 00230 ACE_TRY_CHECK; 00231 00232 FILE *iorf = ACE_OS::fopen (ior_file, ACE_TEXT("w")); 00233 if (iorf != 0) 00234 { 00235 ACE_OS::fprintf (iorf, "%s\n", ior.in ()); 00236 ACE_OS::fclose (iorf); 00237 } 00238 } 00239 00240 if (pid_file != 0) 00241 { 00242 FILE *pidf = ACE_OS::fopen (pid_file, ACE_TEXT("w")); 00243 if (pidf != 0) 00244 { 00245 ACE_OS::fprintf (pidf, 00246 "%ld\n", 00247 static_cast<long> (ACE_OS::getpid ())); 00248 ACE_OS::fclose (pidf); 00249 } 00250 } 00251 00252 // **************************************************************** 00253 00254 this->channel_name_.length (1); 00255 00256 if (this->bind_to_naming_service_) 00257 { 00258 CORBA::Object_var obj = 00259 orb->resolve_initial_references ("NameService" 00260 ACE_ENV_ARG_PARAMETER); 00261 ACE_TRY_CHECK; 00262 00263 this->naming_context_ = 00264 CosNaming::NamingContext::_narrow (obj.in () 00265 ACE_ENV_ARG_PARAMETER); 00266 ACE_TRY_CHECK; 00267 00268 this->channel_name_.length (1); 00269 this->channel_name_[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(service_name)); 00270 00271 if (use_rebind) 00272 { 00273 this->naming_context_->rebind (this->channel_name_, 00274 event_channel.in () 00275 ACE_ENV_ARG_PARAMETER); 00276 ACE_TRY_CHECK; 00277 } 00278 else 00279 { 00280 this->naming_context_->bind (this->channel_name_, 00281 event_channel.in () 00282 ACE_ENV_ARG_PARAMETER); 00283 ACE_TRY_CHECK; 00284 } 00285 } 00286 return CosEventChannelAdmin::EventChannel::_duplicate (event_channel.in () ); 00287 00288 #if defined (TAO_HAS_TYPED_EVENT_CHANNEL) 00289 } 00290 else 00291 { 00292 // If Typed EC, initialize the IFR, then create and activate the typed event service 00293 00294 // **************************************************************** 00295 // IFR initialization 00296 if (TAO_debug_level >= 10) 00297 { 00298 ACE_DEBUG ((LM_DEBUG, 00299 ACE_TEXT ("***** Initializing the IFR connection... *****\n"))); 00300 } 00301 00302 CORBA::Repository_var interface_repository; 00303 00304 CORBA::Object_var ifr_obj_var = 00305 orb->resolve_initial_references ("InterfaceRepository" ACE_ENV_ARG_PARAMETER); 00306 ACE_TRY_CHECK; 00307 00308 if (CORBA::is_nil(ifr_obj_var.in () )) 00309 { 00310 if (TAO_debug_level >= 10) 00311 { 00312 ACE_DEBUG ((LM_DEBUG, 00313 ACE_TEXT ("***** resolve_initial_references for IFR failed\n *****"))); 00314 } 00315 return CORBA::Object::_nil (); 00316 } 00317 else 00318 { 00319 interface_repository = CORBA::Repository::_narrow(ifr_obj_var.in () 00320 ACE_ENV_ARG_PARAMETER); 00321 ACE_TRY_CHECK; 00322 00323 if (CORBA::is_nil(interface_repository.in () )) 00324 { 00325 if (TAO_debug_level >= 10) 00326 { 00327 ACE_DEBUG ((LM_DEBUG, 00328 ACE_TEXT ("***** CORBA::Repository::_narrow failed *****\n"))); 00329 } 00330 return CORBA::Object::_nil (); 00331 } 00332 else 00333 { 00334 if (TAO_debug_level >= 10) 00335 { 00336 ACE_DEBUG ((LM_DEBUG, 00337 ACE_TEXT ("***** ...IFR connection completed *****\n"))); 00338 } 00339 } 00340 } 00341 00342 // Create and activate the typed event service 00343 this->typed_attributes_ = new TAO_CEC_TypedEventChannel_Attributes(poa.in (), 00344 poa.in (), 00345 orb, 00346 interface_repository.in ()); 00347 if (destroy == 1) 00348 { 00349 this->typed_attributes_->destroy_on_shutdown = 1; 00350 } 00351 00352 this->factory_ = 0; 00353 00354 this->typed_ec_impl_ = new TAO_CEC_TypedEventChannel (*this->typed_attributes_, 00355 this->factory_, 00356 this->terminate_flag_); 00357 00358 this->typed_ec_impl_->activate (ACE_ENV_SINGLE_ARG_PARAMETER); 00359 ACE_TRY_CHECK; 00360 00361 CosTypedEventChannelAdmin::TypedEventChannel_var event_channel = 00362 this->typed_ec_impl_->_this (ACE_ENV_SINGLE_ARG_PARAMETER); 00363 ACE_TRY_CHECK; 00364 00365 if (ior_file != 0) 00366 { 00367 CORBA::String_var ior = 00368 orb->object_to_string (event_channel.in () ACE_ENV_ARG_PARAMETER); 00369 ACE_TRY_CHECK; 00370 00371 FILE *iorf = ACE_OS::fopen (ior_file, ACE_TEXT("w")); 00372 if (iorf != 0) 00373 { 00374 ACE_OS::fprintf (iorf, "%s\n", ior.in ()); 00375 ACE_OS::fclose (iorf); 00376 } 00377 } 00378 00379 if (pid_file != 0) 00380 { 00381 FILE *pidf = ACE_OS::fopen (pid_file, ACE_TEXT("w")); 00382 if (pidf != 0) 00383 { 00384 ACE_OS::fprintf (pidf, 00385 "%ld\n", 00386 static_cast<long> (ACE_OS::getpid ())); 00387 ACE_OS::fclose (pidf); 00388 } 00389 } 00390 00391 // **************************************************************** 00392 00393 this->channel_name_.length (1); 00394 00395 if (this->bind_to_naming_service_) 00396 { 00397 CORBA::Object_var obj = 00398 orb->resolve_initial_references ("NameService" 00399 ACE_ENV_ARG_PARAMETER); 00400 ACE_TRY_CHECK; 00401 00402 this->naming_context_ = 00403 CosNaming::NamingContext::_narrow (obj.in () 00404 ACE_ENV_ARG_PARAMETER); 00405 ACE_TRY_CHECK; 00406 00407 this->channel_name_.length (1); 00408 this->channel_name_[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(service_name)); 00409 00410 if (use_rebind) 00411 { 00412 this->naming_context_->rebind (this->channel_name_, 00413 event_channel.in () 00414 ACE_ENV_ARG_PARAMETER); 00415 ACE_TRY_CHECK; 00416 } 00417 else 00418 { 00419 this->naming_context_->bind (this->channel_name_, 00420 event_channel.in () 00421 ACE_ENV_ARG_PARAMETER); 00422 ACE_TRY_CHECK; 00423 } 00424 } 00425 return CosTypedEventChannelAdmin::TypedEventChannel::_duplicate (event_channel.in () ); 00426 } 00427 #endif /* TAO_HAS_TYPED_EVENT_CHANNEL */ 00428 00429 // **************************************************************** 00430 } 00431 ACE_CATCHANY 00432 { 00433 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, argv[0]); 00434 return CORBA::Object::_nil (); 00435 } 00436 ACE_ENDTRY; 00437 } |
|
Reimplemented from ACE_Shared_Object. Definition at line 440 of file CEC_Event_Loader.cpp. References ACE_CATCHANY, ACE_CHECK_RETURN, ACE_DECLARE_NEW_CORBA_ENV, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_TRY, ACE_TRY_CHECK, ACE_TRY_CHECK_EX, ACE_TRY_EX, bind_to_naming_service_, TAO_CEC_EventChannel::destroy(), and ec_impl_.
00441 { 00442 // + Since it was activated with _this() you have to do the 00443 // canonical: 00444 // get_object_id 00445 ACE_DECLARE_NEW_CORBA_ENV; 00446 ACE_TRY 00447 { 00448 #if defined (TAO_HAS_TYPED_EVENT_CHANNEL) 00449 if(this->typed_ec_impl_) 00450 { 00451 // Release the resources of the Typed Event Channel 00452 this->typed_ec_impl_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); 00453 ACE_TRY_CHECK; 00454 00455 // Deactivate the Typed EC 00456 // This will raise an exception if destroy == 1 00457 PortableServer::POA_var t_poa = 00458 this->typed_ec_impl_->_default_POA (ACE_ENV_SINGLE_ARG_PARAMETER); 00459 ACE_TRY_CHECK; 00460 00461 PortableServer::ObjectId_var t_id = 00462 t_poa->servant_to_id (this->typed_ec_impl_ ACE_ENV_ARG_PARAMETER); 00463 ACE_TRY_CHECK; 00464 00465 t_poa->deactivate_object (t_id.in () ACE_ENV_ARG_PARAMETER); 00466 ACE_TRY_CHECK; 00467 } 00468 #else 00469 // Release the resources of the Event Channel 00470 this->ec_impl_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); 00471 ACE_TRY_CHECK; 00472 00473 // Deactivate the EC 00474 PortableServer::POA_var poa = 00475 this->ec_impl_->_default_POA (ACE_ENV_SINGLE_ARG_PARAMETER); 00476 ACE_TRY_CHECK; 00477 00478 PortableServer::ObjectId_var id = 00479 poa->servant_to_id (this->ec_impl_ ACE_ENV_ARG_PARAMETER); 00480 ACE_TRY_CHECK; 00481 00482 poa->deactivate_object (id.in () ACE_ENV_ARG_PARAMETER); 00483 ACE_TRY_CHECK; 00484 #endif /* TAO_HAS_TYPED_EVENT_CHANNEL */ 00485 } 00486 ACE_CATCHANY 00487 { 00488 // Do Nothing 00489 } 00490 ACE_ENDTRY; 00491 ACE_CHECK_RETURN (-1); 00492 00493 ACE_TRY_EX (foo) 00494 { 00495 // Unbind the Naming Service 00496 if (this->bind_to_naming_service_) 00497 { 00498 this->naming_context_->unbind (this->channel_name_ 00499 ACE_ENV_ARG_PARAMETER); 00500 ACE_TRY_CHECK_EX (foo); 00501 } 00502 00503 #if defined (TAO_HAS_TYPED_EVENT_CHANNEL) 00504 // Since we created them, we also have to delete them. 00505 delete this->typed_attributes_; 00506 delete this->typed_ec_impl_; 00507 #endif /* TAO_HAS_TYPED_EVENT_CHANNEL */ 00508 delete this->attributes_; 00509 delete this->ec_impl_; 00510 } 00511 ACE_CATCHANY 00512 { 00513 // Do Nothing 00514 return -1; 00515 } 00516 ACE_ENDTRY; 00517 ACE_CHECK_RETURN (-1); 00518 00519 return 0; 00520 } |
|
Reimplemented from ACE_Shared_Object. Definition at line 55 of file CEC_Event_Loader.cpp. References ACE_ANY_EXCEPTION, ACE_CATCHANY, ACE_DECLARE_NEW_CORBA_ENV, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_PRINT_EXCEPTION, ACE_TRY, ACE_TRY_CHECK, create_object(), ACE_Argv_Type_Converter::get_argc(), ACE_Argv_Type_Converter::get_ASCII_argv(), ACE_Argv_Type_Converter::get_TCHAR_argv(), CORBA::is_nil(), and CORBA::ORB_init().
00056 { 00057 ACE_DECLARE_NEW_CORBA_ENV; 00058 ACE_TRY 00059 { 00060 // Copy command line parameter. 00061 ACE_Argv_Type_Converter command_line(argc, argv); 00062 00063 // ORB initialization boiler plate... 00064 this->orb_= 00065 CORBA::ORB_init (command_line.get_argc(), command_line.get_ASCII_argv(), 0 ACE_ENV_ARG_PARAMETER); 00066 ACE_TRY_CHECK; 00067 00068 CORBA::Object_var obj = 00069 this->create_object (this->orb_.in (), command_line.get_argc(), command_line.get_TCHAR_argv() ACE_ENV_ARG_PARAMETER); 00070 ACE_TRY_CHECK; 00071 00072 if (CORBA::is_nil (obj.in() )) 00073 return -1; 00074 } 00075 ACE_CATCHANY 00076 { 00077 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, argv[0]); 00078 return -1; 00079 } 00080 ACE_ENDTRY; 00081 return 0; 00082 } |
|
|
|
Attributes used to configure the Event Service properties.
Definition at line 75 of file CEC_Event_Loader.h. |
|
Flag to check if '-x' option is passed.
Definition at line 95 of file CEC_Event_Loader.h. Referenced by fini(). |
|
The name used when binding to the NamingService.
Definition at line 98 of file CEC_Event_Loader.h. |
|
The Event Service implementation class.
Definition at line 81 of file CEC_Event_Loader.h. Referenced by fini(). |
|
Factory used to configure the Event Service strategies.
Definition at line 78 of file CEC_Event_Loader.h. |
|
Naming Context needed if '-x' option is passed.
Definition at line 92 of file CEC_Event_Loader.h. |
|
Keep a pointer to the underlying ORB.
Definition at line 69 of file CEC_Event_Loader.h. |
|
Flag to control the event loop.
Definition at line 72 of file CEC_Event_Loader.h. |