summaryrefslogtreecommitdiff
path: root/TAO/tao/iiopobj.h
blob: 01676f9ce09e73801a15dd4423e94c7c65463284 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// This may look like C, but it's really -*- C++ -*-

// ============================================================================
//
// = LIBRARY
//    TAO
//
// = FILENAME
//    iiopobj.h
//
// = DESCRIPTION
//     IIOP objref representation
//
//     This allows stubs which support multiple protocols, since the
//     stub (and DII) code only work with the parent "STUB_Objref"
//     class when making calls.
//
// = AUTHOR
//     Copyright 1994-1995 by Sun Microsystems Inc.
//
// ============================================================================

#if !defined (TAO_IIOPOBJ_H)
#  define TAO_IIOPOBJ_H

class TAO_Export IIOP
  // = TITLE
  //   This class provides a namespace.
{
public:
  // IIOP Protocol version is distinct from GIOP version.
  enum
  {
    MY_MAJOR = 1,
    MY_MINOR = 0
  };

  struct Version
  {
    CORBA::Octet major;
    CORBA::Octet minor;

    Version (CORBA::Octet maj = MY_MAJOR,
             CORBA::Octet min = MY_MINOR);
  };

  struct Profile
    // = TITLE
    // IOR support ... Profile is encapsulated in an IIOP profile
    // entry within an IOR.  Note that this structure is specified
    // by CORBA 2.0, so we can't screw with it too much.
  {
    Version iiop_version;
    TAO_opaque object_key;
    char *host;
    CORBA::UShort port;

    Profile (void);
    // Default constructor.

    Profile (const Profile &src);
    // Copy constructor.

    Profile (const char *host,
             const CORBA::UShort port,
             const char *object_key);
    // Called by client <_bind>.

    Profile (const char *host,
             const CORBA::UShort port,
             const char *object_key,
             const ACE_INET_Addr &addr);
    // Called by server.

    Profile (const ACE_INET_Addr &addr,
             const char *object_key);
    // Called by client or server.

    Profile (const ACE_INET_Addr &addr,
             const TAO_opaque &object_key);
    // Called by client or server.

    ~Profile (void);
    // Destructor.

    void object_addr (const ACE_INET_Addr *);
    // Sets <object_addr_> cache from <host> and <port>

    ACE_INET_Addr &object_addr (void);
    // Returns the <ACE_INET_Addr> for this profile.

  private:
    int set (const char *host,
             const CORBA::UShort port,
             const ACE_INET_Addr *addr);
    // Internal helper method (called by the next two methods).

    int set (const char *host,
             const CORBA::UShort port,
             const char *object_key,
             const ACE_INET_Addr *addr = 0);
    // Called by server.

    int set (const char *host,
             const CORBA::UShort port,
             const TAO_opaque &object_key,
             const ACE_INET_Addr *addr = 0);
    // Called by server.

    int set (const ACE_INET_Addr &addr,
             const char *object_key);
    // Called by client or server.

    int set (const ACE_INET_Addr &addr,
             const TAO_opaque &object_key);
    // Called by client or server.

    Profile &operator = (const Profile &src);
    // Disallow copy constructor.
    
    ACE_INET_Addr object_addr_;
    // Cached instance of <ACE_INET_Addr> for use in making
    // invocations, etc.
  };
};

class TAO_Export IIOP_Object : public STUB_Object
  // = TITLE
  //   Representation of an IIOP objref: the profile body, and any
  //   forwarded pointer.  Implementations of basic invocation code;
  //   how to marshal an objref.  Contains a CORBA::Object interface.
  //
  // = DESCRIPTION
  //   NOTE that this uses (single) implementation inheritance to share
  //   most of the basic code for an object reference.

  // @@ What does it mean to have an 'extern "C"' object?!  This is so
  // that it is visible to DCOM, which is a C linkage, I believe.  This
  // is all holdover from the original DB code, and the COM integration
  // is the least understood of any of it.
{
public:
  void do_call (CORBA::Environment &env,
		const TAO_Call_Data *info,
		...);
  // SII-based invocation.

  void do_dynamic_call (const char *opname,
			CORBA::Boolean is_roundtrip,
			CORBA::NVList_ptr args,
			CORBA::NamedValue_ptr result,
			CORBA::Flags flags,
			CORBA::ExceptionList &exceptions,
			CORBA::Environment &env);
  // DII-based invocation.

  // = Support for tables keyed by objrefs.

  CORBA::ULong hash (CORBA::ULong maximum,
                     CORBA::Environment &env);
  CORBA::Boolean is_equivalent (CORBA::Object_ptr other_obj,
                                CORBA::Environment &env);
  // XXX All objref representations should know how to marshal
  // themselves.  That will involve ensuring that the IOR that gets
  // marshaled talks a specific protocol, otherwise the target of a
  // message would not be invoke using the objref it receives
  // (compromising functionality in a very basic and mysterious
  // mannter).  So for example an objref might need to create a proxy
  // for itself rather than marshaling its own representation.  [ The
  // IIOP engine does not need to worry about such issues since it
  // only supports one protocol -- the problem won't show up.
  // "Multiprotocol ORBs" will need to solve that problem though.  ]

  // = Thread-safe accessors for the forwarding profile
  IIOP::Profile *fwd_profile (void);
  // THREAD-SAFE.  Returns the current forwarding profile.

  IIOP::Profile *fwd_profile (IIOP::Profile *new_profile);
  // THREAD-SAFE.  Sets a new value for the forwarding profile and
  // returns the current value.

  // = Non-thread-safe accessors for the forwarding profile
  ACE_SYNCH_MUTEX &fwd_profile_lock (void);
  // Gives reference to the lock guarding the forwarding profile.

  IIOP::Profile *fwd_profile_i (void);
  // THREAD-SAFE.  Returns the current forwarding profile.

  IIOP::Profile *fwd_profile_i (IIOP::Profile *new_profile);
  // THREAD-SAFE.  Sets a new value for the forwarding profile and
  // returns the current value.

  // = Construction
  IIOP_Object (char *repository_id);
  // Construct from a repository (type) ID.

  IIOP_Object (char *repository_id,
               const IIOP::Profile &profile);
  // Construct from a repository ID and a profile ID.

  IIOP_Object (const char *host = ACE_DEFAULT_SERVER_HOST,
               const CORBA::UShort p = TAO_DEFAULT_SERVER_PORT,
               const char *objkey = "0",
               char *repository_id = 0);
  // This constructor will usually be used by a <_bind> call on the
  // client side.

  IIOP_Object (char *repository_id,
               const ACE_INET_Addr &addr, 
               const char *objkey = "0");
  // Constructor used typically by the server side.

  // = COM stuff
  ULONG __stdcall AddRef (void);
  ULONG __stdcall Release (void);
  HRESULT __stdcall QueryInterface (REFIID type_id,
				    void **ppv);

  virtual const char *_get_name (CORBA::Environment &env);
  // Get the underlying object key, which is stored as a
  // NUL-terminated character string.  Note that this does not
  // allocate any new memory, so this return value should not be
  // changed by the caller.

  IIOP::Profile profile;
  // @@ Please document me (this should be private).

private:
  CORBA::Object base;
  // @@ Please document me.

  ACE_SYNCH_MUTEX IUnknown_lock_;
  // Mutex to protect <IUnknown>-related stuff.

  u_int refcount_;
  // Number of outstanding references to this object.

  ACE_SYNCH_MUTEX fwd_profile_lock_;
  // This lock covers the mutable info in all IIOP objref data,
  // namely the forwarded-to objref.  It must be held when a client
  // thread is reading or modifying that data, to prevent one from
  // overwriting data the other's reading or writing.

  IIOP::Profile *fwd_profile_;
  // This is a pointer to a profile used if the object is not
  // colocated in the current process.

  ~IIOP_Object (void);
  // Destructor is to be called only through Release()

  // = Disallow copy constructor and assignment operator

  IIOP_Object (const IIOP_Object &);
  operator = (const IIOP_Object &);

#if defined (__GNUG__)
  // G++ (even 2.6.3) stupidly thinks instances can't be created.
  // This de-warns.
  friend class everyone_needs_a_friend;
#endif /* __GNUG__ */
};

#endif	/* TAO_IIOPOBJ_H */