3 //=============================================================================
7 * Header file for CORBA's ORB type.
9 * @author DOC Center - Washington University at St. Louis
10 * @author DOC Group - Vanderbilt University
11 * @author DOC Laboratory - University of California at Irvine
13 //=============================================================================
18 #include /**/ "ace/pre.h"
20 #include "tao/UserException.h"
22 #if !defined (ACE_LACKS_PRAGMA_ONCE)
24 #endif /* ACE_LACKS_PRAGMA_ONCE */
26 #include "tao/orb_typesC.h"
27 #include "tao/objectid.h"
28 #include "tao/VarOut_T.h"
29 #include "tao/Pseudo_VarOut_T.h"
30 #include "tao/Seq_Var_T.h"
31 #include "tao/Seq_Out_T.h"
32 #include "tao/Sequence_T.h"
33 #include "tao/Policy_ForwardC.h"
34 #include "tao/ServicesC.h"
36 #include "ace/Thread_Mutex.h"
37 #include "ace/Guard_T.h"
40 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
44 TAO_SERVICEID_NAMESERVICE
,
45 TAO_SERVICEID_TRADINGSERVICE
,
46 TAO_SERVICEID_IMPLREPOSERVICE
,
47 TAO_SERVICEID_INTERFACEREPOSERVICE
,
48 TAO_SERVICEID_MCASTSERVER
51 /// Forward declarations.
53 class TAO_Client_Strategy_Factory
;
54 class TAO_Server_Strategy_Factory
;
58 class TAO_Valuetype_Adapter
;
59 class TAO_Acceptor_Filter
;
62 // ****************************************************************
67 class StructMemberSeq
;
70 class ORB_ObjectIdList
;
73 typedef Object
* Object_ptr
;
76 typedef ExceptionList
* ExceptionList_ptr
;
79 typedef ContextList
* ContextList_ptr
;
82 typedef Context
* Context_ptr
;
85 typedef NVList
*NVList_ptr
;
88 typedef NamedValue
*NamedValue_ptr
;
91 typedef Policy
*Policy_ptr
;
94 typedef OperationDef
* OperationDef_ptr
;
96 typedef CORBA::ULong PolicyType
;
98 // TODO - implement OMG's 'ORBid CORBA::ORB::id ()'.
104 ORB_ObjectIdList_var
;
110 ORB_ObjectIdList_out
;
112 class ValueFactoryBase
;
113 typedef ValueFactoryBase
*ValueFactory
;
115 typedef UShort ServiceType
;
118 typedef Request
* Request_ptr
;
119 typedef TAO_Pseudo_Var_T
<Request
> Request_var
;
120 typedef TAO_Pseudo_Out_T
<Request
> Request_out
;
123 typedef ORB
* ORB_ptr
;
124 typedef TAO_Pseudo_Var_T
<ORB
> ORB_var
;
125 typedef TAO_Pseudo_Out_T
<ORB
> ORB_out
;
127 typedef CORBA::Short ValueModifier
;
129 #if (TAO_HAS_MINIMUM_CORBA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
131 // Typedefs for CORBA::RequestSeq, which is an argument of
132 // send_multiple_requests_*().
134 TAO::unbounded_object_reference_sequence
<
135 CORBA::Request
, CORBA::Request_var
155 * @brief ORB pseudo-object.
157 * The "ORB" pseudo-object is used in bootstrapping, such as to
158 * create object references from strings. This class is intended
159 * to be inherited by others, which will provide some more of the
160 * CORBA support. Implementations of this "CORBA::ORB" class must
161 * know how to create stringify/destringify their objrefs, as well
162 * as how to marshal and unmarshal them.
167 class TAO_Export InvalidName
: public CORBA::UserException
171 InvalidName (const InvalidName
&);
174 InvalidName
&operator= (const InvalidName
&);
176 static InvalidName
*_downcast (CORBA::Exception
*);
177 static CORBA::Exception
*_alloc ();
179 virtual CORBA::Exception
*_tao_duplicate () const;
181 virtual void _raise () const;
183 virtual void _tao_encode (TAO_OutputCDR
&) const;
185 virtual void _tao_decode (TAO_InputCDR
&);
188 typedef char *ObjectId
;
189 typedef CORBA::String_var ObjectId_var
;
190 typedef CORBA::String_out ObjectId_out
;
191 static CORBA::TypeCode_ptr
const _tc_ObjectId
;
193 typedef CORBA::ORB_ObjectIdList ObjectIdList
;
194 typedef CORBA::ORB_ObjectIdList_var ObjectIdList_var
;
195 typedef CORBA::ORB_ObjectIdList_out ObjectIdList_out
;
196 typedef CORBA::ORB_ObjectIdList
*ObjectIdList_ptr
;
197 static CORBA::TypeCode_ptr
const _tc_ObjectIdList
;
199 /// Return a duplicate of @c orb.
201 * When work with this duplicate is complete, it should be freed
202 * up using CORBA::release().
204 static CORBA::ORB_ptr
_duplicate (CORBA::ORB_ptr orb
);
206 /// Returns a pointer to a nil ORB, i.e., an non-existent ORB. This
207 /// can be used for initialization or in comparisons.
208 static CORBA::ORB_ptr
_nil ();
210 /// Return this ORB's ORBid.
214 * Turn a string-ified object reference back into an object
215 * pointer. Typically these strings are created using
216 * object_to_string(), but not necessarily locally.
218 CORBA::Object_ptr
string_to_object (const char *str
);
220 #if defined (ACE_USES_WCHAR)
222 * Turn a string-ified object reference back into an object
223 * pointer. Typically these strings are created using
224 * object_to_string(), but not necessarily locally.
225 * This is a TAO specific extension.
227 CORBA::Object_ptr
string_to_object (const wchar_t *str
);
230 * Turn an object reference into a string. Each type of ORB,
231 * e.g. an IIOP ORB, must implement this. This can be used by
232 * servers to publish their whereabouts to clients. The output of
233 * this is typically eventually given to @c string_to_object() as
236 char * object_to_string (CORBA::Object_ptr obj
);
238 #if !defined(CORBA_E_MICRO)
239 // Value factory operations (CORBA 2.3 ptc/98-10-05 Ch. 4.2 p.4-7)
240 CORBA::ValueFactory
register_value_factory (
241 const char *repository_id
,
242 CORBA::ValueFactory factory
);
245 #if !defined(CORBA_E_MICRO)
246 void unregister_value_factory (const char * repository_id
);
249 #if !defined(CORBA_E_MICRO)
250 CORBA::ValueFactory
lookup_value_factory (const char *repository_id
);
253 #if (TAO_HAS_MINIMUM_CORBA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
255 void create_list (CORBA::Long count
, CORBA::NVList_ptr
&new_list
);
257 void create_operation_list(CORBA::OperationDef_ptr opDef
,
258 CORBA::NVList_ptr
& result
);
260 void create_named_value (CORBA::NamedValue_ptr
&nmval
);
262 void create_exception_list (CORBA::ExceptionList_ptr
&exclist
);
264 void create_environment (CORBA::Environment_ptr
&new_env
);
266 // The following are not implemented and just throw
267 // CORBA::NO_IMPLEMENT.
269 void create_context_list (CORBA::ContextList_ptr
&ctxtlist
);
271 void get_default_context (CORBA::Context_ptr
&ctx
);
273 CORBA::Boolean
get_service_information (
274 CORBA::ServiceType service_type
,
275 CORBA::ServiceInformation_out service_information
);
277 void send_multiple_requests_oneway (const CORBA::RequestSeq
&req
);
279 void send_multiple_requests_deferred (const CORBA::RequestSeq
&req
);
281 void get_next_response (CORBA::Request_ptr
&req
);
283 CORBA::Boolean
poll_next_response ();
285 /// The ORB TypeCode creation functions.
287 CORBA::TypeCode_ptr
create_struct_tc (
290 const CORBA::StructMemberSeq
&members
);
292 CORBA::TypeCode_ptr
create_union_tc (
295 CORBA::TypeCode_ptr discriminator_type
,
296 const CORBA::UnionMemberSeq
&members
);
298 CORBA::TypeCode_ptr
create_enum_tc (
301 const CORBA::EnumMemberSeq
&members
);
303 CORBA::TypeCode_ptr
create_alias_tc (
306 CORBA::TypeCode_ptr original_type
);
308 CORBA::TypeCode_ptr
create_exception_tc (
311 const CORBA::StructMemberSeq
&members
);
313 CORBA::TypeCode_ptr
create_interface_tc (const char *id
, const char *name
);
315 CORBA::TypeCode_ptr
create_string_tc (CORBA::ULong bound
);
317 CORBA::TypeCode_ptr
create_wstring_tc (CORBA::ULong bound
);
319 CORBA::TypeCode_ptr
create_fixed_tc (
320 CORBA::UShort digits
,
321 CORBA::UShort scale
);
323 CORBA::TypeCode_ptr
create_sequence_tc (
325 CORBA::TypeCode_ptr element_type
);
327 CORBA::TypeCode_ptr
create_array_tc (
329 CORBA::TypeCode_ptr element_type
);
331 CORBA::TypeCode_ptr
create_value_tc (
334 CORBA::ValueModifier type_modifier
,
335 CORBA::TypeCode_ptr concrete_base
,
336 const CORBA::ValueMemberSeq
&members
);
338 CORBA::TypeCode_ptr
create_value_box_tc (
341 CORBA::TypeCode_ptr boxed_type
);
343 CORBA::TypeCode_ptr
create_native_tc (const char *id
, const char *name
);
345 CORBA::TypeCode_ptr
create_recursive_tc (const char *id
);
347 CORBA::TypeCode_ptr
create_abstract_interface_tc (
351 CORBA::TypeCode_ptr
create_local_interface_tc (
355 CORBA::TypeCode_ptr
create_component_tc (
359 CORBA::TypeCode_ptr
create_home_tc (
363 CORBA::TypeCode_ptr
create_event_tc (
366 CORBA::ValueModifier type_modifier
,
367 CORBA::TypeCode_ptr concrete_base
,
368 const CORBA::ValueMemberSeq
&members
);
370 #endif /* TAO_HAS_MINIMUM_CORBA */
372 // = ORB event loop methods.
375 * Instructs the ORB to initialize itself and run its event loop in
376 * the current thread, not returning until the ORB has shut down.
377 * If an error occurs during initialization or at runtime, a CORBA
378 * system exception will be thrown.
383 * Instructs the ORB to initialize itself and run its event loop in
384 * the current thread, not returning until the ORB has shut down or
385 * the time value specified through @a tv has expired. If an
386 * error occurs during initialization or at runtime, a CORBA
387 * system exception will be thrown. @a tv is reduced by the
388 * amount of time spent in this call.
390 * If this function is called with a @ tv value, client threads
391 * making invocations will continue their operations. When the
392 * operation times out and returns, any invocations showing up on
393 * the server will be buffered by TCP.
395 void run (ACE_Time_Value
&tv
);
398 * Instructs the ORB to initialize itself and run its event loop in
399 * the current thread, not returning until the ORB has shut down or
400 * the time value specified through @a tv has expired. If an error
401 * occurs during initialization or at runtime, a CORBA system
402 * exception will be thrown. @a tv is reduced by the amount of time
403 * spent in this call. If @a tv is 0, it means that the timeout
404 * is infinite. If @a tv is @c ACE_Time_Value::zero, it specifies
405 * to poll and does not block.
407 * If this function is called with @a tv value, client threads
408 * making invocations will continue their operations. When the
409 * operation times out and returns, any invocations showing up on
410 * the server will be buffered by TCP.
412 void run (ACE_Time_Value
*tv
);
414 /// Returns an indication of whether the ORB needs to perform some
416 CORBA::Boolean
work_pending ();
418 /// Returns an indication of whether the ORB needs to perform some
419 /// work but will look for work pending for no more than the
422 * @note This is useful for implementing an event loop with an
425 CORBA::Boolean
work_pending (ACE_Time_Value
&tv
);
428 * This operation performs an implementation-defined unit of work.
429 * Note that the default behavior is to block if the unit of work
430 * is not present; this behavior can be modified by passing an
431 * appropriate @c ACE_Time_Value as described in run().
433 void perform_work ();
434 void perform_work (ACE_Time_Value
&tv
);
435 void perform_work (ACE_Time_Value
*tv
);
438 * This operation instructs the ORB to shut down. Shutting down the
439 * ORB causes all Object Adapters to be shut down. If
440 * @c wait_for_completion parameter is TRUE, this operation blocks
441 * until all ORB processing (including request processing and object
442 * deactivation or other operations associated with object adapters)
445 void shutdown (CORBA::Boolean wait_for_completion
= false);
448 * Explicitly destroy the ORB, releasing any resources. Note that
449 * TAO *cannot* implicitly release the resources even if you have
450 * destroyed all the references to a particular ORB since
451 * CORBA::ORB_init() is required to return the same pointer if
452 * called with the same ORBid, only after ORB::destroy() is called
453 * it may return a new one.
455 * The results of multi-threaded applications, trying to destroy ()
456 * the ORB in one thread and trying to service a request in another
457 * thread are not well defined. TAO does not support such cases.
462 * This method acts as a mini-bootstrapping Naming Service, which is
463 * provided by the ORB for certain well-known object references. TAO
464 * supports the "NameService", "TradingService", "RootPOA",
465 * "ImplRepo", and "POACurrent" via this method. The @c timeout
466 * value bounds the amount of time the ORB blocks waiting to
467 * resolve the service. This is most useful for bootstrapping
468 * remote services, such as the "NameService" or "TradingService",
469 * that are commonly resolved via multicast. By default, the
470 * value is 0, which means "use the @c
471 * TAO_DEFAULT_SERVICE_RESOLUTION_TIMEOUT timeout period".
473 * @note By using a default value for the @c timeout parameter,
474 * TAO will remains compliant with the CORBA
475 * resolve_initial_references() specification.
477 CORBA::Object_ptr
resolve_initial_references (
479 ACE_Time_Value
*timeout
= 0);
481 #if !defined(CORBA_E_MICRO)
482 /// Register an object reference with the ORB.
483 void register_initial_reference (const char * id
, CORBA::Object_ptr obj
);
485 /// Unregister an object reference with the ORB.
486 CORBA::Object_ptr
unregister_initial_reference (const char * id
);
489 /// Returns a sequence of ObjectIds that lists which objects have
490 /// references available via the initial references mechanism.
491 CORBA::ORB::ObjectIdList_ptr
list_initial_services ();
493 #if !defined(CORBA_E_MICRO)
494 CORBA::Policy_ptr
create_policy (CORBA::PolicyType type
,
495 const CORBA::Any
& val
);
498 // ----------------------------------------------------------------
499 // = TAO-specific extensions to the CORBA specification.
500 // ----------------------------------------------------------------
502 #if !defined(CORBA_E_MICRO)
503 /// Create an empty policy, usually to be filled in later by
505 CORBA::Policy_ptr
_create_policy (CORBA::PolicyType type
);
508 /// Reference counting...
509 unsigned long _incr_refcount ();
510 unsigned long _decr_refcount ();
511 unsigned long _refcount () const;
513 /// Set the IOR flag.
514 void _use_omg_ior_format (CORBA::Boolean ior
);
516 /// Get the IOR flag.
517 CORBA::Boolean
_use_omg_ior_format ();
519 /// Get the ORB core.
520 TAO_ORB_Core
*orb_core () const;
522 /// Factory method that creates an ORB.
523 static CORBA::ORB_ptr
_tao_make_ORB (TAO_ORB_Core
* orb_core
);
525 // Useful for template programming.
526 typedef ORB_ptr _ptr_type
;
527 typedef ORB_var _var_type
;
528 typedef ORB_out _out_type
;
530 /// Get the Timeout value
531 ACE_Time_Value
*get_timeout ();
534 // We must be created via the @c CORBA::ORB_init() function.
535 ORB (TAO_ORB_Core
*orb_core
);
539 * Protected destructor to enforce proper memory management
540 * through the reference counting mechanism.
544 /// Resolve the Policy Manager for this ORB.
545 CORBA::Object_ptr
resolve_policy_manager ();
547 /// Resolve the Policy Current for this thread.
548 CORBA::Object_ptr
resolve_policy_current ();
551 /// Resolve the given service based on the service ID.
553 * "@c resolve_service" is a legacy name. This method now simply
554 * sets up a default initial reference that will be subsequently
555 * used in resolve_initial_references().
557 void resolve_service (TAO::MCAST_SERVICEID service_id
);
559 /// Convert an OMG IOR into an object reference.
560 CORBA::Object_ptr
ior_string_to_object (const char* ior
);
562 /// Convert an URL style IOR into an object reference.
563 CORBA::Object_ptr
url_ior_string_to_object (const char* ior
);
565 /// Check if ORB has shutdown. If it has, throw the appropriate
567 void check_shutdown ();
569 /// Set the timeout value
570 void set_timeout (ACE_Time_Value
* timeout
);
573 /// Maintains a reference count of number of instantiations of the
575 std::atomic
<uint32_t> refcount_
;
577 /// The ORB_Core that created us....
578 TAO_ORB_Core
* orb_core_
;
580 /// Decides whether to use the URL notation or to use IOR notation.
581 CORBA::Boolean use_omg_ior_format_
;
583 // Prevent copying and assignment.
585 ORB
&operator= (const ORB
&);
588 ACE_Time_Value
* timeout_
;
590 } // End namespace CORBA
592 TAO_END_VERSIONED_NAMESPACE_DECL
594 #if defined (__ACE_INLINE__)
595 # include "tao/ORB.inl"
596 #endif /* __ACE_INLINE__ */
598 #include /**/ "ace/post.h"
600 #endif /* TAO_ORB_H */