1 // -*- Mode: C++; -*-
2 // Package : omniORB
3 // CORBA_Object.h Created on: 2001/08/17
4 // Author : Duncan Grisby (dpg1)
5 //
6 // Copyright (C) 2001 AT&T Laboratories Cambridge
7 //
8 // This file is part of the omniORB library
9 //
10 // The omniORB library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library. If not, see http://www.gnu.org/licenses/
22 //
23 //
24 // Description:
25 // CORBA::Object
26 //
27
28 #ifndef INSIDE_OMNIORB_CORBA_MODULE
29 # error "Must only be #included by CORBA.h"
30 #endif
31
32 //////////////////////////////////////////////////////////////////////
33 /////////////////////////////// Object ///////////////////////////////
34 //////////////////////////////////////////////////////////////////////
35
36 class Object_Helper {
37 public:
38 typedef Object_ptr _ptr_type;
39
40 static _ptr_type _nil();
41 static _CORBA_Boolean is_nil(_ptr_type);
42 static void release(_ptr_type);
43 static void duplicate(_ptr_type);
44 static void marshalObjRef(_ptr_type, cdrStream&);
45 static _ptr_type unmarshalObjRef(cdrStream&);
46 };
47
48 class Object {
49 public:
50 typedef Object_ptr _ptr_type;
51 typedef Object_var _var_type;
52
53 virtual ~Object();
54
55 void _create_request(Context_ptr ctx,
56 const char *operation,
57 NVList_ptr arg_list,
58 NamedValue_ptr result,
59 Request_out request,
60 Flags req_flags);
61
62 void _create_request(Context_ptr ctx,
63 const char *operation,
64 NVList_ptr arg_list,
65 NamedValue_ptr result,
66 ExceptionList_ptr exceptions,
67 ContextList_ptr ctxlist,
68 Request_out request,
69 Flags req_flags);
70
71 Request_ptr _request(const char* operation);
72
73 ImplementationDef_ptr _get_implementation();
74 _objref_InterfaceDef* _get_interface();
75 // = InterfaceDef_ptr _get_interface();
76
77 Boolean _is_a(const char* repoId);
78 virtual Boolean _non_existent();
79 Boolean _is_equivalent(_ptr_type other_object);
80 ULong _hash(ULong maximum);
81
82 static _ptr_type _duplicate(_ptr_type);
_narrow(Object_ptr o)83 static inline _ptr_type _narrow(Object_ptr o) { return _duplicate(o); }
_unchecked_narrow(Object_ptr o)84 static inline _ptr_type _unchecked_narrow(Object_ptr o) {
85 return _duplicate(o);
86 }
87 static _ptr_type _nil();
88
89 //////////////////////
90 // omniORB internal //
91 //////////////////////
92
Object()93 inline Object() : pd_obj(0), pd_magic(_PR_magic) {}
94
_NP_is_nil()95 inline Boolean _NP_is_nil() const { return pd_obj == 0; }
_NP_is_pseudo()96 inline Boolean _NP_is_pseudo() const { return pd_obj == (omniObjRef*) 1; }
_PR_getobj()97 inline omniObjRef* _PR_getobj() { return pd_obj; }
_PR_setobj(omniObjRef * o)98 inline void _PR_setobj(omniObjRef* o) { pd_obj = o; }
_PR_is_valid(Object_ptr p)99 static inline _CORBA_Boolean _PR_is_valid(Object_ptr p) {
100 return p ? (p->pd_magic == _PR_magic) : 1;
101 }
102
103 virtual void _NP_incrRefCount();
104 virtual void _NP_decrRefCount();
105 virtual void* _ptrToObjRef(const char* repoId);
106
107 static void _marshalObjRef(Object_ptr, cdrStream&);
108 static Object_ptr _unmarshalObjRef(cdrStream&);
109
110 static _core_attr const char* _PD_repoId;
111 static _core_attr const ULong _PR_magic;
112
113 private:
114 omniObjRef* pd_obj;
115 // <obj> is 0 for a nil reference, 1 for a pseudo reference.
116
117 ULong pd_magic;
118 };
119
is_nil(Object_ptr o)120 _CORBA_MODULE_FN inline Boolean is_nil(Object_ptr o) {
121 if( !Object::_PR_is_valid(o) ) return 0;
122 if( o ) return o->_NP_is_nil();
123 else {
124 // omniORB does not use a nil pointer to represent a nil object
125 // reference. The program has passed in a pointer which has not
126 // been initialised by CORBA::Object::_nil() or similar functions.
127 // Some ORBs seems to be quite lax about this. We don't want to
128 // break the applications that make this assumption. Just call
129 // _CORBA_use_nil_ptr_as_nil_objref() to take note of this.
130 return _CORBA_use_nil_ptr_as_nil_objref();
131 }
132 }
release(Object_ptr o)133 _CORBA_MODULE_FN inline void release(Object_ptr o) {
134 if( o && !o->_NP_is_nil() ) {
135 if( o->_NP_is_pseudo() ) o->_NP_decrRefCount();
136 else omni::releaseObjRef(o->_PR_getobj());
137 }
138 }
139