ORB_Core.cpp

Go to the documentation of this file.
00001 // $Id: ORB_Core.cpp 79514 2007-08-28 10:30:06Z johnnyw $
00002 
00003 #include "tao/ORB_Core.h"
00004 #include "tao/ORB_Core_TSS_Resources.h"
00005 #include "tao/ORB_Table.h"
00006 #include "tao/TAO_Internal.h"
00007 #include "tao/default_server.h"
00008 #include "tao/Profile.h"
00009 #include "tao/Stub.h"
00010 #include "tao/LF_Follower.h"
00011 #include "tao/Leader_Follower.h"
00012 #include "tao/LF_Event_Loop_Thread_Helper.h"
00013 #include "tao/Connector_Registry.h"
00014 #include "tao/Transport_Queueing_Strategies.h"
00015 #include "tao/Object_Loader.h"
00016 #include "tao/ObjectIdListC.h"
00017 #include "tao/BiDir_Adapter.h"
00018 #include "tao/Collocation_Resolver.h"
00019 #include "tao/Flushing_Strategy.h"
00020 #include "tao/Request_Dispatcher.h"
00021 #include "tao/Stub_Factory.h"
00022 #include "tao/Thread_Lane_Resources.h"
00023 #include "tao/Thread_Lane_Resources_Manager.h"
00024 #include "tao/TSS_Resources.h"
00025 #include "tao/Protocols_Hooks.h"
00026 #include "tao/Network_Priority_Protocols_Hooks.h"
00027 #include "tao/IORInterceptor_Adapter.h"
00028 #include "tao/IORInterceptor_Adapter_Factory.h"
00029 #include "tao/debug.h"
00030 #include "tao/TAOC.h"
00031 #include "tao/Endpoint_Selector_Factory.h"
00032 #include "tao/Client_Strategy_Factory.h"
00033 #include "tao/Adapter_Factory.h"
00034 #include "tao/Adapter.h"
00035 #include "tao/GUIResource_Factory.h"
00036 #include "tao/PolicyFactory_Registry_Adapter.h"
00037 #include "tao/PolicyFactory_Registry_Factory.h"
00038 #include "tao/ORBInitializer_Registry_Adapter.h"
00039 #include "tao/Codeset_Manager.h"
00040 #include "tao/GIOP_Fragmentation_Strategy.h"
00041 #include "tao/SystemException.h"
00042 
00043 #include "tao/Valuetype_Adapter.h"
00044 #include "tao/Valuetype_Adapter_Factory.h"
00045 
00046 #if (TAO_HAS_CORBA_MESSAGING == 1)
00047 #include "tao/Policy_Manager.h"
00048 #include "tao/Policy_Current.h"
00049 #endif /* TAO_HAS_CORBA_MESSAGING == 1 */
00050 
00051 #include "ace/Reactor.h"
00052 #include "ace/Dynamic_Service.h"
00053 #include "ace/Arg_Shifter.h"
00054 #include "ace/Argv_Type_Converter.h"
00055 #include "ace/Static_Object_Lock.h"
00056 #include "ace/Auto_Ptr.h"
00057 #include "ace/CORBA_macros.h"
00058 
00059 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
00060 // Needed to set ACE_LOG_MSG::msg_ostream()
00061 // FUZZ: disable check_for_streams_include
00062 #  include "ace/streams.h"
00063 #endif /* !ACE_LACKS_IOSTREAM_TOTALLY */
00064 
00065 #include "ace/OS_NS_strings.h"
00066 #include "ace/OS_NS_string.h"
00067 #include "ace/Message_Block.h"
00068 
00069 #if TAO_HAS_INTERCEPTORS == 1
00070 # include "tao/ClientRequestInterceptor_Adapter.h"
00071 # include "tao/ClientRequestInterceptor_Adapter_Factory.h"
00072 # include "tao/ServerRequestInterceptor_Adapter.h"
00073 # include "tao/ServerRequestInterceptor_Adapter_Factory.h"
00074 #endif  /* TAO_HAS_INTERCEPTORS == 1  */
00075 
00076 
00077 #if !defined (__ACE_INLINE__)
00078 # include "tao/ORB_Core.inl"
00079 #endif /* ! __ACE_INLINE__ */
00080 
00081 ACE_RCSID (tao,
00082            ORB_Core,
00083            "$Id: ORB_Core.cpp 79514 2007-08-28 10:30:06Z johnnyw $")
00084 
00085 ACE_STATIC_SVC_DEFINE(TAO_ORB_Core_Static_Resources,
00086                       ACE_TEXT ("TAO_ORB_Core_Static_Resources"),
00087                       ACE_SVC_OBJ_T,
00088                       &ACE_SVC_NAME (TAO_ORB_Core_Static_Resources),
00089                       ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00090                        0)
00091 ACE_FACTORY_DEFINE (TAO, TAO_ORB_Core_Static_Resources)
00092 
00093 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00094 
00095 // ****************************************************************
00096 
00097 CORBA::Environment&
00098 TAO_default_environment (void)
00099 {
00100   return *TAO_TSS_Resources::instance ()->default_environment_;
00101 }
00102 
00103 // ****************************************************************
00104 
00105 // Initialize instance_ to 0, since this is what we test for in the call
00106 // to instance ().  Note that this does not require a constructor call, so
00107 // it is always initialized by the time that instance () can be called.
00108 //TAO_ORB_Core_Static_Resources* TAO_ORB_Core_Static_Resources::instance_ = 0;
00109 
00110 // Force an instance to be created at module initialization time,
00111 // since we do not want to worry about double checked locking and
00112 // the race condition to initialize the lock.
00113 TAO_ORB_Core_Static_Resources*
00114 TAO_ORB_Core_Static_Resources::initialization_reference_ =
00115   TAO_ORB_Core_Static_Resources::instance ();
00116 
00117 TAO_ORB_Core_Static_Resources*
00118 TAO_ORB_Core_Static_Resources::instance (void)
00119 {
00120   ACE_Service_Gestalt *current = ACE_Service_Config::current();
00121   TAO_ORB_Core_Static_Resources* tocsr =
00122     ACE_Dynamic_Service<TAO_ORB_Core_Static_Resources>::instance
00123     (current, "TAO_ORB_Core_Static_Resources", true);
00124 
00125   if (tocsr == 0)
00126     {
00127       // This new is never freed on purpose.  The data specified by
00128       // it needs to be around for the last shared library that references
00129       // this class.  This could occur in a destructor in a shared library
00130       // that is unloaded after this one.  One solution to avoid this
00131       // harmless memory leak would be to use reference counting.
00132       current->process_directive(ace_svc_desc_TAO_ORB_Core_Static_Resources);
00133       tocsr = ACE_Dynamic_Service<TAO_ORB_Core_Static_Resources>::instance
00134         (current, "TAO_ORB_Core_Static_Resources", true);
00135 
00136       ACE_Service_Gestalt *global = ACE_Service_Config::global();
00137       if (current != global)
00138         {
00139           TAO_ORB_Core_Static_Resources* global_tocsr =
00140             ACE_Dynamic_Service<TAO_ORB_Core_Static_Resources>::instance
00141             (global,"TAO_ORB_Core_Static_Resources");
00142           *tocsr = *global_tocsr;
00143         }
00144     }
00145 
00146   return tocsr;
00147 }
00148 
00149 TAO_ORB_Core_Static_Resources::TAO_ORB_Core_Static_Resources (void)
00150   : network_priority_protocols_hooks_name_ (
00151       "Network_Priority_Protocols_Hooks"),
00152     connection_timeout_hook_ (0),
00153     resource_factory_name_ ("Resource_Factory"),
00154     dynamic_adapter_name_ ("Dynamic_Adapter"),
00155     ifr_client_adapter_name_ ("IFR_Client_Adapter"),
00156     typecodefactory_adapter_name_ ("TypeCodeFactory_Adapter"),
00157     iorinterceptor_adapter_factory_name_ ("IORInterceptor_Adapter_Factory"),
00158     valuetype_adapter_factory_name_ ("Valuetype_Adapter_Factory"),
00159     alt_connection_timeout_hook_ (0)
00160 {
00161 }
00162 
00163 TAO_ORB_Core_Static_Resources&
00164 TAO_ORB_Core_Static_Resources::operator=(const TAO_ORB_Core_Static_Resources& other)
00165 {
00166   this->network_priority_protocols_hooks_name_ =
00167     other.network_priority_protocols_hooks_name_;
00168   this->connection_timeout_hook_ = other.connection_timeout_hook_;
00169   this->resource_factory_name_ = other.resource_factory_name_;
00170   this->dynamic_adapter_name_ = other.dynamic_adapter_name_;
00171   this->ifr_client_adapter_name_ = other.ifr_client_adapter_name_;
00172   this->typecodefactory_adapter_name_ = other.typecodefactory_adapter_name_;
00173   this->iorinterceptor_adapter_factory_name_ =
00174     other.iorinterceptor_adapter_factory_name_;
00175   this->valuetype_adapter_factory_name_ =
00176     other.valuetype_adapter_factory_name_;
00177   this->alt_connection_timeout_hook_ = other.alt_connection_timeout_hook_;
00178   return *this;
00179 }
00180 
00181 // ****************************************************************
00182 
00183 TAO_ORB_Core::TAO_ORB_Core (const char *orbid,
00184                             ACE_Service_Gestalt* gestalt)
00185   : protocols_hooks_ (0),
00186     network_priority_protocols_hooks_ (0),
00187 #if TAO_USE_LOCAL_MEMORY_POOL == 1
00188     use_local_memory_pool_ (true),
00189 #else
00190     use_local_memory_pool_ (false),
00191 #endif
00192     lock_ (),
00193     thread_lane_resources_manager_ (0),
00194     collocation_resolver_ (0),
00195     stub_factory_ (0),
00196     protocol_factories_ (0),
00197     implrepo_service_ (CORBA::Object::_nil ()),
00198     use_implrepo_ (0),
00199     imr_endpoints_in_ior_ (1),
00200     typecode_factory_ (CORBA::Object::_nil ()),
00201     codec_factory_ (CORBA::Object::_nil ()),
00202     compression_manager_ (CORBA::Object::_nil ()),
00203     dynany_factory_ (CORBA::Object::_nil ()),
00204     ior_manip_factory_ (CORBA::Object::_nil ()),
00205     ior_table_ (CORBA::Object::_nil ()),
00206     orb_ (CORBA::ORB::_nil ()),
00207     root_poa_ (),
00208     orb_params_ (),
00209     init_ref_map_ (TAO_DEFAULT_OBJECT_REF_TABLE_SIZE),
00210     object_ref_table_ (),
00211     object_key_table_ (),
00212     orbid_ (ACE_OS::strdup (orbid ? orbid : "")),
00213     resource_factory_ (0),
00214     client_factory_ (0),
00215     server_factory_ (0),
00216     opt_for_collocation_ (true),
00217     use_global_collocation_ (true),
00218     collocation_strategy_ (THRU_POA),
00219 
00220 #if (TAO_HAS_CORBA_MESSAGING == 1)
00221 
00222     policy_manager_ (0),
00223     default_policies_ (0),
00224     policy_current_ (0),
00225 
00226 #endif /* TAO_HAS_CORBA_MESSAGING == 1 */
00227 
00228     poa_current_ (),
00229     adapter_registry_ (this),
00230     poa_adapter_ (0),
00231     tm_ (),
00232     tss_cleanup_funcs_ (),
00233     tss_resources_ (),
00234     has_shutdown_ (true),  // Start the ORB in a  "shutdown" state.  Only
00235                            // after CORBA::ORB_init() is called will the
00236                            // ORB no longer be shutdown.  This does not
00237                            // mean that the ORB can be reinitialized.  It
00238                            // can only be initialized once.
00239     thread_per_connection_use_timeout_ (1),
00240     open_lock_ (),
00241     endpoint_selector_factory_ (0),
00242 #if (TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1)
00243     eager_transport_queueing_strategy_ (0),
00244     delayed_transport_queueing_strategy_ (0),
00245     flush_transport_queueing_strategy_ (0),
00246 #endif /* TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1 */
00247     refcount_ (1),
00248     policy_factory_registry_ (0),
00249     orbinitializer_registry_ (0),
00250 #if (TAO_HAS_INTERCEPTORS == 1)
00251     pi_current_ (CORBA::Object::_nil ()),
00252     client_request_interceptor_adapter_ (0),
00253     server_request_interceptor_adapter_ (0),
00254 #endif  /* TAO_HAS_INTERCEPTORS == 1 */
00255     ior_interceptor_adapter_ (0),
00256     valuetype_adapter_ (0),
00257     parser_registry_ (),
00258     bidir_adapter_ (0),
00259     bidir_giop_policy_ (0),
00260     flushing_strategy_ (0),
00261     codeset_manager_ (0),
00262     config_ (gestalt),
00263     sync_scope_hook_ (0),
00264     timeout_hook_ (0)
00265 {
00266 #if (TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1)
00267 
00268   ACE_NEW (this->flush_transport_queueing_strategy_,
00269            TAO::Flush_Transport_Queueing_Strategy);
00270 
00271 #endif /* TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1 */
00272 
00273 #if (TAO_HAS_CORBA_MESSAGING == 1)
00274 
00275   ACE_NEW (this->policy_manager_,
00276            TAO_Policy_Manager);
00277 
00278   ACE_NEW (this->default_policies_,
00279            TAO_Policy_Set (TAO_POLICY_ORB_SCOPE));
00280 
00281   ACE_NEW (this->policy_current_,
00282            TAO_Policy_Current);
00283 
00284 #endif /* TAO_HAS_CORBA_MESSAGING == 1 */
00285 
00286   // Initialize the default request dispatcher.
00287   ACE_NEW (this->request_dispatcher_,
00288            TAO_Request_Dispatcher);
00289 
00290 }
00291 
00292 TAO_ORB_Core::~TAO_ORB_Core (void)
00293 {
00294   delete this->thread_lane_resources_manager_;
00295 
00296   delete this->flushing_strategy_;
00297 
00298   ACE_OS::free (this->orbid_);
00299 
00300 #if (TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1)
00301 
00302   delete this->eager_transport_queueing_strategy_;
00303   delete this->delayed_transport_queueing_strategy_;
00304   delete this->flush_transport_queueing_strategy_;
00305 
00306 #endif /* TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1 */
00307 
00308 #if (TAO_HAS_CORBA_MESSAGING == 1)
00309 
00310   ::CORBA::release (this->policy_manager_);
00311   delete this->default_policies_;
00312   ::CORBA::release (this->policy_current_);
00313 
00314 #endif /* TAO_HAS_CORBA_MESSAGING == 1 */
00315 
00316   delete this->request_dispatcher_;
00317 
00318   delete this->policy_factory_registry_;
00319 
00320   // Don't delete, is a process wide singleton shared by all orbs
00321   orbinitializer_registry_ = 0;
00322 
00323   ::CORBA::release (this->orb_);
00324 
00325   delete this->codeset_manager_;
00326   this->codeset_manager_ = 0;
00327 
00328   // This will destroy the service repository for this core
00329   (void) TAO::ORB::close_services (this->config_);
00330 
00331   if (this->config_ != ACE_Service_Config::global())
00332     delete this->config_;
00333 
00334   this->config_ = 0;
00335 }
00336 
00337 int
00338 TAO_ORB_Core::init (int &argc, char *argv[] )
00339 {
00340   // Right now, this code expects to begin parsing in argv[1] rather
00341   // than argv[0].  I don't think that's wise.  I think we need to
00342   // change that convention to argv[0] and let the initializing code
00343   // make any necessary shifts.
00344   //
00345   // Parse arguments to the ORB.  Typically the ORB is passed
00346   // arguments straight from the command line, so we will simply pass
00347   // through them and respond to the ones we understand and ignore
00348   // those we don't.
00349   //
00350   // In some instances, we may actually build another vector of
00351   // arguments and stash it for use initializing other components such
00352   // as the RootPOA.
00353 
00354   bool use_ior = true;
00355   int cdr_tradeoff = ACE_DEFAULT_CDR_MEMCPY_TRADEOFF;
00356 
00357   // The following things should be changed to use the ACE_Env_Value<>
00358   // template sometime.
00359 
00360   // Name Service port use for Multicast
00361   unsigned short ns_port = 0;
00362 
00363   // Trading Service port used for Multicast
00364   unsigned short ts_port = 0;
00365 
00366   // Implementation Repository Service port #.
00367   unsigned short ir_port = 0;
00368 
00369   // Buffer sizes for kernel socket buffers
00370   // @@ should be a default defined for each protocol implementation?
00371   //    since we may have protocols loaded which use shared memory of
00372   //    some form, fredk
00373   int rcv_sock_size = -1;
00374   int snd_sock_size = -1;
00375 
00376   // Use TCP_NODELAY.
00377   int nodelay = 1;
00378 
00379   // Use SO_KEEPALIVE (default 0).
00380   int so_keepalive = 0;
00381 
00382   // Use SO_DONTROUTE (default 0)
00383   int so_dontroute = 0;
00384 
00385   // Use dotted decimal addresses
00386   // @@ This option will be treated as a suggestion to each loaded
00387   //    protocol to use a character representation for the numeric
00388   //    address, otherwise use a logical name. fredk
00389 #if (TAO_USE_DOTTED_DECIMAL_ADDRESSES == 1)
00390   int dotted_decimal_addresses = 1;
00391 #else
00392   int dotted_decimal_addresses = 0;
00393 #endif /* TAO_USE_DOTTED_DECIMAL_ADDRESSES */
00394 
00395   // Disable looking up the host name for incoming connections.
00396   int no_server_side_name_lookups = 0;
00397 
00398 #if defined (TAO_STD_PROFILE_COMPONENTS)
00399   int std_profile_components = 1;
00400 #else
00401   int std_profile_components = 0;
00402 #endif /* TAO_STD_PROFILE_COMPONENTS */
00403 
00404   int linger = -1;
00405 
00406   int use_parallel_connects = 0;
00407 
00408   // Copy command line parameter not to use original.
00409   ACE_Argv_Type_Converter command_line (argc, argv);
00410 
00411   ACE_Arg_Shifter arg_shifter (command_line.get_argc (),
00412                                command_line.get_TCHAR_argv ());
00413 
00414   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00415                     monitor,
00416                     this->lock_,
00417                     -1);
00418 
00419 #if (TAO_NEGOTIATE_CODESETS == 1)
00420   int negotiate_codesets = 1;
00421 #else
00422   int negotiate_codesets = 0;
00423 #endif /* TAO_NEGOTIATE_CODESETS */
00424 
00425   // Pick up the value of the use_implrepo_ flag from an environment variable
00426   // called "TAO_USE_IMR". Do it here so that it can be overridden by
00427   // the "-ORBUseIMR" command line argument.
00428   //
00429   char* const use_IMR_env_var_value = ACE_OS::getenv  ("TAO_USE_IMR") ;
00430   if  (use_IMR_env_var_value != 0)
00431     {
00432       this->use_implrepo_ = ACE_OS::atoi  (use_IMR_env_var_value) ;
00433     }
00434 
00435 
00436   while (arg_shifter.is_anything_left ())
00437     {
00438       const ACE_TCHAR *current_arg = 0;
00439 
00440       ////////////////////////////////////////////////////////////////
00441       // begin with the 'parameterless' flags                       //
00442       ////////////////////////////////////////////////////////////////
00443       if (0 != (current_arg = arg_shifter.get_the_parameter
00444                 (ACE_TEXT("-ORBDottedDecimalAddresses"))))
00445         {
00446           // Use dotted decimal addresses
00447           // @@ this should be renamed.  See above comment. fredk
00448           dotted_decimal_addresses =
00449             ACE_OS::atoi (current_arg);
00450 
00451           arg_shifter.consume_arg ();
00452         }
00453       else if (0 != (current_arg = arg_shifter.get_the_parameter
00454                 (ACE_TEXT("-ORBNoServerSideNameLookups"))))
00455         {
00456           // Don't look up the host name for incoming connections
00457           no_server_side_name_lookups =
00458             ACE_OS::atoi (current_arg);
00459 
00460           arg_shifter.consume_arg ();
00461         }
00462       else if (0 != (current_arg = arg_shifter.get_the_parameter
00463                 (ACE_TEXT("-ORBNameServicePort"))))
00464         {
00465           // Specify the port number for the NameService.
00466           // Unrelated to ORB Protocols, this is used for multicast.
00467 
00468           ns_port = static_cast <CORBA::UShort> (ACE_OS::atoi (current_arg));
00469 
00470           arg_shifter.consume_arg ();
00471         }
00472       else if (0 != (current_arg = arg_shifter.get_the_parameter
00473                 (ACE_TEXT("-ORBMulticastDiscoveryEndpoint"))))
00474         {
00475           // Specify mcast address:port@network_interface for the
00476           // Naming Service Multicast Discovery Protocol.
00477           // If there is no colon, its only the port no.
00478           // If there is a '@' also, it means that the network
00479           // interface name is specified.
00480           this->orb_params ()->mcast_discovery_endpoint (
00481             ACE_TEXT_ALWAYS_CHAR(current_arg));
00482 
00483           arg_shifter.consume_arg ();
00484         }
00485       else if (0 != (current_arg = arg_shifter.get_the_parameter
00486                 (ACE_TEXT("-ORBNodelay"))))
00487         {
00488           // Use TCP_NODELAY or not.
00489           nodelay =
00490             ACE_OS::atoi (current_arg);
00491 
00492           arg_shifter.consume_arg ();
00493         }
00494       else if (0 != (current_arg = arg_shifter.get_the_parameter
00495                 (ACE_TEXT("-ORBKeepalive"))))
00496         {
00497           // Use SO_KEEPALIVE or not.
00498           so_keepalive =
00499             ACE_OS::atoi (current_arg);
00500 
00501           arg_shifter.consume_arg ();
00502         }
00503       else if (0 != (current_arg = arg_shifter.get_the_parameter
00504                 (ACE_TEXT("-ORBDontRoute"))))
00505         {
00506           // Use SO_DONTROUTE or not.
00507           so_dontroute =
00508             ACE_OS::atoi (current_arg);
00509 
00510           arg_shifter.consume_arg ();
00511         }
00512       else if (0 != (current_arg = arg_shifter.get_the_parameter
00513                 (ACE_TEXT("-ORBTradingServicePort"))))
00514         {
00515           // Specify the port number for the TradingService.
00516 
00517           ts_port = static_cast <CORBA::UShort> (ACE_OS::atoi (current_arg));
00518 
00519           arg_shifter.consume_arg ();
00520         }
00521       else if (0 != (current_arg = arg_shifter.get_the_parameter
00522                 (ACE_TEXT("-ORBImplRepoServicePort"))))
00523         {
00524           // Specify the multicast port number for the Implementation
00525           // Repository.
00526           ir_port = static_cast <CORBA::UShort> (ACE_OS::atoi (current_arg));
00527 
00528           arg_shifter.consume_arg ();
00529         }
00530       else if (0 != (current_arg = arg_shifter.get_the_parameter
00531                 (ACE_TEXT("-ORBRcvSock"))))
00532         {
00533           // @@ All protocol implementation may not use sockets, so
00534           //    this can either be a generic I/O Buffer size or
00535           //    Buffer info can be a per protocol specification, fredk
00536 
00537           // Specify the size of the socket's receive buffer
00538 
00539           rcv_sock_size = ACE_OS::atoi (current_arg);
00540 
00541           arg_shifter.consume_arg ();
00542         }
00543       else if (0 != (current_arg = arg_shifter.get_the_parameter
00544                 (ACE_TEXT("-ORBSndSock"))))
00545         {
00546           // @@ All protocol implementation may not use sockets, so
00547           //    this can either be a generic I/O Buffer size or
00548           //    Buffer info can be a per protocol specification, fredk
00549 
00550           // Specify the size of the socket's send buffer
00551           snd_sock_size = ACE_OS::atoi (current_arg);
00552 
00553           arg_shifter.consume_arg ();
00554         }
00555       else if (0 != (current_arg = arg_shifter.get_the_parameter
00556                 (ACE_TEXT("-ORBObjRefStyle"))))
00557         {
00558           // Specifies the style of printed objrefs: URL or IOR
00559           //
00560           // BEGIN COMMENTS FROM IIOP-1.4 On Win32, we should be
00561           // collecting information from the Registry such as what
00562           // ORBs are configured, specific configuration details like
00563           // whether they generate IOR or URL style stringified
00564           // objrefs and which addresses they listen to (e.g. allowing
00565           // multihomed hosts to implement firewalls), user-meaningful
00566           // orb names (they will normally indicate domains), and
00567           // more.
00568           //
00569           // On UNIX, we should collect that from some private config
00570           // file.
00571           //
00572           // Instead, this just treats the "internet" ORB name
00573           // specially and makes it always use URL-style stringified
00574           // objrefs, where the hostname and TCP port number are
00575           // explicit (and the whole objref is readable by mortals).
00576           // BEGIN COMMENTS FROM IIOP-1.4
00577           const ACE_TCHAR *opt = current_arg;
00578           if (ACE_OS::strcasecmp (opt, ACE_TEXT("URL")) == 0)
00579             use_ior = false;
00580           else if (ACE_OS::strcasecmp (opt, ACE_TEXT("IOR")) == 0)
00581             use_ior = true;
00582 
00583           arg_shifter.consume_arg ();
00584         }
00585       else if (0 != (current_arg = arg_shifter.get_the_parameter
00586                 (ACE_TEXT("-ORBCollocationStrategy"))))
00587         {
00588           // Specify which collocation policy we want to use.
00589           const ACE_TCHAR *opt = current_arg;
00590           if (ACE_OS::strcasecmp (opt, ACE_TEXT("thru_poa")) == 0)
00591             this->collocation_strategy_ = THRU_POA;
00592           else if (ACE_OS::strcasecmp (opt, ACE_TEXT("direct")) == 0)
00593             this->collocation_strategy_ = DIRECT;
00594 
00595           arg_shifter.consume_arg ();
00596         }
00597       else if (0 != (current_arg = arg_shifter.get_the_parameter
00598                 (ACE_TEXT("-ORBCollocation"))))
00599         {
00600           // Specify whether we want to optimize against collocation
00601           // objects.  Valid arguments are: "global", "no", and "per-orb".
00602           // Default is global.
00603 
00604           const ACE_TCHAR *opt = current_arg;
00605           if (ACE_OS::strcasecmp (opt, ACE_TEXT("global")) == 0)
00606             {
00607               this->opt_for_collocation_ = true;
00608               this->use_global_collocation_ = true;
00609             }
00610           else if (ACE_OS::strcasecmp (opt, ACE_TEXT("NO")) == 0)
00611             {
00612               this->opt_for_collocation_ = false;
00613               this->use_global_collocation_ = false;
00614             }
00615           else if (ACE_OS::strcasecmp (opt, ACE_TEXT("per-orb")) == 0)
00616             {
00617               this->opt_for_collocation_ = true;
00618               this->use_global_collocation_ = false;
00619             }
00620           else
00621             {
00622               ACE_DEBUG ((LM_WARNING,
00623                           ACE_TEXT ("WARNING: Unknown option to ")
00624                           ACE_TEXT ("'-ORBCollocation': %s\n"), opt));
00625             }
00626 
00627           arg_shifter.consume_arg ();
00628         }
00629       else if (0 != (current_arg = arg_shifter.get_the_parameter
00630                 (ACE_TEXT("-ORBPreferredInterfaces"))))
00631         {
00632           if (this->orb_params ()->preferred_interfaces (
00633                 ACE_TEXT_ALWAYS_CHAR (current_arg)) == false)
00634             throw ::CORBA::INTERNAL (
00635               CORBA::SystemException::_tao_minor_code (
00636                 TAO_ORB_CORE_INIT_LOCATION_CODE,
00637                 0),
00638               CORBA::COMPLETED_NO);
00639 
00640           arg_shifter.consume_arg ();
00641         }
00642       else if (0 != (current_arg = arg_shifter.get_the_parameter
00643                 (ACE_TEXT("-ORBEnforcePreferredInterfaces"))))
00644         {
00645           int enforce_pref_interfaces = ACE_OS::atoi (current_arg);
00646           if (enforce_pref_interfaces)
00647             this->orb_params ()->enforce_pref_interfaces (false);
00648           else
00649             this->orb_params ()->enforce_pref_interfaces (true);
00650 
00651           arg_shifter.consume_arg ();
00652         }
00653 #if defined (ACE_HAS_IPV6)
00654       else if (0 != (current_arg = arg_shifter.get_the_parameter
00655                 (ACE_TEXT("-ORBPreferIPV6Interfaces"))))
00656         {
00657           int prefer_ipv6_interfaces = ACE_OS::atoi (current_arg);
00658           if (prefer_ipv6_interfaces)
00659             this->orb_params ()->prefer_ipv6_interfaces (true);
00660           else
00661             this->orb_params ()->prefer_ipv6_interfaces (false);
00662 
00663           arg_shifter.consume_arg ();
00664         }
00665       else if (0 != (current_arg = arg_shifter.get_the_parameter
00666                 (ACE_TEXT("-ORBConnectIPV6Only"))))
00667         {
00668           int connect_ipv6_only = ACE_OS::atoi (current_arg);
00669           if (connect_ipv6_only)
00670             this->orb_params ()->connect_ipv6_only (true);
00671           else
00672             this->orb_params ()->connect_ipv6_only (false);
00673 
00674           arg_shifter.consume_arg ();
00675         }
00676       else if ((current_arg = arg_shifter.get_the_parameter
00677                 (ACE_TEXT("-ORBUseIPV6LinkLocal"))))
00678         {
00679           int use_ipv6_link_local = ACE_OS::atoi (current_arg);
00680           if (use_ipv6_link_local)
00681             this->orb_params ()->use_ipv6_link_local (true);
00682           else
00683             this->orb_params ()->use_ipv6_link_local (false);
00684 
00685           arg_shifter.consume_arg ();
00686         }
00687 #endif /* ACE_HAS_IPV6 */
00688       else if (0 != (current_arg = arg_shifter.get_the_parameter
00689                 (ACE_TEXT("-ORBCDRTradeoff"))))
00690         {
00691           cdr_tradeoff = ACE_OS::atoi (current_arg);
00692 
00693           arg_shifter.consume_arg ();
00694         }
00695 
00696       // A new <ObjectID>:<IOR> mapping has been specified. This will be
00697       // used by the resolve_initial_references ().
00698 
00699       else if (0 != (current_arg = arg_shifter.get_the_parameter
00700                 (ACE_TEXT("-ORBInitRef"))))
00701         {
00702           const ACE_TCHAR *pos = ACE_OS::strchr (current_arg, '=');
00703           if (pos == 0)
00704             {
00705               ACE_ERROR ((LM_ERROR,
00706                           ACE_TEXT ("Invalid ORBInitRef argument '%s'")
00707                           ACE_TEXT ("format is ObjectID=IOR\n"),
00708                           current_arg));
00709               throw ::CORBA::INTERNAL (
00710                 CORBA::SystemException::_tao_minor_code (
00711                   TAO_ORB_CORE_INIT_LOCATION_CODE,
00712                   0),
00713                 CORBA::COMPLETED_NO);
00714             }
00715           ACE_CString object_id (ACE_TEXT_ALWAYS_CHAR(current_arg),
00716                                  pos - current_arg);
00717           ACE_CString IOR (ACE_TEXT_ALWAYS_CHAR(pos + 1));
00718           if (!this->init_ref_map_.insert (
00719                  std::make_pair (InitRefMap::key_type (object_id),
00720                                  InitRefMap::data_type (IOR))).second)
00721             {
00722               ACE_ERROR ((LM_ERROR,
00723                           ACE_TEXT ("Duplicate -ORBInitRef ")
00724                           ACE_TEXT ("argument '%s'\n"),
00725                           current_arg));
00726               throw ::CORBA::INTERNAL (
00727                 CORBA::SystemException::_tao_minor_code (
00728                   TAO_ORB_CORE_INIT_LOCATION_CODE,
00729                   0),
00730                 CORBA::COMPLETED_NO);
00731             }
00732           arg_shifter.consume_arg ();
00733         }
00734       else if (0 != (current_arg = arg_shifter.get_the_parameter
00735                 (ACE_TEXT("-ORBDefaultInitRef"))))
00736         {
00737           // Set the list of prefixes from -ORBDefaultInitRef.
00738           this->orb_params ()->default_init_ref
00739             (ACE_TEXT_ALWAYS_CHAR(current_arg));
00740 
00741           arg_shifter.consume_arg ();
00742         }
00743       else if (0 != (current_arg = arg_shifter.get_the_parameter
00744                 (ACE_TEXT("-ORBStdProfileComponents"))))
00745         {
00746           std_profile_components =
00747             ACE_OS::atoi (current_arg);
00748           arg_shifter.consume_arg ();
00749         }
00750       else if (0 != (current_arg = arg_shifter.get_the_parameter
00751                 (ACE_TEXT("-ORBAMICollocation"))))
00752         {
00753           int ami_collocation = ACE_OS::atoi (current_arg);
00754           if (ami_collocation)
00755             this->orb_params ()->ami_collication (true);
00756           else
00757             this->orb_params ()->ami_collication (false);
00758 
00759           arg_shifter.consume_arg ();
00760         }
00761       else if (0 != (current_arg = arg_shifter.get_the_parameter
00762                 (ACE_TEXT("-ORBResources"))))
00763         {
00764           ACE_DEBUG ((LM_WARNING,
00765                       ACE_TEXT ("\"-ORBResources\" has been ")
00766                       ACE_TEXT ("deprecated.\n")));
00767 
00768           arg_shifter.consume_arg ();
00769         }
00770       else if (0 != (current_arg = arg_shifter.get_the_parameter
00771                 (ACE_TEXT("-ORBLogFile"))))
00772         {
00773           // redirect all ACE_DEBUG and ACE_ERROR output to a file
00774           // USAGE: -ORBLogFile <file>
00775           // default: if <file> is present     = append
00776           //          if <file> is not present = create
00777 
00778           const ACE_TCHAR *file_name = current_arg;
00779           arg_shifter.consume_arg ();
00780 
00781           // would rather use ACE_OSTREAM_TYPE out here..
00782           // but need ACE_FSTREAM_TYPE to call ->open(...)
00783           // and haven't found such a macro to rep FILE* and/or fstream*
00784 
00785 #if defined (ACE_LACKS_IOSTREAM_TOTALLY)
00786 
00787           FILE* output_stream = ACE_OS::fopen (file_name, ACE_TEXT ("a"));
00788 
00789           ACE_LOG_MSG->msg_ostream (output_stream, 1);
00790 
00791 #else /* ! ACE_LACKS_IOSTREAM_TOTALLY */
00792 
00793           ofstream* output_stream = 0;
00794 
00795           //
00796           // note: we are allocating dynamic memory here....but
00797           // I assume it will persist for the life of the program
00798           //
00799 
00800           ACE_NEW_THROW_EX (output_stream,
00801                             ofstream (),
00802                             CORBA::NO_MEMORY (
00803                               CORBA::SystemException::_tao_minor_code (
00804                                 TAO_ORB_CORE_INIT_LOCATION_CODE,
00805                                 ENOMEM),
00806                               CORBA::COMPLETED_NO));
00807 
00808           output_stream->open (ACE_TEXT_ALWAYS_CHAR (file_name),
00809                                ios::out | ios::app);
00810 
00811           if (!output_stream->bad ())
00812             {
00813               ACE_LOG_MSG->msg_ostream (output_stream, 1);
00814             }
00815 
00816 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
00817 
00818           ACE_LOG_MSG->clr_flags (ACE_Log_Msg::STDERR | ACE_Log_Msg::LOGGER);
00819           ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
00820 
00821         }
00822       else if (0 != (current_arg = arg_shifter.get_the_parameter
00823                 (ACE_TEXT("-ORBVerboseLogging"))))
00824         {
00825           unsigned long verbose_logging = ACE_OS::atoi (current_arg);
00826 
00827           arg_shifter.consume_arg ();
00828 
00829           typedef void (ACE_Log_Msg::*PTMF)(u_long);
00830           PTMF flagop = &ACE_Log_Msg::set_flags;
00831           u_long value;
00832 
00833           switch (verbose_logging)
00834             {
00835             case 0:
00836               flagop = &ACE_Log_Msg::clr_flags;
00837               value = ACE_Log_Msg::VERBOSE | ACE_Log_Msg::VERBOSE_LITE;
00838               break;
00839             case 1:
00840               value = ACE_Log_Msg::VERBOSE_LITE; break;
00841             default:
00842               value = ACE_Log_Msg::VERBOSE; break;
00843             }
00844 
00845           (ACE_LOG_MSG->*flagop)(value);
00846         }
00847       else if (0 != (current_arg = arg_shifter.get_the_parameter
00848                 (ACE_TEXT("-ORBUseIMR"))))
00849         {
00850           // Use IR or not.
00851           this->use_implrepo_ = ACE_OS::atoi (current_arg);
00852 
00853           arg_shifter.consume_arg ();
00854         }
00855       else if (0 != (current_arg = arg_shifter.get_the_parameter
00856                 (ACE_TEXT("-ORBIMREndpointsInIOR"))))
00857         {
00858           this->imr_endpoints_in_ior_ = ACE_OS::atoi (current_arg);
00859 
00860           arg_shifter.consume_arg ();
00861         }
00862       else if (0 != (current_arg = arg_shifter.get_the_parameter
00863                 (ACE_TEXT("-ORBid"))))
00864         {
00865           // The ORBid is actually set in ORB_init(), and then passed
00866           // to the TAO_ORB_Core() constructor.  However, in the case
00867           // where the ORBid third argument to ORB_init() is not zero,
00868           // any "-ORBid" arguments in the argv argument list are
00869           // supposed to be ignored, according to the CORBA spec.  As
00870           // such, "-ORBid" must be removed from the argument list
00871           // since ORB_init() must remove all "-ORB" option
00872           // arguments.
00873 
00874           // We obtain a lock on the ORB table when setting the
00875           // ORBid.  For this reason we should *not* set the ORBid
00876           // here.  CORBA::ORB_init() does all of the proper locking
00877           // and setting.
00878 
00879           arg_shifter.consume_arg ();
00880         }
00881       else if (0 != (current_arg = arg_shifter.get_the_parameter
00882                 (ACE_TEXT("-ORBServerId"))))
00883         {
00884           // The this->server_id_ is to uniquely identify a server to
00885           // an IMR.
00886           // Fill in later.
00887           this->server_id_.set(ACE_TEXT_ALWAYS_CHAR(current_arg));
00888 
00889           arg_shifter.consume_arg ();
00890         }
00891       else if (0 != (current_arg = arg_shifter.get_the_parameter
00892                (ACE_TEXT("-ORBLingerTimeout"))))
00893         {
00894           linger = ACE_OS::atoi (current_arg);
00895 
00896           arg_shifter.consume_arg ();
00897         }
00898       else if (0 != (current_arg = arg_shifter.get_the_parameter
00899                 (ACE_TEXT("-ORBEndpoint"))))
00900         {
00901           // Each "endpoint" is of the form:
00902           //
00903           //   protocol://V.v@addr1,addr2,...,addrN
00904           //
00905           // or:
00906           //
00907           //   protocol://addr1,addr2,...,addrN
00908           //
00909           // where "V.v" is an optional protocol version for each
00910           // addr.  All endpoint strings should be of the above
00911           // form(s).
00912           //
00913           // Multiple sets of endpoint may be seperated by a semi-colon `;'.
00914           // For example:
00915           //
00916           //   corbaloc:space:2001,1.2@odyssey:2010;uiop://foo,bar
00917           //
00918           // All endpoint strings should be of the above form(s).
00919 
00920           this->set_endpoint_helper (TAO_DEFAULT_LANE,
00921                                      ACE_TEXT_ALWAYS_CHAR (current_arg)
00922                                     );
00923 
00924           arg_shifter.consume_arg ();
00925         }
00926       else if (0 != (current_arg = arg_shifter.get_the_parameter
00927                 (ACE_TEXT("-ORBListenEndpoints"))))
00928         {
00929           // This option is similar to the -ORBEndPoint option. May be
00930           // ORBEndpoint option will be deprecated in future. But, for
00931           // now, I (Priyanka) am leaving so that both options can be
00932           // used.
00933 
00934           this->set_endpoint_helper (TAO_DEFAULT_LANE,
00935                                      ACE_TEXT_ALWAYS_CHAR (current_arg)
00936                                     );
00937 
00938           arg_shifter.consume_arg ();
00939         }
00940       else if ((0 != (current_arg = arg_shifter.get_the_parameter
00941                 (ACE_TEXT("-ORBLaneEndpoint")))) ||
00942                (0 != (current_arg = arg_shifter.get_the_parameter
00943                 (ACE_TEXT("-ORBLaneListenEndpoints")))))
00944         {
00945           // This option is similar to the -ORBEndPoint option but
00946           // specifies endpoints for each lane.
00947 
00948           if (arg_shifter.is_option_next ())
00949             return -1;
00950 
00951           ACE_CString lane (ACE_TEXT_ALWAYS_CHAR (current_arg));
00952           arg_shifter.consume_arg ();
00953 
00954           if (arg_shifter.is_option_next ())
00955             return -1;
00956 
00957           ACE_CString endpoints (ACE_TEXT_ALWAYS_CHAR
00958                                   (arg_shifter.get_current ()));
00959           arg_shifter.consume_arg ();
00960 
00961           this->set_endpoint_helper (lane,
00962                                      endpoints
00963                                     );
00964         }
00965       else if (0 != (current_arg = arg_shifter.get_the_parameter
00966                 (ACE_TEXT("-ORBNoProprietaryActivation"))))
00967         {
00968           // This option can be used to set to not use any proprietary
00969           // activation framework. The only TAO proprietary activation
00970           // framework is IMR. So, by setting this option in TAO, the
00971           // IMR shouldnt be used .. even if the ORBUseIMR option is
00972           // set.
00973           // Fill in later
00974           // @@ To do later: Priyanka.
00975 
00976           throw ::CORBA::NO_IMPLEMENT ();
00977         }
00978        else if (0 != (current_arg = arg_shifter.get_the_parameter
00979                  (ACE_TEXT("-ORBUseSharedProfile"))))
00980          {
00981            this->orb_params ()->shared_profile
00982              (ACE_OS::atoi (current_arg));
00983 
00984            arg_shifter.consume_arg ();
00985          }
00986        else if (0 != (current_arg = arg_shifter.get_the_parameter
00987                  (ACE_TEXT("-ORBNegotiateCodesets"))))
00988          {
00989            negotiate_codesets =
00990              (ACE_OS::atoi (current_arg));
00991 
00992            arg_shifter.consume_arg ();
00993          }
00994        else if (0 != (current_arg = arg_shifter.get_the_parameter
00995                  (ACE_TEXT("-ORBUseParallelConnects"))))
00996          {
00997            use_parallel_connects = ACE_OS::atoi (current_arg);
00998            arg_shifter.consume_arg ();
00999          }
01000        else if (0 != (current_arg = arg_shifter.get_the_parameter
01001                  (ACE_TEXT("-ORBParallelConnectDelay"))))
01002          {
01003            this->orb_params ()->parallel_connect_delay
01004              (ACE_OS::atoi (current_arg));
01005            arg_shifter.consume_arg ();
01006          }
01007       else if (0 != (current_arg = arg_shifter.get_the_parameter
01008                 (ACE_TEXT("-ORBSingleReadOptimization"))))
01009         {
01010           this->orb_params ()->single_read_optimization
01011             (ACE_OS::atoi (current_arg));
01012 
01013           arg_shifter.consume_arg ();
01014         }
01015       else if (0 != (current_arg = arg_shifter.get_the_parameter
01016                 (ACE_TEXT("-ORBDisableRTCollocation"))))
01017         {
01018           int disable_rt_collocation = ACE_OS::atoi (current_arg);
01019           if (disable_rt_collocation)
01020             this->orb_params ()->disable_rt_collocation_resolver (true);
01021           else
01022             this->orb_params ()->disable_rt_collocation_resolver (false);
01023 
01024           arg_shifter.consume_arg ();
01025         }
01026       else if (0 != (current_arg = arg_shifter.get_the_parameter
01027                 (ACE_TEXT("-ORBUseLocalMemoryPool"))))
01028         {
01029           this->use_local_memory_pool_ = (0 != ACE_OS::atoi (current_arg));
01030 
01031           arg_shifter.consume_arg ();
01032         }
01033       else if (0 != (current_arg = arg_shifter.get_the_parameter
01034                 (ACE_TEXT("-ORBMaxMessageSize"))))
01035         {
01036           this->orb_params_.max_message_size (ACE_OS::atoi (current_arg));
01037 
01038           arg_shifter.consume_arg ();
01039         }
01040 
01041       ////////////////////////////////////////////////////////////////
01042       // catch any unknown -ORB args                                //
01043       ////////////////////////////////////////////////////////////////
01044       else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-ORB")) != -1)
01045         {
01046           if (TAO_debug_level > 0)
01047             {
01048               current_arg = arg_shifter.get_current ();
01049               ACE_ERROR ((LM_ERROR,
01050                           ACE_TEXT ("ERROR: Unknown \"-ORB\" option ")
01051                           ACE_TEXT ("<%s>.\n"),
01052                           ((current_arg == 0) ? ACE_TEXT("<NULL>")
01053                                               : current_arg)));
01054             }
01055 
01056           throw ::CORBA::BAD_PARAM (
01057             CORBA::SystemException::_tao_minor_code (
01058               TAO_ORB_CORE_INIT_LOCATION_CODE,
01059               EINVAL),
01060             CORBA::COMPLETED_NO);
01061         }
01062 
01063       ////////////////////////////////////////////////////////////////
01064       // ok, we can't interpret this argument, move to next argument//
01065       ////////////////////////////////////////////////////////////////
01066       else
01067         {
01068           // Any arguments that don't match are ignored so that the
01069           // caller can still use them.
01070           arg_shifter.ignore_arg ();
01071         }
01072     }
01073 
01074   const char *env_endpoint =
01075     ACE_OS::getenv ("TAO_ORBENDPOINT");
01076 
01077   if (env_endpoint != 0)
01078     {
01079       int result =
01080         this->orb_params ()->add_endpoints (TAO_DEFAULT_LANE,
01081                                             env_endpoint);
01082 
01083       if (result != 0)
01084         {
01085           if (TAO_debug_level > 0)
01086             {
01087               ACE_ERROR ((LM_ERROR,
01088                           ACE_TEXT ("ERROR: Environment variable ")
01089                           ACE_TEXT ("TAO_ORBENDPOINT set to invalid value ")
01090                           ACE_TEXT ("<%s>.\n"),
01091                           env_endpoint));
01092             }
01093 
01094           throw ::CORBA::BAD_PARAM (
01095             CORBA::SystemException::_tao_minor_code (
01096               TAO_ORB_CORE_INIT_LOCATION_CODE,
01097               EINVAL),
01098             CORBA::COMPLETED_NO);
01099         }
01100     }
01101 
01102 #if defined (SIGPIPE) && !defined (ACE_LACKS_UNIX_SIGNALS)
01103   // There's really no way to deal with this in a portable manner, so
01104   // we just have to suck it up and get preprocessor conditional and
01105   // ugly.
01106   //
01107   // Impractical to have each call to the ORB protect against the
01108   // implementation artifact of potential writes to dead connections,
01109   // as it'd be way expensive.  Do it here; who cares about SIGPIPE in
01110   // these kinds of applications, anyway?
01111   (void) ACE_OS::signal (SIGPIPE, (ACE_SignalHandler) SIG_IGN);
01112 #endif /* SIGPIPE */
01113 
01114 
01115   // Calling the open method here so that the svc.conf file is
01116   // opened and TAO_default_resource_factory::init () is called by the
01117   // time this method is called.
01118   this->parser_registry_.open (this);
01119 
01120   // Initialize the pointers to resources in the ORB Core instance,
01121   // e.g., reactor, connector, etc.  Must do this after we open
01122   // services because we'll load the factory from there.
01123   TAO_Resource_Factory *trf = this->resource_factory ();
01124 
01125   if (trf == 0)
01126     {
01127       ACE_ERROR ((LM_ERROR,
01128                   ACE_TEXT ("(%P|%t) %p\n"),
01129                   ACE_TEXT ("ORB Core unable to find a ")
01130                   ACE_TEXT ("Resource Factory instance")));
01131       throw ::CORBA::INTERNAL (
01132         CORBA::SystemException::_tao_minor_code (
01133           TAO_ORB_CORE_INIT_LOCATION_CODE,
01134           0),
01135         CORBA::COMPLETED_NO);
01136     }
01137 
01138   // Set whether or not to use the local memory pool for the cdr allocators.
01139 
01140   trf->use_local_memory_pool (this->use_local_memory_pool_);
01141 
01142   // @@ ????
01143   // Make sure the reactor is initialized...
01144   ACE_Reactor *reactor = this->reactor ();
01145   if (reactor == 0)
01146     {
01147       ACE_ERROR ((LM_ERROR,
01148                   ACE_TEXT ("(%P|%t) %p\n"),
01149                   ACE_TEXT ("ORB Core unable to initialize reactor")));
01150       throw ::CORBA::INITIALIZE (
01151         CORBA::SystemException::_tao_minor_code (
01152           TAO_ORB_CORE_INIT_LOCATION_CODE,
01153           0),
01154         CORBA::COMPLETED_NO);
01155     }
01156 
01157   TAO_Server_Strategy_Factory *ssf = this->server_factory ();
01158 
01159   if (ssf == 0)
01160     {
01161       ACE_ERROR ((LM_ERROR,
01162                   ACE_TEXT ("(%P|%t) %p\n"),
01163                   ACE_TEXT ("ORB Core unable to find a ")
01164                   ACE_TEXT ("Server Strategy Factory instance")));
01165       throw ::CORBA::INTERNAL (
01166         CORBA::SystemException::_tao_minor_code (
01167           TAO_ORB_CORE_INIT_LOCATION_CODE,
01168           0),
01169         CORBA::COMPLETED_NO);
01170     }
01171 
01172   ssf->open (this);
01173 
01174   // Open the ObjectKey_Table
01175   (void) this->object_key_table_.init (this);
01176 
01177   // Obtain the timeout value for the thread-per-connection model
01178   this->thread_per_connection_use_timeout_ =
01179     ssf->thread_per_connection_timeout (this->thread_per_connection_timeout_);
01180 
01181   if (thread_per_connection_use_timeout_ == -1)
01182     {
01183       if (ACE_OS::strcasecmp (TAO_DEFAULT_THREAD_PER_CONNECTION_TIMEOUT,
01184                               "INFINITE") == 0)
01185         {
01186           this->thread_per_connection_use_timeout_ = 0;
01187         }
01188       else
01189         {
01190           this->thread_per_connection_use_timeout_ = 1;
01191           int milliseconds =
01192             ACE_OS::atoi (TAO_DEFAULT_THREAD_PER_CONNECTION_TIMEOUT);
01193           // Use a temporary to obtain automatic normalization.
01194           this->thread_per_connection_timeout_ =
01195             ACE_Time_Value (0, 1000 * milliseconds);
01196         }
01197     }
01198   if (this->thread_per_connection_use_timeout_ == 0)
01199     {
01200       // Do not wait for the server threads because they may block
01201       // forever.
01202       this->tm_.wait_on_exit (0);
01203     }
01204 
01205   // Initialize the "ORB" pseudo-object now.
01206   this->orb_ = CORBA::ORB::_tao_make_ORB (this);
01207 
01208   // This should probably move into the ORB Core someday rather then
01209   // being done at this level.
01210   this->orb_->_use_omg_ior_format (use_ior);
01211 
01212   // Set all kinds of orb parameters whose setting needed to be
01213   // deferred until after the service config entries had been
01214   // determined.
01215 
01216   this->orb_params ()->service_port (TAO::MCAST_NAMESERVICE, ns_port);
01217 
01218   if (ns_port != 0)
01219     {
01220       static char const mcast_fmt[] = "mcast://:%d::";
01221       static size_t const PORT_BUF_SIZE = 256;
01222 
01223       char def_init_ref[PORT_BUF_SIZE] = { 0 };
01224 
01225       ACE_OS::snprintf (def_init_ref,
01226                         PORT_BUF_SIZE,
01227                         mcast_fmt,
01228                         ns_port);
01229 
01230       this->orb_params ()->default_init_ref (def_init_ref);
01231     }
01232 
01233   this->orb_params ()->service_port (TAO::MCAST_TRADINGSERVICE, ts_port);
01234   this->orb_params ()->service_port (TAO::MCAST_IMPLREPOSERVICE, ir_port);
01235 
01236   this->orb_params ()->use_dotted_decimal_addresses (dotted_decimal_addresses);
01237   // When caching incoming transports don't use the host name if
01238   // -ORBDottedDecimalAddresses or -ORBNoServerSideNameLookups is true.
01239   this->orb_params ()->cache_incoming_by_dotted_decimal_address
01240                                             (no_server_side_name_lookups
01241                                              || dotted_decimal_addresses);
01242 
01243   this->orb_params ()->use_parallel_connects
01244     (use_parallel_connects != 0);
01245 
01246   this->orb_params ()->linger (linger);
01247   this->orb_params ()->nodelay (nodelay);
01248   this->orb_params ()->sock_keepalive (so_keepalive);
01249   this->orb_params ()->sock_dontroute (so_dontroute);
01250   if (rcv_sock_size >= 0)
01251     this->orb_params ()->sock_rcvbuf_size (rcv_sock_size);
01252   if (snd_sock_size >= 0)
01253     this->orb_params ()->sock_sndbuf_size (snd_sock_size);
01254   if (cdr_tradeoff >= 0)
01255     this->orb_params ()->cdr_memcpy_tradeoff (cdr_tradeoff);
01256 
01257   this->orb_params ()->std_profile_components (std_profile_components);
01258 
01259   this->orb_params ()->negotiate_codesets (negotiate_codesets);
01260 
01261   if (this->codeset_manager())
01262     this->codeset_manager_->open();
01263   else
01264     if  (TAO_debug_level > 0)
01265         ACE_DEBUG ((LM_DEBUG,
01266                     ACE_TEXT("TAO (%P|%t) ORB_Core: ")
01267                     ACE_TEXT("Codeset Manager not available\n")));
01268 
01269   // Set up the pluggable protocol infrastructure.  First get a
01270   // pointer to the protocol factories set, then obtain pointers to
01271   // all factories loaded by the service configurator.
01272   // Load all protocol factories!
01273   if (trf->init_protocol_factories () == -1)
01274     throw ::CORBA::INITIALIZE (
01275       CORBA::SystemException::_tao_minor_code (
01276         TAO_ORB_CORE_INIT_LOCATION_CODE,
01277         0),
01278       CORBA::COMPLETED_NO);
01279 
01280   // init the ORB core's pointer
01281   this->protocol_factories_ = trf->get_protocol_factories ();
01282 
01283   // Initialize the flushing strategy
01284   this->flushing_strategy_ = trf->create_flushing_strategy ();
01285 
01286   // Look in the service repository for an instance of the Protocol Hooks.
01287   const char *protocols_hooks_name = this->orb_params ()->protocols_hooks_name ();
01288 
01289   this->protocols_hooks_ =
01290     ACE_Dynamic_Service<TAO_Protocols_Hooks>::instance
01291     (this->configuration (),
01292      ACE_TEXT_CHAR_TO_TCHAR (protocols_hooks_name));
01293 
01294   if (this->protocols_hooks_ != 0)
01295     {
01296       // Initialize the protocols hooks instance.
01297       this->protocols_hooks_->init_hooks (this);
01298     }
01299 
01300   // If available, allow the Adapter Factory to setup.
01301   ACE_Service_Object *adapter_factory =
01302     ACE_Dynamic_Service<ACE_Service_Object>::instance (
01303       this->configuration (),
01304       this->orb_params ()->poa_factory_name ());
01305 
01306   if (adapter_factory != 0)
01307     {
01308       adapter_factory->init (0, 0);
01309     }
01310 
01311   // Look in the service repository for an instance of the
01312   // Network Priority Protocol Hooks.
01313   const ACE_CString &network_priority_protocols_hooks_name =
01314      TAO_ORB_Core_Static_Resources::instance ()->
01315        network_priority_protocols_hooks_name_;
01316 
01317   this->network_priority_protocols_hooks_ =
01318     ACE_Dynamic_Service<TAO_Network_Priority_Protocols_Hooks>::instance
01319     (this->configuration (),
01320      ACE_TEXT_CHAR_TO_TCHAR (network_priority_protocols_hooks_name.c_str()));
01321 
01322   if (this->network_priority_protocols_hooks_ != 0)
01323     {
01324       // Initialize the protocols hooks instance.
01325       this->network_priority_protocols_hooks_->init_hooks (this);
01326     }
01327 
01328   // As a last step perform initializations of the service callbacks
01329   this->services_callbacks_init ();
01330 
01331   // The ORB has been initialized, meaning that the ORB is no longer
01332   // in the shutdown state.
01333   this->has_shutdown_ = false;
01334 
01335   return 0;
01336 }
01337 
01338 
01339 int
01340 TAO_ORB_Core::fini (void)
01341 {
01342   try
01343     {
01344       // Shutdown the ORB and block until the shutdown is complete.
01345       this->shutdown (1);
01346     }
01347   catch (const ::CORBA::Exception& ex)
01348     {
01349       ACE_CString message =
01350         "Exception caught in trying to shutdown ";
01351       message += this->orbid_;
01352       message += "\n";
01353 
01354       ex._tao_print_exception (message.c_str ());
01355     }
01356 
01357   // Wait for any server threads, ignoring any failures.
01358   (void) this->thr_mgr ()->wait ();
01359 
01360   ::CORBA::release (this->implrepo_service_);
01361 
01362   ::CORBA::release (this->typecode_factory_);
01363 
01364   ::CORBA::release (this->codec_factory_);
01365 
01366   ::CORBA::release (this->dynany_factory_);
01367 
01368   ::CORBA::release (this->ior_manip_factory_);
01369 
01370   ::CORBA::release (this->ior_table_);
01371 
01372   if (TAO_debug_level > 2)
01373     {
01374       ACE_DEBUG ((LM_DEBUG,
01375                   ACE_TEXT ("Destroying ORB <%s>\n"),
01376                   ACE_TEXT_CHAR_TO_TCHAR (this->orbid_)));
01377     }
01378 
01379   // Finalize lane resources.
01380   //
01381   // @@ Do not call this->thread_lane_resources_manager().finalize().
01382   // this->thread_lane_manager_resources() can seg fault if the
01383   // factory method it invokes returns a zero pointer, which can
01384   // easily occur if the ORB is partially initialized due to a Service
01385   // Configurator initialization failure.  Instead check if the
01386   // cached pointer is non-zero and then finalize.
01387   //
01388   // @todo Fix potential seg fault in
01389   //       TAO_ORB_Core::thread_lane_resources_manager().
01390   if (this->thread_lane_resources_manager_ != 0)
01391     this->thread_lane_resources_manager_->finalize ();
01392 
01393   // Destroy the object_key table
01394   this->object_key_table_.destroy ();
01395 
01396   delete this;
01397 
01398   return 0;
01399 }
01400 
01401 void
01402 TAO_ORB_Core::set_resource_factory (const char *resource_factory_name)
01403 {
01404   TAO_ORB_Core_Static_Resources::instance ()->resource_factory_name_ =
01405     resource_factory_name;
01406 }
01407 
01408 void
01409 TAO_ORB_Core::set_gui_resource_factory (TAO::GUIResource_Factory *gui_resource_factory)
01410 {
01411   if (TAO_TSS_Resources::instance ()->gui_resource_factory_ != 0)
01412     {
01413       if (TAO_debug_level > 2)
01414         {
01415           ACE_DEBUG ((LM_DEBUG,
01416                       "TAO (%P|%t) - Deleting old gui_resource_factory.\n"));
01417         }
01418       delete TAO_TSS_Resources::instance ()->gui_resource_factory_;
01419     }
01420 
01421   TAO_TSS_Resources::instance ()->gui_resource_factory_ = gui_resource_factory;
01422 }
01423 
01424 void
01425 TAO_ORB_Core::dynamic_adapter_name (const char *name)
01426 {
01427   TAO_ORB_Core_Static_Resources::instance ()->dynamic_adapter_name_ = name;
01428 }
01429 
01430 const char *
01431 TAO_ORB_Core::dynamic_adapter_name (void)
01432 {
01433   return TAO_ORB_Core_Static_Resources::instance ()->dynamic_adapter_name_.c_str();
01434 }
01435 
01436 void
01437 TAO_ORB_Core::ifr_client_adapter_name (const char *name)
01438 {
01439   TAO_ORB_Core_Static_Resources::instance ()->ifr_client_adapter_name_ = name;
01440 }
01441 
01442 const char *
01443 TAO_ORB_Core::ifr_client_adapter_name (void)
01444 {
01445   return TAO_ORB_Core_Static_Resources::instance ()->ifr_client_adapter_name_.c_str();
01446 }
01447 
01448 void
01449 TAO_ORB_Core::typecodefactory_adapter_name (const char *name)
01450 {
01451   TAO_ORB_Core_Static_Resources::instance ()->typecodefactory_adapter_name_ = name;
01452 }
01453 
01454 const char *
01455 TAO_ORB_Core::typecodefactory_adapter_name (void)
01456 {
01457   return TAO_ORB_Core_Static_Resources::instance ()->typecodefactory_adapter_name_.c_str();
01458 }
01459 
01460 void
01461 TAO_ORB_Core::iorinterceptor_adapter_factory_name (const char *name)
01462 {
01463   TAO_ORB_Core_Static_Resources::instance ()->iorinterceptor_adapter_factory_name_ = name;
01464 }
01465 
01466 const char *
01467 TAO_ORB_Core::iorinterceptor_adapter_factory_name (void)
01468 {
01469   return TAO_ORB_Core_Static_Resources::instance ()->iorinterceptor_adapter_factory_name_.c_str();
01470 }
01471 
01472 void
01473 TAO_ORB_Core::valuetype_adapter_factory_name (const char *name)
01474 {
01475   TAO_ORB_Core_Static_Resources::instance ()->valuetype_adapter_factory_name_ = name;
01476 }
01477 
01478 const char *
01479 TAO_ORB_Core::valuetype_adapter_factory_name (void)
01480 {
01481   return TAO_ORB_Core_Static_Resources::instance ()->valuetype_adapter_factory_name_.c_str();
01482 }
01483 
01484 TAO_Resource_Factory *
01485 TAO_ORB_Core::resource_factory (void)
01486 {
01487   // Check if there is a cached reference.
01488   if (this->resource_factory_ != 0)
01489     {
01490       return this->resource_factory_;
01491     }
01492 
01493   // Look in the service repository for an instance.
01494   ACE_CString &resource_factory_name =
01495     TAO_ORB_Core_Static_Resources::instance ()->resource_factory_name_;
01496 
01497   this->resource_factory_ =
01498     ACE_Dynamic_Service<TAO_Resource_Factory>::instance
01499       (this->configuration (),
01500        ACE_TEXT_CHAR_TO_TCHAR (resource_factory_name.c_str()));
01501 
01502   return this->resource_factory_;
01503 }
01504 
01505 TAO::GUIResource_Factory *
01506 TAO_ORB_Core::gui_resource_factory (void)
01507 {
01508   return TAO_TSS_Resources::instance ()->gui_resource_factory_;
01509 }
01510 
01511 
01512 TAO_Thread_Lane_Resources_Manager &
01513 TAO_ORB_Core::thread_lane_resources_manager (void)
01514 {
01515   // Check if there is a cached reference.
01516   if (this->thread_lane_resources_manager_ != 0)
01517     return *this->thread_lane_resources_manager_;
01518 
01519   // If not, lookup the corresponding factory and ask it to make one.
01520   const char *thread_lane_resources_manager_factory_name =
01521     this->orb_params ()->thread_lane_resources_manager_factory_name ();
01522 
01523   TAO_Thread_Lane_Resources_Manager_Factory *factory =
01524     ACE_Dynamic_Service<TAO_Thread_Lane_Resources_Manager_Factory>::instance
01525       (this->configuration (),
01526        ACE_TEXT_CHAR_TO_TCHAR (thread_lane_resources_manager_factory_name));
01527 
01528   this->thread_lane_resources_manager_ =
01529     factory->create_thread_lane_resources_manager (*this);
01530 
01531   return *this->thread_lane_resources_manager_;
01532 }
01533 
01534 TAO_Collocation_Resolver &
01535 TAO_ORB_Core::collocation_resolver (void)
01536 {
01537   // Check if there is a cached reference.
01538   if (this->collocation_resolver_ != 0)
01539     return *this->collocation_resolver_;
01540 
01541   // If not, lookup it up.
01542   this->collocation_resolver_ =
01543     ACE_Dynamic_Service<TAO_Collocation_Resolver>::instance
01544       (this->configuration (),
01545        ACE_TEXT_CHAR_TO_TCHAR (this->orb_params ()->collocation_resolver_name ()));
01546 
01547   return *this->collocation_resolver_;
01548 }
01549 
01550 TAO::PolicyFactory_Registry_Adapter *
01551 TAO_ORB_Core::policy_factory_registry_i (void)
01552 {
01553 
01554   TAO_PolicyFactory_Registry_Factory *loader =
01555     ACE_Dynamic_Service<TAO_PolicyFactory_Registry_Factory>::instance
01556       (this->configuration (),
01557        ACE_TEXT ("PolicyFactory_Loader"));
01558 
01559   if (loader == 0)
01560     {
01561       this->configuration ()->process_directive (
01562         ACE_DYNAMIC_SERVICE_DIRECTIVE("PolicyFactory_Loader",
01563                                       "TAO_PI",
01564                                       "_make_TAO_PolicyFactory_Loader",
01565                                       ""));
01566       loader =
01567         ACE_Dynamic_Service<TAO_PolicyFactory_Registry_Factory>::instance
01568           (this->configuration (),
01569            ACE_TEXT ("PolicyFactory_Loader"));
01570     }
01571 
01572   if (loader != 0)
01573     {
01574       this->policy_factory_registry_ =
01575         loader->create ();
01576     }
01577 
01578   return this->policy_factory_registry_;
01579 }
01580 
01581 TAO::ORBInitializer_Registry_Adapter *
01582 TAO_ORB_Core::orbinitializer_registry_i (void)
01583 {
01584   // @todo The ORBInitializer_Registry is supposed to be a singleton.
01585 
01586   ACE_Service_Gestalt * const config = this->configuration ();
01587 
01588   // If not, lookup it up.
01589   this->orbinitializer_registry_ =
01590     ACE_Dynamic_Service<TAO::ORBInitializer_Registry_Adapter>::instance
01591       (config,
01592        ACE_TEXT ("ORBInitializer_Registry"));
01593 
01594 #if !defined (TAO_AS_STATIC_LIBS)
01595       // In case we build shared, try to load the PI Client library, in a
01596       // static build we just can't do this, so don't try it, lower layers
01597       // output an error then.
01598   if (this->orbinitializer_registry_ == 0)
01599     {
01600       config->process_directive (
01601         ACE_DYNAMIC_SERVICE_DIRECTIVE ("ORBInitializer_Registry",
01602                                        "TAO_PI",
01603                                        "_make_ORBInitializer_Registry",
01604                                        ""));
01605       this->orbinitializer_registry_ =
01606         ACE_Dynamic_Service<TAO::ORBInitializer_Registry_Adapter>::instance
01607           (config,
01608            ACE_TEXT ("ORBInitializer_Registry"));
01609     }
01610 #endif /* !TAO_AS_STATIC_LIBS */
01611 
01612   return this->orbinitializer_registry_;
01613 }
01614 
01615 TAO_Stub_Factory *
01616 TAO_ORB_Core::stub_factory (void)
01617 {
01618   // Check if there is a cached reference.
01619   if (this->stub_factory_ != 0)
01620     return this->stub_factory_;
01621 
01622   // If not, look in the service repository for an instance.
01623   const char *stub_factory_name =
01624     this->orb_params ()->stub_factory_name ();
01625 
01626   this->stub_factory_ =
01627     ACE_Dynamic_Service<TAO_Stub_Factory>::instance
01628       (this->configuration (),
01629        ACE_TEXT_CHAR_TO_TCHAR (stub_factory_name));
01630 
01631   return this->stub_factory_;
01632 }
01633 
01634 TAO_Endpoint_Selector_Factory *
01635 TAO_ORB_Core::endpoint_selector_factory (void)
01636 {
01637   // Check if there is a cached reference.
01638   if (this->endpoint_selector_factory_ != 0)
01639     return this->endpoint_selector_factory_;
01640 
01641   // If not, look in the service repository for an instance.
01642   const char* endpoint_selector_factory_name =
01643     this->orb_params ()->endpoint_selector_factory_name ();
01644 
01645   this->endpoint_selector_factory_ =
01646     ACE_Dynamic_Service<TAO_Endpoint_Selector_Factory>::instance
01647       (this->configuration (),
01648        ACE_TEXT_CHAR_TO_TCHAR (endpoint_selector_factory_name));
01649 
01650   return this->endpoint_selector_factory_;
01651 }
01652 
01653 void
01654 TAO_ORB_Core::set_network_priority_protocols_hooks (
01655   const char *network_priority_protocols_hooks_name)
01656 {
01657   // Is synchronization necessary?
01658   TAO_ORB_Core_Static_Resources::instance ()->
01659     network_priority_protocols_hooks_name_ =
01660       network_priority_protocols_hooks_name;
01661 }
01662 
01663 void
01664 TAO_ORB_Core::services_callbacks_init (void)
01665 {
01666   // We (should) know what are the services that would need
01667   // callbacks. So, what we do is go through the Service Configurator
01668   // list for looking at the services that we want to load.
01669   this->ft_service_.init (this);
01670 
01671   // @@ Other service callbacks can be added here
01672 }
01673 
01674 TAO::Invocation_Status
01675 TAO_ORB_Core::service_raise_comm_failure (
01676     IOP::ServiceContextList &clist,
01677     TAO_Profile *profile)
01678 {
01679   if (this->ft_service_.service_callback ())
01680     {
01681       return this->ft_service_.service_callback ()->
01682                  raise_comm_failure (clist, profile);
01683     }
01684 
01685   throw ::CORBA::COMM_FAILURE (
01686     CORBA::SystemException::_tao_minor_code (
01687       TAO_INVOCATION_RECV_REQUEST_MINOR_CODE,
01688       errno),
01689     CORBA::COMPLETED_MAYBE);
01690 }
01691 
01692 
01693 TAO::Invocation_Status
01694 TAO_ORB_Core::service_raise_transient_failure (
01695     IOP::ServiceContextList &clist,
01696     TAO_Profile *profile)
01697 {
01698   if (this->ft_service_.service_callback ())
01699     {
01700       return
01701         this->ft_service_.service_callback ()->raise_transient_failure (clist,
01702                                  profile);
01703     }
01704 
01705   return TAO::TAO_INVOKE_FAILURE;
01706 }
01707 
01708 void
01709 TAO_ORB_Core::service_context_list (
01710     TAO_Stub *stub,
01711     TAO_Service_Context &service_context,
01712     CORBA::Boolean restart)
01713 {
01714   // @NOTE: Can use Interceptors instead..
01715   if (this->protocols_hooks_ != 0)
01716     {
01717       this->protocols_hooks_->rt_service_context (stub, service_context, restart);
01718     }
01719 
01720   // call the network priority protocols hooks that has been
01721   // registered.
01722   if (network_priority_protocols_hooks_ != 0)
01723     {
01724       this->network_priority_protocols_hooks_->np_service_context (stub,
01725         service_context, restart);
01726     }
01727 }
01728 
01729 TAO_Client_Strategy_Factory *
01730 TAO_ORB_Core::client_factory (void)
01731 {
01732   if (this->client_factory_ == 0)
01733     {
01734       // Look in the service repository for an instance.
01735       this->client_factory_ =
01736         ACE_Dynamic_Service<TAO_Client_Strategy_Factory>::instance
01737           (this->configuration (),
01738            ACE_TEXT ("Client_Strategy_Factory"));
01739     }
01740 
01741   return this->client_factory_;
01742 }
01743 
01744 TAO_Server_Strategy_Factory *
01745 TAO_ORB_Core::server_factory (void)
01746 {
01747   if (this->server_factory_ == 0)
01748     {
01749       // Look in the service repository for an instance.
01750       this->server_factory_ =
01751         ACE_Dynamic_Service<TAO_Server_Strategy_Factory>::instance
01752           (this->configuration (),
01753            ACE_TEXT ("Server_Strategy_Factory"));
01754     }
01755 
01756   return this->server_factory_;
01757 }
01758 
01759 CORBA::Object_ptr
01760 TAO_ORB_Core::root_poa (void)
01761 {
01762   // DCL ..
01763   if (CORBA::is_nil (this->root_poa_.in ()))
01764     {
01765 
01766       // Making sure the initialization process in the current thread uses
01767       // the correct service repository (ours), instead of the global one.
01768       ACE_Service_Config_Guard scg (this->configuration ());
01769 
01770       TAO_Adapter_Factory *factory =
01771         ACE_Dynamic_Service<TAO_Adapter_Factory>::instance
01772           (this->configuration (),
01773           this->orb_params ()->poa_factory_name ());
01774 
01775       if (factory == 0)
01776         {
01777           this->configuration()->process_directive (
01778            ACE_TEXT_CHAR_TO_TCHAR (
01779              this->orb_params ()->poa_factory_directive ()));
01780 
01781           factory =
01782             ACE_Dynamic_Service<TAO_Adapter_Factory>::instance
01783               (this->configuration (),
01784               this->orb_params ()->poa_factory_name ());
01785         }
01786 
01787       if (factory == 0)
01788         {
01789           return CORBA::Object::_nil ();
01790         }
01791 
01792       ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
01793                         monitor,
01794                         this->open_lock_,
01795                         0);
01796 
01797       if (CORBA::is_nil (this->root_poa_.in ()))
01798         {
01799           auto_ptr<TAO_Adapter> poa_adapter (factory->create (this));
01800 
01801           poa_adapter->open ();
01802 
01803           // @@ Not exception safe
01804           this->root_poa_ = poa_adapter->root ();
01805 
01806           this->adapter_registry_.insert (poa_adapter.get ());
01807 
01808           poa_adapter.release ();
01809         }
01810     }
01811 
01812   return CORBA::Object::_duplicate (this->root_poa_.in ());
01813 }
01814 
01815 TAO_Adapter *
01816 TAO_ORB_Core::poa_adapter (void)
01817 {
01818   if (this->poa_adapter_ == 0)
01819     {
01820       ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
01821       if (this->poa_adapter_ == 0)
01822         {
01823           this->poa_adapter_ =
01824             this->adapter_registry_.find_adapter ("RootPOA");
01825         }
01826     }
01827   return this->poa_adapter_;
01828 }
01829 
01830 TAO_Stub *
01831 TAO_ORB_Core::create_stub (const char *repository_id,
01832                            const TAO_MProfile &profiles)
01833 {
01834   TAO_Stub *retval =
01835     this->stub_factory ()->create_stub (repository_id, profiles, this);
01836   return retval;
01837 }
01838 
01839 void
01840 TAO_ORB_Core::request_dispatcher (TAO_Request_Dispatcher *request_dispatcher)
01841 {
01842   // Assume ownership of the request dispatcher.
01843   TAO_Request_Dispatcher *tmp = this->request_dispatcher_;
01844   this->request_dispatcher_ = request_dispatcher;
01845   delete tmp;
01846 }
01847 
01848 TAO_Stub *
01849 TAO_ORB_Core::create_stub_object (TAO_MProfile &mprofile,
01850                                   const char *type_id,
01851                                   CORBA::PolicyList *policy_list)
01852 {
01853   // Add the Polices contained in "policy_list" to each profile so
01854   // that those policies will be exposed to the client in the IOR.  In
01855   // particular each CORBA::Policy has to be converted in to
01856   // Messaging::PolicyValue, and then all the Messaging::PolicyValue
01857   // should be embedded inside a Messaging::PolicyValueSeq which
01858   // became in turns the "body" of the IOP::TaggedComponent. This
01859   // conversion is a responsability of the CORBA::Profile class.  (See
01860   // orbos\98-05-05.pdf Section 5.4)
01861   if (policy_list->length () != 0)
01862     {
01863       TAO_Profile * profile = 0;
01864 
01865       CORBA::ULong const count = mprofile.profile_count ();
01866       for (CORBA::ULong i = 0; i < count; ++i)
01867         {
01868           // Get the ith profile
01869           profile = mprofile.get_profile (i);
01870           profile->policies (policy_list);
01871         }
01872     }
01873 
01874   /// Initialize a TAO_Stub object with the mprofile thats passed.
01875   TAO_Stub *stub = this->create_stub (type_id, mprofile);
01876 
01877   stub->base_profiles ().policy_list (policy_list);
01878 
01879   return stub;
01880 }
01881 
01882 void
01883 TAO_ORB_Core::load_policy_validators (TAO_Policy_Validator &validator)
01884 {
01885   if (this->bidir_adapter_ == 0)
01886     {
01887       this->bidir_adapter_ =
01888         ACE_Dynamic_Service<TAO_BiDir_Adapter>::instance
01889           (this->configuration (), ACE_TEXT ("BiDirGIOP_Loader"));
01890     }
01891 
01892   // Call the BiDir library if it has been loaded
01893   if (this->bidir_adapter_)
01894     this->bidir_adapter_->load_policy_validators (validator);
01895 }
01896 
01897 CORBA::Object_ptr
01898 TAO_ORB_Core::create_object (TAO_Stub *stub)
01899 {
01900   // @@ What about forwarding.  With this approach we are never forwarded
01901   //    when we use collocation!
01902   const TAO_MProfile &mprofile = stub->base_profiles ();
01903 
01904   // @@ We should thow CORBA::NO_MEMORY in platforms with exceptions,
01905   // but we are stuck in platforms without exceptions!
01906   TAO_ORB_Core_Auto_Ptr collocated_orb_core;
01907   CORBA::Object_ptr x = 0;
01908 
01909   {
01910     // Lock the ORB_Table against concurrent modification while we
01911     // iterate through the ORBs.
01912     ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
01913                       guard,
01914                       TAO::ORB_Table::instance()->lock (),
01915                       CORBA::Object::_nil ());
01916 
01917     TAO::ORB_Table * const table = TAO::ORB_Table::instance ();
01918     TAO::ORB_Table::iterator const end = table->end ();
01919     for (TAO::ORB_Table::iterator i = table->begin (); i != end; ++i)
01920       {
01921         ::TAO_ORB_Core * const other_core = (*i).second.core ();
01922 
01923         if (this->is_collocation_enabled (other_core, mprofile))
01924           {
01925             other_core->_incr_refcnt();
01926              TAO_ORB_Core_Auto_Ptr tmp_auto_ptr (other_core);
01927              collocated_orb_core = tmp_auto_ptr;
01928             break;
01929           }
01930       }
01931   }
01932 
01933   if (collocated_orb_core.get ())
01934     {
01935       TAO_Adapter_Registry *ar =
01936         collocated_orb_core.get ()->adapter_registry ();
01937 
01938       x = ar->create_collocated_object (stub, mprofile);
01939     }
01940 
01941 
01942   if (!x)
01943     {
01944       // The constructor sets the proxy broker as the
01945       // Remote one.
01946       ACE_NEW_RETURN (x,
01947                       CORBA::Object (stub, 0),
01948                       0);
01949     }
01950 
01951   return x;
01952 }
01953 
01954 CORBA::Long
01955 TAO_ORB_Core::initialize_object (TAO_Stub *stub, CORBA::Object_ptr)
01956 {
01957   // @@ What about forwarding.  With this approach we are never forwarded
01958   //    when we use collocation!
01959   const TAO_MProfile &mprofile =
01960     stub->base_profiles ();
01961 
01962   return initialize_object_i (stub, mprofile);
01963 }
01964 
01965 CORBA::Long
01966 TAO_ORB_Core::reinitialize_object (TAO_Stub *stub)
01967 {
01968   return initialize_object_i (stub, stub->forward_profiles ()
01969                                     ? *(stub->forward_profiles ())
01970                                     : stub->base_profiles ());
01971 }
01972 
01973 CORBA::Long
01974 TAO_ORB_Core::initialize_object_i (TAO_Stub *stub, const TAO_MProfile &mprofile)
01975 
01976 {
01977   CORBA::Long retval = 0;
01978   TAO_ORB_Core_Auto_Ptr collocated_orb_core;
01979 
01980   {
01981     // Lock the ORB_Table against concurrent modification while we
01982     // iterate through the ORBs.
01983     ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
01984                               guard,
01985                               TAO::ORB_Table::instance()->lock (),
01986                               0));
01987 
01988     TAO::ORB_Table * const table = TAO::ORB_Table::instance ();
01989     TAO::ORB_Table::iterator const end = table->end ();
01990     for (TAO::ORB_Table::iterator i = table->begin (); i != end; ++i)
01991       {
01992         TAO_ORB_Core * const other_core = (*i).second.core ();
01993 
01994         if (this->is_collocation_enabled (other_core,
01995                                           mprofile))
01996           {
01997             other_core->_incr_refcnt ();
01998             TAO_ORB_Core_Auto_Ptr tmp_auto_ptr (other_core);
01999             collocated_orb_core = tmp_auto_ptr;
02000             break;
02001           }
02002       }
02003   }
02004 
02005   if (collocated_orb_core.get ())
02006     {
02007       TAO_Adapter_Registry *ar =
02008         collocated_orb_core.get ()->adapter_registry ();
02009 
02010       retval = ar->initialize_collocated_object (stub);
02011     }
02012 
02013   return retval;
02014 }
02015 
02016 CORBA::Boolean
02017 TAO_ORB_Core::is_collocation_enabled (TAO_ORB_Core *orb_core,
02018                                       const TAO_MProfile &mp)
02019 {
02020   TAO_MProfile mp_temp;
02021 
02022   TAO_Profile* profile = 0;
02023   if (this->service_profile_selection(mp, profile) && profile)
02024   {
02025     mp_temp.add_profile(profile);
02026   }
02027 
02028   if (!orb_core->optimize_collocation_objects ())
02029     return 0;
02030 
02031   if (!orb_core->use_global_collocation () && orb_core != this)
02032     return 0;
02033 
02034   if (!orb_core->is_collocated (profile ? mp_temp : mp))
02035     return 0;
02036 
02037   return 1;
02038 }
02039 
02040 int
02041 TAO_ORB_Core::is_collocated (const TAO_MProfile& mprofile)
02042 {
02043   // @@ Lots of issues arise when dealing with collocation.  What about
02044   //    forwarding or what if this is a multi-profile IOR where the order is
02045   //    significant and only one of the profiles is collocated.  For example
02046   //    when using a multiple servers for fault tolerance.  For now, we just
02047   //    look through all profiles and if any are colocated then we assume
02048   //    the object is collocated.
02049   // @@ Note, if collocated we can not be forwarded!
02050   //    Also, acceptor_registry_->is_collocated (...) will check the
02051   //    address (ORB Host) but not the object_key.  This should be checked
02052   //    also.
02053 
02054   return this->thread_lane_resources_manager ().is_collocated (mprofile);
02055 }
02056 
02057 // ****************************************************************
02058 
02059 TAO_Leader_Follower &
02060 TAO_ORB_Core::leader_follower (void)
02061 {
02062   return this->lane_resources ().leader_follower ();
02063 }
02064 
02065 TAO_LF_Strategy &
02066 TAO_ORB_Core::lf_strategy (void)
02067 {
02068   return this->thread_lane_resources_manager ().lf_strategy ();
02069 }
02070 
02071 int
02072 TAO_ORB_Core::run (ACE_Time_Value *tv, int perform_work)
02073 {
02074   // ORB::run may be called from a thread, different from the one that
02075   // did the ORB_init, consequently we must establish the Service
02076   // Gestalt, this thread will consider "global"
02077 
02078   ACE_Service_Config_Guard use_orbs (this->configuration());
02079 
02080   if (TAO_debug_level > 2)
02081     {
02082       ACE_DEBUG ((LM_DEBUG,
02083                   ACE_TEXT ("TAO (%P|%t) - ORB_Core::run, ")
02084                   ACE_TEXT ("start [%s]\n"),
02085                   perform_work?ACE_TEXT("perform_work"):ACE_TEXT("run")));
02086     }
02087 
02088   // Fetch the Reactor
02089   ACE_Reactor *r = this->reactor ();
02090 
02091   int result = 1;
02092   // 1 to detect that nothing went wrong
02093 
02094   // Loop handling client requests until the ORB is shutdown.
02095 
02096   // We could use the leader-follower lock to check for the state
02097   // if this variable or use the lock <create_event_loop_lock> in
02098   // the server strategy factory.
02099   // We don't need to do this because we use the Reactor
02100   // mechanisms to shutdown in a thread-safe way.
02101 
02102   while (this->has_shutdown () == false)
02103     {
02104       // Every time we perform an interation we have to become the
02105       // leader again, because it is possible that a client has
02106       // acquired the leader role...
02107       TAO_Leader_Follower &leader_follower =
02108         this->leader_follower ();
02109 
02110       TAO_LF_Strategy &lf_strategy =
02111         this->lf_strategy ();
02112 
02113       TAO_LF_Event_Loop_Thread_Helper helper (leader_follower,
02114                                               lf_strategy,
02115                                               tv);
02116       result = helper.event_loop_return ();
02117       if (result != 0)
02118         {
02119           if (errno == ETIME)
02120             return 0;
02121           else
02122             return result;
02123         }
02124 
02125       // Set the owning thread of the Reactor to the one which we're
02126       // currently in.  This is necessary b/c it's possible that the
02127       // application is calling us from a thread other than that in which
02128       // the Reactor's CTOR (which sets the owner) was called.
02129       //
02130       // We need to do this on every iteration because the reactor may be
02131       // acquired by one of the client threads in the LF waiting
02132       // strategy
02133       r->owner (ACE_Thread::self ());
02134 
02135       if (TAO_debug_level > 2)
02136         {
02137           ACE_DEBUG ((LM_DEBUG,
02138                       ACE_TEXT ("TAO (%P|%t) - ORB_Core::run, ")
02139                       ACE_TEXT ( "calling handle_events()\n")));
02140         }
02141 
02142       result = r->handle_events (tv);
02143 
02144       if (TAO_debug_level > 2)
02145         {
02146           ACE_DEBUG ((LM_DEBUG,
02147                       ACE_TEXT ("TAO (%P|%t) - ORB_Core::run, ")
02148                       ACE_TEXT ("handle_events() returns %d\n"),
02149                       result));
02150         }
02151 
02152       if (result == -1)
02153         {
02154           // An error, terminate the loop
02155           break;
02156         }
02157       if (result == 0
02158           && tv != 0
02159           && *tv == ACE_Time_Value::zero)
02160         {
02161           // A timeout, terminate the loop...
02162           break;
02163         }
02164 
02165       if (perform_work)
02166         {
02167           // This is running on behalf of a perform_work() call,
02168           // The loop should run only once.
02169           break;
02170         }
02171       // Otherwise just continue..
02172     }
02173 
02174   if (this->has_shutdown () == true &&
02175       this->server_factory_->activate_server_connections ())
02176       this->tm_.wait ();
02177 
02178   if (TAO_debug_level > 2)
02179     {
02180       ACE_DEBUG ((LM_DEBUG,
02181                   ACE_TEXT ("TAO (%P|%t) - ORB_Core::run, ")
02182                   ACE_TEXT ("ends with result = %d\n"),
02183                   result));
02184     }
02185 
02186   return result;
02187 }
02188 
02189 
02190 void
02191 TAO_ORB_Core::shutdown (CORBA::Boolean wait_for_completion)
02192 {
02193   {
02194     ACE_GUARD (TAO_SYNCH_MUTEX, monitor, this->lock_);
02195 
02196     if (this->has_shutdown () == true)
02197       return;
02198 
02199     // Check if we are on the right state, i.e. do not accept
02200     // shutdowns with the 'wait_for_completion' flag set in the middle
02201     // of an upcall (because those deadlock).
02202     this->adapter_registry_.check_close (wait_for_completion);
02203 
02204     // Set the 'has_shutdown' flag, so any further attempt to shutdown
02205     // becomes a noop.
02206     this->has_shutdown_ = true;
02207 
02208     // need to release the mutex, because some of the shutdown
02209     // operations invoke application code, that could (and in practice
02210     // does!) callback into ORB Core code.
02211   }
02212 
02213   this->adapter_registry_.close (wait_for_completion);
02214 
02215   // Shutdown reactor.
02216   this->thread_lane_resources_manager ().shutdown_reactor ();
02217 
02218   // Cleanup transports that use the RW strategies
02219   this->thread_lane_resources_manager ().cleanup_rw_transports ();
02220 
02221   // Grab the thread manager
02222   ACE_Thread_Manager *tm = this->thr_mgr ();
02223 
02224   // Try to cancel all the threads in the ORB.
02225   tm->cancel_all ();
02226 
02227   // If <wait_for_completion> is set, wait for all threads to exit.
02228   if (wait_for_completion != 0)
02229     tm->wait ();
02230 
02231   // Explicitly destroy the valuetype adapter
02232   delete this->valuetype_adapter_;
02233   this->valuetype_adapter_ = 0;
02234 
02235   // Explicitly destroy the object reference table since it
02236   // contains references to objects, which themselves may contain
02237   // reference to this ORB.
02238   this->object_ref_table_.destroy ();
02239 
02240 #if (TAO_HAS_INTERCEPTORS == 1)
02241   CORBA::release (this->pi_current_);
02242   this->pi_current_ = CORBA::Object::_nil ();
02243 #endif  /* TAO_HAS_INTERCEPTORS == 1 */
02244 }
02245 
02246 void
02247 TAO_ORB_Core::destroy (void)
02248 {
02249   //
02250   // All destroy() should do is (a) call shutdown() and (b) unbind()
02251   // from the ORB table.  Nothing else should really be added to this
02252   // method.  Everything else should go to the shutdown() method.
02253   // Remember when the ORB Core is finally removed from the ORB table,
02254   // the reference count goes to zero and fini() is called.  fini()
02255   // calls shutdown() and does not call destroy() since destroy() will
02256   // try to unbind from the ORB table again.  Additional code should
02257   // not be added to destroy() since there is no guarantee that
02258   // orb->destroy() will ever be called by the user.  Since TAO
02259   // guarantees that shutdown() will be called, all cleanup code
02260   // should go there.
02261   //
02262 
02263   // Shutdown the ORB and block until the shutdown is complete.
02264   this->shutdown (1);
02265 
02266   // Invoke Interceptor::destroy() on all registered interceptors.
02267   this->destroy_interceptors ();
02268 
02269   // Now remove it from the ORB table so that it's ORBid may be
02270   // reused.
02271   TAO::ORB_Table::instance ()->unbind (this->orbid_);
02272 }
02273 
02274 void
02275 TAO_ORB_Core::check_shutdown (void)
02276 {
02277   if (this->has_shutdown ())
02278     {
02279       // As defined by the CORBA 2.3 specification, throw a
02280       // CORBA::BAD_INV_ORDER exception with minor code 4 if the ORB
02281       // has shutdown by the time an ORB function is called.
02282 
02283       throw ::CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 4, CORBA::COMPLETED_NO);
02284     }
02285 }
02286 
02287 void
02288 TAO_ORB_Core::destroy_interceptors (void)
02289 {
02290   try
02291     {
02292       ACE_GUARD (TAO_SYNCH_MUTEX, monitor, this->lock_);
02293 
02294 #if TAO_HAS_INTERCEPTORS == 1
02295       if (this->client_request_interceptor_adapter_ != 0)
02296         {
02297           this->client_request_interceptor_adapter_->destroy_interceptors ();
02298 
02299           delete this->client_request_interceptor_adapter_;
02300           this->client_request_interceptor_adapter_ = 0;
02301         }
02302 
02303       if (this->server_request_interceptor_adapter_ != 0)
02304         {
02305           this->server_request_interceptor_adapter_->destroy_interceptors ();
02306 
02307           delete this->server_request_interceptor_adapter_;
02308           this->server_request_interceptor_adapter_ = 0;
02309         }
02310 
02311 #endif  /* TAO_HAS_INTERCEPTORS == 1 */
02312 
02313       if (this->ior_interceptor_adapter_ != 0)
02314         {
02315           this->ior_interceptor_adapter_->destroy_interceptors ();
02316 
02317           this->ior_interceptor_adapter_ = 0;
02318         }
02319 
02320     }
02321   catch (...)
02322     {
02323       // .. catch all the exceptions..
02324       if (TAO_debug_level > 3)
02325         {
02326           ACE_DEBUG ((LM_DEBUG,
02327                       ACE_TEXT ("TAO (%P|%t) - Exception in TAO_ORB_Core")
02328                       ACE_TEXT ("::destroy_interceptors () \n")));
02329         }
02330     }
02331 
02332   return;
02333 }
02334 
02335 TAO_Thread_Lane_Resources &
02336 TAO_ORB_Core::lane_resources (void)
02337 {
02338   return this->thread_lane_resources_manager ().lane_resources ();
02339 }
02340 
02341 void
02342 TAO_ORB_Core::resolve_typecodefactory_i (void)
02343 {
02344   TAO_Object_Loader *loader =
02345     ACE_Dynamic_Service<TAO_Object_Loader>::instance
02346       (this->configuration (),
02347        ACE_TEXT ("TypeCodeFactory_Loader"));
02348 
02349   if (loader == 0)
02350     {
02351       this->configuration ()->process_directive
02352         (ACE_DYNAMIC_SERVICE_DIRECTIVE("TypeCodeFactory",
02353                                        "TAO_TypeCodeFactory",
02354                                        "_make_TAO_TypeCodeFactory_Loader",
02355                                        ""));
02356       loader =
02357         ACE_Dynamic_Service<TAO_Object_Loader>::instance
02358         (this->configuration (),
02359          ACE_TEXT ("TypeCodeFactory_Loader"));
02360 
02361       if (loader == 0)
02362         {
02363           ACE_ERROR ((LM_ERROR,
02364                       ACE_TEXT ("(%P|%t) Unable to instantiate ")
02365                       ACE_TEXT ("a TypeCodeFactory_Loader\n")));
02366           throw ::CORBA::ORB::InvalidName ();
02367         }
02368     }
02369 
02370   this->typecode_factory_ =
02371     loader->create_object (this->orb_, 0, 0);
02372 }
02373 
02374 void
02375 TAO_ORB_Core::resolve_codecfactory_i (void)
02376 {
02377   TAO_Object_Loader *loader =
02378     ACE_Dynamic_Service<TAO_Object_Loader>::instance
02379       (this->configuration (),
02380        ACE_TEXT ("CodecFactory_Loader"));
02381 
02382   if (loader == 0)
02383     {
02384       this->configuration()->process_directive
02385         (ACE_DYNAMIC_SERVICE_DIRECTIVE("CodecFactory",
02386                                        "TAO_CodecFactory",
02387                                        "_make_TAO_CodecFactory_Loader",
02388                                        ""));
02389       loader =
02390         ACE_Dynamic_Service<TAO_Object_Loader>::instance
02391           (this->configuration (), ACE_TEXT ("CodecFactory_Loader"));
02392     }
02393 
02394   if (loader != 0)
02395     {
02396       this->codec_factory_ =
02397         loader->create_object (this->orb_, 0, 0);
02398     }
02399 }
02400 
02401 void
02402 TAO_ORB_Core::resolve_compression_manager_i (void)
02403 {
02404   TAO_Object_Loader *loader =
02405     ACE_Dynamic_Service<TAO_Object_Loader>::instance
02406       (this->configuration (),
02407        ACE_TEXT ("Compression_Loader"));
02408 
02409   if (loader == 0)
02410     {
02411       this->configuration()->process_directive
02412         (ACE_DYNAMIC_SERVICE_DIRECTIVE("Compression",
02413                                        "TAO_Compression",
02414                                        "_make_TAO_Compression_Loader",
02415                                        ""));
02416       loader =
02417         ACE_Dynamic_Service<TAO_Object_Loader>::instance
02418           (this->configuration (), ACE_TEXT ("Compression_Loader"));
02419     }
02420 
02421   if (loader != 0)
02422     {
02423       this->compression_manager_ = loader->create_object (this->orb_, 0, 0);
02424     }
02425 }
02426 
02427 void
02428 TAO_ORB_Core::resolve_poa_current_i (void)
02429 {
02430   TAO_Object_Loader *loader =
02431     ACE_Dynamic_Service<TAO_Object_Loader>::instance
02432       (this->configuration(),
02433        ACE_TEXT ("TAO_POA_Current_Factory"));
02434 
02435   if (loader == 0)
02436     {
02437       this->configuration()->process_directive
02438         (ACE_DYNAMIC_SERVICE_DIRECTIVE("TAO_POA_Current_Factory",
02439                                        "TAO_PortableServer",
02440                                        "_make_TAO_POA_Current_Factory",
02441                                        ""));
02442       loader =
02443         ACE_Dynamic_Service<TAO_Object_Loader>::instance
02444           (this->configuration(), ACE_TEXT ("TAO_POA_Current_Factory"));
02445     }
02446 
02447   if (loader != 0)
02448     {
02449       this->poa_current_ = loader->create_object (this->orb_, 0, 0);
02450     }
02451 }
02452 
02453 
02454 #if TAO_HAS_INTERCEPTORS == 1
02455 
02456 void
02457 TAO_ORB_Core::resolve_picurrent_i (void)
02458 {
02459   TAO_Object_Loader *loader =
02460     ACE_Dynamic_Service<TAO_Object_Loader>::instance
02461       (this->configuration (),
02462        ACE_TEXT ("PICurrent_Loader"));
02463 
02464   if (loader == 0)
02465     {
02466       this->configuration ()->process_directive
02467         (ACE_DYNAMIC_SERVICE_DIRECTIVE("PICurrent_Loader",
02468                                        "TAO_PI",
02469                                        "_make_TAO_PICurrent_Loader",
02470                                        ""));
02471       loader =
02472         ACE_Dynamic_Service<TAO_Object_Loader>::instance
02473           (this->configuration (), ACE_TEXT ("PICurrent_Loader"));
02474     }
02475 
02476   if (loader != 0)
02477     {
02478       CORBA::Object_ptr pi = loader->create_object (this->orb_, 0, 0);
02479 
02480       this->pi_current_ = pi;
02481     }
02482 }
02483 
02484 #endif /* TAO_HAS_INTERCEPTORS == 1 */
02485 
02486 
02487 void
02488 TAO_ORB_Core::resolve_dynanyfactory_i (void)
02489 {
02490   TAO_Object_Loader *loader =
02491     ACE_Dynamic_Service<TAO_Object_Loader>::instance
02492       (this->configuration (),
02493        ACE_TEXT ("DynamicAny_Loader"));
02494 
02495   if (loader == 0)
02496     {
02497       this->configuration ()->process_directive
02498         (ACE_DYNAMIC_SERVICE_DIRECTIVE("DynamicAny_Loader",
02499                                        "TAO_DynamicAny",
02500                                        "_make_TAO_DynamicAny_Loader",
02501                                        ""));
02502       loader =
02503         ACE_Dynamic_Service<TAO_Object_Loader>::instance
02504         (this->configuration (),
02505          ACE_TEXT ("DynamicAny_Loader"));
02506     }
02507 
02508   if (loader != 0)
02509     {
02510       this->dynany_factory_ = loader->create_object (this->orb_, 0, 0);
02511     }
02512 }
02513 
02514 void
02515 TAO_ORB_Core::resolve_iormanipulation_i (void)
02516 {
02517   TAO_Object_Loader *loader =
02518     ACE_Dynamic_Service<TAO_Object_Loader>::instance
02519       (this->configuration (),
02520        ACE_TEXT ("IORManip_Loader"));
02521 
02522   if (loader == 0)
02523     {
02524       this->configuration()->process_directive
02525         (ACE_DYNAMIC_SERVICE_DIRECTIVE("IORManip_Loader",
02526                                        "TAO_IORManip",
02527                                        "_make_TAO_IORManip_Loader",
02528                                        ""));
02529       loader =
02530         ACE_Dynamic_Service<TAO_Object_Loader>::instance
02531           (this->configuration (), ACE_TEXT ("IORManip_Loader"));
02532     }
02533 
02534   if (loader != 0)
02535     {
02536       this->ior_manip_factory_ = loader->create_object (this->orb_, 0, 0);
02537     }
02538 }
02539 
02540 void
02541 TAO_ORB_Core::resolve_ior_table_i (void)
02542 {
02543   TAO_Adapter_Factory *factory =
02544     ACE_Dynamic_Service<TAO_Adapter_Factory>::instance
02545       (this->configuration (),
02546        ACE_TEXT ("TAO_IORTable"));
02547 
02548   if (factory == 0)
02549     {
02550       this->configuration ()->process_directive
02551         (ACE_DYNAMIC_SERVICE_DIRECTIVE("TAO_IORTable",
02552                                        "TAO_IORTable",
02553                                        "_make_TAO_Table_Adapter_Factory",
02554                                        ""));
02555       factory =
02556         ACE_Dynamic_Service<TAO_Adapter_Factory>::instance
02557           (this->configuration (), ACE_TEXT ("TAO_IORTable"));
02558     }
02559 
02560   if (factory != 0)
02561     {
02562       ACE_Auto_Ptr <TAO_Adapter> iortable_adapter (factory->create (this));
02563       iortable_adapter->open ();
02564 
02565       CORBA::Object_var tmp_root = iortable_adapter->root ();
02566 
02567       this->adapter_registry_.insert (iortable_adapter.get ());
02568 
02569       // It is now (exception) safe to release ownership from the auto pointers
02570       this->ior_table_= tmp_root._retn ();
02571       iortable_adapter.release ();
02572     }
02573 }
02574 
02575 int
02576 TAO_ORB_Core::set_endpoint_helper (const ACE_CString &lane,
02577                                    const ACE_CString &endpoints)
02578 {
02579   if (this->orb_params ()->add_endpoints (lane,
02580                                           endpoints) != 0)
02581     {
02582       ACE_ERROR ((LM_ERROR,
02583                   ACE_TEXT ("(%P|%t)\n")
02584                   ACE_TEXT ("Invalid endpoint(s) specified:\n%s\n"),
02585                   ACE_TEXT_CHAR_TO_TCHAR(endpoints.c_str ())));
02586       throw ::CORBA::BAD_PARAM (
02587         CORBA::SystemException::_tao_minor_code (
02588           TAO_ORB_CORE_INIT_LOCATION_CODE,
02589           EINVAL),
02590         CORBA::COMPLETED_NO);
02591     }
02592 
02593   return 0;
02594 }
02595 
02596 CORBA::Object_ptr
02597 TAO_ORB_Core::resolve_rir (const char *name)
02598 {
02599   // Get the table of initial references specified through
02600   // -ORBInitRef.
02601   ACE_CString ior;
02602   ACE_CString object_id ((const char *) name);
02603 
02604   // Get the list of initial reference prefixes specified through
02605   // -ORBDefaultInitRef.
02606   CORBA::String_var default_init_ref =
02607     this->orb_params ()->default_init_ref ();
02608 
02609   // Check if a DefaultInitRef was specified.
02610   if (ACE_OS::strlen (default_init_ref.in ()) != 0)
02611     {
02612       static const char corbaloc_prefix[] = "corbaloc:";
02613       static const char mcast_prefix[] = "mcast:";
02614       char object_key_delimiter = 0;
02615 
02616       ACE_CString list_of_profiles (default_init_ref.in ());
02617 
02618       // Check if the protocol is corbaloc: or mcast:.
02619       // If it is, set the object_key_delimiter.
02620       if ((ACE_OS::strncmp (default_init_ref.in (),
02621                             corbaloc_prefix,
02622                             sizeof corbaloc_prefix -1) == 0) ||
02623           (ACE_OS::strncmp (default_init_ref.in (),
02624                             mcast_prefix,
02625                             sizeof mcast_prefix -1) == 0))
02626         {
02627           object_key_delimiter = '/';
02628         }
02629       else
02630         {
02631           TAO_Connector_Registry *conn_reg = this->connector_registry ();
02632 
02633           // Obtain the appropriate object key delimiter for the
02634           // specified protocol.
02635           object_key_delimiter =
02636             conn_reg->object_key_delimiter (list_of_profiles.c_str ());
02637         }
02638 
02639       // Make sure that the default initial reference doesn't end
02640       // with the object key delimiter character.
02641       if (list_of_profiles[list_of_profiles.length() - 1] !=
02642           object_key_delimiter)
02643             list_of_profiles += ACE_CString (object_key_delimiter);
02644 
02645       list_of_profiles += object_id;
02646 
02647       return this->orb ()->string_to_object (list_of_profiles.c_str ());
02648     }
02649 
02650   return CORBA::Object::_nil ();
02651 }
02652 
02653 CORBA::ORB::ObjectIdList *
02654 TAO_ORB_Core::list_initial_references (void)
02655 {
02656   // Unsupported initial services should NOT be included in the below list!
02657   static const char *initial_services[] = { TAO_LIST_OF_INITIAL_SERVICES };
02658   // Make sure the "terminating" zero is the last array element so
02659   // that there is a stop condition when iterating through the list.
02660 
02661   static const size_t initial_services_size =
02662     sizeof (initial_services) / sizeof (initial_services[0]);
02663 
02664   const size_t total_size =
02665     initial_services_size
02666     + this->init_ref_map_.size ()
02667     + this->object_ref_table_.current_size ();
02668 
02669   CORBA::ORB::ObjectIdList *tmp = 0;
02670 
02671   ACE_NEW_THROW_EX (tmp,
02672                     CORBA::ORB::ObjectIdList (
02673                       static_cast<CORBA::ULong> (total_size)),
02674                     CORBA::NO_MEMORY ());
02675 
02676   CORBA::ORB::ObjectIdList_var list (tmp);
02677   list->length (static_cast<CORBA::ULong> (total_size));
02678 
02679   CORBA::ULong index = 0;
02680   // Index for ObjectIdList members.
02681 
02682   // Iterate over the registered initial references.
02683   for (index = 0; index < initial_services_size; ++index)
02684     list[index] = initial_services[index];
02685 
02686   // Now iterate over the initial references created by the user and
02687   // add them to the sequence.
02688 
02689   // References registered via
02690   // ORBInitInfo::register_initial_reference().
02691   TAO_Object_Ref_Table::iterator const obj_ref_end =
02692     this->object_ref_table_.end ();
02693 
02694   for (TAO_Object_Ref_Table::iterator i = this->object_ref_table_.begin ();
02695        i != obj_ref_end;
02696        ++i, ++index)
02697     list[index] = CORBA::string_dup ((*i).first.in ());
02698 
02699   // References registered via INS.
02700   InitRefMap::iterator const end = this->init_ref_map_.end ();
02701 
02702   for (InitRefMap::iterator j = this-> init_ref_map_.begin ();
02703        j != end;
02704        ++j, ++index)
02705     list[index] = (*j).second.c_str ();
02706 
02707   return list._retn ();
02708 }
02709 
02710 // ****************************************************************
02711 ACE_Allocator*
02712 TAO_ORB_Core::input_cdr_dblock_allocator (void)
02713 {
02714   return this->lane_resources ().input_cdr_dblock_allocator ();
02715 }
02716 
02717 ACE_Allocator*
02718 TAO_ORB_Core::input_cdr_buffer_allocator (void)
02719 {
02720   return this->lane_resources ().input_cdr_buffer_allocator ();
02721 }
02722 
02723 ACE_Allocator*
02724 TAO_ORB_Core::input_cdr_msgblock_allocator (void)
02725 {
02726   return this->lane_resources ().input_cdr_msgblock_allocator ();
02727 }
02728 
02729 ACE_Allocator*
02730 TAO_ORB_Core::output_cdr_dblock_allocator (void)
02731 {
02732 
02733   return this->lane_resources ().output_cdr_dblock_allocator ();
02734 }
02735 
02736 ACE_Allocator*
02737 TAO_ORB_Core::output_cdr_buffer_allocator (void)
02738 {
02739   return this->lane_resources ().output_cdr_buffer_allocator ();
02740 }
02741 
02742 
02743 ACE_Allocator*
02744 TAO_ORB_Core::output_cdr_msgblock_allocator (void)
02745 {
02746   return this->lane_resources ().output_cdr_msgblock_allocator ();
02747 }
02748 
02749 
02750 ACE_Allocator *
02751 TAO_ORB_Core::transport_message_buffer_allocator (void)
02752 {
02753   return this->lane_resources ().transport_message_buffer_allocator ();
02754 }
02755 
02756 
02757 ACE_Data_Block*
02758 TAO_ORB_Core::create_input_cdr_data_block (size_t size)
02759 {
02760 
02761   ACE_Allocator *dblock_allocator = 0;
02762   ACE_Allocator *buffer_allocator = 0;
02763 
02764   dblock_allocator =
02765     this->input_cdr_dblock_allocator ();
02766   buffer_allocator =
02767     this->input_cdr_buffer_allocator ();
02768 
02769   ACE_Lock* lock_strategy = 0;
02770   if (this->resource_factory ()->use_locked_data_blocks ())
02771     {
02772       lock_strategy = &this->data_block_lock_;
02773     }
02774 
02775   return this->create_data_block_i (size,
02776                                     buffer_allocator,
02777                                     dblock_allocator,
02778                                     lock_strategy);
02779 }
02780 
02781 ACE_Data_Block *
02782 TAO_ORB_Core::create_data_block_i (size_t size,
02783                                    ACE_Allocator *buffer_allocator,
02784                                    ACE_Allocator *dblock_allocator,
02785                                    ACE_Lock *lock_strategy)
02786 {
02787   ACE_Data_Block *nb = 0;
02788 
02789   ACE_NEW_MALLOC_RETURN (
02790                          nb,
02791                          static_cast<ACE_Data_Block*> (
02792                            dblock_allocator->malloc (sizeof (ACE_Data_Block))),
02793                          ACE_Data_Block (size,
02794                                          ACE_Message_Block::MB_DATA,
02795                                          0,
02796                                          buffer_allocator,
02797                                          lock_strategy,
02798                                          0,
02799                                          dblock_allocator),
02800                          0);
02801 
02802   return nb;
02803 }
02804 
02805 TAO_Connector_Registry *
02806 TAO_ORB_Core::connector_registry (void)
02807 {
02808   TAO_Connector_Registry *conn =
02809     this->lane_resources ().connector_registry ();
02810 
02811   return conn;
02812 }
02813 
02814 auto_ptr<TAO_GIOP_Fragmentation_Strategy>
02815 TAO_ORB_Core::fragmentation_strategy (TAO_Transport * transport)
02816 {
02817   return
02818     this->resource_factory ()->create_fragmentation_strategy (
02819       transport,
02820       this->orb_params_.max_message_size ());
02821 }
02822 
02823 ACE_Reactor *
02824 TAO_ORB_Core::reactor (void)
02825 {
02826   return this->leader_follower ().reactor ();
02827 }
02828 
02829 CORBA::Object_ptr
02830 TAO_ORB_Core::implrepo_service (void)
02831 {
02832   if (!this->use_implrepo_)
02833     return CORBA::Object::_nil ();
02834 
02835   if (CORBA::is_nil (this->implrepo_service_))
02836     {
02837 
02838       try
02839         {
02840           CORBA::Object_var temp =
02841             this->orb_->resolve_initial_references ("ImplRepoService");
02842 
02843           ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, CORBA::Object::_nil ());
02844 
02845           // @@ Worry about assigning a different IOR? (brunsch)
02846           this->implrepo_service_ = temp._retn ();
02847         }
02848       catch (const ::CORBA::Exception&)
02849         {
02850           // Just make sure that we have a null pointer.  Ignore the exception
02851           // anyway.
02852           this->implrepo_service_ = CORBA::Object::_nil ();
02853         }
02854     }
02855 
02856   return CORBA::Object::_duplicate (this->implrepo_service_);
02857 }
02858 
02859 void
02860 TAO_ORB_Core::call_sync_scope_hook (TAO_Stub *stub,
02861                                     bool &has_synchronization,
02862                                     Messaging::SyncScope &scope)
02863 {
02864   Sync_Scope_Hook sync_scope_hook = this->sync_scope_hook_;
02865 
02866   if (sync_scope_hook == 0)
02867     {
02868       has_synchronization = false;
02869       return;
02870     }
02871 
02872   (*sync_scope_hook) (this, stub, has_synchronization, scope);
02873 }
02874 
02875 #if (TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1)
02876 
02877 TAO::Transport_Queueing_Strategy *
02878 TAO_ORB_Core::get_transport_queueing_strategy (TAO_Stub *,
02879                                                Messaging::SyncScope &scope)
02880 {
02881   switch (scope)
02882   {
02883     case Messaging::SYNC_WITH_TRANSPORT:
02884     case Messaging::SYNC_WITH_SERVER:
02885     case Messaging::SYNC_WITH_TARGET:
02886     {
02887       return this->flush_transport_queueing_strategy_;
02888     }
02889     break;
02890     case Messaging::SYNC_NONE:
02891     {
02892       return this->eager_transport_queueing_strategy_;
02893     }
02894     break;
02895     case TAO::SYNC_DELAYED_BUFFERING:
02896     {
02897       return this->delayed_transport_queueing_strategy_;
02898     }
02899     break;
02900     default:
02901     {
02902       return 0;
02903     }
02904   }
02905 }
02906 
02907 #endif /* TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1 */
02908 
02909 int
02910 TAO_ORB_Core::add_tss_cleanup_func (ACE_CLEANUP_FUNC cleanup, size_t &slot_id)
02911 {
02912   return this->tss_cleanup_funcs_.register_cleanup_function (cleanup, slot_id);
02913 }
02914 
02915 void
02916 TAO_ORB_Core::call_timeout_hook (TAO_Stub *stub,
02917                                  bool &has_timeout,
02918                                  ACE_Time_Value &time_value)
02919 {
02920   Timeout_Hook timeout_hook = this->timeout_hook_;
02921 
02922   if (timeout_hook == 0)
02923     {
02924       has_timeout = false;
02925       return;
02926     }
02927   (*timeout_hook) (this, stub, has_timeout, time_value);
02928 }
02929 
02930 void
02931 TAO_ORB_Core::connection_timeout (TAO_Stub *stub,
02932                                   bool &has_timeout,
02933                                   ACE_Time_Value &time_value)
02934 {
02935   Timeout_Hook connection_timeout_hook =
02936     TAO_ORB_Core_Static_Resources::instance ()->connection_timeout_hook_;
02937 
02938   if (connection_timeout_hook == 0)
02939     {
02940       has_timeout = false;
02941       return;
02942     }
02943 
02944   (*connection_timeout_hook) (this, stub, has_timeout, time_value);
02945 
02946   Timeout_Hook alt_connection_timeout_hook =
02947     TAO_ORB_Core_Static_Resources::instance ()->alt_connection_timeout_hook_;
02948 
02949   if (alt_connection_timeout_hook == 0)
02950     return;
02951 
02952   if (!has_timeout || time_value == ACE_Time_Value::zero )
02953     {
02954       (*alt_connection_timeout_hook) (this, stub, has_timeout,time_value);
02955       return;
02956     }
02957 
02958   // At this point, both the primary and alternate hooks are defined, and
02959   // the primary did indeed set a value
02960   ACE_Time_Value tv1;
02961   bool ht1;
02962   (*alt_connection_timeout_hook) (this, stub, ht1,tv1);
02963   if (ht1 && tv1 > ACE_Time_Value::zero && tv1 < time_value)
02964     time_value = tv1;
02965 }
02966 
02967 void
02968 TAO_ORB_Core::connection_timeout_hook (Timeout_Hook hook)
02969 {
02970   // Saving the hook pointer so that we can use it later when needed.
02971   // For now there are only two entry points that may supply a connection
02972   // timeout hook. But there might be future entry points, so this should
02973   // probably be addressed by a more sophisticated mechanism.
02974 
02975 #define TOCSRi TAO_ORB_Core_Static_Resources::instance ()
02976 
02977   // A consern was raised that since this function is called by two
02978   // different initializers there may be a race condition that might
02979   // require a lock. We are not using a lock at this time because of
02980   // two callers, one happens only during service directive processing
02981   // and the other only during ORB Initialization time. The former
02982   // happens when the OC_Endpoint_Selector_Factory is loaded, the
02983   // latter is part of the messaging library. The messaging library
02984   // calls this function as part of pre_init processing, and this call
02985   // happes for every ORB instance. This was the case before these The
02986   // latter call occurs when the messaging library is loaded. The
02987   // redundant calls occured then as well. Second, it isn't clear how
02988   // a lock in this static method would react in the face of windows
02989   // dlls, shared memory segments, etc. Therefore we are continuing to
02990   // keep this code lockless as it always was, assuming no
02991   // simultanious overwrite will occur.
02992 
02993   if (TOCSRi->connection_timeout_hook_ == 0)
02994     {
02995       if (TAO_debug_level > 2)
02996         {
02997           ACE_DEBUG ((LM_DEBUG,
02998                       ACE_TEXT("TAO (%P|%t) setting primary hook\n")));
02999         }
03000       TOCSRi->connection_timeout_hook_ = hook;
03001     }
03002   else if (TOCSRi->connection_timeout_hook_ != hook &&
03003            TOCSRi->alt_connection_timeout_hook_ == 0)
03004     {
03005       if (TAO_debug_level > 2)
03006         {
03007           ACE_DEBUG ((LM_DEBUG,
03008                       ACE_TEXT("TAO (%P|%t) setting alternate hook\n")));
03009         }
03010       TOCSRi->alt_connection_timeout_hook_ = hook;
03011     }
03012   else
03013     if (TAO_debug_level > 2)
03014       {
03015         ACE_DEBUG ((LM_DEBUG,
03016                     ACE_TEXT ("TAO (%P|%t) not overwriting alternate hook.")
03017                     ACE_TEXT (" Is it still null? %d\n"),
03018                     TOCSRi->alt_connection_timeout_hook_ == 0));
03019       }
03020 
03021 #undef TOCSRi
03022 }
03023 
03024 #if (TAO_HAS_CORBA_MESSAGING == 1)
03025 
03026 CORBA::Policy_ptr
03027 TAO_ORB_Core::get_policy (CORBA::PolicyType type)
03028 {
03029   CORBA::Policy_var result;
03030 
03031   TAO_Policy_Manager *policy_manager = this->policy_manager ();
03032   if (policy_manager != 0)
03033     {
03034       result = policy_manager->get_policy (type);
03035     }
03036 
03037   if (CORBA::is_nil (result.in ()))
03038     {
03039       result = this->get_default_policies ()->get_policy (type);
03040     }
03041 
03042   return result._retn ();
03043 }
03044 
03045 CORBA::Policy_ptr
03046 TAO_ORB_Core::get_policy_including_current (CORBA::PolicyType type)
03047 {
03048   TAO_Policy_Current &policy_current = this->policy_current ();
03049 
03050   CORBA::Policy_var result = policy_current.get_policy (type);
03051 
03052   if (CORBA::is_nil (result.in ()))
03053     {
03054       result = this->get_policy (type);
03055     }
03056 
03057   return result._retn ();
03058 }
03059 
03060 CORBA::Policy_ptr
03061 TAO_ORB_Core::get_cached_policy (TAO_Cached_Policy_Type type)
03062 {
03063   CORBA::Policy_var result;
03064 
03065   TAO_Policy_Manager *policy_manager = this->policy_manager ();
03066   if (policy_manager != 0)
03067     {
03068       result = policy_manager->get_cached_policy (type);
03069     }
03070 
03071   if (CORBA::is_nil (result.in ()))
03072     {
03073       result = this->get_default_policies ()->get_cached_policy (type);
03074     }
03075 
03076   return result._retn ();
03077 }
03078 
03079 CORBA::Policy_ptr
03080 TAO_ORB_Core::get_cached_policy_including_current (TAO_Cached_Policy_Type type)
03081 {
03082   TAO_Policy_Current &policy_current = this->policy_current ();
03083 
03084   CORBA::Policy_var result = policy_current.get_cached_policy (type);
03085 
03086   if (CORBA::is_nil (result.in ()))
03087     {
03088       result = this->get_cached_policy (type);
03089     }
03090 
03091   return result._retn ();
03092 }
03093 
03094 #endif /* (TAO_HAS_CORBA_MESSAGING == 1) */
03095 
03096 CORBA::Environment *
03097 TAO_ORB_Core::default_environment (void) const
03098 {
03099   return TAO_TSS_Resources::instance ()->default_environment_;
03100 }
03101 
03102 void
03103 TAO_ORB_Core::default_environment (CORBA::Environment *env)
03104 {
03105   TAO_TSS_Resources::instance ()->default_environment_ = env;
03106 }
03107 
03108 void
03109 TAO_ORB_Core::add_interceptor (
03110    PortableInterceptor::IORInterceptor_ptr interceptor)
03111 {
03112   if (this->ior_interceptor_adapter ())
03113     {
03114       this->ior_interceptor_adapter_->add_interceptor (interceptor);
03115     }
03116   else
03117     {
03118       ACE_ERROR ((LM_ERROR,
03119                   ACE_TEXT ("(%P|%t) %p\n"),
03120                   ACE_TEXT ("ERROR: ORB Core unable to find the ")
03121                   ACE_TEXT ("IORInterceptor Adapter Factory instance")));
03122 
03123       throw ::CORBA::INTERNAL ();
03124     }
03125 }
03126 
03127 TAO_IORInterceptor_Adapter *
03128 TAO_ORB_Core::ior_interceptor_adapter (void)
03129 {
03130   if (this->ior_interceptor_adapter_ == 0)
03131     {
03132       ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
03133                         ace_mon,
03134                         this->lock_,
03135                         0);
03136 
03137       if (this->ior_interceptor_adapter_ == 0)
03138         {
03139           try
03140             {
03141               TAO_IORInterceptor_Adapter_Factory * ior_ap_factory =
03142                 ACE_Dynamic_Service<TAO_IORInterceptor_Adapter_Factory>::instance
03143                   (this->configuration (),
03144                    ACE_TEXT_CHAR_TO_TCHAR (TAO_ORB_Core::iorinterceptor_adapter_factory_name ()));
03145 
03146               if (ior_ap_factory)
03147                 {
03148                   this->ior_interceptor_adapter_ = ior_ap_factory->create ();
03149                 }
03150             }
03151           catch (const ::CORBA::Exception& ex)
03152             {
03153               ex._tao_print_exception (
03154                 "Cannot initialize the ior_interceptor_adapter \n");
03155             }
03156         }
03157     }
03158 
03159   return this->ior_interceptor_adapter_;
03160 }
03161 
03162 #if TAO_HAS_INTERCEPTORS == 1
03163 
03164 void
03165 TAO_ORB_Core::add_interceptor (
03166    PortableInterceptor::ClientRequestInterceptor_ptr interceptor
03167    )
03168 {
03169   if (this->clientrequestinterceptor_adapter_i ())
03170     {
03171       this->client_request_interceptor_adapter_->add_interceptor (interceptor);
03172     }
03173   else
03174     {
03175       ACE_ERROR ((LM_ERROR,
03176                   ACE_TEXT ("(%P|%t) %p\n"),
03177                   ACE_TEXT ("ERROR: ORB Core unable to find the ")
03178                   ACE_TEXT ("Client Request Interceptor Adapter Factory ")
03179                   ACE_TEXT ("instance")));
03180 
03181       throw ::CORBA::INTERNAL ();
03182     }
03183 }
03184 
03185 TAO::ClientRequestInterceptor_Adapter *
03186 TAO_ORB_Core::clientrequestinterceptor_adapter_i (void)
03187 {
03188   if (this->client_request_interceptor_adapter_ == 0)
03189     {
03190       ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
03191                         ace_mon,
03192                         this->lock_,
03193                         0);
03194 
03195       if (this->client_request_interceptor_adapter_ == 0)
03196         {
03197           TAO_ClientRequestInterceptor_Adapter_Factory *factory =
03198             ACE_Dynamic_Service<TAO_ClientRequestInterceptor_Adapter_Factory>::instance
03199               (this->configuration (),
03200                ACE_TEXT ("ClientRequestInterceptor_Adapter_Factory"));
03201 
03202           if (factory)
03203             {
03204               this->client_request_interceptor_adapter_ =
03205                 factory->create ();
03206             }
03207         }
03208     }
03209 
03210   return this->client_request_interceptor_adapter_;
03211 }
03212 
03213 void
03214 TAO_ORB_Core::add_interceptor (
03215    PortableInterceptor::ServerRequestInterceptor_ptr interceptor
03216    )
03217 {
03218   if (this->serverrequestinterceptor_adapter_i ())
03219     {
03220       this->server_request_interceptor_adapter_->add_interceptor (interceptor);
03221     }
03222   else
03223     {
03224       ACE_ERROR ((LM_ERROR,
03225                   ACE_TEXT ("(%P|%t) %p\n"),
03226                   ACE_TEXT ("ERROR: ORB Core unable to find the ")
03227                   ACE_TEXT ("Server Request Interceptor Adapter Factory ")
03228                   ACE_TEXT ("instance")));
03229 
03230       throw ::CORBA::INTERNAL ();
03231     }
03232 }
03233 
03234 void
03235 TAO_ORB_Core::add_interceptor (
03236    PortableInterceptor::ClientRequestInterceptor_ptr interceptor,
03237    const CORBA::PolicyList& policies)
03238 {
03239   if (this->clientrequestinterceptor_adapter_i ())
03240     {
03241       this->client_request_interceptor_adapter_->add_interceptor (
03242         interceptor,
03243         policies);
03244 
03245     }
03246   else
03247     {
03248       ACE_ERROR ((LM_ERROR,
03249                   ACE_TEXT ("(%P|%t) %p\n"),
03250                   ACE_TEXT ("ERROR: ORB Core unable to find the ")
03251                   ACE_TEXT ("Client Request Interceptor Adapter Factory ")
03252                   ACE_TEXT ("instance")));
03253 
03254       throw ::CORBA::INTERNAL ();
03255     }
03256 }
03257 
03258 void
03259 TAO_ORB_Core::add_interceptor (
03260    PortableInterceptor::ServerRequestInterceptor_ptr interceptor,
03261    const CORBA::PolicyList& policies)
03262 {
03263   if (this->serverrequestinterceptor_adapter_i ())
03264     {
03265       this->server_request_interceptor_adapter_->add_interceptor (
03266         interceptor,
03267         policies);
03268 
03269     }
03270   else
03271     {
03272       ACE_ERROR ((LM_ERROR,
03273                   ACE_TEXT ("(%P|%t) %p\n"),
03274                   ACE_TEXT ("ERROR: ORB Core unable to find the ")
03275                   ACE_TEXT ("Server Request Interceptor Adapter Factory ")
03276                   ACE_TEXT ("instance")));
03277 
03278       throw ::CORBA::INTERNAL ();
03279     }
03280 }
03281 
03282 TAO::ServerRequestInterceptor_Adapter *
03283 TAO_ORB_Core::serverrequestinterceptor_adapter_i (void)
03284 {
03285   if (this->server_request_interceptor_adapter_ == 0)
03286     {
03287       ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
03288                         ace_mon,
03289                         this->lock_,
03290                         0);
03291 
03292       if (this->server_request_interceptor_adapter_ == 0)
03293         {
03294           TAO_ServerRequestInterceptor_Adapter_Factory *factory =
03295             ACE_Dynamic_Service<TAO_ServerRequestInterceptor_Adapter_Factory>::instance
03296               (this->configuration (),
03297                ACE_TEXT ("ServerRequestInterceptor_Adapter_Factory"));
03298 
03299           if (factory)
03300             {
03301               this->server_request_interceptor_adapter_ =
03302                 factory->create ();
03303             }
03304         }
03305     }
03306 
03307   return this->server_request_interceptor_adapter_;
03308 }
03309 
03310 #endif  /* TAO_HAS_INTERCEPTORS == 1  */
03311 
03312 TAO_Valuetype_Adapter *
03313 TAO_ORB_Core::valuetype_adapter (void)
03314 {
03315   if (this->valuetype_adapter_ == 0)
03316     {
03317       ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
03318                         ace_mon,
03319                         this->lock_,
03320                         0);
03321 
03322       if (this->valuetype_adapter_ == 0)
03323         {
03324           try
03325             {
03326               TAO_Valuetype_Adapter_Factory * vt_ap_factory =
03327                 ACE_Dynamic_Service<TAO_Valuetype_Adapter_Factory>::instance (
03328                     TAO_ORB_Core::valuetype_adapter_factory_name ()
03329                   );
03330 
03331               if (vt_ap_factory)
03332                 {
03333                   this->valuetype_adapter_ = vt_ap_factory->create ();
03334                 }
03335             }
03336           catch (const ::CORBA::Exception& ex)
03337             {
03338               ex._tao_print_exception (
03339                 "Cannot initialize the valuetype_adapter \n");
03340             }
03341         }
03342 
03343       if (this->valuetype_adapter_ == 0)
03344         {
03345            throw ::CORBA::INTERNAL ();
03346         }
03347     }
03348 
03349   return this->valuetype_adapter_;
03350 }
03351 
03352 // ****************************************************************
03353 
03354 TAO_Export TAO_ORB_Core *
03355 TAO_ORB_Core_instance (void)
03356 {
03357   // @@ This is a slight violation of layering, we should use
03358   //    TAO_ORB_Core_instance(), but that breaks during startup.
03359   TAO::ORB_Table * const orb_table = TAO::ORB_Table::instance ();
03360   if (orb_table->first_orb () == 0)
03361     {
03362       ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, guard,
03363                                 *ACE_Static_Object_Lock::instance (), 0));
03364 
03365       if (orb_table->first_orb () == 0)
03366         {
03367           // Calling CORBA::ORB_init() returns a duplicated ORB
03368           // reference, so make sure that reference is stored in an
03369           // ORB_var so that no leak occurs.  The duplicate ORB
03370           // reference isn't needed outside the scope of this function
03371           // since the corresponding ORB Core instance will still
03372           // exist in the ORB table after the ORB reference is
03373           // destroyed.
03374 
03375           try
03376             {
03377               int argc = 0;
03378               CORBA::ORB_var orb =
03379                 CORBA::ORB_init (argc, 0, 0);
03380             }
03381           catch (const ::CORBA::Exception&)
03382             {
03383               // @@ What should we do here?
03384             }
03385         }
03386     }
03387 
03388   return orb_table->first_orb ();
03389 }
03390 
03391 
03392 TAO::Collocation_Strategy
03393 TAO_ORB_Core::collocation_strategy (CORBA::Object_ptr object)
03394 {
03395   TAO_Stub *stub = object->_stubobj ();
03396   if (!CORBA::is_nil (stub->servant_orb_var ().in ()) &&
03397       stub->servant_orb_var ()->orb_core () != 0)
03398     {
03399       TAO_ORB_Core *orb_core =
03400         stub->servant_orb_var ()->orb_core ();
03401 
03402       const int collocated =
03403         orb_core->collocation_resolver ().is_collocated (object);
03404 
03405       if (collocated)
03406         {
03407           switch (stub->servant_orb_var ()->orb_core ()->get_collocation_strategy ())
03408             {
03409             case THRU_POA:
03410               return TAO::TAO_CS_THRU_POA_STRATEGY;
03411 
03412             case DIRECT:
03413               {
03414                 /////////////////////////////////////////////////////////////
03415                 // If the servant is null and you are collocated this means
03416                 // that the POA policy NON-RETAIN is set, and with that policy
03417                 // using the DIRECT collocation strategy is just insane.
03418                 /////////////////////////////////////////////////////////////
03419                 ACE_ASSERT (object->_servant () != 0);
03420                 return TAO::TAO_CS_DIRECT_STRATEGY;
03421               }
03422             }
03423         }
03424     }
03425 
03426   // In this case the Object is a client.
03427   return TAO::TAO_CS_REMOTE_STRATEGY;
03428 }
03429 
03430 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Sun Jan 27 13:07:35 2008 for TAO by doxygen 1.3.6