~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to TAO/CIAO/examples/handcrafted/BasicSP_EC2/EC/EC_exec.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// EC_exec.cpp,v 1.1 2003/08/05 18:59:46 edwardgt Exp
2
 
 
3
 
#include "EC_exec.h"
4
 
#include "ace/Timer_Queue.h"
5
 
#include "ace/Reactor.h"
6
 
 
7
 
//=================================================================
8
 
 
9
 
MyImpl::timeout_Handler::timeout_Handler (MyImpl::EC_exec_i *cb)
10
 
  : active_ (0),
11
 
    done_ (0),
12
 
    tid_ (0),
13
 
    pulse_callback_ (cb)
14
 
{
15
 
  // Nothing
16
 
  this->reactor (new ACE_Reactor);
17
 
}
18
 
 
19
 
MyImpl::timeout_Handler::~timeout_Handler ()
20
 
{
21
 
  delete this->reactor ();
22
 
  this->reactor (0);
23
 
}
24
 
 
25
 
int
26
 
MyImpl::timeout_Handler::open ()
27
 
{
28
 
  return this->activate ();
29
 
}
30
 
 
31
 
int
32
 
MyImpl::timeout_Handler::close ()
33
 
{
34
 
  this->done_ = 1;
35
 
  this->reactor ()->notify ();
36
 
 
37
 
  ACE_DEBUG ((LM_DEBUG, "Waiting\n"));
38
 
  return this->wait ();
39
 
}
40
 
 
41
 
int
42
 
MyImpl::timeout_Handler::start (CORBA::Long hertz)
43
 
{
44
 
  if (hertz == 0 || this->active_ != 0)        // Not valid
45
 
    return -1;
46
 
 
47
 
  long usec = 1000000 / hertz;
48
 
 
49
 
  this->tid_ = this->reactor ()->schedule_timer (this,
50
 
                                                 0,
51
 
                                                 ACE_Time_Value (0, usec),
52
 
                                                 ACE_Time_Value (0, usec));
53
 
 
54
 
  this->active_ = 1;
55
 
  return 0;
56
 
}
57
 
 
58
 
int
59
 
MyImpl::timeout_Handler::stop (void)
60
 
{
61
 
  if (this->active_ == 0)       // Not valid.
62
 
    return -1;
63
 
 
64
 
  this->reactor ()->cancel_timer (this);
65
 
 
66
 
  this->active_ = 0;
67
 
  return 0;
68
 
}
69
 
 
70
 
int
71
 
MyImpl::timeout_Handler::active (void)
72
 
{
73
 
  return this->active_;
74
 
}
75
 
 
76
 
int
77
 
MyImpl::timeout_Handler::handle_close (ACE_HANDLE handle,
78
 
                                     ACE_Reactor_Mask close_mask)
79
 
{
80
 
  ACE_DEBUG ((LM_DEBUG,
81
 
              ACE_TEXT ("[%x] handle = %d, close_mask = %d\n"),
82
 
              this,
83
 
              handle,
84
 
              close_mask));
85
 
 
86
 
  return 0;
87
 
}
88
 
 
89
 
int
90
 
MyImpl::timeout_Handler::handle_timeout (const ACE_Time_Value &,
91
 
                                       const void *)
92
 
{
93
 
  this->pulse_callback_->pulse ();
94
 
 
95
 
//   ACE_DEBUG ((LM_DEBUG,
96
 
//               ACE_TEXT ("[%x] with count #%05d timed out at %d.%d!\n"),
97
 
//               this,
98
 
//               tv.sec (),
99
 
//               tv.usec ()));
100
 
 
101
 
  return 0;
102
 
}
103
 
 
104
 
int
105
 
MyImpl::timeout_Handler::svc (void)
106
 
{
107
 
  this->reactor ()->owner (ACE_OS::thr_self ());
108
 
 
109
 
  while (!this->done_)
110
 
    this->reactor ()->handle_events ();
111
 
 
112
 
  return 0;
113
 
}
114
 
 
115
 
//=================================================================
116
 
 
117
 
MyImpl::EC_exec_i::EC_exec_i ()
118
 
  : hertz_ (0),
119
 
    pulser_ (this)
120
 
{
121
 
 
122
 
}
123
 
 
124
 
MyImpl::EC_exec_i::EC_exec_i (CORBA::Long hz)
125
 
  : hertz_ (hz),
126
 
    pulser_ (this)
127
 
{
128
 
}
129
 
 
130
 
MyImpl::EC_exec_i::~EC_exec_i ()
131
 
{
132
 
}
133
 
 
134
 
CORBA::Long
135
 
MyImpl::EC_exec_i::hertz (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
136
 
  ACE_THROW_SPEC ((CORBA::SystemException))
137
 
{
138
 
  return this->hertz_;
139
 
}
140
 
 
141
 
void
142
 
MyImpl::EC_exec_i::hertz (CORBA::Long hertz
143
 
                                  ACE_ENV_ARG_DECL_NOT_USED)
144
 
  ACE_THROW_SPEC ((CORBA::SystemException))
145
 
{
146
 
  this->hertz_ = hertz;
147
 
}
148
 
 
149
 
// Operations from supported interface(s)
150
 
 
151
 
void
152
 
MyImpl::EC_exec_i::start (ACE_ENV_SINGLE_ARG_DECL)
153
 
  ACE_THROW_SPEC ((CORBA::SystemException))
154
 
{
155
 
  if (this->hertz_ == 0 || this->pulser_.active())
156
 
    ACE_THROW (CORBA::BAD_INV_ORDER ());
157
 
 
158
 
  // @@ Start the rate generator
159
 
  this->pulser_.start (this->hertz_);
160
 
}
161
 
 
162
 
void
163
 
MyImpl::EC_exec_i::stop (ACE_ENV_SINGLE_ARG_DECL)
164
 
  ACE_THROW_SPEC ((CORBA::SystemException))
165
 
{
166
 
  if (! this->pulser_.active ())
167
 
    ACE_THROW (CORBA::BAD_INV_ORDER ());
168
 
 
169
 
  // @@ stop the rate generator
170
 
  this->pulser_.stop ();
171
 
}
172
 
 
173
 
CORBA::Boolean
174
 
MyImpl::EC_exec_i::active (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
175
 
  ACE_THROW_SPEC ((CORBA::SystemException))
176
 
{
177
 
  return this->pulser_.active ();
178
 
}
179
 
 
180
 
// Operations from Components::SessionComponent
181
 
 
182
 
void
183
 
MyImpl::EC_exec_i::set_session_context (Components::SessionContext_ptr ctx
184
 
                                                ACE_ENV_ARG_DECL_WITH_DEFAULTS)
185
 
  ACE_THROW_SPEC ((CORBA::SystemException,
186
 
                   Components::CCMException))
187
 
{
188
 
  ACE_DEBUG ((LM_DEBUG, "MyImpl::EC_exec_i::set_session_context\n"));
189
 
 
190
 
  this->context_ =
191
 
    BasicSP::CCM_EC_Context::_narrow (ctx
192
 
                                             ACE_ENV_ARG_PARAMETER);
193
 
  ACE_CHECK;
194
 
 
195
 
  if (CORBA::is_nil (this->context_.in ()))
196
 
    ACE_THROW (CORBA::INTERNAL ());
197
 
  // Urm, we actually discard exceptions thown from this operation.
198
 
 
199
 
}
200
 
 
201
 
void
202
 
MyImpl::EC_exec_i::ccm_activate (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
203
 
  ACE_THROW_SPEC ((CORBA::SystemException,
204
 
                   Components::CCMException))
205
 
{
206
 
  ACE_DEBUG ((LM_DEBUG, "MyImpl::EC_exec_i::ccm_activate\n"));
207
 
 
208
 
  this->pulser_.open ();
209
 
}
210
 
 
211
 
void
212
 
MyImpl::EC_exec_i::ccm_passivate (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
213
 
  ACE_THROW_SPEC ((CORBA::SystemException,
214
 
                   Components::CCMException))
215
 
{
216
 
  ACE_DEBUG ((LM_DEBUG, "MyImpl::EC_exec_i::ccm_passivate\n"));
217
 
  this->pulser_.close ();
218
 
}
219
 
 
220
 
void
221
 
MyImpl::EC_exec_i::ccm_remove (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
222
 
  ACE_THROW_SPEC ((CORBA::SystemException,
223
 
                   Components::CCMException))
224
 
{
225
 
  ACE_DEBUG ((LM_DEBUG, "MyImpl::EC_exec_i::ccm_remove\n"));
226
 
}
227
 
 
228
 
void
229
 
MyImpl::EC_exec_i::pulse (void)
230
 
{
231
 
  ACE_TRY_NEW_ENV
232
 
    {
233
 
      ACE_DEBUG ((LM_DEBUG,
234
 
                  ACE_TEXT ("Pushing BasicSP::TimeOut event!\n")));
235
 
 
236
 
      BasicSP::TimeOut_var ev = new OBV_BasicSP::TimeOut ();
237
 
 
238
 
      this->context_->push_timeout (ev.in ()
239
 
                                  ACE_ENV_ARG_PARAMETER);
240
 
    }
241
 
  ACE_CATCHANY
242
 
    {
243
 
      // @@ do nothing?
244
 
    }
245
 
  ACE_ENDTRY;
246
 
 
247
 
}
248
 
 
249
 
MyImpl::ECHome_exec_i::ECHome_exec_i ()
250
 
{
251
 
}
252
 
 
253
 
MyImpl::ECHome_exec_i::~ECHome_exec_i ()
254
 
{
255
 
}
256
 
 
257
 
::Components::EnterpriseComponent_ptr
258
 
MyImpl::ECHome_exec_i::new_EC (CORBA::Long hertz
259
 
                               ACE_ENV_ARG_DECL)
260
 
  ACE_THROW_SPEC ((CORBA::SystemException,
261
 
                   Components::CCMException))
262
 
{
263
 
  return new MyImpl::EC_exec_i (hertz);
264
 
}
265
 
 
266
 
::Components::EnterpriseComponent_ptr
267
 
MyImpl::ECHome_exec_i::create (ACE_ENV_SINGLE_ARG_DECL)
268
 
  ACE_THROW_SPEC ((CORBA::SystemException,
269
 
                   Components::CCMException))
270
 
{
271
 
  return new MyImpl::EC_exec_i ();
272
 
}
273
 
 
274
 
 
275
 
extern "C" EC_EXEC_Export ::Components::HomeExecutorBase_ptr
276
 
createECHome_Impl (void)
277
 
{
278
 
  return new MyImpl::ECHome_exec_i ();
279
 
}