ORB.cpp

Go to the documentation of this file.
00001 // "$Id: ORB.cpp 79514 2007-08-28 10:30:06Z johnnyw $"
00002 
00003 #include "tao/ORB.h"
00004 
00005 ACE_RCSID (tao,
00006            ORB,
00007            "$Id: ORB.cpp 79514 2007-08-28 10:30:06Z johnnyw $")
00008 
00009 #include "tao/ORB_Table.h"
00010 #include "tao/Connector_Registry.h"
00011 #include "tao/IOR_Parser.h"
00012 #include "tao/Stub.h"
00013 #include "tao/ORB_Core.h"
00014 #include "tao/ORB_Core_TSS_Resources.h"
00015 #include "tao/TAO_Internal.h"
00016 #include "tao/Dynamic_Adapter.h"
00017 #include "tao/Profile.h"
00018 #include "tao/default_ports.h"
00019 #include "tao/ORBInitializer_Registry_Adapter.h"
00020 #include "tao/PolicyFactory_Registry_Adapter.h"
00021 #include "tao/NVList_Adapter.h"
00022 #include "tao/TAO_Singleton_Manager.h"
00023 #include "tao/Policy_Current.h"
00024 #include "tao/Policy_Manager.h"
00025 #include "tao/Valuetype_Adapter.h"
00026 #include "tao/IFR_Client_Adapter.h"
00027 #include "tao/TypeCodeFactory_Adapter.h"
00028 #include "tao/debug.h"
00029 #include "tao/CDR.h"
00030 #include "tao/SystemException.h"
00031 #include "tao/default_environment.h"
00032 #include "tao/ObjectIdListC.h"
00033 
00034 #if !defined (__ACE_INLINE__)
00035 # include "tao/ORB.inl"
00036 #endif /* ! __ACE_INLINE__ */
00037 
00038 #include "ace/Dynamic_Service.h"
00039 #include "ace/Service_Config.h"
00040 #include "ace/Arg_Shifter.h"
00041 #include "ace/Reactor.h"
00042 #include "ace/Argv_Type_Converter.h"
00043 #include "ace/ACE.h"
00044 #include "ace/Static_Object_Lock.h"
00045 #include "ace/OS_NS_strings.h"
00046 #include "ace/OS_NS_string.h"
00047 #include "ace/OS_NS_ctype.h"
00048 #include "ace/CORBA_macros.h"
00049 
00050 static const char ior_prefix[] = "IOR:";
00051 
00052 // = Static initialization.
00053 
00054 namespace
00055 {
00056   // Count of the number of ORBs.
00057   int orb_init_count = 0;
00058 }
00059 
00060 // ****************************************************************
00061 
00062 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00063 
00064 CORBA::ORB::InvalidName::InvalidName (void)
00065   : CORBA::UserException ("IDL:omg.org/CORBA/ORB/InvalidName:1.0",
00066                           "InvalidName")
00067 {
00068 }
00069 
00070 // Destructor - all members are of self managing types.
00071 CORBA::ORB::InvalidName::~InvalidName (void)
00072 {
00073 }
00074 
00075 // Copy constructor.
00076 CORBA::ORB::InvalidName::InvalidName (const CORBA::ORB::InvalidName &exc)
00077   : CORBA::UserException (exc._rep_id (),
00078                           exc._name ())
00079 {
00080 }
00081 
00082 // Assignment operator.
00083 CORBA::ORB::InvalidName&
00084 CORBA::ORB::InvalidName::operator= (const ::CORBA::ORB::InvalidName &_tao_excp)
00085 {
00086   this->UserException::operator= (_tao_excp);
00087   return *this;
00088 }
00089 
00090 CORBA::ORB::InvalidName *
00091 CORBA::ORB::InvalidName::_downcast (CORBA::Exception *exc)
00092 {
00093   return dynamic_cast<InvalidName *> (exc);
00094 }
00095 
00096 CORBA::Exception *CORBA::ORB::InvalidName::_alloc (void)
00097 {
00098   CORBA::Exception *retval = 0;
00099   ACE_NEW_RETURN (retval, ::CORBA::ORB::InvalidName, 0);
00100   return retval;
00101 }
00102 
00103 CORBA::Exception *
00104 CORBA::ORB::InvalidName::_tao_duplicate (void) const
00105 {
00106   CORBA::Exception *result = 0;
00107   ACE_NEW_RETURN (
00108       result,
00109       ::CORBA::ORB::InvalidName (*this),
00110       0);
00111   return result;
00112 }
00113 
00114 void CORBA::ORB::InvalidName::_raise (void) const
00115 {
00116   throw *this;
00117 }
00118 
00119 void CORBA::ORB::InvalidName::_tao_encode (TAO_OutputCDR &) const
00120 {
00121   throw ::CORBA::MARSHAL ();
00122 }
00123 
00124 void CORBA::ORB::InvalidName::_tao_decode (TAO_InputCDR &)
00125 {
00126   throw ::CORBA::MARSHAL ();
00127 }
00128 
00129 // ****************************************************************
00130 
00131 CORBA::ORB::ORB (TAO_ORB_Core *orb_core)
00132   : refcount_ (1)
00133   , orb_core_ (orb_core)
00134   , use_omg_ior_format_ (1)
00135   , timeout_ (0)
00136 {
00137 }
00138 
00139 CORBA::ORB::~ORB (void)
00140 {
00141   // This destructor is only invoked when the last ORB reference (not
00142   // instance) is being destroyed.
00143 }
00144 
00145 void
00146 CORBA::ORB::shutdown (CORBA::Boolean wait_for_completion)
00147 {
00148   // We cannot lock the exceptions here. We need to propogate
00149   // BAD_INV_ORDER  exceptions if needed to the caller. Locking
00150   // exceptions down would render us non-compliant with the spec.
00151   this->check_shutdown ();
00152 
00153   this->orb_core ()->shutdown (wait_for_completion);
00154 }
00155 
00156 void
00157 CORBA::ORB::destroy (void)
00158 {
00159   if (this->orb_core () == 0)
00160     {
00161       // If the ORB_Core pointer is zero, assume that the ORB_Core has
00162       // been destroyed.
00163 
00164       // As defined by the CORBA 2.3 specification, throw a
00165       // CORBA::OBJECT_NOT_EXIST exception if the ORB has been
00166       // destroyed by the time an ORB function is called.
00167 
00168       throw ::CORBA::OBJECT_NOT_EXIST (0, CORBA::COMPLETED_NO);
00169     }
00170 
00171   if (TAO_debug_level > 2)
00172     {
00173       ACE_DEBUG ((LM_DEBUG,
00174                   ACE_TEXT ("CORBA::ORB::destroy() called on ORB <%s>.\n"),
00175                   ACE_TEXT_CHAR_TO_TCHAR (this->orb_core ()->orbid ())));
00176     }
00177 
00178   this->orb_core ()->destroy ();
00179 
00180   // Now invalidate the pointer to the ORB_Core that created this
00181   // ORB.
00182   this->orb_core_ = 0;
00183 }
00184 
00185 void
00186 CORBA::ORB::run (void)
00187 {
00188   this->run (0);
00189 }
00190 
00191 void
00192 CORBA::ORB::run (ACE_Time_Value &tv)
00193 {
00194   this->run (&tv);
00195 }
00196 
00197 void
00198 CORBA::ORB::run (ACE_Time_Value *tv)
00199 {
00200   this->check_shutdown ();
00201 
00202   this->orb_core ()->run (tv, 0);
00203 }
00204 
00205 void
00206 CORBA::ORB::perform_work (void)
00207 {
00208   this->perform_work (0);
00209 }
00210 
00211 void
00212 CORBA::ORB::perform_work (ACE_Time_Value &tv)
00213 {
00214   this->perform_work (&tv);
00215 }
00216 
00217 void
00218 CORBA::ORB::perform_work (ACE_Time_Value *tv)
00219 {
00220   // This method should not be called if the ORB has been shutdown.
00221   this->check_shutdown ();
00222 
00223   this->orb_core ()->run (tv, 1);
00224 }
00225 
00226 CORBA::Boolean
00227 CORBA::ORB::work_pending (ACE_Time_Value &tv)
00228 {
00229   // This method should not be called if the ORB has been shutdown.
00230   this->check_shutdown ();
00231 
00232   int const result = this->orb_core_->reactor ()->work_pending (tv);
00233   if (result == 0 || (result == -1 && errno == ETIME))
00234     return 0;
00235 
00236   if (result == -1)
00237     throw ::CORBA::INTERNAL ();
00238 
00239   return 1;
00240 }
00241 
00242 CORBA::Boolean
00243 CORBA::ORB::work_pending (void)
00244 {
00245   // This method should not be called if the ORB has been shutdown.
00246   this->check_shutdown ();
00247 
00248   const int result = this->orb_core_->reactor ()->work_pending ();
00249   if (result == 0)
00250     return 0;
00251 
00252   if (result == -1)
00253     throw ::CORBA::INTERNAL ();
00254 
00255   return 1;
00256 }
00257 
00258 #if (TAO_HAS_MINIMUM_CORBA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00259 
00260 void
00261 CORBA::ORB::create_list (CORBA::Long count, CORBA::NVList_ptr &new_list)
00262 {
00263   TAO_NVList_Adapter *adapter =
00264     ACE_Dynamic_Service<TAO_NVList_Adapter>::instance ("TAO_NVList_Adapter");
00265 
00266   if (adapter == 0)
00267     {
00268       ACE_ERROR ((LM_ERROR,
00269                   ACE_TEXT ("(%P|%t) %p\n"),
00270                   ACE_TEXT ("ORB unable to find the ")
00271                   ACE_TEXT ("NVList Adapter instance")));
00272       throw ::CORBA::INTERNAL ();
00273     }
00274 
00275   adapter->create_list (count, new_list);
00276 }
00277 
00278 void
00279 CORBA::ORB::create_exception_list (CORBA::ExceptionList_ptr &list)
00280 {
00281   TAO_Dynamic_Adapter *dynamic_adapter =
00282     ACE_Dynamic_Service<TAO_Dynamic_Adapter>::instance (
00283         TAO_ORB_Core::dynamic_adapter_name ());
00284 
00285   dynamic_adapter->create_exception_list (list);
00286 }
00287 
00288 void
00289 CORBA::ORB::create_operation_list (CORBA::OperationDef_ptr opDef,
00290                                    CORBA::NVList_ptr &result)
00291 {
00292   TAO_IFR_Client_Adapter *adapter =
00293     ACE_Dynamic_Service<TAO_IFR_Client_Adapter>::instance (
00294         TAO_ORB_Core::ifr_client_adapter_name ());
00295 
00296   if (adapter == 0)
00297     {
00298       throw ::CORBA::INTF_REPOS ();
00299     }
00300 
00301   adapter->create_operation_list (this, opDef, result);
00302 }
00303 
00304 
00305 void
00306 CORBA::ORB::create_environment (CORBA::Environment_ptr &environment)
00307 {
00308   ACE_NEW_THROW_EX (environment,
00309                     CORBA::Environment (),
00310                     CORBA::NO_MEMORY (
00311                       CORBA::SystemException::_tao_minor_code (
00312                         0,
00313                         ENOMEM),
00314                       CORBA::COMPLETED_NO));
00315 }
00316 
00317 void
00318 CORBA::ORB::create_named_value (CORBA::NamedValue_ptr &nv)
00319 {
00320   TAO_NVList_Adapter *adapter =
00321     ACE_Dynamic_Service<TAO_NVList_Adapter>::instance (
00322         "TAO_NVList_Adapter");
00323 
00324   if (adapter == 0)
00325     {
00326       ACE_ERROR ((LM_ERROR,
00327                   ACE_TEXT ("(%P|%t) %p\n"),
00328                   ACE_TEXT ("ORB unable to find the ")
00329                   ACE_TEXT ("NVList Adapter instance")));
00330 
00331       throw ::CORBA::INTERNAL ();
00332     }
00333 
00334   adapter->create_named_value (nv);
00335 }
00336 
00337 // The following functions are not implemented - they just throw
00338 // CORBA::NO_IMPLEMENT.
00339 
00340 CORBA::Boolean
00341 CORBA::ORB::get_service_information (
00342   CORBA::ServiceType /* service_type */,
00343   CORBA::ServiceInformation_out /* service_information */)
00344 {
00345   throw ::CORBA::NO_IMPLEMENT (
00346     CORBA::SystemException::_tao_minor_code (
00347       0,
00348       ENOTSUP),
00349     CORBA::COMPLETED_NO);
00350 }
00351 
00352 void
00353 CORBA::ORB::create_context_list (CORBA::ContextList_ptr &)
00354 {
00355   throw ::CORBA::NO_IMPLEMENT (
00356                CORBA::SystemException::_tao_minor_code (
00357                  0,
00358                  ENOTSUP),
00359                CORBA::COMPLETED_NO);
00360 }
00361 
00362 void
00363 CORBA::ORB::get_default_context (CORBA::Context_ptr &)
00364 {
00365   throw ::CORBA::NO_IMPLEMENT (
00366                CORBA::SystemException::_tao_minor_code (
00367                  0,
00368                  ENOTSUP),
00369                CORBA::COMPLETED_NO);
00370 }
00371 
00372 void
00373 CORBA::ORB::send_multiple_requests_oneway (const CORBA::RequestSeq &)
00374 {
00375   throw ::CORBA::NO_IMPLEMENT (
00376                CORBA::SystemException::_tao_minor_code (
00377                  0,
00378                  ENOTSUP),
00379                CORBA::COMPLETED_NO);
00380 }
00381 
00382 void
00383 CORBA::ORB::send_multiple_requests_deferred (const CORBA::RequestSeq &)
00384 {
00385   throw ::CORBA::NO_IMPLEMENT (
00386                CORBA::SystemException::_tao_minor_code (
00387                  0,
00388                  ENOTSUP),
00389                CORBA::COMPLETED_NO);
00390 }
00391 
00392 void
00393 CORBA::ORB::get_next_response (CORBA::Request_ptr &)
00394 {
00395   throw ::CORBA::NO_IMPLEMENT (
00396                CORBA::SystemException::_tao_minor_code (
00397                  0,
00398                  ENOTSUP),
00399                CORBA::COMPLETED_NO);
00400 }
00401 
00402 CORBA::Boolean
00403 CORBA::ORB::poll_next_response (void)
00404 {
00405   throw ::CORBA::NO_IMPLEMENT (
00406     CORBA::SystemException::_tao_minor_code (
00407       0,
00408       ENOTSUP),
00409     CORBA::COMPLETED_NO);
00410 }
00411 
00412 // ****************************************************************
00413 
00414 CORBA::TypeCode_ptr
00415 CORBA::ORB::create_struct_tc (
00416     const char *id,
00417     const char *name,
00418     const CORBA::StructMemberSeq & members)
00419 {
00420   TAO_TypeCodeFactory_Adapter *adapter =
00421     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00422         TAO_ORB_Core::typecodefactory_adapter_name ());
00423 
00424   if (adapter == 0)
00425     {
00426       throw ::CORBA::INTERNAL ();
00427     }
00428 
00429   return adapter->create_struct_tc (id, name, members);
00430 }
00431 
00432 CORBA::TypeCode_ptr
00433 CORBA::ORB::create_union_tc (
00434     const char *id,
00435     const char *name,
00436     CORBA::TypeCode_ptr discriminator_type,
00437     const CORBA::UnionMemberSeq & members)
00438 {
00439   TAO_TypeCodeFactory_Adapter *adapter =
00440     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00441         TAO_ORB_Core::typecodefactory_adapter_name ());
00442 
00443   if (adapter == 0)
00444     {
00445       throw ::CORBA::INTERNAL ();
00446     }
00447 
00448   return adapter->create_union_tc (id,
00449                                    name,
00450                                    discriminator_type,
00451                                    members);
00452 }
00453 
00454 CORBA::TypeCode_ptr
00455 CORBA::ORB::create_enum_tc (
00456     const char *id,
00457     const char *name,
00458     const CORBA::EnumMemberSeq & members)
00459 {
00460   TAO_TypeCodeFactory_Adapter *adapter =
00461     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00462         TAO_ORB_Core::typecodefactory_adapter_name ());
00463 
00464   if (adapter == 0)
00465     {
00466       throw ::CORBA::INTERNAL ();
00467     }
00468 
00469   return adapter->create_enum_tc (id, name, members);
00470 }
00471 
00472 CORBA::TypeCode_ptr
00473 CORBA::ORB::create_alias_tc (
00474     const char *id,
00475     const char *name,
00476     CORBA::TypeCode_ptr original_type)
00477 {
00478   TAO_TypeCodeFactory_Adapter *adapter =
00479     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00480         TAO_ORB_Core::typecodefactory_adapter_name ());
00481 
00482   if (adapter == 0)
00483     {
00484       throw ::CORBA::INTERNAL ();
00485     }
00486 
00487   return adapter->create_alias_tc (id, name, original_type);
00488 }
00489 
00490 CORBA::TypeCode_ptr
00491 CORBA::ORB::create_exception_tc (
00492     const char *id,
00493     const char *name,
00494     const CORBA::StructMemberSeq & members)
00495 {
00496   TAO_TypeCodeFactory_Adapter *adapter =
00497     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00498         TAO_ORB_Core::typecodefactory_adapter_name ());
00499 
00500   if (adapter == 0)
00501     {
00502       throw ::CORBA::INTERNAL ();
00503     }
00504 
00505   return adapter->create_exception_tc (id, name, members);
00506 }
00507 
00508 CORBA::TypeCode_ptr
00509 CORBA::ORB::create_interface_tc (
00510     const char *id,
00511     const char *name)
00512 {
00513   TAO_TypeCodeFactory_Adapter *adapter =
00514     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00515         TAO_ORB_Core::typecodefactory_adapter_name ());
00516 
00517   if (adapter == 0)
00518     {
00519       throw ::CORBA::INTERNAL ();
00520     }
00521 
00522   return adapter->create_interface_tc (id, name);
00523 }
00524 
00525 CORBA::TypeCode_ptr
00526 CORBA::ORB::create_string_tc (
00527     CORBA::ULong bound)
00528 {
00529   TAO_TypeCodeFactory_Adapter *adapter =
00530     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00531         TAO_ORB_Core::typecodefactory_adapter_name ());
00532 
00533   if (adapter == 0)
00534     {
00535       throw ::CORBA::INTERNAL ();
00536     }
00537 
00538   return adapter->create_string_tc (bound);
00539 }
00540 
00541 CORBA::TypeCode_ptr
00542 CORBA::ORB::create_wstring_tc (
00543     CORBA::ULong bound)
00544 {
00545   TAO_TypeCodeFactory_Adapter *adapter =
00546     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00547         TAO_ORB_Core::typecodefactory_adapter_name ());
00548 
00549   if (adapter == 0)
00550     {
00551       throw ::CORBA::INTERNAL ();
00552     }
00553 
00554   return adapter->create_wstring_tc (bound);
00555 }
00556 
00557 CORBA::TypeCode_ptr
00558 CORBA::ORB::create_fixed_tc (
00559     CORBA::UShort digits,
00560     CORBA::UShort scale)
00561 {
00562   TAO_TypeCodeFactory_Adapter *adapter =
00563     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00564         TAO_ORB_Core::typecodefactory_adapter_name ());
00565 
00566   if (adapter == 0)
00567     {
00568       throw ::CORBA::INTERNAL ();
00569     }
00570 
00571   return adapter->create_fixed_tc (digits, scale);
00572 }
00573 
00574 CORBA::TypeCode_ptr
00575 CORBA::ORB::create_sequence_tc (
00576     CORBA::ULong bound,
00577     CORBA::TypeCode_ptr element_type)
00578 {
00579   TAO_TypeCodeFactory_Adapter *adapter =
00580     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00581         TAO_ORB_Core::typecodefactory_adapter_name ());
00582 
00583   if (adapter == 0)
00584     {
00585       throw ::CORBA::INTERNAL ();
00586     }
00587 
00588   return adapter->create_sequence_tc (bound, element_type);
00589 }
00590 
00591 CORBA::TypeCode_ptr
00592 CORBA::ORB::create_array_tc (
00593     CORBA::ULong length,
00594     CORBA::TypeCode_ptr element_type)
00595 {
00596   TAO_TypeCodeFactory_Adapter *adapter =
00597     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00598         TAO_ORB_Core::typecodefactory_adapter_name ());
00599 
00600   if (adapter == 0)
00601     {
00602       throw ::CORBA::INTERNAL ();
00603     }
00604 
00605   return adapter->create_array_tc (length, element_type);
00606 }
00607 
00608 CORBA::TypeCode_ptr
00609 CORBA::ORB::create_value_tc (
00610     const char *id,
00611     const char *name,
00612     CORBA::ValueModifier type_modifier,
00613     CORBA::TypeCode_ptr concrete_base,
00614     const CORBA::ValueMemberSeq & members)
00615 {
00616   TAO_TypeCodeFactory_Adapter *adapter =
00617     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00618         TAO_ORB_Core::typecodefactory_adapter_name ());
00619 
00620   if (adapter == 0)
00621     {
00622       throw ::CORBA::INTERNAL ();
00623     }
00624 
00625   return adapter->create_value_tc (id, name,
00626                                    type_modifier,
00627                                    concrete_base,
00628                                    members);
00629 }
00630 
00631 CORBA::TypeCode_ptr
00632 CORBA::ORB::create_value_box_tc (
00633     const char *id,
00634     const char *name,
00635     CORBA::TypeCode_ptr boxed_type)
00636 {
00637   TAO_TypeCodeFactory_Adapter *adapter =
00638     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00639         TAO_ORB_Core::typecodefactory_adapter_name ());
00640 
00641   if (adapter == 0)
00642     {
00643       throw ::CORBA::INTERNAL ();
00644     }
00645 
00646   return adapter->create_value_box_tc (id, name, boxed_type);
00647 }
00648 
00649 CORBA::TypeCode_ptr
00650 CORBA::ORB::create_native_tc (const char *id, const char *name)
00651 {
00652   TAO_TypeCodeFactory_Adapter *adapter =
00653     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00654         TAO_ORB_Core::typecodefactory_adapter_name ());
00655 
00656   if (adapter == 0)
00657     {
00658       throw ::CORBA::INTERNAL ();
00659     }
00660 
00661   return adapter->create_native_tc (id, name);
00662 }
00663 
00664 CORBA::TypeCode_ptr
00665 CORBA::ORB::create_recursive_tc (const char *id)
00666 {
00667   TAO_TypeCodeFactory_Adapter *adapter =
00668     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00669         TAO_ORB_Core::typecodefactory_adapter_name ());
00670 
00671   if (adapter == 0)
00672     {
00673       throw ::CORBA::INTERNAL ();
00674     }
00675 
00676   return adapter->create_recursive_tc (id);
00677 }
00678 
00679 CORBA::TypeCode_ptr
00680 CORBA::ORB::create_abstract_interface_tc (const char *id, const char *name)
00681 {
00682   TAO_TypeCodeFactory_Adapter *adapter =
00683     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00684         TAO_ORB_Core::typecodefactory_adapter_name ());
00685 
00686   if (adapter == 0)
00687     {
00688       throw ::CORBA::INTERNAL ();
00689     }
00690 
00691   return adapter->create_abstract_interface_tc (id, name);
00692 }
00693 
00694 CORBA::TypeCode_ptr
00695 CORBA::ORB::create_local_interface_tc (const char *id, const char *name)
00696 {
00697   TAO_TypeCodeFactory_Adapter *adapter =
00698     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00699         TAO_ORB_Core::typecodefactory_adapter_name ());
00700 
00701   if (adapter == 0)
00702     {
00703       throw ::CORBA::INTERNAL ();
00704     }
00705 
00706   return adapter->create_local_interface_tc (id, name);
00707 }
00708 
00709 CORBA::TypeCode_ptr
00710 CORBA::ORB::create_component_tc (const char *id, const char *name)
00711 {
00712   TAO_TypeCodeFactory_Adapter *adapter =
00713     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00714         TAO_ORB_Core::typecodefactory_adapter_name ());
00715 
00716   if (adapter == 0)
00717     {
00718       throw ::CORBA::INTERNAL ();
00719     }
00720 
00721   return adapter->create_component_tc (id, name);
00722 }
00723 
00724 CORBA::TypeCode_ptr
00725 CORBA::ORB::create_home_tc (const char *id, const char *name)
00726 {
00727   TAO_TypeCodeFactory_Adapter *adapter =
00728     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00729         TAO_ORB_Core::typecodefactory_adapter_name ());
00730 
00731   if (adapter == 0)
00732     {
00733       throw ::CORBA::INTERNAL ();
00734     }
00735 
00736   return adapter->create_home_tc (id, name);
00737 }
00738 
00739 CORBA::TypeCode_ptr
00740 CORBA::ORB::create_event_tc (
00741     const char *id,
00742     const char *name,
00743     CORBA::ValueModifier type_modifier,
00744     CORBA::TypeCode_ptr concrete_base,
00745     const CORBA::ValueMemberSeq &members)
00746 {
00747   TAO_TypeCodeFactory_Adapter *adapter =
00748     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00749         TAO_ORB_Core::typecodefactory_adapter_name ());
00750 
00751   if (adapter == 0)
00752     {
00753       throw ::CORBA::INTERNAL ();
00754     }
00755 
00756   return adapter->create_event_tc (id,
00757                                    name,
00758                                    type_modifier,
00759                                    concrete_base,
00760                                    members);
00761 }
00762 
00763 // ****************************************************************
00764 
00765 #endif /* TAO_HAS_MINIMUM_CORBA */
00766 
00767 CORBA::Object_ptr
00768 CORBA::ORB::resolve_policy_manager (void)
00769 {
00770 #if (TAO_HAS_CORBA_MESSAGING == 1)
00771 
00772   TAO_Policy_Manager *policy_manager = this->orb_core_->policy_manager ();
00773 
00774   if (policy_manager == 0)
00775     {
00776       return CORBA::Object::_nil ();
00777     }
00778 
00779   return CORBA::Object::_duplicate (policy_manager);
00780 
00781 #else
00782 
00783   return CORBA::Object::_nil ();
00784 
00785 #endif /* TAO_HAS_CORBA_MESSAGING == 1 */
00786 }
00787 
00788 CORBA::Object_ptr
00789 CORBA::ORB::resolve_policy_current (void)
00790 {
00791 #if (TAO_HAS_CORBA_MESSAGING == 1)
00792 
00793   TAO_Policy_Current &policy_current = this->orb_core_->policy_current ();
00794   return CORBA::Object::_duplicate (&policy_current);
00795 
00796 #else
00797 
00798   return CORBA::Object::_nil ();
00799 
00800 #endif /* TAO_HAS_CORBA_MESSAGING == 1 */
00801 }
00802 
00803 void
00804 CORBA::ORB::resolve_service (TAO::MCAST_SERVICEID mcast_service_id)
00805 {
00806 #if defined ACE_HAS_IP_MULTICAST
00807   static char const * const env_service_port[] =
00808   {
00809     "NameServicePort",
00810     "TradingServicePort",
00811     "ImplRepoServicePort",
00812     "InterfaceRepoServicePort"
00813   };
00814 
00815   static unsigned short const default_service_port[] =
00816   {
00817     TAO_DEFAULT_NAME_SERVER_REQUEST_PORT,
00818     TAO_DEFAULT_TRADING_SERVER_REQUEST_PORT,
00819     TAO_DEFAULT_IMPLREPO_SERVER_REQUEST_PORT,
00820     TAO_DEFAULT_INTERFACEREPO_SERVER_REQUEST_PORT
00821   };
00822 
00823   // By now, the table filled in with -ORBInitRef arguments has been
00824   // checked.  We only get here if the table didn't contain an initial
00825   // reference for the requested Service.
00826 
00827   CORBA::String_var default_init_ref =
00828         this->orb_core_->orb_params ()->default_init_ref ();
00829 
00830   static char const mcast_prefix[] = "mcast://:::";
00831 
00832   if ((ACE_OS::strncmp (default_init_ref.in (),
00833                         mcast_prefix,
00834                         sizeof (mcast_prefix) - 1) == 0))
00835     {
00836       // First, determine if the port was supplied on the command line
00837       unsigned short port =
00838         this->orb_core_->orb_params ()->service_port (mcast_service_id);
00839 
00840       if (port == 0)
00841         {
00842           // Look for the port among our environment variables.
00843           char const * const port_number =
00844             ACE_OS::getenv (env_service_port[mcast_service_id]);
00845 
00846           if (port_number != 0)
00847             port = static_cast<unsigned short> (ACE_OS::atoi (port_number));
00848           else
00849             port = default_service_port[mcast_service_id];
00850         }
00851 
00852       // Set the port value in ORB_Params: modify the default mcast
00853       // value.
00854       static char const mcast_fmt[] = "mcast://:%d::";
00855       static size_t const PORT_BUF_SIZE = 256;
00856 
00857       char def_init_ref[PORT_BUF_SIZE] = { 0 };
00858 
00859       ACE_OS::snprintf (def_init_ref,
00860                         PORT_BUF_SIZE,
00861                         mcast_fmt,
00862                         port);
00863 
00864       this->orb_core_->orb_params ()->default_init_ref (def_init_ref);
00865     }
00866 #else
00867   ACE_UNUSED_ARG (mcast_service_id);
00868 #endif /* ACE_HAS_IP_MULTICAST */
00869 }
00870 
00871 CORBA::Object_ptr
00872 CORBA::ORB::resolve_initial_references (const char *name,
00873                                         ACE_Time_Value *timeout)
00874 {
00875   // This method should not be called if the ORB has been shutdown.
00876   this->check_shutdown ();
00877 
00878   CORBA::Object_var result;
00879 
00880   if (ACE_OS::strcmp (name, TAO_OBJID_ROOTPOA) == 0)
00881     {
00882       result = this->orb_core ()->root_poa ();
00883     }
00884   else if (ACE_OS::strcmp (name, TAO_OBJID_POACURRENT) == 0)
00885     {
00886       result = this->orb_core ()->resolve_poa_current ();
00887     }
00888   else if (ACE_OS::strcmp (name, TAO_OBJID_POLICYMANAGER) == 0)
00889     {
00890       result = this->resolve_policy_manager ();
00891     }
00892   else if (ACE_OS::strcmp (name, TAO_OBJID_POLICYCURRENT) == 0)
00893     {
00894       result = this->resolve_policy_current ();
00895     }
00896   else if (ACE_OS::strcmp (name, TAO_OBJID_IORMANIPULATION) == 0)
00897     {
00898       result = this->orb_core ()->resolve_ior_manipulation ();
00899     }
00900   else if (ACE_OS::strcmp (name, TAO_OBJID_IORTABLE) == 0)
00901     {
00902       result = this->orb_core ()->resolve_ior_table ();
00903     }
00904   else if (ACE_OS::strcmp (name, TAO_OBJID_DYNANYFACTORY) == 0)
00905     {
00906       result = this->orb_core ()->resolve_dynanyfactory ();
00907     }
00908   else if (ACE_OS::strcmp (name, TAO_OBJID_TYPECODEFACTORY) == 0)
00909     {
00910       result = this->orb_core ()->resolve_typecodefactory ();
00911     }
00912   else if (ACE_OS::strcmp (name, TAO_OBJID_CODECFACTORY) == 0)
00913     {
00914       result = this->orb_core ()->resolve_codecfactory ();
00915     }
00916   else if (ACE_OS::strcmp (name, TAO_OBJID_COMPRESSIONMANAGER) == 0)
00917     {
00918       result = this->orb_core ()->resolve_compression_manager ();
00919     }
00920 #if TAO_HAS_INTERCEPTORS == 1
00921   else if (ACE_OS::strcmp (name, TAO_OBJID_PICurrent) == 0)
00922     {
00923       result = this->orb_core ()->resolve_picurrent ();
00924     }
00925 #endif
00926 
00927   // -----------------------------------------------------------------
00928 
00929   if (CORBA::is_nil (result.in ()))
00930     {
00931       // Search the object reference table.  This search must occur before
00932       // the InitRef table search, since it may contain local objects.
00933       result =
00934         this->orb_core ()->object_ref_table ().resolve_initial_reference (
00935           name);
00936     }
00937 
00938   if (!CORBA::is_nil (result.in ()))
00939     return result._retn ();
00940 
00941   // -----------------------------------------------------------------
00942 
00943   // Check ORBInitRef options.
00944 
00945   // @@ There appears to be long standing (i.e. back when the map was
00946   //    an ACE_Hash_Map_Manager) race condition here since the map
00947   //    access is not synchronized.
00948 
00949   // Is the service name in the IOR Table.
00950   TAO_ORB_Core::InitRefMap::iterator ior =
00951     this->orb_core_->init_ref_map ()->find (ACE_CString (name));
00952 
00953   if (ior != this->orb_core_->init_ref_map ()->end ())
00954     return this->string_to_object ((*ior).second.c_str ());
00955 
00956   // Look for an environment variable called "<name>IOR".
00957   //
00958   CORBA::String_var ior_env_var_name =
00959     CORBA::string_alloc (static_cast<CORBA::ULong> (ACE_OS::strlen (name) + 3));
00960 
00961   ACE_OS::strcpy (ior_env_var_name.inout (), name);
00962 
00963   ACE_OS::strcat (ior_env_var_name.inout (), "IOR");
00964 
00965   ACE_CString service_ior = ACE_OS::getenv (ior_env_var_name.in ());
00966 
00967   if (ACE_OS::strcmp (service_ior.c_str (), "") != 0)
00968     {
00969       result = this->string_to_object (service_ior.c_str());
00970 
00971       return result._retn ();
00972     }
00973 
00974   // May be trying the explicitly specified services and the well
00975   // known services should be tried first before falling on to default
00976   // services.
00977 
00978   // Set the timeout value.
00979   this->set_timeout (timeout);
00980 
00981   if (ACE_OS::strcmp (name, TAO_OBJID_NAMESERVICE) == 0)
00982     {
00983       this->resolve_service (TAO::MCAST_NAMESERVICE);
00984     }
00985   else if (ACE_OS::strcmp (name, TAO_OBJID_TRADINGSERVICE) == 0)
00986     {
00987       this->resolve_service (TAO::MCAST_TRADINGSERVICE);
00988     }
00989   else if (ACE_OS::strcmp (name, TAO_OBJID_IMPLREPOSERVICE) == 0)
00990     {
00991       this->resolve_service (TAO::MCAST_IMPLREPOSERVICE);
00992     }
00993   else if (ACE_OS::strcmp (name, TAO_OBJID_INTERFACEREP) == 0)
00994     {
00995       this->resolve_service (TAO::MCAST_INTERFACEREPOSERVICE);
00996     }
00997 
00998   // Is not one of the well known services, try to find it in the
00999   // InitRef table....check the defaultinitref values also.
01000 
01001   result = this->orb_core ()->resolve_rir (name);
01002 
01003   if (!CORBA::is_nil (result.in ()))
01004     return result._retn ();
01005   // -----------------------------------------------------------------
01006 
01007   throw ::CORBA::ORB::InvalidName ();
01008 }
01009 
01010 #if !defined(CORBA_E_MICRO)
01011 void
01012 CORBA::ORB::register_initial_reference (const char * id, CORBA::Object_ptr obj)
01013 {
01014   if (id == 0 || ACE_OS::strlen (id) == 0)
01015     throw ::CORBA::ORB::InvalidName ();
01016 
01017   if (CORBA::is_nil (obj))
01018     throw ::CORBA::BAD_PARAM (CORBA::OMGVMCID | 27, CORBA::COMPLETED_NO);
01019 
01020   TAO_Object_Ref_Table &table = this->orb_core_->object_ref_table ();
01021 
01022   if (table.register_initial_reference (id, obj) == -1)
01023     throw ::CORBA::ORB::InvalidName ();
01024 }
01025 #endif
01026 
01027 CORBA::ORB::ObjectIdList_ptr
01028 CORBA::ORB::list_initial_services (void)
01029 {
01030   this->check_shutdown ();
01031 
01032   return
01033     this->orb_core ()->list_initial_references ();
01034 }
01035 
01036 void
01037 CORBA::ORB::check_shutdown (void)
01038 {
01039   if (this->orb_core () != 0)
01040     {
01041       this->orb_core ()->check_shutdown ();
01042     }
01043   else
01044     {
01045       // If the ORB_Core pointer is zero, assume that the ORB_Core has
01046       // been destroyed.
01047 
01048       // As defined by the CORBA 2.3 specification, throw a
01049       // CORBA::OBJECT_NOT_EXIST exception if the ORB has been
01050       // destroyed by the time an ORB function is called.
01051 
01052       throw ::CORBA::OBJECT_NOT_EXIST (0, CORBA::COMPLETED_NO);
01053     }
01054 }
01055 
01056 // ****************************************************************
01057 
01058 void
01059 TAO::ORB::init_orb_globals (void)
01060 {
01061   // This method should be invoked atomically.  It is the caller's
01062   // responsibility to ensure that this condition is satisfied.
01063 
01064   // Prevent multiple initializations.
01065   if (orb_init_count != 0)
01066     {
01067       return;
01068     }
01069   else
01070     {
01071       ++orb_init_count;
01072     }
01073 }
01074 
01075 CORBA::ORB_ptr
01076 CORBA::ORB::_tao_make_ORB (TAO_ORB_Core * orb_core)
01077 {
01078   CORBA::ORB_ptr orb = CORBA::ORB_ptr ();
01079 
01080   ACE_NEW_RETURN (orb,
01081                   CORBA::ORB (orb_core),
01082                   CORBA::ORB::_nil ());
01083 
01084   return orb;
01085 }
01086 
01087 // ****************************************************************
01088 
01089 namespace TAO
01090 {
01091   bool
01092   parse_orb_opt (ACE_Argv_Type_Converter& command_line,
01093                  const ACE_TCHAR* orb_opt,
01094                  ACE_CString& opt_arg)
01095   {
01096 
01097     if (opt_arg.length () > 0)
01098       return false;
01099 
01100     ACE_Arg_Shifter arg_shifter (command_line.get_argc (),
01101                                  command_line.get_TCHAR_argv ());
01102 
01103     size_t opt_len = ACE_OS::strlen (orb_opt);
01104 
01105     bool found = false;
01106     while (arg_shifter.is_anything_left ())
01107       {
01108         const ACE_TCHAR *current_arg = arg_shifter.get_current ();
01109 
01110         if (ACE_OS::strcasecmp (current_arg,
01111                                 orb_opt) == 0)
01112           {
01113             found = true;
01114             arg_shifter.consume_arg ();
01115             if (arg_shifter.is_parameter_next ())
01116               {
01117                 opt_arg =
01118                   ACE_TEXT_ALWAYS_CHAR (arg_shifter.get_current ());
01119                 arg_shifter.consume_arg ();
01120               }
01121           }
01122         else if (ACE_OS::strncasecmp (current_arg, orb_opt,
01123                                       opt_len) == 0)
01124           {
01125             arg_shifter.consume_arg ();
01126             // The rest of the argument is the ORB id...
01127             // but we should skip an optional space...
01128             if (current_arg[opt_len] == ' ')
01129               opt_arg =
01130                 ACE_TEXT_ALWAYS_CHAR (current_arg + opt_len + 1);
01131             else
01132               opt_arg = ACE_TEXT_ALWAYS_CHAR (current_arg + opt_len);
01133           }
01134         else
01135           arg_shifter.ignore_arg ();
01136       }
01137     return found;
01138   }
01139 }
01140 
01141 // ORB initialization, per OMG document 98-12-01.
01142 CORBA::ORB_ptr
01143 CORBA::ORB_init (int &argc, char *argv[], const char *orbid)
01144 {
01145   // Use this string variable to hold the orbid
01146   ACE_CString orbid_string (orbid);
01147 
01148   // Copy command line parameter not to use original.
01149   ACE_Argv_Type_Converter command_line(argc, argv);
01150 
01151   {
01152     // Using ACE_Static_Object_Lock::instance() precludes ORB_init()
01153     // from being called within a static object CTOR.
01154     ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
01155                               guard,
01156                               *ACE_Static_Object_Lock::instance (),
01157                               CORBA::ORB::_nil ()));
01158 
01159     // Make sure TAO's singleton manager is initialized.
01160     // We need to initialize before TAO_default_environment() is called
01161     // since that call instantiates a TAO_TSS_Singleton.
01162     if (TAO_Singleton_Manager::instance ()->init () == -1)
01163       {
01164         return CORBA::ORB::_nil ();
01165       }
01166 
01167     TAO::ORB::init_orb_globals ();
01168   }
01169 
01170   // Make sure the following is done after the global ORB
01171   // initialization since we need to have exceptions initialized.
01172 
01173   // It doesn't make sense for argc to be zero and argv to be
01174   // non-empty/zero, or for argc to be greater than zero and argv be
01175   // zero.
01176   size_t const argv0_len =
01177     (command_line.get_TCHAR_argv ()
01178      ? (*command_line.get_TCHAR_argv ()
01179         ? ACE_OS::strlen (*command_line.get_TCHAR_argv ())
01180         : 0)
01181      : 0);
01182 
01183   if ((command_line.get_argc () == 0 && argv0_len != 0)
01184       || (command_line.get_argc () != 0
01185           && (command_line.get_TCHAR_argv () == 0
01186               || command_line.get_TCHAR_argv ()[0] == 0)))
01187     {
01188       throw ::CORBA::BAD_PARAM (
01189         CORBA::SystemException::_tao_minor_code (
01190           0,
01191           EINVAL),
01192         CORBA::COMPLETED_NO);
01193     }
01194 
01195   TAO::parse_orb_opt (command_line, ACE_TEXT("-ORBid"), orbid_string);
01196 
01197   // Get ORB Core
01198   TAO_ORB_Core_Auto_Ptr oc (
01199     TAO::ORB_Table::instance ()->find (orbid_string.c_str ()));
01200 
01201     // The ORB was already initialized.  Just return that one.
01202   if (oc.get () != 0)
01203     {
01204       return CORBA::ORB::_duplicate (oc->orb ());
01205     }
01206 
01207 
01208   // Determine the service object registry this ORB will use. The choises
01209   // are: (a) the legacy (global); (b) its own, local, or (c) share somebody
01210   // else's configuration
01211 
01212   // By default use the process (application?) global configuration context
01213   ACE_Service_Gestalt* gestalt = ACE_Service_Config::current ();
01214 
01215   // Use this string variable to hold the config identity
01216   ACE_CString orbconfig_string;
01217   ACE_Auto_Ptr<ACE_Service_Gestalt> guard_gestalt(0);
01218 
01219   if (TAO::parse_orb_opt (command_line,
01220                          ACE_TEXT("-ORBGestalt"),
01221                          orbconfig_string))
01222     {
01223       const ACE_TCHAR *arg = ACE_TEXT_CHAR_TO_TCHAR(orbconfig_string.c_str ());
01224       const ACE_TCHAR *local = ACE_TEXT("LOCAL");
01225       const ACE_TCHAR *shared = ACE_TEXT("ORB:");
01226       // Need a local repo? Make one which typically should not be as
01227       // big as the default repository
01228       if  (ACE_OS::strcasecmp (arg,local) == 0)
01229         {
01230           ACE_NEW_THROW_EX (gestalt,
01231                             ACE_Service_Gestalt
01232                             (ACE_Service_Gestalt::MAX_SERVICES / 4, true),
01233                             CORBA::NO_MEMORY
01234                             (CORBA::SystemException::_tao_minor_code (0,
01235                                                                       ENOMEM),
01236                              CORBA::COMPLETED_NO));
01237           guard_gestalt.reset(gestalt);
01238         }
01239       else if (ACE_OS::strncmp (arg, shared, sizeof (shared) - 1) == 0)
01240         {
01241           // @TODO: At some point, we need to implement a lookup of an
01242           // existing configuration context based on the orbid
01243           // following the "ORB:" It may be the case that contexts may
01244           // be initialized separate from the ORB of the same ID, in
01245           // which case we would need some sort of table of contexts
01246           // at which point we would either find this one or make a
01247           // new one. And making a new one would require assigning it
01248           // to the guard_gestalt just like the local.
01249           if (TAO_debug_level > 0)
01250             {
01251               ACE_ERROR ((LM_ERROR,
01252                           ACE_TEXT ("ERROR: Sharing ORB configuration ")
01253                           ACE_TEXT ("contexts is not yet supported\n")));
01254             }
01255 
01256           throw ::CORBA::BAD_PARAM
01257             (CORBA::SystemException::_tao_minor_code
01258              ( TAO_ORB_CORE_INIT_LOCATION_CODE,
01259                ENOTSUP),
01260              CORBA::COMPLETED_NO);
01261         }
01262       else
01263         {
01264           if (TAO_debug_level > 0)
01265             {
01266               ACE_ERROR ((LM_ERROR,
01267                           ACE_TEXT ("ERROR: -ORBGestalt unknown value <%s>\n"),
01268                           orbconfig_string.c_str()));
01269             }
01270 
01271           throw ::CORBA::BAD_PARAM
01272             (CORBA::SystemException::_tao_minor_code
01273              ( TAO_ORB_CORE_INIT_LOCATION_CODE,
01274                EINVAL),
01275              CORBA::COMPLETED_NO);
01276         }
01277     }
01278 
01279   // An ORB corresponding to the desired ORBid doesn't exist so create
01280   // a new one.
01281   TAO_ORB_Core * tmp = 0;
01282   ACE_NEW_THROW_EX (tmp,
01283                     TAO_ORB_Core (orbid_string.c_str (), gestalt),
01284                     CORBA::NO_MEMORY (
01285                       CORBA::SystemException::_tao_minor_code (0,
01286                                                                ENOMEM),
01287                       CORBA::COMPLETED_NO));
01288 
01289   // The ORB table increases the reference count on the ORB Core
01290   // so do not release it here.  Allow the TAO_ORB_Core_Auto_Ptr
01291   // to decrease the reference count on the ORB Core when it goes
01292   // out of scope.
01293   oc.reset (tmp);
01294 
01295   // The ORB now owns its configuration and the auto pointer is not
01296   // necessary anymore.
01297   guard_gestalt.release ();
01298 
01299   // Having the ORB's default static services be shared among all ORBs
01300   // is tempting from the point of view of reducing the dynamic
01301   // footprint. However, if the ORB in a DLL and the rest of that
01302   // application most likely neither cares, nor wishes to know about
01303   // them. Furthermore, if the ORB DLL gets unloaded, the static
01304   // services it had registered globaly will no longer be accesible,
01305   // which will have disastrous consequences at the process
01306   // shutdown. Hence, the ACE_Service_Config_Guard ensures that for
01307   // the current thread, any references to the global
01308   // ACE_Service_Config will be re-routed to this ORB's service gestalt.
01309 
01310   ACE_Service_Config_Guard scg (oc->configuration ());
01311 
01312   // Initialize the Service Configurator.  This must occur before the
01313   // ORBInitializer::pre_init() method is invoked on each registered
01314   // ORB initializer.
01315   int result = TAO::ORB::open_services (oc->configuration (),
01316                                         command_line.get_argc (),
01317                                         command_line.get_TCHAR_argv ());
01318 
01319   // Check for errors returned from <TAO_Internal::open_services>.
01320   if (result != 0 && errno != ENOENT)
01321     {
01322       ACE_ERROR ((LM_ERROR,
01323                   ACE_TEXT ("(%P|%t) %p\n"),
01324                   ACE_TEXT ("Unable to initialize the ")
01325                   ACE_TEXT ("Service Configurator")));
01326       throw ::CORBA::INITIALIZE (
01327         CORBA::SystemException::_tao_minor_code (
01328           TAO_ORB_CORE_INIT_LOCATION_CODE,
01329           0),
01330         CORBA::COMPLETED_NO);
01331     }
01332 
01333   TAO::ORBInitializer_Registry_Adapter * orbinitializer_registry =
01334     oc.get ()->orbinitializer_registry ();
01335 
01336   PortableInterceptor::SlotId slotid = 0;
01337   size_t pre_init_count = 0;
01338 
01339   if (orbinitializer_registry != 0)
01340     {
01341       pre_init_count =
01342         orbinitializer_registry->pre_init (oc.get (),
01343                                            command_line.get_argc(),
01344                                            command_line.get_ASCII_argv(),
01345                                            slotid);
01346     }
01347 
01348   // Initialize the ORB Core instance.
01349   result = oc->init (command_line.get_argc(),
01350                      command_line.get_ASCII_argv());
01351 
01352   if (orbinitializer_registry != 0)
01353     {
01354       orbinitializer_registry->post_init (pre_init_count,
01355                                           oc.get (),
01356                                           command_line.get_argc(),
01357                                           command_line.get_ASCII_argv(),
01358                                           slotid);
01359     }
01360 
01361   if (TAO_debug_level > 2)
01362     {
01363       ACE_DEBUG ((LM_DEBUG,
01364                   ACE_TEXT("TAO (%P|%t) created new ORB <%s>\n"),
01365                   ACE_TEXT_CHAR_TO_TCHAR (orbid_string.c_str ())));
01366     }
01367 
01368   // Before returning remember to store the ORB into the table...
01369   if (TAO::ORB_Table::instance ()->bind (orbid_string.c_str (),
01370                                          oc.get ()) != 0)
01371     throw ::CORBA::INTERNAL (0, CORBA::COMPLETED_NO);
01372 
01373   // Return a duplicate since the ORB_Core should release the last
01374   // reference to the ORB.
01375   return CORBA::ORB::_duplicate (oc->orb ());
01376 }
01377 
01378 // ****************************************************************
01379 
01380 // Object reference stringification.
01381 char *
01382 CORBA::ORB::object_to_string (CORBA::Object_ptr obj)
01383 {
01384   // This method should not be called if the ORB has been shutdown.
01385   this->check_shutdown ();
01386 
01387   if (!CORBA::is_nil (obj))
01388     {
01389       if (!obj->can_convert_to_ior ())
01390         throw ::CORBA::MARSHAL (CORBA::OMGVMCID | 4, CORBA::COMPLETED_NO);
01391 
01392       // Allow a user to provide custom object stringification
01393       char* user_string =
01394         obj->convert_to_ior (this->use_omg_ior_format_, ior_prefix);
01395 
01396       if (user_string != 0)
01397         return user_string;
01398     }
01399 
01400   // Application writer controls what kind of objref strings they get,
01401   // maybe along with other things, by how they initialize the ORB.
01402 
01403   if (use_omg_ior_format_)
01404     {
01405       // By default, orbs use IOR strings; these are ugly (and error
01406       // prone) but specified by CORBA.
01407       //
01408       // XXX there should be a simple way to reuse this code in other
01409       // ORB implementations ...
01410 
01411 #if defined (ACE_INITIALIZE_MEMORY_BEFORE_USE)
01412       char buf [ACE_CDR::DEFAULT_BUFSIZE] = { 0 };
01413 #else
01414       // Avoid the initialization overhead if not compiling with
01415       // support for a memory profiler.  There is no need to actually perform
01416       // initialization otherwise.
01417       char buf [ACE_CDR::DEFAULT_BUFSIZE];
01418 #endif /* ACE_INITIALIZE_MEMORY_BEFORE_USE */
01419 
01420       TAO_OutputCDR cdr (buf,  sizeof buf,
01421                          TAO_ENCAP_BYTE_ORDER,
01422                          this->orb_core_->output_cdr_buffer_allocator (),
01423                          this->orb_core_->output_cdr_dblock_allocator (),
01424                          this->orb_core_->output_cdr_msgblock_allocator (),
01425                          this->orb_core_->orb_params ()->cdr_memcpy_tradeoff (),
01426                          TAO_DEF_GIOP_MAJOR,
01427                          TAO_DEF_GIOP_MINOR);
01428 
01429       // There is no translator currently available for stringifying an object
01430       // reference, since there is no transport with which to choose an NCS/TCS
01431       // pair.
01432 
01433       // support limited oref ACE_OS::strcmp.
01434       (void) ACE_OS::memset (buf, 0, sizeof (buf));
01435 
01436       // Marshal the objref into an encapsulation bytestream.
01437       (void) cdr.write_octet (TAO_ENCAP_BYTE_ORDER);
01438       if (!(cdr << obj))
01439         throw ::CORBA::MARSHAL ();
01440 
01441       // Now hexify the encapsulated CDR data into a string, and
01442       // return that string.
01443 
01444       size_t const total_len = cdr.total_length ();
01445 
01446       char *cp = 0;
01447       ACE_ALLOCATOR_RETURN (cp,
01448                             CORBA::string_alloc (
01449                               sizeof ior_prefix
01450                               + 2
01451                               * static_cast<CORBA::ULong> (total_len)),
01452                             0);
01453 
01454       CORBA::String_var string = cp;
01455 
01456       ACE_OS::strcpy (cp, ior_prefix);
01457       cp += sizeof (ior_prefix) - 1;
01458 
01459       for (const ACE_Message_Block *i = cdr.begin (); i != 0; i = i->cont ())
01460         {
01461           const char *bytes = i->rd_ptr ();
01462           size_t len = i->length ();
01463 
01464           while (len--)
01465             {
01466               *cp++ = static_cast<char> (ACE::nibble2hex ((*bytes) >> 4));
01467               *cp++ = static_cast<char> (ACE::nibble2hex (*bytes));
01468               ++bytes;
01469             }
01470         }
01471       // Null terminate the string..
01472       *cp = 0;
01473 
01474       return string._retn ();
01475     }
01476   else
01477     {
01478       // It is perfectly valid to marshal a nil object reference.
01479       // However, it is not possible to convert a nil object reference
01480       // to a URL IOR, so throw an exception.
01481       if (CORBA::is_nil (obj) || obj->_stubobj () == 0)
01482         {
01483           if (TAO_debug_level > 0)
01484             ACE_ERROR ((LM_ERROR,
01485                         ACE_TEXT ("Nil object reference or TAO_Stub ")
01486                         ACE_TEXT ("pointer is zero when converting\n")
01487                         ACE_TEXT ("object reference to URL IOR.\n")));
01488 
01489           throw ::CORBA::MARSHAL (
01490             CORBA::SystemException::_tao_minor_code (
01491               0,
01492               EINVAL),
01493             CORBA::COMPLETED_NO);
01494         }
01495 
01496       TAO_MProfile &mp = obj->_stubobj ()->base_profiles ();
01497 
01498       if (mp.profile_count () == 0)
01499         {
01500           if (TAO_debug_level > 0)
01501             ACE_ERROR ((LM_ERROR,
01502                         ACE_TEXT ("(%P|%t) Cannot stringify given ")
01503                         ACE_TEXT ("object.  No profiles.\n")));
01504 
01505 
01506           throw ::CORBA::MARSHAL (
01507             CORBA::SystemException::_tao_minor_code (
01508               0,
01509               EINVAL),
01510             CORBA::COMPLETED_NO);
01511         }
01512 
01513       // For now we just use the first profile.
01514       TAO_Profile *profile = mp.get_profile (0);
01515 
01516       return profile->to_string ();
01517     }
01518 }
01519 
01520 // Destringify arbitrary objrefs.  This method is called from
01521 // <resolve_name_service> with an IOR <multicast_to_service>.
01522 
01523 CORBA::Object_ptr
01524 CORBA::ORB::string_to_object (const char *str)
01525 {
01526   // This method should not be called if the ORB has been shutdown.
01527   this->check_shutdown ();
01528 
01529   // Check for NULL pointer
01530   if (str == 0)
01531     throw ::CORBA::INV_OBJREF (
01532       CORBA::SystemException::_tao_minor_code (
01533         0,
01534         EINVAL),
01535       CORBA::COMPLETED_NO);
01536 
01537   TAO_IOR_Parser *ior_parser =
01538     this->orb_core_->parser_registry ()->match_parser (str);
01539 
01540   if (ior_parser != 0)
01541     {
01542       return ior_parser->parse_string (str, this);
01543     }
01544 
01545   if (ACE_OS::strncmp (str, ior_prefix, sizeof ior_prefix - 1) == 0)
01546     return this->ior_string_to_object (str + sizeof ior_prefix - 1);
01547   else
01548     return this->url_ior_string_to_object (str);
01549 }
01550 
01551 // ****************************************************************
01552 
01553 char *
01554 CORBA::ORB::id (void)
01555 {
01556   return CORBA::string_dup (this->orb_core_->orbid ());
01557 }
01558 
01559 // ****************************************************************
01560 
01561 #if !defined(CORBA_E_MICRO)
01562 CORBA::Policy_ptr
01563 CORBA::ORB::create_policy (CORBA::PolicyType type, const CORBA::Any& val)
01564 {
01565   this->check_shutdown ();
01566 
01567   TAO::PolicyFactory_Registry_Adapter *adapter =
01568     this->orb_core_->policy_factory_registry ();
01569 
01570   if (adapter == 0)
01571     {
01572       throw ::CORBA::INTERNAL ();
01573     }
01574 
01575   // Attempt to obtain the policy from the policy factory registry.
01576   return adapter->create_policy (type, val);
01577 }
01578 #endif
01579 
01580 #if !defined(CORBA_E_MICRO)
01581 CORBA::Policy_ptr
01582 CORBA::ORB::_create_policy (CORBA::PolicyType type)
01583 {
01584   this->check_shutdown ();
01585 
01586   TAO::PolicyFactory_Registry_Adapter *adapter =
01587     this->orb_core_->policy_factory_registry ();
01588 
01589   if (adapter == 0)
01590     {
01591       throw ::CORBA::INTERNAL ();
01592     }
01593 
01594   // Attempt to obtain the policy from the policy factory registry.
01595   return adapter->_create_policy (type);
01596 }
01597 #endif
01598 
01599 // Destringify OMG-specified "IOR" string.
01600 //
01601 // XXX there should be a simple way to reuse this code in other ORB
01602 // implementations ...
01603 
01604 CORBA::Object_ptr
01605 CORBA::ORB::ior_string_to_object (const char *str)
01606 {
01607   // Unhex the bytes, and make a CDR deencapsulation stream from the
01608   // resulting data.
01609   ACE_Message_Block mb (ACE_OS::strlen (str) / 2 + 1
01610                         + ACE_CDR::MAX_ALIGNMENT + 1);
01611 
01612   ACE_CDR::mb_align (&mb);
01613 
01614   char *buffer = mb.rd_ptr ();
01615   const char *tmp = str;
01616   size_t len = 0;
01617 
01618   while (tmp [0] && tmp [1])
01619     {
01620       // Some platforms define 'byte' as a macro, solve the problem
01621       // here.
01622 #undef byte
01623       unsigned char byte;
01624 
01625       if (!(ACE_OS::ace_isxdigit (tmp [0]) && ACE_OS::ace_isxdigit (tmp [1])))
01626         break;
01627 
01628       byte = (u_char) (ACE::hex2byte (tmp [0]) << 4);
01629       byte |= ACE::hex2byte (tmp [1]);
01630 
01631       buffer [len++] = byte;
01632       tmp += 2;
01633     }
01634 
01635     if (tmp [0] && !ACE_OS::ace_isspace (tmp [0]))
01636     {
01637       throw ::CORBA::BAD_PARAM ();
01638     }
01639 
01640   // Create deencapsulation stream ... then unmarshal objref from that
01641   // stream.
01642 
01643   int byte_order = *(mb.rd_ptr ());
01644   mb.rd_ptr (1);
01645   mb.wr_ptr (len);
01646   TAO_InputCDR stream (&mb,
01647                        byte_order,
01648                        TAO_DEF_GIOP_MAJOR,
01649                        TAO_DEF_GIOP_MINOR,
01650                        this->orb_core_);
01651 
01652   CORBA::Object_ptr objref = CORBA::Object::_nil ();
01653   stream >> objref;
01654   return objref;
01655 }
01656 
01657 // ****************************************************************
01658 
01659 // Convert an URL style IOR in an object
01660 
01661 CORBA::Object_ptr
01662 CORBA::ORB::url_ior_string_to_object (const char* str)
01663 {
01664   TAO_MProfile mprofile;
01665   // It is safe to declare this on the stack since the contents of
01666   // mprofile get copied.  No memory is allocated for profile storage
01667   // here.  The Connector Registry will determine the exact number
01668   // of profiles and tell the MProfile object to allocate enough memory
01669   // to hold them all.
01670 
01671   TAO_Connector_Registry *conn_reg = this->orb_core_->connector_registry ();
01672 
01673   int const retv = conn_reg->make_mprofile (str, mprofile);
01674   // Return nil.
01675 
01676   if (retv != 0)
01677     {
01678       throw ::CORBA::INV_OBJREF (
01679         CORBA::SystemException::_tao_minor_code (
01680           0,
01681           EINVAL),
01682         CORBA::COMPLETED_NO);
01683     }
01684 
01685   // Now make the TAO_Stub.
01686   TAO_Stub *data = this->orb_core_->create_stub ((char *) 0, mprofile);
01687 
01688   TAO_Stub_Auto_Ptr safe_objdata (data);
01689 
01690   // Figure out if the servant is collocated.
01691   CORBA::Object_ptr obj = this->orb_core_->create_object (safe_objdata.get ());
01692 
01693   if (CORBA::is_nil (obj))
01694     return CORBA::Object::_nil ();
01695 
01696   // Transfer ownership to the CORBA::Object
01697   (void) safe_objdata.release ();
01698 
01699   return obj;
01700 }
01701 
01702 // *************************************************************
01703 // Valuetype factory operations
01704 // *************************************************************
01705 
01706 #if !defined(CORBA_E_MICRO)
01707 CORBA::ValueFactory
01708 CORBA::ORB::register_value_factory (const char *repository_id,
01709                                     CORBA::ValueFactory factory)
01710 {
01711   TAO_Valuetype_Adapter *vta = this->orb_core ()->valuetype_adapter ();
01712 
01713   if (vta)
01714     {
01715       int const result = vta->vf_map_rebind (repository_id, factory);
01716 
01717       if (result == 0) // No previous factory found
01718         {
01719           return 0;
01720         }
01721 
01722       if (result == -1)
01723         {
01724           // Error on bind.
01725           throw ::CORBA::MARSHAL ();
01726         }
01727     }
01728 
01729   return factory;    // previous factory was found
01730 }
01731 #endif
01732 
01733 #if !defined(CORBA_E_MICRO)
01734 void
01735 CORBA::ORB::unregister_value_factory (const char *repository_id)
01736 {
01737   TAO_Valuetype_Adapter *vta = this->orb_core ()->valuetype_adapter ();
01738 
01739   if (vta)
01740     {
01741       // Dont care whther it was successful or not!
01742       (void) vta->vf_map_unbind (repository_id);
01743     }
01744 }
01745 #endif
01746 
01747 #if !defined(CORBA_E_MICRO)
01748 CORBA::ValueFactory
01749 CORBA::ORB::lookup_value_factory (const char *repository_id)
01750 {
01751   TAO_Valuetype_Adapter *vta = this->orb_core ()->valuetype_adapter ();
01752 
01753   if (vta)
01754     {
01755       return vta->vf_map_find (repository_id);
01756     }
01757 
01758   return 0;
01759 }
01760 #endif
01761 
01762 TAO_END_VERSIONED_NAMESPACE_DECL

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