summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Notify/Object.cpp
blob: bff1c6ab139e85294cfeb3136ff81b51e960e3b1 (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
// $Id$

#include "Object.h"
#include "POA_Helper.h"
#include "Worker_Task.h"
#include "Properties.h"
#include "Builder.h"
#include "ThreadPool_Task.h"
#include "Reactive_Task.h"
#include "tao/debug.h"

#if ! defined (__ACE_INLINE__)
#include "Object.inl"
#endif /* __ACE_INLINE__ */

ACE_RCSID(RT_Notify, TAO_NS_Object, "$Id$")

TAO_NS_Object::TAO_NS_Object (void)
  :event_manager_ (0), admin_properties_ (0), id_ (0), poa_ (0), worker_task_ (0), own_worker_task_ (0), proxy_poa_ (0), own_proxy_poa_ (0), shutdown_ (0)
{
  if (TAO_debug_level > 1 )
    ACE_DEBUG ((LM_DEBUG,"object:%x  created\n", this ));
}

TAO_NS_Object::~TAO_NS_Object ()
{
  if (TAO_debug_level > 1 )
    ACE_DEBUG ((LM_DEBUG,"object:%x  destroyed\n", this ));
}

void
TAO_NS_Object::init (TAO_NS_POA_Helper* poa, TAO_NS_POA_Helper* proxy_poa, TAO_NS_Worker_Task* worker_task)
{
  poa_ = poa;
  proxy_poa_ = proxy_poa;
  worker_task_ = worker_task;
}

CORBA::Object_ptr
TAO_NS_Object::activate (ACE_ENV_SINGLE_ARG_DECL)
{
  return poa_->activate (this->servant (), id_ ACE_ENV_ARG_PARAMETER);
}

void
TAO_NS_Object::deactivate (ACE_ENV_SINGLE_ARG_DECL)
{
  poa_->deactivate (id_ ACE_ENV_ARG_PARAMETER);
}

void
TAO_NS_Object::shutdown (ACE_ENV_SINGLE_ARG_DECL)
{
  this->deactivate (ACE_ENV_SINGLE_ARG_PARAMETER);

  this->shutdown_worker_task ();
  this->shutdown_proxy_poa ();
}

CORBA::Object_ptr
TAO_NS_Object::ref (ACE_ENV_SINGLE_ARG_DECL)
{
  return poa_->id_to_reference (id_ ACE_ENV_ARG_PARAMETER);
}

void
TAO_NS_Object::shutdown_worker_task (void)
{
  // Only do this if we are the owner.
  if (own_worker_task_ == 1)
    {
      this->worker_task_->shutdown (); // the worker deletes itself when its <close> hook is eventually called.
    }
}

void
TAO_NS_Object::shutdown_proxy_poa (void)
{
  if (own_proxy_poa_ == 1)
    {
      ACE_DECLARE_NEW_CORBA_ENV;
      proxy_poa_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
      delete proxy_poa_;
    }
}

void
TAO_NS_Object::worker_task_own (TAO_NS_Worker_Task* worker_task)
{
  this->worker_task (worker_task);

  // claim ownership.
  this->own_worker_task_ = 1;
}

void
TAO_NS_Object::worker_task (TAO_NS_Worker_Task* worker_task)
{
  // shutdown the current worker.
  this->shutdown_worker_task ();

  this->worker_task_ = worker_task;

  this->own_worker_task_ = 0;
}

void
TAO_NS_Object::proxy_poa (TAO_NS_POA_Helper* proxy_poa)
{
  // shutdown current poa.
  this->shutdown_proxy_poa ();

  this->proxy_poa_ = proxy_poa;

  // claim ownership.
  own_proxy_poa_ = 1;
}

void
TAO_NS_Object::set_qos (const CosNotification::QoSProperties & qos ACE_ENV_ARG_DECL)
{
  CosNotification::PropertyErrorSeq err_seq;

  TAO_NS_QoSProperties qos_properties;

  qos_properties.init (qos, err_seq);

  // Apply the appropriate concurrency QoS
  if (qos_properties.thread_pool ().is_valid ())
    {
      if (qos_properties.thread_pool ().value ().static_threads == 0)
        this->apply_reactive_concurrency (ACE_ENV_SINGLE_ARG_PARAMETER);
      else
        this->apply_thread_pool_concurrency (qos_properties.thread_pool ().value () ACE_ENV_ARG_PARAMETER);
    }
  else if (qos_properties.thread_pool_lane ().is_valid ())
    this->apply_lane_concurrency (qos_properties.thread_pool_lane ().value () ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  // Update the Thread Task's QoS properties..
  this->worker_task_->update_qos_properties (qos_properties);

  // Inform subclasses of QoS changed.
  this->qos_changed (qos_properties);

  // Init the the overall QoS on this object.
  if (this->qos_properties_.init (qos, err_seq) == 1) // Unsupported Property
    ACE_THROW (CosNotification::UnsupportedQoS (err_seq));
}

void
TAO_NS_Object::apply_reactive_concurrency (ACE_ENV_SINGLE_ARG_DECL)
{
  TAO_NS_Reactive_Task* worker_task;

  ACE_NEW_THROW_EX (worker_task,
                    TAO_NS_Reactive_Task (),
                    CORBA::NO_MEMORY ());
  ACE_CHECK;

  this->worker_task_own (worker_task);
}

void
TAO_NS_Object::apply_thread_pool_concurrency (const NotifyExt::ThreadPoolParams& tp_params ACE_ENV_ARG_DECL)
{
  TAO_NS_ThreadPool_Task* worker_task;

  ACE_NEW_THROW_EX (worker_task,
                    TAO_NS_ThreadPool_Task (),
                    CORBA::NO_MEMORY ());
  ACE_CHECK;

  worker_task->init (tp_params, this->admin_properties_ ACE_ENV_ARG_PARAMETER);

  this->worker_task_own (worker_task);
}

void
TAO_NS_Object::apply_lane_concurrency (const NotifyExt::ThreadPoolLanesParams& /*tpl_params*/ ACE_ENV_ARG_DECL)
{
  // No lane support
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

CosNotification::QoSProperties*
TAO_NS_Object::get_qos (ACE_ENV_SINGLE_ARG_DECL)
{
  CosNotification::QoSProperties_var properties;

  ACE_NEW_THROW_EX (properties,
                    CosNotification::QoSProperties (),
                    CORBA::NO_MEMORY ());

  this->qos_properties_.populate (properties);

  return properties._retn ();
}

void
TAO_NS_Object::qos_changed (const TAO_NS_QoSProperties& /*qos_properties*/)
{
  // NOP.
}

TAO_NS_Timer*
TAO_NS_Object::timer (void)
{
  return this->worker_task_->timer ();
}