1 // -*- Mode: C++; -*-
2 //                            Package   : omniORB2
3 // omniInternal.h             Created on: 6/2/96
4 //                            Author    : Sai Lai Lo (sll)
5 //
6 //    Copyright (C) 2003-2009 Apasphere Ltd
7 //    Copyright (C) 1996-1999 AT&T Laboratories Cambridge
8 //
9 //    This file is part of the omniORB library
10 //
11 //    The omniORB library is free software; you can redistribute it and/or
12 //    modify it under the terms of the GNU Lesser General Public
13 //    License as published by the Free Software Foundation; either
14 //    version 2.1 of the License, or (at your option) any later version.
15 //
16 //    This library is distributed in the hope that it will be useful,
17 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
18 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 //    Lesser General Public License for more details.
20 //
21 //    You should have received a copy of the GNU Lesser General Public
22 //    License along with this library. If not, see http://www.gnu.org/licenses/
23 //
24 //
25 // Description:
26 //	*** PROPRIETARY INTERFACE ***
27 //
28 
29 #ifndef __OMNIINTERNAL_H__
30 #define __OMNIINTERNAL_H__
31 
32 #include <stddef.h>
33 
34 #if !defined(__atmos__) && !defined(_WIN32) && !defined(__VMS) && !defined(__rtems__) && !defined(__vxWorks__)
35 #include <strings.h>
36 #include <string.h>
37 #else
38 #include <string.h>
39 #endif
40 #include <omniORB4/CORBA_sysdep.h>
41 #include <omnithread.h>
42 #include <omniORB4/finalCleanup.h>
43 #include <omniORB4/CORBA_basetypes.h>
44 #include <omniORB4/seqTemplatedecls.h>
45 #include <omniORB4/templatedecls.h>
46 #include <omniORB4/valueTemplatedecls.h>
47 #include <omniORB4/stringtypes.h>
48 #include <omniORB4/wstringtypes.h>
49 #ifndef __IOP_hh_EXTERNAL_GUARD__
50 #include <omniORB4/IOP.h>
51 #define __IOP_hh_EXTERNAL_GUARD__
52 #endif
53 #include <omniORB4/GIOP.h>
54 #include <omniORB4/IIOP.h>
55 #include <omniORB4/omniObjKey.h>
56 #include <omniORB4/tracedthread.h>
57 #include <omniORB4/userexception.h>
58 
59 
60 class omniObjRef;
61 class omniServant;
62 class omniIOR;
63 class omniIORHints;
64 class omniObjTableEntry;
65 class omniLocalIdentity;
66 class omniRemoteIdentity;
67 class omniIdentity;
68 
69 OMNI_NAMESPACE_BEGIN(omni)
70 
71 class omniObjAdapter;
72 
73 //
74 // omniORB_x_y
75 //   Define this variable to trap the mismatch of the stub and the runtime
76 //   library. The two digits x,y should be the same as the shared library
77 //   major version number and minor version number. For example, for shared
78 //   library 2.5.0 the variable number should be omniORB_2_5. Notice that
79 //   the variable name stays the same with compatible shared library, e.g.
80 //   2.5.1.
81 //
82 extern _core_attr const char* omniORB_4_2;
83 extern _dyn_attr  const char* omniORB_4_2_dyn;
84 extern _core_attr const _CORBA_ULong omniORB_TAG_ORB_TYPE; // ATT\x00
85 
86 class Strand;
87 class Rope;
88 class IOP_S;
89 class IOP_C;
90 
91 OMNI_NAMESPACE_END(omni)
92 
93 //////////////////////////////////////////////////////////////////////
94 //////////////////////////////// omni ////////////////////////////////
95 //////////////////////////////////////////////////////////////////////
96 
97 _CORBA_MODULE omni
98 
99 _CORBA_MODULE_BEG
100 
101   typedef omni_ptr_arith_t ptr_arith_t;
102 
103   enum alignment_t { ALIGN_1 = 1, ALIGN_2 = 2, ALIGN_4 = 4, ALIGN_8 = 8 };
104 
105   _CORBA_MODULE_VAR _core_attr const _CORBA_Char                myByteOrder;
106   _CORBA_MODULE_VAR _core_attr omni_tracedmutex*                internalLock;
107   _CORBA_MODULE_VAR _core_attr omni_tracedmutex*                objref_rc_lock;
108 
109   _CORBA_MODULE_VAR _core_attr omni_tracedmutex*                poRcLock;
110   // Psuedo-object ref count lock.
111 
112   _CORBA_MODULE_VAR _core_attr _CORBA_Unbounded_Sequence_Octet  myPrincipalID;
113   _CORBA_MODULE_VAR _core_attr const alignment_t                max_alignment;
114   // Maximum value of alignment_t
115 
116   _CORBA_MODULE_VAR _core_attr int remoteInvocationCount;
117   _CORBA_MODULE_VAR _core_attr int localInvocationCount;
118   // These are updated whilst internalLock is held.  However it is
119   // suggested that they may be read without locking, since integer
120   // reads are likely to be atomic.
121 
122   _CORBA_MODULE_VAR _core_attr int mainThreadId;
123   // id of the main thread. 0 by default. Can be changed by calling
124   // omniORB::setMainThread().
125 
126 
align_to(ptr_arith_t p,alignment_t align)127   _CORBA_MODULE_FN inline ptr_arith_t align_to(ptr_arith_t p,
128 					       alignment_t align) {
129     return (p + ((ptr_arith_t) align - 1)) & ~((ptr_arith_t) align - 1);
130   }
131 
hash(const _CORBA_Octet * key,int keysize)132   _CORBA_MODULE_FN inline _CORBA_ULong hash(const _CORBA_Octet* key,
133 					    int keysize)
134   {
135     _CORBA_ULong n = 0;
136     while( keysize-- )  n = ((n << 5) ^ (n >> 27)) ^ *key++;
137     return n;
138   }
139   // Computes a hash of the object key.  The caller must ensure
140   // that the returned value is bounded to the required range.
141 
142   _CORBA_MODULE_FN omni_tracedmutex& nilRefLock();
143   // This is needed to ensure that the mutex is constructed by the
144   // time it is first used.  This can occur at static initialisation
145   // if a _var type is declared at global scope.
146 
147   _CORBA_MODULE_FN void duplicateObjRef(omniObjRef*);
148   // Thread safe.
149 
150   _CORBA_MODULE_FN void releaseObjRef(omniObjRef*);
151   // Must not hold <internalLock>.
152 
153 
154   // Each of the reference creating functions below return a
155   // reference which supports the c++ type interface give by
156   // the repository id <targetRepoId> -- it must be a type for
157   // which we have static information.  <mostDerivedRepoId> is
158   // the interface repository ID recorded in the original IOR.
159   // This may be the empty string (but *not* null).
160 
161   _CORBA_MODULE_FN omniIdentity* createIdentity(omniIOR* ior,
162 						const char* target,
163 						_CORBA_Boolean locked);
164   // Create an identity object that can be used to invoke operations
165   // on the CORBA object identified by <ior>. If the object is local
166   // and activated, the servant is checked for compatibility with
167   // <target>. If they are compatible, the localIdentity is returned;
168   // otherwise, an inProcessIdentity is used.
169   //
170   // The new identity has had gainRef() called. The caller should
171   // release it with loseRef().
172   //
173   // <ior> is always consumed even if the function returns 0.
174   //
175   // <locked> => hold <internalLock>.
176 
177   _CORBA_MODULE_FN omniIdentity* createInProcessIdentity(const _CORBA_Octet* k,
178 							 int keysize);
179   // Returns an omniIdentity to contact an object in this address
180   // space which is unsuitable for contact through a localIdentity.
181 
182   _CORBA_MODULE_FN omniObjRef* createObjRef(const char* targetRepoId,
183 					    omniIOR* ior,
184 					    _CORBA_Boolean locked,
185 					    omniIdentity* id = 0);
186   // Returns an object reference identified by <ior>.  If <id> is not 0, it
187   // is a readily available identity object.
188   // Return 0 if a type error is detected and the object reference cannot be
189   // created.
190   //  <ior> is always consumed even if the function returns 0.
191   //  <locked> => hold <internalLock>.
192 
193   _CORBA_MODULE_FN omniObjRef* createLocalObjRef(const char* mostDerivedRepoId,
194 						 const char* targetRepoId,
195 						 omniObjTableEntry* entry,
196 						 const omniIORHints& hints);
197   // Return a reference to the specified activated local object.
198   //  Must hold <internalLock>.
199 
200   _CORBA_MODULE_FN omniObjRef* createLocalObjRef(const char* mostDerivedRepoId,
201 						 const char* targetRepoId,
202 						 const _CORBA_Octet* key,
203 						 int keysize,
204 						 const omniIORHints& hints);
205   // Return a reference to the local object with the given key, which
206   // may or may not be active.
207   //  Must hold <internalLock>.
208 
209 
210   _CORBA_MODULE_FN void revertToOriginalProfile(omniObjRef* objref);
211   // Reset the implementation of the reference to that stored
212   // in the IOP profile.  Throws INV_OBJREF if cannot instantiate
213   // a suitable rope.  (This is unlikely to happen, since we
214   // suceeded when we made the ref the first time around -- but
215   // someone may have been fiddling with the rope factories).
216   //  Must not hold <internalLock>.
217 
218   _CORBA_MODULE_FN void locationForward(omniObjRef* obj,
219 					omniObjRef* new_location,
220 					_CORBA_Boolean permanent);
221   // This function implements location forwarding.  The implementation
222   // of <obj> is replaced by that in <new_location> (subject to the
223   // usual type checks).  <new_location> is released before returning.
224   //  <new_location> must not be nil.
225   // From GIOP 1.2 onwards, location forward can either be temporary or
226   // permanent. This is indicated by the permanent flag.
227   //  Must not hold <internalLock>.
228   //?? Error behaviour?
229 
strMatch(const char * a,const char * b)230   _CORBA_MODULE_FN inline _CORBA_Boolean strMatch(const char* a,
231 						  const char* b)
232   {
233     do {
234       if (*a != *b) return 0;
235     } while (*a++ && *b++);
236     return 1;
237   }
238 
ptrStrMatch(const char * a,const char * b)239   _CORBA_MODULE_FN inline _CORBA_Boolean ptrStrMatch(const char* a,
240 						     const char* b)
241   {
242     if (a==b) return 1;
243     do {
244       if (*a != *b) return 0;
245     } while (*a++ && *b++);
246     return 1;
247   }
248   // Surprisingly, having these inline string matching functions gives
249   // a noticable performance improvement over using strcmp().
250   // ptrStrMatch() is used in cases where it's likely that the string
251   // pointers are the same; strMatch() is for cases where they
252   // definitely aren't, and saves a little bit of inline code.
253 
254 
255   _CORBA_MODULE_FN void assertFail(const char* file, int line, const char* exp);
256   _CORBA_MODULE_FN void ucheckFail(const char* file, int line, const char* exp);
257 
258 _CORBA_MODULE_END
259 
260 
261 //////////////////////////////////////////////////////////////////////
262 //////////////////////////////////////////////////////////////////////
263 //////////////////////////////////////////////////////////////////////
264 
265 #if 1
266 
267 # define OMNIORB_ASSERT(e)  \
268   do{ if( !(e) )  omni::assertFail(__FILE__,__LINE__, #e); }while(0)
269 
270 # define OMNIORB_USER_CHECK(e)  \
271   do{ if( !(e) )  omni::ucheckFail(__FILE__,__LINE__, #e); }while(0)
272 
273 #else
274 # define OMNIORB_ASSERT(e)
275 # define OMNIORB_USER_CHECK(e)
276 #endif
277 
278 //////////////////////////////////////////////////////////////////////
279 //////////////////////////////////////////////////////////////////////
280 //////////////////////////////////////////////////////////////////////
281 
282 #include <omniORB4/codeSets.h>
283 #include <omniORB4/cdrStream.h>
284 #include <omniORB4/seqTemplatedefns.h>
285 #include <omniORB4/valueTemplatedefns.h>
286 #include <omniORB4/omniObjRef.h>
287 #include <omniORB4/omniServer.h>
288 #include <omniORB4/proxyFactory.h>
289 #include <omniORB4/omniServant.h>
290 
291 
292 //??
293 template <class T>
294 class _CORBA_ConstrType_Variable_Var;
295 
296 
297 #endif // __OMNIINTERNAL_H__
298