summaryrefslogtreecommitdiff
path: root/TAO/tao/LocalObject.h
blob: 04062892a8623aa30811467a9ee286f2c69564ad (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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
// -*- C++ -*-

//=============================================================================
/**
 * @file LocalObject.h
 *
 * $Id$
 *
 * Header file for CORBA's base "LocalObject" type.
 *
 * A "LocalObject" is an entity that can be the target of a local
 * invocation.  See the CORBA Component Model specification for
 * details.
 *
 * @author Nanbor Wang <nanbor@cs.wustl.edu>
 */
//=============================================================================


#ifndef TAO_CORBA_LOCALOBJECT_H
#define TAO_CORBA_LOCALOBJECT_H

#include "ace/pre.h"

#include "Object.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "Object_KeyC.h"

namespace CORBA
{
  /**
   * @class LocalObject
   *
   * @note NW: It is not clear whether minimum CORBA should support
   * LocalObject or not.  I think it should.
   */
  class TAO_Export LocalObject : public virtual CORBA::Object
  {
  public:

    /// Destructor
    virtual ~LocalObject (void);

    /// Increment the ref count
    static LocalObject_ptr _duplicate (LocalObject_ptr obj);

    /// Return a NIL object
    static LocalObject_ptr _nil (void);

    /**
     * @todo Narrowing a LocalObject to a CORBA::Object is broken
     * right now.  The solution seems to be making CORBA::Object an
     * abstract base class and create a CORBA::RemoteObject for
     * regular object.  Or, even easier, add a @c is_local member into
     * CORBA::Object.  I'll take the easier route for now.
     */
    static LocalObject_ptr _narrow (CORBA::Object_ptr obj
                                    ACE_ENV_ARG_DECL_WITH_DEFAULTS);

    /// No-op it is just here to simplify some templates.
    static LocalObject_ptr _unchecked_narrow (CORBA::Object_ptr obj
                                              ACE_ENV_ARG_DECL_WITH_DEFAULTS);

#if (TAO_HAS_MINIMUM_CORBA == 0)

    /// Always returns false.
    virtual CORBA::Boolean _non_existent (
      ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS);

    /// Throws CORBA::NO_IMPLEMENT.
    virtual CORBA::ImplementationDef_ptr _get_implementation (
      ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS);

    /// Gets info about object from the Interface Repository.
    virtual CORBA::InterfaceDef_ptr _get_interface (
      ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS);

    /// Throws NO_IMPLEMENT.
    virtual CORBA::Object_ptr _get_component (
      ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS);

    virtual void _create_request (CORBA::Context_ptr ctx,
                                  const char *operation,
                                  CORBA::NVList_ptr arg_list,
                                  CORBA::NamedValue_ptr result,
                                  CORBA::Request_ptr &request,
                                  CORBA::Flags req_flags
                                  ACE_ENV_ARG_DECL_WITH_DEFAULTS);

    virtual void _create_request (CORBA::Context_ptr ctx,
                                  const char *operation,
                                  CORBA::NVList_ptr arg_list,
                                  CORBA::NamedValue_ptr result,
                                  CORBA::ExceptionList_ptr exclist,
                                  CORBA::ContextList_ptr ctxtlist,
                                  CORBA::Request_ptr &request,
                                  CORBA::Flags req_flags
                                  ACE_ENV_ARG_DECL_WITH_DEFAULTS);

    /// Throws NO_IMPLEMENT.
    virtual CORBA::Request_ptr _request (const char *operation
                                         ACE_ENV_ARG_DECL_WITH_DEFAULTS);

#endif /* TAO_HAS_MINIMUM_CORBA */

#if (TAO_HAS_CORBA_MESSAGING == 1)

    /// Throws CORBA::NO_IMPLEMENT.
    CORBA::Policy_ptr _get_policy (CORBA::PolicyType type
                                   ACE_ENV_ARG_DECL_WITH_DEFAULTS);

    /// Throws CORBA::NO_IMPLEMENT.
    CORBA::Policy_ptr _get_client_policy (CORBA::PolicyType type
                                          ACE_ENV_ARG_DECL_WITH_DEFAULTS);

    /// Throws CORBA::NO_IMPLEMENT.
    CORBA::Object_ptr _set_policy_overrides (
      const CORBA::PolicyList & policies,
      CORBA::SetOverrideType set_add
      ACE_ENV_ARG_DECL_WITH_DEFAULTS);

    /// Throws CORBA::NO_IMPLEMENT.
    CORBA::PolicyList * _get_policy_overrides (
      const CORBA::PolicyTypeSeq & types
      ACE_ENV_ARG_DECL_WITH_DEFAULTS);

    /// Throws CORBA::NO_IMPLEMENT.
    CORBA::Boolean _validate_connection (
      CORBA::PolicyList_out inconsistent_policies
      ACE_ENV_ARG_DECL_WITH_DEFAULTS);

#endif /* TAO_HAS_CORBA_MESSAGING == 1 */

    /**
     * Return a hash value for this object.  The hash is based on the
     * address of the object.  On non-32 bit platforms, the hash may
     * be non-unique.
     */
    virtual CORBA::ULong _hash (CORBA::ULong maximum
                                ACE_ENV_ARG_DECL_WITH_DEFAULTS);

    /**
     * Try to determine if this object is the same as @c other_obj.
     * This method relies on the representation of the object
     * reference's private state.  Since that changes easily (when
     * different ORB protocols are in use) there is no default
     * implementation.
     */
    virtual CORBA::Boolean _is_equivalent (CORBA::Object_ptr other_obj
                                           ACE_ENV_ARG_DECL_WITH_DEFAULTS)
      ACE_THROW_SPEC (());

    // = Reference count managment.
    /// Increment the reference count.
    virtual void _add_ref (void);

    /// Decrement the reference count.
    virtual void _remove_ref (void);

    // = TAO extensions

    /// Throws CORBA::NO_IMPLEMENT.
    virtual TAO::ObjectKey *_key (ACE_ENV_SINGLE_ARG_DECL);

#if !defined(__GNUC__) || __GNUC__ > 2 || __GNUC_MINOR__ >= 8
    /// Useful for template programming.
    typedef LocalObject_ptr _ptr_type;
    typedef LocalObject_var _var_type;
#endif /* __GNUC__ */

  protected:

    /// Default constructor.
    /**
     * Make it protected to prevent instantiation of this class.
     */
    LocalObject (void);

  private:

    /**
     * @name Unimplemented methods
     */
    //@{
    LocalObject (const LocalObject &);
    LocalObject &operator = (const LocalObject &);
    //@}

  };

  class TAO_Export LocalObject_var
  {
  public:
    LocalObject_var (void); // default constructor
    LocalObject_var (LocalObject_ptr);
    LocalObject_var (const LocalObject_var &); // copy constructor
    ~LocalObject_var (void); // destructor

    LocalObject_var &operator= (LocalObject_ptr);
    LocalObject_var &operator= (const LocalObject_var &);
    LocalObject_ptr operator-> (void) const;

    /// in, inout, out, _retn
    operator const LocalObject_ptr &() const;
    operator LocalObject_ptr &();
    LocalObject_ptr in (void) const;
    LocalObject_ptr &inout (void);
    LocalObject_ptr &out (void);
    LocalObject_ptr _retn (void);
    LocalObject_ptr ptr (void) const;

  private:
    LocalObject_ptr ptr_;
  };

  class TAO_Export LocalObject_out
  {
  public:
    LocalObject_out (LocalObject_ptr &);
    LocalObject_out (LocalObject_var &);
    LocalObject_out (const LocalObject_out &);
    LocalObject_out &operator= (const LocalObject_out &);
    LocalObject_out &operator= (const LocalObject_var &);
    LocalObject_out &operator= (LocalObject_ptr);
    operator LocalObject_ptr &();
    LocalObject_ptr &ptr (void);
    LocalObject_ptr operator-> (void);

  private:
    LocalObject_ptr &ptr_;
  };
}   // End CORBA namespace

/**
 * @class TAO_Local_RefCounted_Object
 *
 * @brief This class adds default reference counting to local
 *        objects.
 *
 * This is proprietary convenience class that implements reference
 * counting in locality constrained objects.
 */
class TAO_Export TAO_Local_RefCounted_Object
  : public virtual CORBA::LocalObject
{
public:

  /// Increment reference count.
  virtual void _add_ref (void);

  /// Decrement reference count.
  virtual void _remove_ref (void);

protected:

  // Default constructor.
  /**
   * Make it protected to prevent instantiation of this class.
   */
  TAO_Local_RefCounted_Object (void);

private:

  /**
   * @name Unimplemented methods
   */
  //@{
  TAO_Local_RefCounted_Object (const TAO_Local_RefCounted_Object &);
  TAO_Local_RefCounted_Object &operator = (const TAO_Local_RefCounted_Object &);
  //@}

protected:

  /// Mutex to protect reference count.
  TAO_SYNCH_MUTEX refcount_lock_;

  /// Number of outstanding references to this object.
  CORBA::ULong refcount_;

};


#if defined (__ACE_INLINE__)
# include "LocalObject.i"
#endif /* __ACE_INLINE__ */

#include "ace/post.h"
#endif /* TAO_CORBA_LOCALOBJECT_H */