1 // -*- Mode: C++; -*-
2 //                            Package   : omniORB2
3 // omniIOR.h                  Created on: 11/8/99
4 //                            Author    : Sai Lai Lo (sll)
5 //
6 //    Copyright (C) 2002-2013 Apasphere Ltd
7 //    Copyright (C) 1999-2000 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 __OMNIIOR_H__
30 #define __OMNIIOR_H__
31 
32 #include <omniORB4/giopEndpoint.h>
33 
34 OMNI_NAMESPACE_BEGIN(omni)
35 class Rope;
36 class IORPublish;
OMNI_NAMESPACE_END(omni)37 OMNI_NAMESPACE_END(omni)
38 
39 class omniIORHints {
40 public:
41   const CORBA::PolicyList* policies;
42   inline omniIORHints(const CORBA::PolicyList* p) : policies(p) {}
43 };
44 
45 
46 class omniIOR {
47 public:
48 
49   ///////////////////////////////////////////////////////////////////
50   ///////////////////////////////////////////////////////////////////
51   // Accessor functions for the 2 components of the IOR
repositoryID()52   const char* repositoryID() const {
53     return pd_repositoryID;
54   }
55 
iopProfiles()56   const IOP::TaggedProfileList& iopProfiles() const {
57     return pd_iopProfiles;
58   }
59 
60   // index into pd_iopProfiles which has been chosen and decoded
addr_selected_profile_index()61   _CORBA_Long addr_selected_profile_index() const {
62     return pd_addr_selected_profile_index;
63   }
addr_selected_profile_index(_CORBA_Long index_)64   void addr_selected_profile_index(_CORBA_Long index_) {
65     pd_addr_selected_profile_index = index_;
66   }
67 
68   // set and get functions for addr_mode.
69   // The value of addr_mode determines what AddressingDisposition mode
70   // the ORB will use to invoke on the object. The mode is only relevant
71   // for GIOP 1.2 upwards.
addr_mode()72   GIOP::AddressingDisposition addr_mode() const {
73     return pd_addr_mode;
74   }
75 
addr_mode(GIOP::AddressingDisposition m)76   void addr_mode(GIOP::AddressingDisposition m) {
77     pd_addr_mode = m;
78   }
79 
80 
81   ///////////////////////////////////////////////////////////////////
82   ///////////////////////////////////////////////////////////////////
83   // Information encoded in the taggedprofilelist may be decoded
84   // into the more accessible forms and stored in an IORInfo.
85   //
86   class IORInfo;
87   IORInfo* getIORInfo() const;
88 
89   // Within IORInfo, additional decoded info can be deposited using
90   // the IORExtraInfo class. Typically this is used by decodeIOR interceptors
91   // to insert extra info into the IOR for later retreival.
92   //
93   class IORExtraInfo {
94   public:
IORExtraInfo(const IOP::ComponentId cid)95     IORExtraInfo(const IOP::ComponentId cid) : compid(cid) {}
~IORExtraInfo()96     virtual ~IORExtraInfo() {}
97     IOP::ComponentId compid;
98   private:
99     IORExtraInfo();
100     IORExtraInfo(const IORExtraInfo&);
101     IORExtraInfo& operator=(const IORExtraInfo&);
102   };
103   // For each unique ComponentId (e.g., TAG_GROUP) one can add
104   // an IORExtraInfo element to the extra_info list.
105   // Each extrainfo element should be constructed by deriving from
106   // this class so that extra members can be held.
107 
108   typedef _CORBA_PseudoValue_Sequence<IORExtraInfo*> IORExtraInfoList;
109 
110   class IORInfo {
111   public:
112 
113     // GIOP version.
version()114     const GIOP::Version& version() const {
115       return pd_version;
116     }
117 
version(const GIOP::Version & ver)118     void version(const GIOP::Version& ver) {
119       pd_version = ver;
120     }
121 
122     // List of address to use
_OMNI_NS(giopAddressList)123     _OMNI_NS(giopAddressList)& addresses() {
124       return pd_addresses;
125     }
126 
127     // ORB ID
orbType()128     _CORBA_ULong orbType() const { return pd_orb_type; }
orbType(_CORBA_ULong t)129     void orbType(_CORBA_ULong t) { pd_orb_type = t; }
130 
131     // Transmission code set for char and string
_OMNI_NS(omniCodeSet::TCS_C)132     _OMNI_NS(omniCodeSet::TCS_C)* TCS_C() const { return pd_tcs_c; }
TCS_C(_OMNI_NS (omniCodeSet::TCS_C)* tcs_c)133     void TCS_C(_OMNI_NS(omniCodeSet::TCS_C)* tcs_c) { pd_tcs_c = tcs_c; }
134 
135     // Transmission code set for wchar and wstring
_OMNI_NS(omniCodeSet::TCS_W)136     _OMNI_NS(omniCodeSet::TCS_W)* TCS_W() const { return pd_tcs_w; }
TCS_W(_OMNI_NS (omniCodeSet::TCS_W)* tcs_w)137     void TCS_W(_OMNI_NS(omniCodeSet::TCS_W)* tcs_w) { pd_tcs_w = tcs_w; }
138 
139     // Extra info list
extraInfo()140     IORExtraInfoList&       extraInfo()       { return pd_extra_info; }
extraInfo()141     const IORExtraInfoList& extraInfo() const { return pd_extra_info; }
142 
143     // Flags (defined in giopStrandFlags.h)
flags()144     inline _CORBA_ULong flags() const             { return pd_flags;  }
flags(_CORBA_ULong flags)145     inline void         flags(_CORBA_ULong flags) { pd_flags = flags; }
146 
147     IORInfo();
148     ~IORInfo();
149 
150   private:
151     GIOP::Version                      pd_version;
152     _OMNI_NS(giopAddressList)          pd_addresses;
153     _CORBA_ULong                       pd_orb_type;
154     _OMNI_NS(omniCodeSet::TCS_C)*      pd_tcs_c;
155     _OMNI_NS(omniCodeSet::TCS_W)*      pd_tcs_w;
156     IORExtraInfoList                   pd_extra_info;
157     _CORBA_ULong                       pd_flags;
158   };
159 
160 public:
161 
162   ///////////////////////////////////////////////////////////////////
163   ///////////////////////////////////////////////////////////////////
164   omniIOR(char* repoId, IOP::TaggedProfileList* iop);
165   // Both repoId and iop are consumed by the object.
166 
167   omniIOR(char* repoId, IOP::TaggedProfile* iop, _CORBA_ULong niops,
168 	  _CORBA_ULong selected_profile_index);
169   // Both repoId and iop are consumed by the object.
170 
171   omniIOR(const char* repoId, const _CORBA_Octet* key, int keysize,
172 	  const omniIORHints& hints);
173   // Create an IOR for a local object with the given key
174   //  Must hold <omni::internalLock>.
175 
176   enum interceptorOption { NoInterceptor,
177 			   DefaultInterceptors,
178 			   AllInterceptors };
179 
180   omniIOR(const char* repoId,
181 	  const _CORBA_Unbounded_Sequence_Octet& key,
182 	  const IIOP::Address* addrs, _CORBA_ULong naddrs,
183 	  GIOP::Version ver, interceptorOption call_interceptors,
184           const IOP::MultipleComponentProfile* tagged_components = 0);
185 
186   ~omniIOR();
187 
188   void marshalIORAddressingInfo(cdrStream& s) const;
189 
190   // Synchronisation and reference counting:
191   //
192   // The object is reference counted. Call duplcate() to increment the
193   // reference count. Call release() to decrement the reference count.
194   //
195   // The reference count is protected by the mutex omniIOR::lock.
196   //
197   omniIOR* duplicate();
198   // return a pointer to this object.
199   // Atomic and thread safe. Caller must not hold omniIOR::lock.
200 
201   void release();
202   // If the reference count is 0, delete is called on the object.
203   // Atomic and thread safe. Caller must not hold omniIOR::lock
204 
205   static _core_attr omni_tracedmutex* lock;
206 
207 
208 public:
209   // ORB internal functions.
210 
211   omniIOR* duplicateNoLock();
212   // Must hold <omniIOR::lock>. Otherwise same semantics as duplicate().
213 
214   void releaseNoLock();
215   // Must hold <omniIOR::lock>. Otherwise same semantics as release().
216 
217   ///////////////////////////////////////////////////////////////////
218   // Create a new taggedcomponent slot in the IIOP profile.
219   // The caller can write to the tagged component immediately after this
220   // call.
221   // Use this call only in the encodeIOR interceptors.
222   static IOP::TaggedComponent& newIIOPtaggedComponent(IOP::MultipleComponentProfile&);
223 
224   void decodeIOPprofile(const IIOP::ProfileBody&);
225   // Decode the information in the argument into IORInfo accessible via
226   // getIORInfo().
227 
228   // Handlers for each of the tagged component used by the ORB
229   static void  unmarshal_TAG_ORB_TYPE(const IOP::TaggedComponent&, omniIOR&);
230 
231   ////
232   static void  unmarshal_TAG_CODE_SETS(const IOP::TaggedComponent&, omniIOR&);
233   static void  add_TAG_CODE_SETS(const _OMNI_NS(CONV_FRAME::CodeSetComponentInfo)&);
234 
235   ////
236   static void  unmarshal_TAG_ALTERNATE_IIOP_ADDRESS(const IOP::TaggedComponent&,
237                                                    omniIOR&);
238   static void  add_TAG_ALTERNATE_IIOP_ADDRESS(const IIOP::Address&,
239                                               _OMNI_NS(IORPublish)* eps);
240 
241   ////
242   static void  unmarshal_TAG_SSL_SEC_TRANS(const IOP::TaggedComponent&,
243 					   omniIOR&);
244   static void  add_TAG_SSL_SEC_TRANS(const IIOP::Address&,
245 				     _CORBA_UShort         supports,
246 				     _CORBA_UShort         requires,
247                                      _OMNI_NS(IORPublish)* eps);
248 
249   ////
250   static void unmarshal_TAG_CSI_SEC_MECH_LIST(const IOP::TaggedComponent&,
251 					      omniIOR&);
252 
253   ////
254   static void  unmarshal_TAG_OMNIORB_BIDIR(const IOP::TaggedComponent&,
255 					   omniIOR&);
256   static void  add_TAG_OMNIORB_BIDIR(const char* sendfrom,
257 				     omniIOR&);
258 
259   ////
260   static void  unmarshal_TAG_OMNIORB_UNIX_TRANS(const IOP::TaggedComponent&,
261 						omniIOR&);
262   static void  add_TAG_OMNIORB_UNIX_TRANS(const char*           filename,
263                                           _OMNI_NS(IORPublish)* eps);
264 
265   ////
266   static void  unmarshal_TAG_OMNIORB_PERSISTENT_ID(const IOP::TaggedComponent&,
267 						   omniIOR&);
268 
269   ////
270   static void  add_IIOP_ADDRESS(const IIOP::Address&,
271                                 _OMNI_NS(IORPublish)* eps);
272   // Add this address to the IIOP profile.
273 
274 private:
275 
276   _CORBA_String_member               pd_repositoryID;
277   IOP::TaggedProfileList_var 	     pd_iopProfiles;
278   _CORBA_Long                        pd_addr_selected_profile_index;
279   GIOP::AddressingDisposition        pd_addr_mode;
280   IORInfo*                           pd_iorInfo;
281   int                                pd_refCount;
282   // Protected by <omniIOR::lock>
283 
284   omniIOR();
285   omniIOR(const omniIOR&);
286   omniIOR& operator=(const omniIOR&);
287 
288 };
289 
290 class omniIOR_var {
291 public:
omniIOR_var()292   inline omniIOR_var() : pd_ior(0) {}
omniIOR_var(omniIOR * ior)293   inline omniIOR_var(omniIOR* ior) : pd_ior(ior) {}
_retn()294   inline omniIOR* _retn() { omniIOR* p = pd_ior; pd_ior = 0; return p; }
295   inline operator omniIOR* () const { return pd_ior; }
296   inline omniIOR* operator->() const { return pd_ior; }
297   inline omniIOR_var& operator=(omniIOR* p) {
298     if (pd_ior) pd_ior->release();
299     pd_ior = p;
300     return *this;
301   }
~omniIOR_var()302   inline ~omniIOR_var() {
303     if (pd_ior) pd_ior->release();
304   }
305 private:
306   omniIOR* pd_ior;
307 };
308 
309 
310 #endif // __OMNIIOR_H__
311