summaryrefslogtreecommitdiff
path: root/TAO/tao/Utils/ORB_Manager.h
blob: a181e1c5d12019e62aba860f66bfa2b3a3aad6ac (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
/* -*- C++ -*- */

//=============================================================================
/**
 *  @file   ORB_Manager.h
 *
 *  $Id$
 *
 *  @author Chris Cleeland <cleeland@cs.wustl.edu>
 */
//=============================================================================

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

#include "utils_export.h"
#include "tao/PortableServer/PortableServer.h"

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

#include "tao/ORB.h"

/**
 * @class TAO_ORB_Manager
 *
 * @brief Helper class for simple ORB/POA initialization and
 * registering servants with the POA.
 *
 * This class is a TAO extension that makes it easier to write
 * CORBA applications.  It's just a wrapper and doesn't do
 * anything special within the ORB itself.
 */
class TAO_UTILS_Export TAO_ORB_Manager
{
public:
  // = Initialization and termination methods.
  /** Constructor.
   *
   *  @param orb  pointer to an ORB which is duplicated an stored
   *              internally in an ORB_var.  If pointer is 0,
   *              a new ORB pointer is created internally in the init()
   *              call.
   *
   *  @param poa  pointer to a POA which is duplicated and stored
   *              internally in a POA_var.  If pointer is 0,
   *              a pointer to the Root POA is obtained from the ORB.
   *
   *  @param poa_manager pointer to a POA Manager which is duplicated
   *                     and stored internally in a POAManager_var.
   *                     If pointer is 0, a new POAManager is created
   *                     internally in the init() call.
   */
  TAO_ORB_Manager (CORBA::ORB_ptr orb = 0,
                   PortableServer::POA_ptr poa = 0,
                   PortableServer::POAManager_ptr poa_manager = 0);

  /**
   * Initialize the ORB/root POA, using the supplied command line
   * arguments or the default ORB components.
   *
   * @retval -1 Failure
   * @retval 0 Success
   */
  int init (int &argc,
            char *argv[]
            ACE_ENV_ARG_DECL_WITH_DEFAULTS);

  /**
   * Initialize the ORB/root POA, using the supplied command line
   * arguments or the default ORB components.
   *
   * @retval -1 Failure
   * @retval 0 Success
   */
  int init (int &argc,
            char *argv[],
            const char *orb_name
            ACE_ENV_ARG_DECL_WITH_DEFAULTS);

  /**
   * Creates a child poa under the root poa with PERSISTENT and
   * USER_ID policies.  Call this if you want a @c child_poa with the
   * above policies, otherwise call init.
   *
   * @retval -1 Failure
   * @retval 0 Success
   */
  int init_child_poa (int &argc,
                      char *argv[],
                      const char *poa_name
                      ACE_ENV_ARG_DECL_WITH_DEFAULTS);

  /**
   * Creates a child poa under the root poa with PERSISTENT and
   * USER_ID policies.  Call this if you want a @a child_poa with the
   * above policies, otherwise call init.
   *
   * @retval -1 Failure
   * @retval 0 Success
   */
  int init_child_poa (int &argc,
                      char *argv[],
                      const char *poa_name,
                      const char *orb_name
                      ACE_ENV_ARG_DECL_WITH_DEFAULTS);

  /**
   * Shut down.  Invoke the destroy() methods on the orb and poa.
   *
   * @retval -1 Failure
   * @retval 0 Success
   */
  int fini (ACE_ENV_SINGLE_ARG_DECL);

  /// Destructor.
  ~TAO_ORB_Manager (void);

  // = Accessor methods.

  /**
   *  Put POA manager into the <Active> state, so that incoming corba
   *  requests are processed.  This method is useful for clients,
   *  which are not going to enter "orb->run" loop, yet may want to
   *  service incoming requests while waiting for a result of CORBA
   *  call on a server.
   *
   * @retval -1 Failure
   * @retval 0 Success
   */
  int activate_poa_manager (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS);

  /**
   * Activate <servant>, using the POA <activate_object> call.  Users
   * can call this method multiple times to activate multiple objects.
   *
   * @return 0 on failure, a string representation of the object ID if
   *         successful.  Caller of this method is responsible for
   *         memory deallocation of the string.
   */
  char *activate (PortableServer::Servant servant
                  ACE_ENV_ARG_DECL_WITH_DEFAULTS);

  /** Deactivate object in RootPOA.
   *
   *  @param id  A string representation of the Object ID
   *             of the servant to deactivate in the POA
   */
  void deactivate (const char *id
                   ACE_ENV_ARG_DECL_WITH_DEFAULTS);

  /**
   * Precondition: init_child_poa has been called.  Activate <servant>
   * using the POA <activate_object_with_id> created from the string
   * <object_name>. Users should call this to activate objects under
   * the child_poa.
   *
   * @param object_name  String name which will be used to create
   *                     an Object ID for the servant.
   * @param servant  The servant to activate under the child POA.
   *
   * @return 0 on failure, a string representation of the object ID if
   *           successful.  Caller of this method is responsible for
   *           memory deallocation of the string.
   */
  char *activate_under_child_poa (const char *object_name,
                                  PortableServer::Servant servant
                                  ACE_ENV_ARG_DECL_WITH_DEFAULTS);

  /**
   * Deactivate object in child POA.
   *
   * @param id  string representation of the object ID, which represents
   *            the object to deactivate in the POA
   */
  void deactivate_under_child_poa (const char *id
                                   ACE_ENV_ARG_DECL_WITH_DEFAULTS);

  /**
   * Run the ORB event loop with the specified @a tv time value.
   *
   * @param tv  the time interval for how long to run the ORB event loop.
   * @retval -1 Failure
   * @retval 0 Success
   */
  int run (ACE_Time_Value &tv
           ACE_ENV_ARG_DECL_WITH_DEFAULTS);

  /**
   * Run the ORB event loop.
   */
  int run (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS);

  /**
   * Accessor which returns the ORB pointer.  Following the normal
   * CORBA memory management rules of return values from functions,
   * this function duplicates the orb return value before returning
   * it.
   *
   * @return ORB pointer which has been duplicated, so caller
   *         must release pointer when done.
   */
  CORBA::ORB_ptr orb (void);

  /**
   * Accessor which returns the root poa. Following the normal CORBA
   * memory management rules of return values from functions, this
   * function duplicates the poa return value before returning it.
   *
   * @return Root POA pointer which has been duplicated.  Caller
   *         must release pointer when done.
   */
  PortableServer::POA_ptr root_poa (void);

  /**
   * Accessor which returns the child poa. Following the normal CORBA
   * memory management rules of return values from functions, this
   * function duplicates the poa return value before returning it.
   *
   * @return Child POA pointer which has been duplicated.  Caller
   *         must release pointer when done.
   */
  PortableServer::POA_ptr child_poa (void);

  /**
   * Accessor which returns the poa manager. Following the normal
   * CORBA memory management rules of return values from functions,
   * this function duplicates the poa manager return value before
   * returning it.
   *
   * @return POAManager pointer which has been duplicated.  Caller
   *         must release pointer when done.
   */
  PortableServer::POAManager_ptr poa_manager (void);

protected:
  /// The ORB.
  CORBA::ORB_var orb_;

  /// The POA for this ORB.
  PortableServer::POA_var poa_;

  /// Child poa under the root POA.
  PortableServer::POA_var child_poa_;

  /// The POA manager of poa_.
  PortableServer::POAManager_var poa_manager_;
};


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