summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Event/EC_Lifetime_Utils.h
blob: 39c2d42020b829d25f24ed3c2b39c6448c36a390 (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
/* -*- C++ -*- */
/**
 *  @file EC_Lifetime_Utils.h
 *
 *  $Id$
 *
 *  @author Jody Hagins (jody@atdesk.com)
 *  @author Marina Spivak (marina@atdesk.com)
 *
 *  This file is a temporary place for general CORBA application
 *  utility classes.  These classes will be moved out from the EC
 *  library and into TAO or will be replaced by other TAO classes with
 *  similar functionality.
 */

#ifndef TAO_EC_LIFETIME_UTILS_H
#define TAO_EC_LIFETIME_UTILS_H
#include /**/ "ace/pre.h"

#include /**/ "event_export.h"
#include "orbsvcs/orbsvcs/RtecEventChannelAdminC.h"
#include "tao/PortableServer/PortableServerC.h"
#include "tao/ORB.h"

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

/**
 * @class TAO_EC_Object_Deactivator
 *
 * @brief Utility for deactivating servants from POA.
 *
 * Maintains state necessary to deactivate a servant from POA.
 * Can be told to deactivate a servant explicitly or can do so
 * automagically, in its destructor.
 */
class TAO_RTEvent_Export TAO_EC_Object_Deactivator
{
public:
  /// Default constructor.  Deactivation info can be supplied later
  /// through set_values ().
  TAO_EC_Object_Deactivator (void);

  /// Constructor.  Set @a id which will be deactivated from @ poa in
  /// the deactivator's destructor, unless deactivate () or
  /// disallow_deactivation () are invoked before the destruction.
  TAO_EC_Object_Deactivator (PortableServer::POA_ptr poa,
                             PortableServer::ObjectId const & id);

  /// Destructor.  Deactivates id_ from poa_ if those values have
  /// been set, and neither deactivate() nor disallow_deactivation()
  /// have been invoked.
  ~TAO_EC_Object_Deactivator (void);

  /// Set <id> which will be deactivated from <poa> in
  /// the deactivator's destructor, unless deactivate () or
  /// disallow_deactivation () are invoked before the destruction.
  void set_values (PortableServer::POA_ptr poa,
                   PortableServer::ObjectId const & id);

  /// Take on the state of @a deactivator. @a deactivator loses its state.
  void set_values (TAO_EC_Object_Deactivator & deactivator);

  /// Explicitly enable deactivation to happen in destructor or when
  /// deactivate() is called.
  void allow_deactivation (void);

  /// Explicitly disable deactivation from happening in destructor or
  /// when deactivate() is called.
  void disallow_deactivation (void);

  /// Perform deactivation now if <poa_> and <id_> values have been set, and
  /// deactivation hasn't happened yet nor has it been explicitly
  /// disallowed.  CORBA exceptions occurring during deactivation are
  /// not propagated.   Deactivation will NOT happen in the destructor.
  void deactivate (void);

  /// Accessor for the POA used in deactivation.
  PortableServer::POA_var poa (void) const;

private:

  /// Disallow.
  //@{
  TAO_EC_Object_Deactivator (const TAO_EC_Object_Deactivator &rhs);
  TAO_EC_Object_Deactivator& operator= (const TAO_EC_Object_Deactivator &rhs);
  //@}

  /// POA from which the object will be deactivated.
  PortableServer::POA_var poa_;

  /// ObjectId of the object to be deactivated.
  PortableServer::ObjectId id_;

  /// Flag indicating whether deactivation will be attempted.
  /// The flag is set to false if <poa_> and <id_> haven't been set
  /// yet, or if deactivation already happened, or if
  /// disallow_deactivation () method is invoked.
  int deactivate_;
};

//***************************************************************************

/**
 * @class TAO_EC_Deactivated_Object
 *
 * @brief Object deactivation utility (mix-in) class.
 *
 * Maintains state necessary to deactivate object inheriting from this
 * class from POA.  The state can be set using set_deactivator()
 * method.  Then, the object can deactivate itself by doing
 * this->deactivator_.deactivate ()
 *
 * NOTE: deactivation does NOT happen automatically, and must be
 * explicitly initiated as described above.
 */
class TAO_RTEvent_Export TAO_EC_Deactivated_Object
{
public:

  /// Set deactivation state to that specified by the @a deactivator
  /// argument.
  void set_deactivator (TAO_EC_Object_Deactivator & deactivator);

protected:

  TAO_EC_Deactivated_Object (void);
  ~TAO_EC_Deactivated_Object (void);

  /// Utility for deactivating ourselves from POA.
  TAO_EC_Object_Deactivator deactivator_;
};

//***************************************************************************

/**
 * @class TAO_EC_ORB_Holder
 *
 * @brief Utility for automatically destroying the ORB.
 *
 * Holds a reference to an ORB, and calls destroy() on it in the
 * destructor.
 */
class TAO_RTEvent_Export TAO_EC_ORB_Holder
{
public:
  /// Constructor. No-op.
  TAO_EC_ORB_Holder (void);

  /// Destructor.  If holding an ORB, destroy it.
  ~TAO_EC_ORB_Holder (void);

  /// Set the ORB to be destroyed in destructor to <orb_var>.  If
  /// TAO_EC_ORB_Holder already held an orb prior to invocation of
  /// this method, that orb is NOT destroyed.
  void init (CORBA::ORB_var orb_var);

private:

  /// Disallow.
  //@{
  TAO_EC_ORB_Holder & operator= (const TAO_EC_ORB_Holder &rhs);
  TAO_EC_ORB_Holder(const TAO_EC_ORB_Holder &rhs);
  //@}

  /// ORB to be destroyed.
  CORBA::ORB_var orb_;
};

//***************************************************************************

/**
 * @class TAO_EC_Event_Channel_Holder
 *
 * @brief Utility for automatically destroying the Event Channel.
 *
 * Holds a reference to an Event Channel, and calls destroy() on it in the
 * destructor.
 */
class TAO_RTEvent_Export TAO_EC_Event_Channel_Holder
{
public:
  /// Constructor. No-op.
  TAO_EC_Event_Channel_Holder (void);

  /// Destructor.  If holding an Event Channel, destroy it.
  ~TAO_EC_Event_Channel_Holder (void);

  /// Set the Event Channel to be destroyed in destructor to @a ec_var.  If
  /// TAO_EC_Event_Channel_Holder already held an Event Channel prior
  /// to invocation of this method, that Event Channel is NOT destroyed.
  void init (RtecEventChannelAdmin::EventChannel_var ec_var);

private:

  /// Disallow.
  //@{
  TAO_EC_Event_Channel_Holder & operator= (const TAO_EC_Event_Channel_Holder &rhs);
  TAO_EC_Event_Channel_Holder(const TAO_EC_Event_Channel_Holder &rhs);
  //@}

  /// EC to be destroyed.
  RtecEventChannelAdmin::EventChannel_var ec_;
};


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

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