3 * MICO --- an Open Source CORBA implementation
4 * Copyright (c) 1997-2003 by The Mico Team
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * For more information, visit the MICO Home Page at
21 * http://www.mico.org/
24 #ifndef __mico_orb_mico_h__
25 #define __mico_orb_mico_h__
28 # define USE_ORB_CACHE
37 typedef ORBRequest *ORBRequest_ptr;
38 typedef ObjVar<ORBRequest> ORBRequest_var;
39 typedef ObjOut<ORBRequest> ORBRequest_out;
42 class PrincipalCurrent_impl : public CORBA::PrincipalCurrent {
44 CORBA::Principal_ptr get_principal ();
58 Principal_ptr _principal;
59 Boolean _response_expected;
61 InvokeStatus _invoke_stat;
62 LocateStatus _locate_stat;
63 ObjectAdapter *_adapter;
72 GIOP::AddressingDisposition _ad;
73 PInterceptor::ServerRequestInfo_impl* _sri;
77 virtual ~ORBInvokeRec ();
81 void init_invoke (ORB_ptr, Object_ptr target,
82 ORBRequest *, Principal_ptr pr,
83 Boolean response_expected,
84 ORBCallback *, ObjectAdapter * = 0);
86 void init_locate (ORB_ptr, Object_ptr,
87 ORBCallback *, ObjectAdapter * = 0);
89 void init_bind (ORB_ptr, const char *,
90 const OctetSeq &tag, Address *, ORBCallback *,
93 void set_request_hint(void *hint)
95 void *get_request_hint()
98 void set_invoke_hint(void *hint)
100 void *get_invoke_hint()
101 { return _inv_hint; }
103 Boolean active() const
106 { _active = FALSE; };
111 Boolean completed () const
112 { return _have_result; }
117 void oa (ObjectAdapter *oaval)
118 { _adapter = oaval; }
120 RequestType request_type ()
123 ORBRequest *request ()
126 const OctetSeq &tag () const
129 ORBCallback *callback ()
132 Principal_ptr principal ()
133 { return _principal; }
135 PInterceptor::ServerRequestInfo_impl* requestinfo()
138 CORBA::Boolean response_expected()
139 { return _response_expected; }
143 void set_answer_invoke (InvokeStatus, Object_ptr, ORBRequest *,
144 GIOP::AddressingDisposition);
145 void set_answer_bind (LocateStatus, Object_ptr);
146 void set_answer_locate (LocateStatus, Object_ptr,
147 GIOP::AddressingDisposition);
149 Boolean get_answer_invoke (InvokeStatus &, Object_ptr &, ORBRequest *&,
150 GIOP::AddressingDisposition &);
151 Boolean get_answer_bind (LocateStatus &, Object_ptr &);
152 Boolean get_answer_locate (LocateStatus &, Object_ptr &,
153 GIOP::AddressingDisposition &);
158 class ORB : public ServerlessObject {
160 typedef CORBA::ULong MsgId;
163 class ResourceManager {
164 ULong _connection_limit;
165 ULong _request_limit;
166 ULong _connection_count;
167 MICOMT::Mutex conn_cnt_mutex;
170 _connection_limit = 10;
172 _connection_count = 0;
174 inline ULong connection_limit (ULong NewLimit) {
175 MICOMT::AutoLock l(conn_cnt_mutex);
176 return _connection_limit = NewLimit;
178 inline ULong connection_limit (void) const {
179 return _connection_limit;
181 inline ULong request_limit (ULong NewLimit) {
182 return _request_limit = NewLimit;
184 inline ULong request_limit (void) const {
185 return _request_limit;
189 // Not used, but might be handy if we ever want to know how many con-
190 // nections are open at any point in time...
192 inline ULong connection_count (void) const {
193 return _connection_count;
196 inline CORBA::Boolean acquire_connection (void) {
197 MICOMT::AutoLock l(conn_cnt_mutex);
198 if (_connection_limit > 0) {
199 if (_connection_count < _connection_limit) {
206 // connection checking disabled by -ORBConnLimit 0
211 inline void release_connection (void) {
212 MICOMT::AutoLock l(conn_cnt_mutex);
216 #endif // HAVE_THREADS
217 typedef std::vector<ObjectAdapter *> OAVec;
218 typedef std::map<MsgId, ORBInvokeRec *, std::less<MsgId> > InvokeMap;
219 typedef std::map<std::string, Object_var, std::less<std::string> >
221 typedef std::map<std::string, ValueFactoryBase_var, std::less<std::string> >
223 typedef std::list<std::string> isa_cacheList;
225 std::string _default_init_ref;
227 MICOMT::Locked<isa_cacheList> _isa_cache;
228 std::vector<std::string> _bindaddrs;
229 MICOMT::RWLocked<OAVec> _adapters;
230 MICOMT::RWLocked<InvokeMap> _invokes;
235 MsgId _theid, _currentid;
236 MICOMT::Mutex _theid_lock;
238 MICOMT::Thread::ThreadKey _current_rec_key;
239 MICOMT::Mutex run_lock_;
240 MICOMT::Thread::ThreadID main_thread_id_;
241 MICOMT::Mutex shutdown_lock_;
242 #endif // HAVE_THREADS
243 InitialRefMap _init_refs;
244 MICOMT::Mutex _init_refs_lock;
247 DomainManager_var _def_manager;
249 MICOMT::Locked<ValueFactoryMap> _value_facs;
252 Boolean _is_shutdown;
254 Boolean _wait_for_completion;
255 OAVec _shutting_down_adapters;
258 ORBInvokeRec *_cache_rec;
259 CORBA::Boolean _cache_used;
262 Boolean is_local (Object_ptr);
263 ObjectAdapter *get_oa (Object_ptr);
264 ORBInvokeRec *create_invoke (MsgId);
265 void add_invoke (ORBInvokeRec *);
266 ORBInvokeRec *get_invoke (MsgId);
267 void del_invoke (MsgId);
269 // internal ORBMsgId handling
270 ORBInvokeRec *get_invoke (ORBMsgId id) { return id; };
274 CORBA::Object_ptr corbaloc_to_object (const char *);
275 CORBA::Object_ptr corbaname_to_object (const char *);
276 CORBA::Object_ptr iioploc_to_object (const char *);
277 CORBA::Object_ptr iiopname_to_object (const char *);
278 CORBA::Object_ptr file_to_object (const char *);
279 CORBA::Object_ptr http_to_object (const char *);
281 Boolean builtin_invoke (ORBMsgId, Object_ptr,
282 ORBRequest *, Principal_ptr);
283 Object_ptr _resolve_initial_references (const char *id);
286 inline ResourceManager &resource_manager (void) {
287 return resourceManager;
291 set_main_thread_id(MICOMT::Thread::ThreadID id)
292 { main_thread_id_ = id; }
293 #endif // HAVE_THREADS
294 typedef IfaceSequenceTmpl<Request_var,Request_ptr> RequestSeq;
295 typedef TSeqVar<RequestSeq> RequestSeq_var;
297 typedef OctetSeq ObjectTag;
298 typedef TSeqVar<ObjectTag> ObjectTag_var;
300 ORB (int &argc, char **argv, const char *rcfile);
303 char *object_to_string (Object_ptr);
304 Object_ptr string_to_object (const char *);
305 Object_ptr ior_to_object (IOR *);
306 Boolean is_impl (Object_ptr);
307 const char *rcfile();
309 static char *tag_to_string (const ObjectTag &);
310 static ObjectTag *string_to_tag (const char *);
312 void create_list (Long, NVList_out);
313 void create_operation_list (OperationDef *,
315 void create_named_value (NamedValue_out);
316 void create_exception_list (ExceptionList_out);
317 void create_context_list (ContextList_out);
318 void create_environment (Environment_out);
320 void get_default_context (Context_out);
323 void get_default_domain_manager (DomainManager_out);
325 CORBA::Boolean get_service_information (
326 CORBA::ServiceType service_type,
327 CORBA::ServiceInformation_out service_information);
329 void send_multiple_requests_oneway (const RequestSeq &);
330 void send_multiple_requests_deferred (const RequestSeq &);
331 Boolean poll_next_response ();
332 void get_next_response (Request_out);
334 Boolean work_pending ();
335 void perform_work ();
337 void shutdown (Boolean wait_for_completion);
341 BOA_ptr BOA_init (int &argc, char **argv, const char *boa_id = "");
342 BOA_ptr BOA_instance (const char *id, Boolean create=TRUE);
344 typedef CORBA::ORB_InvalidName InvalidName;
345 typedef CORBA::ORB_InvalidName_catch InvalidName_catch;
347 typedef char *ObjectId;
348 typedef StringSequenceTmpl<String_var> ObjectIdList;
349 typedef ObjectIdList *ObjectIdList_ptr;
350 typedef TSeqVar<ObjectIdList> ObjectIdList_var;
352 ObjectIdList_ptr list_initial_services ();
353 Object_ptr resolve_initial_references (const char *id)
355 MICOMT::AutoLock l(_init_refs_lock);
356 return _resolve_initial_references(id);
358 Boolean set_initial_reference (const char *id, Object_ptr obj);
359 // added according to PI spec
360 void register_initial_reference (const char *id, Object_ptr obj);
362 Boolean set_default_initial_reference (const char *);
364 virtual TypeCode_ptr create_struct_tc (const char *rep_id,
366 const StructMemberSeq &);
367 virtual TypeCode_ptr create_union_tc (const char *rep_id,
369 TypeCode_ptr disc_type,
370 const UnionMemberSeq &);
371 virtual TypeCode_ptr create_enum_tc (const char *rep_id,
373 const EnumMemberSeq &);
374 virtual TypeCode_ptr create_exception_tc (const char *rep_id,
376 const StructMemberSeq &);
377 virtual TypeCode_ptr create_alias_tc (const char *rep_id,
379 TypeCode_ptr orig_type);
380 virtual TypeCode_ptr create_interface_tc (const char *rep_id,
382 virtual TypeCode_ptr create_string_tc (ULong bound);
383 virtual TypeCode_ptr create_wstring_tc (ULong bound);
384 virtual TypeCode_ptr create_fixed_tc (UShort digits, Short scale);
385 virtual TypeCode_ptr create_sequence_tc (ULong bound,
386 TypeCode_ptr el_type);
387 virtual TypeCode_ptr create_recursive_sequence_tc (ULong bound,
389 virtual TypeCode_ptr create_array_tc (ULong length,
390 TypeCode_ptr el_type);
391 virtual TypeCode_ptr create_value_tc (const char *rep_id, const char *name,
393 TypeCode_ptr concrete_base,
394 const ValueMemberSeq &members);
395 virtual TypeCode_ptr create_value_box_tc (const char *rep_id,
397 TypeCode_ptr boxed_type);
398 virtual TypeCode_ptr create_native_tc (const char *rep_id,
400 virtual TypeCode_ptr create_recursive_tc (const char *rep_id);
401 virtual TypeCode_ptr create_abstract_interface_tc (const char *rep_id,
405 ValueFactory register_value_factory (const char *repoid,
406 ValueFactory factory);
407 void unregister_value_factory (const char *repoid);
408 ValueFactory lookup_value_factory (const char *repoid);
411 CORBA::Policy_ptr create_policy (CORBA::PolicyType type,
412 const CORBA::Any &any);
414 // begin-mico-extension
415 const std::vector<std::string> &bindaddrs () const
419 void bindaddrs (const std::vector<std::string> &b)
424 void dispatcher (Dispatcher *);
425 Dispatcher *dispatcher ()
434 void register_oa (ObjectAdapter *);
435 void unregister_oa (ObjectAdapter *);
437 void register_profile_id (CORBA::ULong id);
438 void unregister_profile_id (CORBA::ULong id);
443 Principal_ptr get_principal (Object_ptr);
446 ORBMsgId new_orbid (MsgId msgid = 0);
447 static MsgId get_msgid (ORBMsgId rec) { return rec ? rec->id() : 0; };
448 ORBMsgId get_orbid (MsgId id) { return get_invoke(id); };
450 //FIXME: hopefully nobody is going to shot me for this :-)
451 void set_request_hint(ORBMsgId id, void *hint) {
452 ORBInvokeRec *rec = get_invoke (id);
454 rec->set_request_hint( hint );
456 void *get_request_hint(ORBMsgId id) {
457 ORBInvokeRec *rec = get_invoke (id);
459 return rec->get_request_hint();
461 void set_invoke_hint(ORBMsgId id, void *hint) {
462 ORBInvokeRec *rec = get_invoke (id);
464 rec->set_invoke_hint( hint );
466 void *get_invoke_hint(ORBMsgId id) {
467 ORBInvokeRec *rec = get_invoke (id);
469 return rec->get_invoke_hint();
472 ORBMsgId invoke_async (Object_ptr, ORBRequest *, Principal_ptr,
473 Boolean rply = TRUE, ORBCallback * = 0,
475 ORBMsgId locate_async (Object_ptr, ORBCallback * = 0, ORBMsgId = 0);
476 ORBMsgId bind_async (const char *repoid, const ObjectTag &,
477 Address *, ORBCallback * = 0, ORBMsgId = 0);
479 InvokeStatus invoke (Object_ptr &, ORBRequest *, Principal_ptr,
480 Boolean rply = TRUE);
481 LocateStatus locate (Object_ptr &);
482 LocateStatus bind (const char *repoid, const ObjectTag &,
483 Address *, Object_ptr &);
484 Object_ptr bind (const char *repoid, const char *addr = 0);
485 Object_ptr bind (const char *repoid, const ObjectTag &,
486 const char *addr = 0);
488 void cancel (ORBMsgId);
490 Boolean wait (ORBMsgId, Long tmout = -1);
491 // Long wait (vector<MsgId> &, Long tmout = -1);
493 void answer_invoke (ORBMsgId, InvokeStatus, Object_ptr, ORBRequest *,
494 GIOP::AddressingDisposition);
495 void answer_bind (ORBMsgId, LocateStatus, Object_ptr);
496 void answer_locate (ORBMsgId, LocateStatus, Object_ptr,
497 GIOP::AddressingDisposition);
498 void answer_shutdown (ObjectAdapter *);
500 InvokeStatus get_invoke_reply (ORBMsgId, Object_out, ORBRequest *&,
501 GIOP::AddressingDisposition &);
502 LocateStatus get_locate_reply (ORBMsgId, Object_out,
503 GIOP::AddressingDisposition &);
504 LocateStatus get_bind_reply (ORBMsgId, Object_out);
506 RequestType request_type (ORBMsgId);
507 void redo_request (ORBMsgId);
509 ImplementationDef *get_impl (Object_ptr);
510 InterfaceDef *get_iface (Object_ptr);
511 Object *get_component (Object_ptr);
512 Boolean is_a (Object_ptr, const char *repoid);
513 Boolean non_existent (Object_ptr);
515 ORBInvokeRec *get_current_invoke_rec ();
516 // end-mico-extension
518 static ORB_ptr _duplicate (ORB_ptr o)
524 static ORB_ptr _nil ()
530 typedef ObjVar<ORB> ORB_var;
531 typedef ObjOut<ORB> ORB_out;
534 // ORB initialization
536 extern ORB_ptr ORB_init (int &argc, char **argv,
537 const char *id = "");
538 extern ORB_ptr ORB_instance (const char *id, Boolean create=TRUE);
541 class ObjectAdapter {
543 typedef CORBA::ULong MsgId;
545 virtual const char *get_oaid () const = 0;
546 virtual Boolean has_object (Object_ptr) = 0;
547 virtual Boolean is_local () const = 0;
550 virtual CORBA::Principal_ptr get_principal (CORBA::Object_ptr) = 0;
553 virtual Boolean invoke (ORBMsgId, Object_ptr, ORBRequest *,
554 Principal_ptr, Boolean response_exp = TRUE) = 0;
555 virtual Boolean bind (ORBMsgId, const char *repoid,
556 const ORB::ObjectTag &,
558 virtual Boolean locate (ORBMsgId, Object_ptr) = 0;
559 virtual Object_ptr skeleton (Object_ptr) = 0;
560 virtual void cancel (ORBMsgId) = 0;
561 virtual void shutdown (Boolean wait_for_completion) = 0;
563 virtual void answer_invoke (ORBMsgId, CORBA::Object_ptr,
565 CORBA::InvokeStatus) = 0;
567 virtual ~ObjectAdapter ();
572 #endif // __mico_orb_mico_h__