summaryrefslogtreecommitdiff
path: root/TAO/CIAO/ciao/ServerActivator_Impl.h
blob: 7ff3c783d7d34fca8d7cddbe0e0fff4d1a6f8200 (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
// -*- C++ -*-

//=============================================================================
/**
 *  @file    ServerActivator_Impl.h
 *
 *  $Id$
 *
 *  This file contains implementation for the servant of
 *  Components::Deployment::ServerActivator interface.
 *
 *  @author Nanbor Wang <nanbor@cs.wustl.edu>
 */
//=============================================================================


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

#include "ace/config-all.h"

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

#include "CCM_DeploymentS.h"
#include "CIAO_ServersS.h"
#include "Object_Set_T.h"

#include "ace/SString.h"


namespace CIAO
{
  /**
   * @class Activator_Callback
   *
   * @brief A call back interface for ComponentServer.
   *
   * Notice that this implementation is *NOT* thread-safe.
   */
  class CIAO_SERVER_Export Activator_Callback_Impl
    : public virtual POA_CIAO::Activator_Callback,
      public virtual PortableServer::RefCountServantBase
  {
  public:
    friend class ServerActivator_Impl;

    /// Constructor.
    Activator_Callback_Impl (CORBA::ORB_ptr o,
                             PortableServer::POA_ptr p,
                             Components::Deployment::ServerActivator_ptr s,
                             const Components::ConfigValues &cofig);

    /// Destructor.
    ~Activator_Callback_Impl ();

    /// Get the containing POA.  This operation does *not*
    /// increase the reference count of the POA.
    virtual PortableServer::POA_ptr _default_POA (void);

    /// Record the ComponentServer reference returned by the newly
    /// spawned ComponentServer and give it back a reference to ServerActivator.
    Components::Deployment::ServerActivator_ptr
    register_component_server (Components::Deployment::ComponentServer_ptr svr,
                               Components::ConfigValues_out config
                               ACE_ENV_ARG_DECL_WITH_DEFAULTS)
      ACE_THROW_SPEC ((CORBA::SystemException));

  protected:
    Components::Deployment::ComponentServer_ptr get_server_ref (void);

    CORBA::ORB_var orb_;

    PortableServer::POA_var poa_;

    /// This servant only lives as long as a call to the
    /// create_component_server method in ServerActivator, so there's
    /// no need to duplicate the object reference here.
    Components::Deployment::ServerActivator_ptr activator_;

    Components::Deployment::ComponentServer_var server_;

    Components::ConfigValues_var config_;
  };

  /**
   * @class ServerActivator_Impl
   *
   * @brief Servant implementation for Components::Deployment::ServerActivator
   *
   * This class implements the Components::Deployment::ServerActivator
   * interface as defined by the CCM spcification.  As the interface
   * implies, this is actually part of the deployment interface and is
   * used to manage the lifecycle of containers running on the server.
   */
  class CIAO_SERVER_Export ServerActivator_Impl
    : public virtual POA_Components::Deployment::ServerActivator,
      public virtual PortableServer::RefCountServantBase
  {
  public:
    /// Constructor
    ServerActivator_Impl (CORBA::ORB_ptr o,
                          PortableServer::POA_ptr p);

    /// Destructor
    virtual ~ServerActivator_Impl (void);

    /// Get the containing POA.  This operation does *not*
    /// increase the reference count of the POA.
    virtual PortableServer::POA_ptr _default_POA (void);

    /**
     * Initialize the ServerActivator.  The currently implementation
     * of ServerActivator can only activate CIAO's own
     * ComponentServer processes.  You should specify the location
     * (pathname) of the ComponentServer and the delay
     * ServerActivator should wait (in second) for ComponentServer to
     * call back.
     *
     * @param server_location A null-termiated char * string pointing
     *    to the pathname of a ComponentServer executable.

     * @param delay instructs how long (in second) a ServerActivator
     *   should wait for a newly spawned ComponentServer to pass back
     *   its IOR.
     *
     * @param installation_ior A null-terminated char * string
     * pointing to the stringified IOR of a ComponentInstallation that
     * ComponentServer can use to location component implementation DLL.
     *
     * @param default_svcconf A null-terminated char * string pointing
     * to the pathname of the default svcconf file a ComponentServer
     * should use (specified using -ORBSvcConfFile) if no hint is given.
     *
     * @param svcconf_map_file A null-terminated char * string
     * pointing to the pathname of a (hint, svcconf pathname) map.
     */
    int init (const char *server_location,
              CORBA::ULong delay,
              const char *installation_ior,
              const char *default_svcconf,
              const char *svcconf_map_file,
              const char *extra_cmdline_flags
              ACE_ENV_ARG_DECL_WITH_DEFAULTS)
      ACE_THROW_SPEC ((CORBA::SystemException));

    /// Components::Deployment::ServerActivator defined attributes/operations.

    virtual Components::Deployment::ComponentServer_ptr
    create_component_server (const Components::ConfigValues & config
                             ACE_ENV_ARG_DECL_WITH_DEFAULTS)
      ACE_THROW_SPEC ((CORBA::SystemException,
                       Components::CreateFailure,
                       Components::InvalidConfiguration));

    virtual void remove_component_server (Components::Deployment::ComponentServer_ptr server
                                          ACE_ENV_ARG_DECL_WITH_DEFAULTS)
      ACE_THROW_SPEC ((CORBA::SystemException,
                       Components::RemoveFailure));

    virtual Components::Deployment::ComponentServers *
    get_component_servers (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS)
      ACE_THROW_SPEC ((CORBA::SystemException));

    /// Return the cached ServerActivator object reference.  Do not
    /// release this object reference, or put it into an var.
    Components::Deployment::ServerActivator_ptr
    _ciao_get_objref (void);

    const char *_ciao_get_ior (void);

  protected:
    /**
     * Contains the information extracted from
     * create_component_server's ConfigValue argument that
     * ServerActivation cares.
     */
    typedef struct CS_config
    {
      // ConfigValue::name: CIAO-svcconf-id
      CORBA::String_var svcconf_hint_;

      // ConfigValue::Name: CIAO-rtcad-filename
      CORBA::String_var rtcad_filename_;
    } CompServ_Config_Info;

    /**
     * Initialize svc_conf_map_ with the supplied filename.
     */
    int init_svcconf_map (const char *map_file);

    /**
     * Returns the pathname to the effective svc.conf file based on
     * "hint."  It may return the default svc.conf file when there's
     * no hint (hint == 0) and we do have a default svc.conf path.
     */
    const char *lookup_svcconf_pathname (const char *hint) const;

    /**
     * Parse the ConfigValue arguement of the function
     * create_component_server and extractg the information into
     */
    void parse_config_value (const Components::ConfigValues &options,
                             CompServ_Config_Info &config_info
                             ACE_ENV_ARG_DECL_WITH_DEFAULTS)
      ACE_THROW_SPEC ((CORBA::SystemException,
                       Components::InvalidConfiguration));


  protected:
    /// location of the ComponentServer.
    CORBA::String_var server_path_;

    /// Keep a pointer to the managing ORB serving this servant.
    CORBA::ORB_var orb_;

    /// Keep a pointer to the managing POA.
    PortableServer::POA_var poa_;

    /// Child poa that uses active object map.
    PortableServer::POA_var callback_poa_;

    /// Cached the IOR string to ComponentInstallation Interface
    CORBA::String_var installation_ior_;

    /// Specify the time in second ServerActivator will wait for a
    /// child ComponentServer to callback.  Default is 5 second.
    CORBA::ULong spawn_delay_;

    /// Cache a object reference to this servant.
    Components::Deployment::ServerActivator_var objref_;

    /// Cache the ior of the previous reference
    CORBA::String_var ior_;

    /// Synchronize access to the object set.
    TAO_SYNCH_MUTEX lock_;

    /// Default svc.conf filename.
    ACE_CString default_svcconf_file_;

    /// Extra command line flags
    ACE_CString extra_flags_;

    typedef ACE_Hash_Map_Manager_Ex<ACE_CString,
                                    ACE_CString,
                                    ACE_Hash<ACE_CString>,
                                    ACE_Equal_To<ACE_CString>,
                                    ACE_Null_Mutex> SVCCONF_MAP;

    /// Map of (canonical svc.conf id, svc.conf) mapping
    SVCCONF_MAP svc_conf_map_;

    /// Keep a list of managed ComponentServer objects.
    Object_Set<Components::Deployment::ComponentServer, Components::Deployment::ComponentServer_var> cs_set_;
  };
}

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

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