ORB.cpp

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

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