Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / ORB.cpp
blobca14b4dc6c7b18c9c812d5252e12f3fd16a7f771
1 #include "tao/ORB.h"
2 #include "tao/ORB_Table.h"
3 #include "tao/Connector_Registry.h"
4 #include "tao/IOR_Parser.h"
5 #include "tao/Stub.h"
6 #include "tao/ORB_Core.h"
7 #include "tao/ORB_Core_TSS_Resources.h"
8 #include "tao/TAO_Internal.h"
9 #include "tao/Dynamic_Adapter.h"
10 #include "tao/Profile.h"
11 #include "tao/default_ports.h"
12 #include "tao/ORBInitializer_Registry_Adapter.h"
13 #include "tao/PolicyFactory_Registry_Adapter.h"
14 #include "tao/NVList_Adapter.h"
15 #include "tao/Policy_Current.h"
16 #include "tao/Policy_Manager.h"
17 #include "tao/Valuetype_Adapter.h"
18 #include "tao/IFR_Client_Adapter.h"
19 #include "tao/TypeCodeFactory_Adapter.h"
20 #include "tao/debug.h"
21 #include "tao/CDR.h"
22 #include "tao/SystemException.h"
23 #include "tao/default_environment.h"
24 #include "tao/ObjectIdListC.h"
26 #if !defined (__ACE_INLINE__)
27 # include "tao/ORB.inl"
28 #endif /* ! __ACE_INLINE__ */
30 #include "ace/Dynamic_Service.h"
31 #include "ace/Service_Config.h"
32 #include "ace/Arg_Shifter.h"
33 #include "ace/Reactor.h"
34 #include "ace/Argv_Type_Converter.h"
35 #include "ace/ACE.h"
36 #include "ace/Static_Object_Lock.h"
37 #include "ace/OS_NS_strings.h"
38 #include "ace/OS_NS_string.h"
39 #include "ace/OS_NS_ctype.h"
40 #include "ace/CORBA_macros.h"
41 #include <cstring>
43 static const char ior_prefix[] = "IOR:";
45 // ****************************************************************
47 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
49 CORBA::ORB::InvalidName::InvalidName ()
50 : CORBA::UserException ("IDL:omg.org/CORBA/ORB/InvalidName:1.0",
51 "InvalidName")
55 // Destructor - all members are of self managing types.
56 CORBA::ORB::InvalidName::~InvalidName ()
60 // Copy constructor.
61 CORBA::ORB::InvalidName::InvalidName (const CORBA::ORB::InvalidName &exc)
62 : CORBA::UserException (exc._rep_id (),
63 exc._name ())
67 // Assignment operator.
68 CORBA::ORB::InvalidName&
69 CORBA::ORB::InvalidName::operator= (const ::CORBA::ORB::InvalidName &_tao_excp)
71 this->UserException::operator= (_tao_excp);
72 return *this;
75 CORBA::ORB::InvalidName *
76 CORBA::ORB::InvalidName::_downcast (CORBA::Exception *exc)
78 return dynamic_cast<InvalidName *> (exc);
81 CORBA::Exception *CORBA::ORB::InvalidName::_alloc ()
83 CORBA::Exception *retval = nullptr;
84 ACE_NEW_RETURN (retval, ::CORBA::ORB::InvalidName, nullptr);
85 return retval;
88 CORBA::Exception *
89 CORBA::ORB::InvalidName::_tao_duplicate () const
91 CORBA::Exception *result = nullptr;
92 ACE_NEW_RETURN (
93 result,
94 ::CORBA::ORB::InvalidName (*this),
95 nullptr);
96 return result;
99 void CORBA::ORB::InvalidName::_raise () const
101 throw *this;
104 void CORBA::ORB::InvalidName::_tao_encode (TAO_OutputCDR &) const
106 throw ::CORBA::MARSHAL ();
109 void CORBA::ORB::InvalidName::_tao_decode (TAO_InputCDR &)
111 throw ::CORBA::MARSHAL ();
114 // ****************************************************************
116 CORBA::ORB::ORB (TAO_ORB_Core *orb_core)
117 : refcount_ (1)
118 , orb_core_ (orb_core)
119 , use_omg_ior_format_ (1)
120 , timeout_ (nullptr)
124 CORBA::ORB::~ORB ()
126 // This destructor is only invoked when the last ORB reference (not
127 // instance) is being destroyed.
130 void
131 CORBA::ORB::shutdown (CORBA::Boolean wait_for_completion)
133 // We cannot lock the exceptions here. We need to propagate
134 // BAD_INV_ORDER exceptions if needed to the caller. Locking
135 // exceptions down would render us non-compliant with the spec.
136 this->check_shutdown ();
138 this->orb_core ()->shutdown (wait_for_completion);
141 void
142 CORBA::ORB::destroy ()
144 if (this->orb_core () == nullptr)
146 // If the ORB_Core pointer is zero, assume that the ORB_Core has
147 // been destroyed.
149 // As defined by the CORBA 2.3 specification, throw a
150 // CORBA::OBJECT_NOT_EXIST exception if the ORB has been
151 // destroyed by the time an ORB function is called.
153 throw ::CORBA::OBJECT_NOT_EXIST (0, CORBA::COMPLETED_NO);
156 if (TAO_debug_level > 2)
158 TAOLIB_DEBUG ((LM_DEBUG,
159 ACE_TEXT ("CORBA::ORB::destroy() called on ORB <%C>.\n"),
160 this->orb_core ()->orbid ()));
163 this->orb_core ()->destroy ();
165 // Now invalidate the pointer to the ORB_Core that created this
166 // ORB.
167 this->orb_core_ = nullptr;
170 void
171 CORBA::ORB::run ()
173 this->run (nullptr);
176 void
177 CORBA::ORB::run (ACE_Time_Value &tv)
179 this->run (&tv);
182 void
183 CORBA::ORB::run (ACE_Time_Value *tv)
185 this->check_shutdown ();
187 this->orb_core ()->run (tv, 0);
190 void
191 CORBA::ORB::perform_work ()
193 this->perform_work (nullptr);
196 void
197 CORBA::ORB::perform_work (ACE_Time_Value &tv)
199 this->perform_work (&tv);
202 void
203 CORBA::ORB::perform_work (ACE_Time_Value *tv)
205 // This method should not be called if the ORB has been shutdown.
206 this->check_shutdown ();
208 this->orb_core ()->run (tv, 1);
211 CORBA::Boolean
212 CORBA::ORB::work_pending (ACE_Time_Value &tv)
214 // This method should not be called if the ORB has been shutdown.
215 this->check_shutdown ();
217 int const result = this->orb_core_->reactor ()->work_pending (tv);
218 if (result == 0 || (result == -1 && errno == ETIME))
219 return false;
221 if (result == -1)
222 throw ::CORBA::INTERNAL ();
224 return true;
227 CORBA::Boolean
228 CORBA::ORB::work_pending ()
230 // This method should not be called if the ORB has been shutdown.
231 this->check_shutdown ();
233 const int result = this->orb_core_->reactor ()->work_pending ();
234 if (result == 0)
235 return false;
237 if (result == -1)
238 throw ::CORBA::INTERNAL ();
240 return true;
243 #if (TAO_HAS_MINIMUM_CORBA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
245 void
246 CORBA::ORB::create_list (CORBA::Long count, CORBA::NVList_ptr &new_list)
248 TAO_NVList_Adapter *adapter =
249 ACE_Dynamic_Service<TAO_NVList_Adapter>::instance ("TAO_NVList_Adapter");
251 if (adapter == nullptr)
253 TAOLIB_ERROR ((LM_ERROR,
254 ACE_TEXT ("(%P|%t) %p\n"),
255 ACE_TEXT ("ORB unable to find the ")
256 ACE_TEXT ("NVList Adapter instance")));
257 throw ::CORBA::INTERNAL ();
260 adapter->create_list (count, new_list);
263 void
264 CORBA::ORB::create_exception_list (CORBA::ExceptionList_ptr &list)
266 TAO_Dynamic_Adapter *dynamic_adapter =
267 ACE_Dynamic_Service<TAO_Dynamic_Adapter>::instance (
268 TAO_ORB_Core::dynamic_adapter_name ());
270 dynamic_adapter->create_exception_list (list);
273 void
274 CORBA::ORB::create_operation_list (CORBA::OperationDef_ptr opDef,
275 CORBA::NVList_ptr &result)
277 TAO_IFR_Client_Adapter *adapter =
278 ACE_Dynamic_Service<TAO_IFR_Client_Adapter>::instance (
279 TAO_ORB_Core::ifr_client_adapter_name ());
281 if (adapter == nullptr)
283 throw ::CORBA::INTF_REPOS ();
286 adapter->create_operation_list (this, opDef, result);
290 void
291 CORBA::ORB::create_environment (CORBA::Environment_ptr &environment)
293 ACE_NEW_THROW_EX (environment,
294 CORBA::Environment (),
295 CORBA::NO_MEMORY (
296 CORBA::SystemException::_tao_minor_code (
298 ENOMEM),
299 CORBA::COMPLETED_NO));
302 void
303 CORBA::ORB::create_named_value (CORBA::NamedValue_ptr &nv)
305 TAO_NVList_Adapter *adapter =
306 ACE_Dynamic_Service<TAO_NVList_Adapter>::instance (
307 "TAO_NVList_Adapter");
309 if (adapter == nullptr)
311 TAOLIB_ERROR ((LM_ERROR,
312 ACE_TEXT ("(%P|%t) %p\n"),
313 ACE_TEXT ("ORB unable to find the ")
314 ACE_TEXT ("NVList Adapter instance")));
316 throw ::CORBA::INTERNAL ();
319 adapter->create_named_value (nv);
322 // The following functions are not implemented - they just throw
323 // CORBA::NO_IMPLEMENT.
325 CORBA::Boolean
326 CORBA::ORB::get_service_information (
327 CORBA::ServiceType /* service_type */,
328 CORBA::ServiceInformation_out /* service_information */)
330 throw ::CORBA::NO_IMPLEMENT (
331 CORBA::SystemException::_tao_minor_code (
333 ENOTSUP),
334 CORBA::COMPLETED_NO);
337 void
338 CORBA::ORB::create_context_list (CORBA::ContextList_ptr &)
340 throw ::CORBA::NO_IMPLEMENT (
341 CORBA::SystemException::_tao_minor_code (
343 ENOTSUP),
344 CORBA::COMPLETED_NO);
347 void
348 CORBA::ORB::get_default_context (CORBA::Context_ptr &)
350 throw ::CORBA::NO_IMPLEMENT (
351 CORBA::SystemException::_tao_minor_code (
353 ENOTSUP),
354 CORBA::COMPLETED_NO);
357 void
358 CORBA::ORB::send_multiple_requests_oneway (const CORBA::RequestSeq &)
360 throw ::CORBA::NO_IMPLEMENT (
361 CORBA::SystemException::_tao_minor_code (
363 ENOTSUP),
364 CORBA::COMPLETED_NO);
367 void
368 CORBA::ORB::send_multiple_requests_deferred (const CORBA::RequestSeq &)
370 throw ::CORBA::NO_IMPLEMENT (
371 CORBA::SystemException::_tao_minor_code (
373 ENOTSUP),
374 CORBA::COMPLETED_NO);
377 void
378 CORBA::ORB::get_next_response (CORBA::Request_ptr &)
380 throw ::CORBA::NO_IMPLEMENT (
381 CORBA::SystemException::_tao_minor_code (
383 ENOTSUP),
384 CORBA::COMPLETED_NO);
387 CORBA::Boolean
388 CORBA::ORB::poll_next_response ()
390 throw ::CORBA::NO_IMPLEMENT (
391 CORBA::SystemException::_tao_minor_code (
393 ENOTSUP),
394 CORBA::COMPLETED_NO);
397 // ****************************************************************
399 CORBA::TypeCode_ptr
400 CORBA::ORB::create_struct_tc (
401 const char *id,
402 const char *name,
403 const CORBA::StructMemberSeq & members)
405 TAO_TypeCodeFactory_Adapter *adapter =
406 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
407 TAO_ORB_Core::typecodefactory_adapter_name ());
409 if (adapter == nullptr)
411 throw ::CORBA::INTERNAL ();
414 return adapter->create_struct_tc (id, name, members);
417 CORBA::TypeCode_ptr
418 CORBA::ORB::create_union_tc (
419 const char *id,
420 const char *name,
421 CORBA::TypeCode_ptr discriminator_type,
422 const CORBA::UnionMemberSeq & members)
424 TAO_TypeCodeFactory_Adapter *adapter =
425 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
426 TAO_ORB_Core::typecodefactory_adapter_name ());
428 if (adapter == nullptr)
430 throw ::CORBA::INTERNAL ();
433 return adapter->create_union_tc (id,
434 name,
435 discriminator_type,
436 members);
439 CORBA::TypeCode_ptr
440 CORBA::ORB::create_enum_tc (
441 const char *id,
442 const char *name,
443 const CORBA::EnumMemberSeq & members)
445 TAO_TypeCodeFactory_Adapter *adapter =
446 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
447 TAO_ORB_Core::typecodefactory_adapter_name ());
449 if (adapter == nullptr)
451 throw ::CORBA::INTERNAL ();
454 return adapter->create_enum_tc (id, name, members);
457 CORBA::TypeCode_ptr
458 CORBA::ORB::create_alias_tc (
459 const char *id,
460 const char *name,
461 CORBA::TypeCode_ptr original_type)
463 TAO_TypeCodeFactory_Adapter *adapter =
464 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
465 TAO_ORB_Core::typecodefactory_adapter_name ());
467 if (adapter == nullptr)
469 throw ::CORBA::INTERNAL ();
472 return adapter->create_alias_tc (id, name, original_type);
475 CORBA::TypeCode_ptr
476 CORBA::ORB::create_exception_tc (
477 const char *id,
478 const char *name,
479 const CORBA::StructMemberSeq & members)
481 TAO_TypeCodeFactory_Adapter *adapter =
482 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
483 TAO_ORB_Core::typecodefactory_adapter_name ());
485 if (adapter == nullptr)
487 throw ::CORBA::INTERNAL ();
490 return adapter->create_exception_tc (id, name, members);
493 CORBA::TypeCode_ptr
494 CORBA::ORB::create_interface_tc (
495 const char *id,
496 const char *name)
498 TAO_TypeCodeFactory_Adapter *adapter =
499 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
500 TAO_ORB_Core::typecodefactory_adapter_name ());
502 if (adapter == nullptr)
504 throw ::CORBA::INTERNAL ();
507 return adapter->create_interface_tc (id, name);
510 CORBA::TypeCode_ptr
511 CORBA::ORB::create_string_tc (
512 CORBA::ULong bound)
514 TAO_TypeCodeFactory_Adapter *adapter =
515 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
516 TAO_ORB_Core::typecodefactory_adapter_name ());
518 if (adapter == nullptr)
520 throw ::CORBA::INTERNAL ();
523 return adapter->create_string_tc (bound);
526 CORBA::TypeCode_ptr
527 CORBA::ORB::create_wstring_tc (
528 CORBA::ULong bound)
530 TAO_TypeCodeFactory_Adapter *adapter =
531 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
532 TAO_ORB_Core::typecodefactory_adapter_name ());
534 if (adapter == nullptr)
536 throw ::CORBA::INTERNAL ();
539 return adapter->create_wstring_tc (bound);
542 CORBA::TypeCode_ptr
543 CORBA::ORB::create_fixed_tc (
544 CORBA::UShort digits,
545 CORBA::UShort scale)
547 TAO_TypeCodeFactory_Adapter *adapter =
548 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
549 TAO_ORB_Core::typecodefactory_adapter_name ());
551 if (adapter == nullptr)
553 throw ::CORBA::INTERNAL ();
556 return adapter->create_fixed_tc (digits, scale);
559 CORBA::TypeCode_ptr
560 CORBA::ORB::create_sequence_tc (
561 CORBA::ULong bound,
562 CORBA::TypeCode_ptr element_type)
564 TAO_TypeCodeFactory_Adapter *adapter =
565 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
566 TAO_ORB_Core::typecodefactory_adapter_name ());
568 if (adapter == nullptr)
570 throw ::CORBA::INTERNAL ();
573 return adapter->create_sequence_tc (bound, element_type);
576 CORBA::TypeCode_ptr
577 CORBA::ORB::create_array_tc (
578 CORBA::ULong length,
579 CORBA::TypeCode_ptr element_type)
581 TAO_TypeCodeFactory_Adapter *adapter =
582 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
583 TAO_ORB_Core::typecodefactory_adapter_name ());
585 if (adapter == nullptr)
587 throw ::CORBA::INTERNAL ();
590 return adapter->create_array_tc (length, element_type);
593 CORBA::TypeCode_ptr
594 CORBA::ORB::create_value_tc (
595 const char *id,
596 const char *name,
597 CORBA::ValueModifier type_modifier,
598 CORBA::TypeCode_ptr concrete_base,
599 const CORBA::ValueMemberSeq & members)
601 TAO_TypeCodeFactory_Adapter *adapter =
602 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
603 TAO_ORB_Core::typecodefactory_adapter_name ());
605 if (adapter == nullptr)
607 throw ::CORBA::INTERNAL ();
610 return adapter->create_value_tc (id, name,
611 type_modifier,
612 concrete_base,
613 members);
616 CORBA::TypeCode_ptr
617 CORBA::ORB::create_value_box_tc (
618 const char *id,
619 const char *name,
620 CORBA::TypeCode_ptr boxed_type)
622 TAO_TypeCodeFactory_Adapter *adapter =
623 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
624 TAO_ORB_Core::typecodefactory_adapter_name ());
626 if (adapter == nullptr)
628 throw ::CORBA::INTERNAL ();
631 return adapter->create_value_box_tc (id, name, boxed_type);
634 CORBA::TypeCode_ptr
635 CORBA::ORB::create_native_tc (const char *id, const char *name)
637 TAO_TypeCodeFactory_Adapter *adapter =
638 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
639 TAO_ORB_Core::typecodefactory_adapter_name ());
641 if (adapter == nullptr)
643 throw ::CORBA::INTERNAL ();
646 return adapter->create_native_tc (id, name);
649 CORBA::TypeCode_ptr
650 CORBA::ORB::create_recursive_tc (const char *id)
652 TAO_TypeCodeFactory_Adapter *adapter =
653 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
654 TAO_ORB_Core::typecodefactory_adapter_name ());
656 if (adapter == nullptr)
658 throw ::CORBA::INTERNAL ();
661 return adapter->create_recursive_tc (id);
664 CORBA::TypeCode_ptr
665 CORBA::ORB::create_abstract_interface_tc (const char *id, const char *name)
667 TAO_TypeCodeFactory_Adapter *adapter =
668 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
669 TAO_ORB_Core::typecodefactory_adapter_name ());
671 if (adapter == nullptr)
673 throw ::CORBA::INTERNAL ();
676 return adapter->create_abstract_interface_tc (id, name);
679 CORBA::TypeCode_ptr
680 CORBA::ORB::create_local_interface_tc (const char *id, const char *name)
682 TAO_TypeCodeFactory_Adapter *adapter =
683 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
684 TAO_ORB_Core::typecodefactory_adapter_name ());
686 if (adapter == nullptr)
688 throw ::CORBA::INTERNAL ();
691 return adapter->create_local_interface_tc (id, name);
694 CORBA::TypeCode_ptr
695 CORBA::ORB::create_component_tc (const char *id, const char *name)
697 TAO_TypeCodeFactory_Adapter *adapter =
698 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
699 TAO_ORB_Core::typecodefactory_adapter_name ());
701 if (adapter == nullptr)
703 throw ::CORBA::INTERNAL ();
706 return adapter->create_component_tc (id, name);
709 CORBA::TypeCode_ptr
710 CORBA::ORB::create_home_tc (const char *id, const char *name)
712 TAO_TypeCodeFactory_Adapter *adapter =
713 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
714 TAO_ORB_Core::typecodefactory_adapter_name ());
716 if (adapter == nullptr)
718 throw ::CORBA::INTERNAL ();
721 return adapter->create_home_tc (id, name);
724 CORBA::TypeCode_ptr
725 CORBA::ORB::create_event_tc (
726 const char *id,
727 const char *name,
728 CORBA::ValueModifier type_modifier,
729 CORBA::TypeCode_ptr concrete_base,
730 const CORBA::ValueMemberSeq &members)
732 TAO_TypeCodeFactory_Adapter *adapter =
733 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
734 TAO_ORB_Core::typecodefactory_adapter_name ());
736 if (adapter == nullptr)
738 throw ::CORBA::INTERNAL ();
741 return adapter->create_event_tc (id,
742 name,
743 type_modifier,
744 concrete_base,
745 members);
748 // ****************************************************************
750 #endif /* TAO_HAS_MINIMUM_CORBA */
752 CORBA::Object_ptr
753 CORBA::ORB::resolve_policy_manager ()
755 #if (TAO_HAS_CORBA_MESSAGING == 1)
757 TAO_Policy_Manager *policy_manager = this->orb_core_->policy_manager ();
759 if (policy_manager == nullptr)
761 return CORBA::Object::_nil ();
764 return CORBA::Object::_duplicate (policy_manager);
766 #else
768 return CORBA::Object::_nil ();
770 #endif /* TAO_HAS_CORBA_MESSAGING == 1 */
773 CORBA::Object_ptr
774 CORBA::ORB::resolve_policy_current ()
776 #if (TAO_HAS_CORBA_MESSAGING == 1)
778 TAO_Policy_Current &policy_current = this->orb_core_->policy_current ();
779 return CORBA::Object::_duplicate (&policy_current);
781 #else
783 return CORBA::Object::_nil ();
785 #endif /* TAO_HAS_CORBA_MESSAGING == 1 */
788 void
789 CORBA::ORB::resolve_service (TAO::MCAST_SERVICEID mcast_service_id)
791 #if defined ACE_HAS_IP_MULTICAST
792 static char const * const env_service_port[] =
794 "NameServicePort",
795 "TradingServicePort",
796 "ImplRepoServicePort",
797 "InterfaceRepoServicePort"
800 static unsigned short const default_service_port[] =
802 TAO_DEFAULT_NAME_SERVER_REQUEST_PORT,
803 TAO_DEFAULT_TRADING_SERVER_REQUEST_PORT,
804 TAO_DEFAULT_IMPLREPO_SERVER_REQUEST_PORT,
805 TAO_DEFAULT_INTERFACEREPO_SERVER_REQUEST_PORT
808 // By now, the table filled in with -ORBInitRef arguments has been
809 // checked. We only get here if the table didn't contain an initial
810 // reference for the requested Service.
812 CORBA::String_var default_init_ref =
813 this->orb_core_->orb_params ()->default_init_ref ();
815 static char const mcast_prefix[] = "mcast://:::";
817 if ((ACE_OS::strncmp (default_init_ref.in (),
818 mcast_prefix,
819 sizeof (mcast_prefix) - 1) == 0))
821 // First, determine if the port was supplied on the command line
822 unsigned short port =
823 this->orb_core_->orb_params ()->service_port (mcast_service_id);
825 if (port == 0)
827 // Look for the port among our environment variables.
828 char const * const port_number =
829 ACE_OS::getenv (env_service_port[mcast_service_id]);
831 if (port_number != nullptr)
832 port = static_cast<unsigned short> (ACE_OS::atoi (port_number));
833 else
834 port = default_service_port[mcast_service_id];
837 // Set the port value in ORB_Params: modify the default mcast
838 // value.
839 static char const mcast_fmt[] = "mcast://:%d::";
840 static size_t const PORT_BUF_SIZE = 256;
842 char def_init_ref[PORT_BUF_SIZE] = { 0 };
844 ACE_OS::snprintf (def_init_ref,
845 PORT_BUF_SIZE,
846 mcast_fmt,
847 port);
849 this->orb_core_->orb_params ()->default_init_ref (def_init_ref);
851 #else
852 ACE_UNUSED_ARG (mcast_service_id);
853 #endif /* ACE_HAS_IP_MULTICAST */
856 CORBA::Object_ptr
857 CORBA::ORB::resolve_initial_references (const char *name,
858 ACE_Time_Value *timeout)
860 // This method should not be called if the ORB has been shutdown.
861 this->check_shutdown ();
863 CORBA::Object_var result;
865 if (ACE_OS::strcmp (name, TAO_OBJID_ROOTPOA) == 0)
867 result = this->orb_core ()->root_poa ();
869 else if (ACE_OS::strcmp (name, TAO_OBJID_POACURRENT) == 0)
871 result = this->orb_core ()->resolve_poa_current ();
873 else if (ACE_OS::strcmp (name, TAO_OBJID_POLICYMANAGER) == 0)
875 result = this->resolve_policy_manager ();
877 else if (ACE_OS::strcmp (name, TAO_OBJID_POLICYCURRENT) == 0)
879 result = this->resolve_policy_current ();
881 else if (ACE_OS::strcmp (name, TAO_OBJID_IORMANIPULATION) == 0)
883 result = this->orb_core ()->resolve_ior_manipulation ();
885 else if (ACE_OS::strcmp (name, TAO_OBJID_IORTABLE) == 0)
887 result = this->orb_core ()->resolve_ior_table ();
889 else if (ACE_OS::strcmp (name, TAO_OBJID_ASYNCIORTABLE) == 0)
891 result = this->orb_core ()->resolve_async_ior_table ();
893 else if (ACE_OS::strcmp (name, TAO_OBJID_DYNANYFACTORY) == 0)
895 result = this->orb_core ()->resolve_dynanyfactory ();
897 else if (ACE_OS::strcmp (name, TAO_OBJID_TYPECODEFACTORY) == 0)
899 result = this->orb_core ()->resolve_typecodefactory ();
901 else if (ACE_OS::strcmp (name, TAO_OBJID_CODECFACTORY) == 0)
903 result = this->orb_core ()->resolve_codecfactory ();
905 else if (ACE_OS::strcmp (name, TAO_OBJID_COMPRESSIONMANAGER) == 0)
907 result = this->orb_core ()->resolve_compression_manager ();
909 else if (ACE_OS::strcmp (name, TAO_OBJID_MONITOR) == 0)
911 result = this->orb_core ()->resolve_monitor ();
913 #if TAO_HAS_INTERCEPTORS == 1
914 else if (ACE_OS::strcmp (name, TAO_OBJID_PICurrent) == 0)
916 result = this->orb_core ()->resolve_picurrent ();
918 #endif
920 // -----------------------------------------------------------------
922 if (CORBA::is_nil (result.in ()))
924 // Search the object reference table. This search must occur before
925 // the InitRef table search, since it may contain local objects.
926 result =
927 this->orb_core ()->object_ref_table ().resolve_initial_reference (name);
930 if (!CORBA::is_nil (result.in ()))
931 return result._retn ();
933 // -----------------------------------------------------------------
935 // Check ORBInitRef options.
937 // @@ There appears to be long standing (i.e. back when the map was
938 // an ACE_Hash_Map_Manager) race condition here since the map
939 // access is not synchronized.
941 // Is the service name in the IOR Table.
942 TAO_ORB_Core::InitRefMap::iterator ior =
943 this->orb_core_->init_ref_map ()->find (ACE_CString (name));
945 if (ior != this->orb_core_->init_ref_map ()->end ())
946 return this->string_to_object ((*ior).second.c_str ());
948 // Look for an environment variable called "<name>IOR".
950 static const char ior_string[] = "IOR";
952 CORBA::String_var ior_env_var_name =
953 CORBA::string_alloc (
954 static_cast<CORBA::ULong> (std::strlen (name) + sizeof (ior_string)));
956 ACE_OS::strcpy (ior_env_var_name.inout (), name);
958 ACE_OS::strcat (ior_env_var_name.inout (), ior_string);
960 ACE_CString service_ior = ACE_OS::getenv (ior_env_var_name.in ());
962 if (ACE_OS::strcmp (service_ior.c_str (), "") != 0)
964 result = this->string_to_object (service_ior.c_str());
966 return result._retn ();
969 // May be trying the explicitly specified services and the well
970 // known services should be tried first before falling on to default
971 // services.
973 // Set the timeout value.
974 this->set_timeout (timeout);
976 if (ACE_OS::strcmp (name, TAO_OBJID_NAMESERVICE) == 0)
978 this->resolve_service (TAO::MCAST_NAMESERVICE);
980 else if (ACE_OS::strcmp (name, TAO_OBJID_TRADINGSERVICE) == 0)
982 this->resolve_service (TAO::MCAST_TRADINGSERVICE);
984 else if (ACE_OS::strcmp (name, TAO_OBJID_IMPLREPOSERVICE) == 0)
986 this->resolve_service (TAO::MCAST_IMPLREPOSERVICE);
988 else if (ACE_OS::strcmp (name, TAO_OBJID_INTERFACEREP) == 0)
990 this->resolve_service (TAO::MCAST_INTERFACEREPOSERVICE);
993 // Is not one of the well known services, try to find it in the
994 // InitRef table....check the defaultinitref values also.
996 result = this->orb_core ()->resolve_rir (name);
998 if (!CORBA::is_nil (result.in ()))
999 return result._retn ();
1000 // -----------------------------------------------------------------
1002 throw ::CORBA::ORB::InvalidName ();
1005 #if !defined(CORBA_E_MICRO)
1006 void
1007 CORBA::ORB::register_initial_reference (const char * id, CORBA::Object_ptr obj)
1009 if (id == nullptr || std::strlen (id) == 0)
1010 throw ::CORBA::ORB::InvalidName ();
1012 if (CORBA::is_nil (obj))
1013 throw ::CORBA::BAD_PARAM (CORBA::OMGVMCID | 27, CORBA::COMPLETED_NO);
1015 TAO_Object_Ref_Table &table = this->orb_core_->object_ref_table ();
1017 if (table.register_initial_reference (id, obj) == -1)
1018 throw ::CORBA::ORB::InvalidName ();
1021 CORBA::Object_ptr
1022 CORBA::ORB::unregister_initial_reference (const char * id)
1024 if (id == nullptr || std::strlen (id) == 0)
1025 throw ::CORBA::ORB::InvalidName ();
1027 TAO_Object_Ref_Table &table = this->orb_core_->object_ref_table ();
1028 CORBA::Object_ptr obj = table.unregister_initial_reference (id);
1030 if (CORBA::is_nil (obj))
1031 throw ::CORBA::ORB::InvalidName ();
1033 return obj;
1035 #endif
1037 CORBA::ORB::ObjectIdList_ptr
1038 CORBA::ORB::list_initial_services ()
1040 this->check_shutdown ();
1042 return this->orb_core ()->list_initial_references ();
1045 void
1046 CORBA::ORB::check_shutdown ()
1048 if (this->orb_core () != nullptr)
1050 this->orb_core ()->check_shutdown ();
1052 else
1054 // If the ORB_Core pointer is zero, assume that the ORB_Core has
1055 // been destroyed.
1057 // As defined by the CORBA 2.3 specification, throw a
1058 // CORBA::OBJECT_NOT_EXIST exception if the ORB has been
1059 // destroyed by the time an ORB function is called.
1061 throw ::CORBA::OBJECT_NOT_EXIST (0, CORBA::COMPLETED_NO);
1066 CORBA::ORB_ptr
1067 CORBA::ORB::_tao_make_ORB (TAO_ORB_Core * orb_core)
1069 CORBA::ORB_ptr orb = CORBA::ORB_ptr ();
1071 ACE_NEW_RETURN (orb,
1072 CORBA::ORB (orb_core),
1073 CORBA::ORB::_nil ());
1075 return orb;
1078 // ****************************************************************
1080 namespace TAO
1082 bool
1083 parse_orb_opt (ACE_Argv_Type_Converter& command_line,
1084 const ACE_TCHAR* orb_opt,
1085 ACE_TString& opt_arg)
1087 if (opt_arg.length () > 0)
1088 return false;
1090 ACE_Arg_Shifter arg_shifter (command_line.get_argc (),
1091 command_line.get_TCHAR_argv ());
1093 size_t opt_len = ACE_OS::strlen (orb_opt);
1095 bool found = false;
1096 while (arg_shifter.is_anything_left ())
1098 const ACE_TCHAR *current_arg = arg_shifter.get_current ();
1100 if (ACE_OS::strcasecmp (current_arg,
1101 orb_opt) == 0)
1103 found = true;
1104 arg_shifter.consume_arg ();
1105 if (arg_shifter.is_parameter_next ())
1107 opt_arg = arg_shifter.get_current ();
1108 arg_shifter.consume_arg ();
1111 else if (ACE_OS::strncasecmp (current_arg, orb_opt,
1112 opt_len) == 0)
1114 arg_shifter.consume_arg ();
1115 // The rest of the argument is the ORB id...
1116 // but we should skip an optional space...
1117 if (current_arg[opt_len] == ' ')
1118 opt_arg = current_arg + opt_len + 1;
1119 else
1120 opt_arg = current_arg + opt_len;
1122 else
1123 arg_shifter.ignore_arg ();
1125 return found;
1128 ACE_Intrusive_Auto_Ptr<ACE_Service_Gestalt>
1129 find_orb_context (const ACE_TString& orbconfig_string)
1131 const ACE_TCHAR *arg = orbconfig_string.c_str ();
1133 // Need a local repo? Make one which typically should not be as
1134 // big as the default repository
1135 if (ACE_OS::strcasecmp (arg, ACE_TEXT("LOCAL")) == 0)
1137 ACE_Service_Gestalt* gestalt = nullptr;
1138 ACE_NEW_THROW_EX (gestalt,
1139 ACE_Service_Gestalt
1140 (ACE_Service_Gestalt::MAX_SERVICES / 4, true),
1141 CORBA::NO_MEMORY
1142 (CORBA::SystemException::_tao_minor_code (0,
1143 ENOMEM),
1144 CORBA::COMPLETED_NO));
1145 return ACE_Intrusive_Auto_Ptr<ACE_Service_Gestalt> (gestalt);
1148 if (ACE_OS::strcasecmp (arg, ACE_TEXT("CURRENT")) == 0)
1150 return ACE_Service_Config::current ();
1153 // Explicit global case?
1154 if (orbconfig_string.is_empty () || ACE_OS::strcasecmp (arg, ACE_TEXT("GLOBAL")) == 0)
1156 return ACE_Service_Config::global ();
1159 // Someone else's context?
1160 const ACE_TCHAR *shared = ACE_TEXT("ORB:");
1161 size_t const shared_len = ACE_OS::strlen(shared);
1162 if (ACE_OS::strncmp (arg, shared, shared_len) == 0)
1164 ACE_TString orbid (orbconfig_string.substr (shared_len));
1166 // Get ORB Core
1167 TAO_ORB_Core_Auto_Ptr oc (TAO::ORB_Table::instance ()->find (
1168 ACE_TEXT_ALWAYS_CHAR(orbid.c_str ())));
1169 if (oc.get () != nullptr)
1170 return oc->configuration ();
1172 if (TAO_debug_level > 0)
1173 TAOLIB_ERROR ((LM_ERROR,
1174 ACE_TEXT ("ERROR: Unable to find ORB: %s. Invalid shared ")
1175 ACE_TEXT ("configuration argument \"%s\"\n"),
1176 orbid.c_str (), arg));
1178 throw ::CORBA::BAD_PARAM
1179 (CORBA::SystemException::_tao_minor_code
1180 ( TAO_ORB_CORE_INIT_LOCATION_CODE,
1181 ENOTSUP),
1182 CORBA::COMPLETED_NO);
1186 // Unknown value
1187 if (TAO_debug_level > 0)
1188 TAOLIB_ERROR ((LM_ERROR,
1189 ACE_TEXT ("ERROR: -ORBGestalt unknown value <%s>\n"),
1190 orbconfig_string.c_str()));
1192 throw ::CORBA::BAD_PARAM
1193 (CORBA::SystemException::_tao_minor_code
1194 ( TAO_ORB_CORE_INIT_LOCATION_CODE,
1195 EINVAL),
1196 CORBA::COMPLETED_NO);
1200 // ORB initialization, per OMG document 98-12-01.
1201 // NOTE we also define wide character versions as a conveniance, IF
1202 // we are building wide character applications.
1203 // The first two versions are wrappers to the actual third and final
1204 // implimentation of ORB_init() which is the "native" char form.
1206 #if defined (ACE_USES_WCHAR)
1207 // Provide the narrow char version as well as the above wide char version.
1208 CORBA::ORB_ptr
1209 CORBA::ORB_init (int &argc,
1210 ACE_ANTI_TCHAR *argv[],
1211 const char *orbid)
1213 ACE_Argv_Type_Converter command_line (argc, argv);
1214 return CORBA::ORB_init (command_line.get_argc (),
1215 command_line.get_TCHAR_argv (),
1216 orbid);
1219 CORBA::ORB_ptr
1220 CORBA::ORB_init (int &argc,
1221 wchar_t *argv[],
1222 const wchar_t *orbid)
1224 return CORBA::ORB_init (argc, argv, ACE_TEXT_ALWAYS_CHAR (orbid));
1226 #endif
1228 CORBA::ORB_ptr
1229 CORBA::ORB_init (int &argc, ACE_TCHAR *argv[], const char *orbid)
1231 // It doesn't make sense for argc to be zero and argv to be
1232 // non-empty/zero, or for argc to be greater than zero and argv be
1233 // zero.
1234 size_t const argv0_len = (argv ? (*argv
1235 ? ACE_OS::strlen (*argv)
1236 : 0)
1237 : 0);
1239 if ((argc == 0 && argv0_len != 0)
1240 || (argc != 0 && (argv == nullptr || argv[0] == nullptr)))
1242 throw ::CORBA::BAD_PARAM (
1243 CORBA::SystemException::_tao_minor_code (
1245 EINVAL),
1246 CORBA::COMPLETED_NO);
1249 // Scan the parameters to find any we could interpret to
1250 // use for initializing the global context. Note that if
1251 // the global context has been initialized already, the
1252 // parameters may either be ignored, or later used to initialize
1253 // a local configuration context. The chosen action depends on
1254 // weather we want the ORB to share the global context or
1255 // have its own, private (or local) context.
1256 if (TAO::ORB::open_global_services (argc, argv) == -1)
1258 return CORBA::ORB::_nil ();
1261 // Copy command line parameter not to corrupt the original.
1262 ACE_Argv_Type_Converter command_line (argc, argv);
1264 // Make sure the following is done after the global ORB
1265 // initialization since we need to have exceptions initialized.
1267 // Use this string variable to hold the orbid
1268 ACE_TString orbid_string (ACE_TEXT_CHAR_TO_TCHAR(orbid));
1269 TAO::parse_orb_opt (command_line, ACE_TEXT("-ORBid"), orbid_string);
1271 // Get ORB Core
1272 TAO_ORB_Core_Auto_Ptr oc (TAO::ORB_Table::instance ()->find (
1273 ACE_TEXT_ALWAYS_CHAR(orbid_string.c_str ())));
1275 // The ORB was already initialized. Just return that one.
1276 if (oc.get () != nullptr)
1278 return CORBA::ORB::_duplicate (oc->orb ());
1281 // Determine the service object registry this ORB will use. The choices
1282 // are: (a) the legacy (global); (b) its own, local, or (c) share somebody
1283 // else's configuration. By default use the process-wide (global) context
1284 // Use this string variable to hold the configuration identity key
1285 ACE_TString orbconfig_string;
1286 TAO::parse_orb_opt (command_line, ACE_TEXT("-ORBGestalt"), orbconfig_string);
1287 ACE_Intrusive_Auto_Ptr<ACE_Service_Gestalt> gestalt = TAO::find_orb_context (orbconfig_string);
1289 // An ORB corresponding to the desired ORBid doesn't exist so create
1290 // a new one.
1291 TAO_ORB_Core * tmp = nullptr;
1292 ACE_NEW_THROW_EX (tmp,
1293 TAO_ORB_Core (ACE_TEXT_ALWAYS_CHAR(orbid_string.c_str ()),
1294 gestalt),
1295 CORBA::NO_MEMORY (
1296 CORBA::SystemException::_tao_minor_code (0,
1297 ENOMEM),
1298 CORBA::COMPLETED_NO));
1300 // The ORB table increases the reference count on the ORB Core
1301 // so do not release it here. Allow the TAO_ORB_Core_Auto_Ptr
1302 // to decrease the reference count on the ORB Core when it goes
1303 // out of scope.
1304 oc.reset (tmp);
1306 // Having the ORB's default static services be shared among all ORBs
1307 // is tempting from the point of view of reducing the dynamic
1308 // footprint. However, if the ORB in a DLL and the rest of that
1309 // application most likely neither cares, nor wishes to know about
1310 // them. Furthermore, if the ORB DLL gets unloaded, the static
1311 // services it had registered globally will no longer be accessible,
1312 // which will have disastrous consequences at the process
1313 // shutdown. Hence, the ACE_Service_Config_Guard ensures that for
1314 // the current thread, any references to the global
1315 // ACE_Service_Config will be re-routed to this ORB's service gestalt.
1317 ACE_Service_Config_Guard scg (oc->configuration ());
1319 // Initialize the Service Configurator. This must occur before the
1320 // ORBInitializer::pre_init() method is invoked on each registered
1321 // ORB initializer.
1322 int result = TAO::ORB::open_services (oc->configuration (),
1323 command_line.get_argc (),
1324 command_line.get_TCHAR_argv ());
1326 // Check for errors returned from <TAO_Internal::open_services>.
1327 if (result != 0 && errno != ENOENT)
1329 TAOLIB_ERROR ((LM_ERROR,
1330 ACE_TEXT ("TAO (%P|%t) %p\n"),
1331 ACE_TEXT ("Unable to initialize the ")
1332 ACE_TEXT ("Service Configurator")));
1333 throw ::CORBA::INITIALIZE (
1334 CORBA::SystemException::_tao_minor_code (
1335 TAO_ORB_CORE_INIT_LOCATION_CODE,
1337 CORBA::COMPLETED_NO);
1340 TAO::ORBInitializer_Registry_Adapter * orbinitializer_registry =
1341 oc.get ()->orbinitializer_registry ();
1343 PortableInterceptor::SlotId slotid = 0;
1344 size_t pre_init_count = 0;
1346 if (orbinitializer_registry != nullptr)
1348 pre_init_count =
1349 orbinitializer_registry->pre_init (oc.get (),
1350 command_line.get_argc(),
1351 command_line.get_ASCII_argv(),
1352 slotid);
1355 // Initialize the ORB Core instance.
1356 result = oc->init (command_line.get_argc(),
1357 command_line.get_ASCII_argv());
1359 if (orbinitializer_registry != nullptr)
1361 orbinitializer_registry->post_init (pre_init_count,
1362 oc.get (),
1363 command_line.get_argc(),
1364 command_line.get_ASCII_argv(),
1365 slotid);
1368 if (TAO_debug_level > 2)
1370 TAOLIB_DEBUG ((LM_DEBUG,
1371 ACE_TEXT("TAO (%P|%t) - Created new ORB <%s>\n"),
1372 orbid_string.c_str ()));
1375 // Before returning remember to store the ORB into the table...
1376 if (TAO::ORB_Table::instance ()->bind (ACE_TEXT_ALWAYS_CHAR(orbid_string.c_str ()),
1377 oc.get ()) != 0)
1378 throw ::CORBA::INTERNAL (0, CORBA::COMPLETED_NO);
1380 // Return a duplicate since the ORB_Core should release the last
1381 // reference to the ORB.
1382 return CORBA::ORB::_duplicate (oc->orb ());
1385 // ****************************************************************
1387 // Object reference stringification.
1388 char *
1389 CORBA::ORB::object_to_string (CORBA::Object_ptr obj)
1391 // This method should not be called if the ORB has been shutdown.
1392 this->check_shutdown ();
1394 if (!CORBA::is_nil (obj))
1396 if (!obj->can_convert_to_ior ())
1397 throw ::CORBA::MARSHAL (CORBA::OMGVMCID | 4, CORBA::COMPLETED_NO);
1399 // Allow a user to provide custom object stringification
1400 char* user_string =
1401 obj->convert_to_ior (this->use_omg_ior_format_, ior_prefix);
1403 if (user_string != nullptr)
1404 return user_string;
1407 // Application writer controls what kind of objref strings they get,
1408 // maybe along with other things, by how they initialize the ORB.
1409 if (use_omg_ior_format_)
1411 // By default, orbs use IOR strings; these are ugly (and error
1412 // prone) but specified by CORBA.
1414 // XXX there should be a simple way to reuse this code in other
1415 // ORB implementations ...
1417 #if defined (ACE_INITIALIZE_MEMORY_BEFORE_USE)
1418 char buf [ACE_CDR::DEFAULT_BUFSIZE] = { 0 };
1419 #else
1420 // Avoid the initialization overhead if not compiling with
1421 // support for a memory profiler. There is no need to actually perform
1422 // initialization otherwise.
1423 char buf [ACE_CDR::DEFAULT_BUFSIZE];
1424 #endif /* ACE_INITIALIZE_MEMORY_BEFORE_USE */
1426 TAO_OutputCDR cdr (buf, sizeof buf,
1427 TAO_ENCAP_BYTE_ORDER,
1428 this->orb_core_->output_cdr_buffer_allocator (),
1429 this->orb_core_->output_cdr_dblock_allocator (),
1430 this->orb_core_->output_cdr_msgblock_allocator (),
1431 this->orb_core_->orb_params ()->cdr_memcpy_tradeoff (),
1432 TAO_DEF_GIOP_MAJOR,
1433 TAO_DEF_GIOP_MINOR);
1435 // There is no translator currently available for stringifying an object
1436 // reference, since there is no transport with which to choose an NCS/TCS
1437 // pair.
1439 // support limited oref ACE_OS::strcmp.
1440 (void) ACE_OS::memset (buf, 0, sizeof (buf));
1442 // Marshal the objref into an encapsulation bytestream.
1443 (void) cdr.write_octet (TAO_ENCAP_BYTE_ORDER);
1444 if (!(cdr << obj))
1445 throw ::CORBA::MARSHAL ();
1447 // Now hexify the encapsulated CDR data into a string, and
1448 // return that string.
1449 size_t const total_len = cdr.total_length ();
1451 char *cp = nullptr;
1452 ACE_ALLOCATOR_RETURN (cp,
1453 CORBA::string_alloc (
1454 sizeof ior_prefix
1456 * static_cast<CORBA::ULong> (total_len)),
1457 nullptr);
1459 CORBA::String_var string = cp;
1461 ACE_OS::strcpy (cp, ior_prefix);
1462 cp += sizeof (ior_prefix) - 1;
1464 for (const ACE_Message_Block *i = cdr.begin (); i != nullptr; i = i->cont ())
1466 const char *bytes = i->rd_ptr ();
1467 size_t len = i->length ();
1469 while (len--)
1471 *cp++ = static_cast<char> (ACE::nibble2hex ((*bytes) >> 4));
1472 *cp++ = static_cast<char> (ACE::nibble2hex (*bytes));
1473 ++bytes;
1476 // Null terminate the string..
1477 *cp = 0;
1479 return string._retn ();
1481 else
1483 // It is perfectly valid to marshal a nil object reference.
1484 // However, it is not possible to convert a nil object reference
1485 // to a URL IOR, so throw an exception.
1486 if (CORBA::is_nil (obj) || obj->_stubobj () == nullptr)
1488 if (TAO_debug_level > 0)
1489 TAOLIB_ERROR ((LM_ERROR,
1490 ACE_TEXT ("Nil object reference or TAO_Stub ")
1491 ACE_TEXT ("pointer is zero when converting\n")
1492 ACE_TEXT ("object reference to URL IOR.\n")));
1494 throw ::CORBA::MARSHAL (
1495 CORBA::SystemException::_tao_minor_code (
1497 EINVAL),
1498 CORBA::COMPLETED_NO);
1501 TAO_MProfile &mp = obj->_stubobj ()->base_profiles ();
1503 // Try the profiles until one returns a string
1504 for (CORBA::ULong index = 0; index < mp.profile_count(); ++index)
1506 char * result = mp.get_profile (index)->to_string();
1507 if (result)
1508 return result;
1511 if (TAO_debug_level > 0)
1512 TAOLIB_ERROR ((LM_ERROR,
1513 ACE_TEXT ("TAO (%P|%t) - Cannot stringify given ")
1514 ACE_TEXT ("object. No or only unknown profiles.\n")));
1516 throw ::CORBA::MARSHAL (
1517 CORBA::SystemException::_tao_minor_code (
1519 EINVAL),
1520 CORBA::COMPLETED_NO);
1524 // Destringify arbitrary objrefs. This method is called from
1525 // <resolve_name_service> with an IOR <multicast_to_service>.
1526 CORBA::Object_ptr
1527 CORBA::ORB::string_to_object (const char *str)
1529 // This method should not be called if the ORB has been shutdown.
1530 this->check_shutdown ();
1532 // Check for NULL pointer
1533 if (str == nullptr)
1534 throw ::CORBA::INV_OBJREF (
1535 CORBA::SystemException::_tao_minor_code (
1537 EINVAL),
1538 CORBA::COMPLETED_NO);
1540 TAO_IOR_Parser *ior_parser =
1541 this->orb_core_->parser_registry ()->match_parser (str);
1543 if (ior_parser != nullptr)
1545 return ior_parser->parse_string (str, this);
1548 if (ACE_OS::strncmp (str, ior_prefix, sizeof ior_prefix - 1) == 0)
1549 return this->ior_string_to_object (str + sizeof ior_prefix - 1);
1550 else
1551 return this->url_ior_string_to_object (str);
1554 #if defined (ACE_USES_WCHAR)
1555 CORBA::Object_ptr
1556 CORBA::ORB::string_to_object (const wchar_t *str)
1558 return this->string_to_object (ACE_TEXT_ALWAYS_CHAR (str));
1560 #endif
1562 // ****************************************************************
1564 char *
1565 CORBA::ORB::id ()
1567 return CORBA::string_dup (this->orb_core_->orbid ());
1570 // ****************************************************************
1572 #if !defined(CORBA_E_MICRO)
1573 CORBA::Policy_ptr
1574 CORBA::ORB::create_policy (CORBA::PolicyType type, const CORBA::Any& val)
1576 this->check_shutdown ();
1578 TAO::PolicyFactory_Registry_Adapter *adapter =
1579 this->orb_core_->policy_factory_registry ();
1581 if (adapter == nullptr)
1583 throw ::CORBA::INTERNAL ();
1586 // Attempt to obtain the policy from the policy factory registry.
1587 return adapter->create_policy (type, val);
1589 #endif
1591 #if !defined(CORBA_E_MICRO)
1592 CORBA::Policy_ptr
1593 CORBA::ORB::_create_policy (CORBA::PolicyType type)
1595 this->check_shutdown ();
1597 TAO::PolicyFactory_Registry_Adapter *adapter =
1598 this->orb_core_->policy_factory_registry ();
1600 if (adapter == nullptr)
1602 throw ::CORBA::INTERNAL ();
1605 // Attempt to obtain the policy from the policy factory registry.
1606 return adapter->_create_policy (type);
1608 #endif
1610 // Destringify OMG-specified "IOR" string.
1612 // XXX there should be a simple way to reuse this code in other ORB
1613 // implementations ...
1614 CORBA::Object_ptr
1615 CORBA::ORB::ior_string_to_object (const char *str)
1617 // Unhex the bytes, and make a CDR deencapsulation stream from the
1618 // resulting data.
1619 ACE_Message_Block mb (std::strlen (str) / 2 + 1
1620 + ACE_CDR::MAX_ALIGNMENT + 1);
1622 ACE_CDR::mb_align (&mb);
1624 char *buffer = mb.rd_ptr ();
1625 const char *tmp = str;
1626 size_t len = 0;
1628 while (tmp [0] && tmp [1])
1630 // Some platforms define 'byte' as a macro, solve the problem
1631 // here.
1632 #undef byte
1633 unsigned char byte;
1635 if (!(ACE_OS::ace_isxdigit (tmp [0]) && ACE_OS::ace_isxdigit (tmp [1])))
1636 break;
1638 byte = (u_char) (ACE::hex2byte (tmp [0]) << 4);
1639 byte |= ACE::hex2byte (tmp [1]);
1641 buffer [len++] = byte;
1642 tmp += 2;
1645 if (tmp [0] && !ACE_OS::ace_isspace (tmp [0]))
1647 throw ::CORBA::BAD_PARAM ();
1650 // Create deencapsulation stream ... then unmarshal objref from that
1651 // stream.
1653 int const byte_order = *(mb.rd_ptr ());
1654 mb.rd_ptr (1);
1655 mb.wr_ptr (len);
1656 TAO_InputCDR stream (&mb,
1657 byte_order,
1658 TAO_DEF_GIOP_MAJOR,
1659 TAO_DEF_GIOP_MINOR,
1660 this->orb_core_);
1662 CORBA::Object_ptr objref = CORBA::Object::_nil ();
1663 stream >> objref;
1664 return objref;
1667 // ****************************************************************
1669 // Convert an URL style IOR in an object
1670 CORBA::Object_ptr
1671 CORBA::ORB::url_ior_string_to_object (const char* str)
1673 TAO_MProfile mprofile;
1674 // It is safe to declare this on the stack since the contents of
1675 // mprofile get copied. No memory is allocated for profile storage
1676 // here. The Connector Registry will determine the exact number
1677 // of profiles and tell the MProfile object to allocate enough memory
1678 // to hold them all.
1680 TAO_Connector_Registry *conn_reg = this->orb_core_->connector_registry ();
1682 if (conn_reg->make_mprofile (str, mprofile) != 0)
1684 throw ::CORBA::INV_OBJREF (
1685 CORBA::SystemException::_tao_minor_code (
1687 EINVAL),
1688 CORBA::COMPLETED_NO);
1691 // Now make the TAO_Stub.
1692 TAO_Stub *data = this->orb_core_->create_stub ((char *) nullptr, mprofile);
1694 TAO_Stub_Auto_Ptr safe_objdata (data);
1696 // Figure out if the servant is collocated.
1697 CORBA::Object_ptr obj = this->orb_core_->create_object (safe_objdata.get ());
1699 if (!CORBA::is_nil (obj))
1701 // Transfer ownership to the CORBA::Object
1702 (void) safe_objdata.release ();
1705 return obj;
1708 // *************************************************************
1709 // Valuetype factory operations
1710 // *************************************************************
1712 #if !defined(CORBA_E_MICRO)
1713 CORBA::ValueFactory
1714 CORBA::ORB::register_value_factory (const char *repository_id,
1715 CORBA::ValueFactory factory)
1717 this->check_shutdown ();
1719 return this->orb_core_->register_value_factory (repository_id, factory);
1721 #endif
1723 #if !defined(CORBA_E_MICRO)
1724 void
1725 CORBA::ORB::unregister_value_factory (const char *repository_id)
1727 this->check_shutdown ();
1729 this->orb_core_->unregister_value_factory (repository_id);
1731 #endif
1733 #if !defined(CORBA_E_MICRO)
1734 CORBA::ValueFactory
1735 CORBA::ORB::lookup_value_factory (const char *repository_id)
1737 this->check_shutdown ();
1739 return this->orb_core_->lookup_value_factory (repository_id);
1741 #endif
1743 TAO_END_VERSIONED_NAMESPACE_DECL