summaryrefslogtreecommitdiff
path: root/TAO/tao/PortableServer/ServantRetentionStrategyNonRetain.cpp
blob: e4e39fbe4bd1f8e3f009e5bc68c2d209cd866eb0 (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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
// -*- C++ -*-

//=============================================================================
/**
 *  @file    ServantRetentionStrategyNonRetain.cpp
 */
//=============================================================================

#include "tao/PortableServer/ServantRetentionStrategyNonRetain.h"
#include "tao/PortableServer/Non_Servant_Upcall.h"
#include "tao/PortableServer/Servant_Upcall.h"
#include "tao/PortableServer/POA_Current_Impl.h"
#include "tao/PortableServer/Root_POA.h"
#include "tao/PortableServer/Servant_Base.h"
#include "tao/debug.h"

#include "ace/OS_NS_sys_time.h"
#include "ace/Time_Value.h"
#include "ace/OS_NS_sys_time.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

namespace TAO
{
  namespace Portable_Server
  {
    ServantRetentionStrategyNonRetain::ServantRetentionStrategyNonRetain () :
      poa_ (0),
      sys_id_count_ (0)
    {
    }

    void
    ServantRetentionStrategyNonRetain::strategy_init (TAO_Root_POA *poa)
    {
      poa_ = poa;
    }

    void
    ServantRetentionStrategyNonRetain::strategy_cleanup ()
    {
      poa_ = 0;
    }

    void
    ServantRetentionStrategyNonRetain::deactivate_object (
      const PortableServer::ObjectId &/*id*/)
    {
      // When using Non_Retain we don't have an active object map and we just
      // can't deactivate any object
      throw PortableServer::POA::WrongPolicy ();
    }

    PortableServer::Servant
    ServantRetentionStrategyNonRetain::find_servant (
      const PortableServer::ObjectId &/*system_id*/)
    {
      throw PortableServer::POA::WrongPolicy ();
    }

    PortableServer::ObjectId *
    ServantRetentionStrategyNonRetain::system_id_to_object_id (
      const PortableServer::ObjectId &system_id)
    {
      // The system id is the id (and no conversion/transformation is
      // needed).
      PortableServer::ObjectId *id = 0;
      ACE_NEW_THROW_EX (id,
                        PortableServer::ObjectId (system_id),
                        CORBA::NO_MEMORY ());

      return id;
    }

    PortableServer::Servant
    ServantRetentionStrategyNonRetain::user_id_to_servant (
      const PortableServer::ObjectId &/*id*/)
    {
      throw PortableServer::POA::WrongPolicy ();
    }

    CORBA::Object_ptr
    ServantRetentionStrategyNonRetain::id_to_reference (
      const PortableServer::ObjectId &/*id*/,
      bool /*indirect*/)
    {
      throw PortableServer::POA::WrongPolicy ();
    }

    TAO_SERVANT_LOCATION
    ServantRetentionStrategyNonRetain::servant_present (
      const PortableServer::ObjectId &/*system_id*/,
      PortableServer::Servant &/*servant*/)
    {
      return TAO_SERVANT_NOT_FOUND;
    }

    PortableServer::Servant
    ServantRetentionStrategyNonRetain::find_servant (
      const PortableServer::ObjectId &system_id,
      TAO::Portable_Server::Servant_Upcall &servant_upcall,
      TAO::Portable_Server::POA_Current_Impl &poa_current_impl)
    {
      // We have the NON_RETAIN policy, user id is the system id.

      // Smartly copy all the data; <poa_current_impl.object_id_> does
      // not own the data.
      poa_current_impl.replace_object_id (system_id);

      servant_upcall.user_id (&system_id);

      return 0;
    }

    int
    ServantRetentionStrategyNonRetain::find_servant_priority (
        const PortableServer::ObjectId &/*system_id*/,
        CORBA::Short &/*priority*/)
    {
      return -1;
    }

    int
    ServantRetentionStrategyNonRetain::is_servant_in_map (
      PortableServer::Servant /*servant*/,
      bool &/*wait_occurred_restart_call*/)
    {
      return 0;
    }

    CORBA::ULong
    ServantRetentionStrategyNonRetain::waiting_servant_deactivation () const
    {
      return 0;
    }

    void
    ServantRetentionStrategyNonRetain::deactivate_all_objects ()
    {
    }

    PortableServer::ObjectId *
    ServantRetentionStrategyNonRetain::servant_to_user_id (
      PortableServer::Servant /*servant*/)
    {
      throw PortableServer::POA::WrongPolicy ();
    }

    CORBA::Object_ptr
    ServantRetentionStrategyNonRetain::servant_to_reference (
      PortableServer::Servant /*servant*/)
    {
      throw PortableServer::POA::WrongPolicy ();
    }

    PortableServer::ObjectId *
    ServantRetentionStrategyNonRetain::activate_object (
      PortableServer::Servant /*servant*/,
      CORBA::Short /*priority*/,
      bool &/*wait_occurred_restart_call*/)
    {
      throw PortableServer::POA::WrongPolicy ();
    }

    void
    ServantRetentionStrategyNonRetain::activate_object_with_id (
      const PortableServer::ObjectId &/*id*/,
      PortableServer::Servant /*servant*/,
      CORBA::Short /*priority*/,
      bool &/*wait_occurred_restart_call*/)
    {
      throw PortableServer::POA::WrongPolicy ();
    }

    CORBA::Object_ptr
    ServantRetentionStrategyNonRetain::create_reference (
      const char *intf,
      CORBA::Short priority)
    {
      // This operation creates an object reference that encapsulates a
      // POA-generated Object Id value and the specified interface
      // repository id. This operation does not cause an activation to
      // take place. The resulting reference may be passed to clients, so
      // that subsequent requests on those references will cause the
      // appropriate servant manager to be invoked, if one is
      // available. The generated Object Id value may be obtained by
      // invoking POA::reference_to_id with the created reference.

      PortableServer::ObjectId_var system_id;
      PortableServer::ObjectId user_id;

      // Otherwise, it is the NON_RETAIN policy.  Therefore, any ol'
      // object id will do (even an empty one). However, to make an
      // object id useful for discriminating objects in applications
      // use a simple id of a counter and a time stamp. The use of a
      // counter by itself is not sufficient for uniqueness over time
      // and a timestamp isn't sufficient since multiple IDs may be
      // requested within the same time unit.

      PortableServer::ObjectId *sys_id = 0;
      ACE_NEW_THROW_EX (sys_id,
                        PortableServer::ObjectId (8),
                        CORBA::NO_MEMORY ());

      sys_id->length(8);

      long count = this->sys_id_count_++;
      ACE_Time_Value now = ACE_OS::gettimeofday();

      ACE_UINT32 *id_ptr = reinterpret_cast<ACE_UINT32 *>(sys_id->get_buffer());

      *(id_ptr++) = count;
      *id_ptr = static_cast<ACE_UINT32>(now.sec());

      system_id = sys_id;

      // User id is the same as system id.
      user_id = system_id.in ();

      // Remember params for potentially invoking <key_to_object> later.
      this->poa_->key_to_object_params_.set (system_id,
                                             intf,
                                             0,
                                             1,
                                             priority,
                                             true);

      return this->poa_->invoke_key_to_object_helper_i (intf, user_id);
    }

#if !defined (CORBA_E_MICRO)
    CORBA::Object_ptr
    ServantRetentionStrategyNonRetain::create_reference_with_id (
      const PortableServer::ObjectId &oid,
      const char *intf,
      CORBA::Short priority)
    {
      // This operation creates an object reference that encapsulates the
      // specified Object Id and interface repository Id values. This
      // operation does not cause an activation to take place.  The
      // resulting reference may be passed to clients, so that subsequent
      // requests on those references will cause the object to be
      // activated if necessary, or the default servant used, depending on
      // the applicable policies.

      PortableServer::Servant servant = 0;
      PortableServer::ObjectId_var system_id;

      // Otherwise, it is the NON_RETAIN policy.  Therefore, user id
      // is the same as system id.
      PortableServer::ObjectId *sys_id = 0;
      ACE_NEW_THROW_EX (sys_id,
                        PortableServer::ObjectId (oid),
                        CORBA::NO_MEMORY ());

      system_id = sys_id;

      // Remember params for potentially invoking <key_to_object> later.
      this->poa_->key_to_object_params_.set (system_id,
                                             intf,
                                             servant,
                                             1,
                                             priority,
                                             true);

      return this->poa_->invoke_key_to_object_helper_i (intf, oid);
    }
#endif

    int
    ServantRetentionStrategyNonRetain::rebind_using_user_id_and_system_id (
      PortableServer::Servant /*servant*/,
      const PortableServer::ObjectId &/*user_id*/,
      const PortableServer::ObjectId &/*system_id*/,
      TAO::Portable_Server::Servant_Upcall &/*servant_upcall*/)
    {
      return -1;
    }

    CORBA::Boolean
    ServantRetentionStrategyNonRetain::servant_has_remaining_activations (
      PortableServer::Servant /*servant*/)
    {
      return false;
    }

    int
    ServantRetentionStrategyNonRetain::unbind_using_user_id (
      const PortableServer::ObjectId &/*user_id*/)
    {
      return 0;
    }

    ::PortableServer::ServantRetentionPolicyValue
    ServantRetentionStrategyNonRetain::type() const
    {
      return ::PortableServer::NON_RETAIN;
    }

    TAO_Active_Object_Map *
    ServantRetentionStrategyNonRetain::get_active_object_map() const
    {
      return 0;
    }
  }
}

TAO_END_VERSIONED_NAMESPACE_DECL