ORB_Core.cpp

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

Generated on Tue Feb 2 17:37:52 2010 for TAO by  doxygen 1.4.7