summaryrefslogtreecommitdiff
path: root/TAO/CIAO/ciao/Container_Impl.cpp
blob: 94b4526bc9284075400a74952018037aa1aafaa0 (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
// $Id$
#include "Container_Impl.h"

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

CIAO::Container_Impl::~Container_Impl ()
{
  // @@ remove all home?
}

PortableServer::POA_ptr
CIAO::Container_Impl::_default_POA (void)
{
  return PortableServer::POA::_duplicate (this->poa_.in ());
}

int
CIAO::Container_Impl::init (const ::Components::ConfigValues &options,
                            Components::Deployment::ComponentInstallation_ptr inst
                            ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_NEW_THROW_EX (this->config_,
                    Components::ConfigValues (),
                    CORBA::INTERNAL ());
  ACE_CHECK_RETURN (-1);

  *this->config_ = options;
  this->installation_ =
    Components::Deployment::ComponentInstallation::_duplicate (inst);

  // @@ Initialize container and create the internal container
  // implementation that actually interacts with installed
  // homes/components.

  // @@ We will need a container factory here later on when we support
  // more kinds of container implementations.

  // @@ Fish out the ComponentServer object reference from <options>.

  ACE_NEW_THROW_EX (this->container_,
                    CIAO::Session_Container (this->orb_.in ()),
                    CORBA::INTERNAL ());
  ACE_CHECK_RETURN (-1);

  return this->container_->init (ACE_ENV_SINGLE_ARG_PARAMETER);
}

::Components::ConfigValues *
CIAO::Container_Impl::configuration (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  Components::ConfigValues *retval;

  ACE_NEW_THROW_EX (retval,
                    Components::ConfigValues (),
                    CORBA::INTERNAL ());
  ACE_CHECK_RETURN (0);

  *retval = this->config_.inout ();

  return retval;
}

::Components::Deployment::ComponentServer_ptr
CIAO::Container_Impl::get_component_server (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  return Components::Deployment::ComponentServer::_duplicate (this->comserv_.in ());
}

::Components::CCMHome_ptr
CIAO::Container_Impl::install_home (const char * id,
                                    const char * entrypt,
                                    const Components::ConfigValues & config
                                    ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   Components::Deployment::UnknownImplId,
                   Components::Deployment::ImplEntryPointNotFound,
                   Components::Deployment::InstallationFailure,
                   Components::InvalidConfiguration))
{
  // use id to locate the softpkg from the ComponentInstallation interface.
  // depending on where we want to parse the softpkg descriptor, we
  // can either use the <entrypt> directly (if we parse the softpkg in
  // Assembly), simply verify that is correct, or even discard this
  // value.

  // @@ Here we need to resolve paths to both component executors and
  // component servants (that matches the container type) for the
  // executor and their entry points before we can install the home.
  struct home_installation_info config_info;
  this->parse_config_values (id,
                             config,
                             config_info
                             ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (0);

  Components::CCMHome_var newhome
    = this->container_->ciao_install_home
    (config_info.executor_dll_.in (),
     entrypt,
     config_info.servant_dll_.in (),
     config_info.servant_entrypt_.in ()
     ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (0);

  {
    ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);

    this->home_set_.add (newhome.in ());
  }
  return newhome._retn ();
}

void
CIAO::Container_Impl::remove_home (Components::CCMHome_ptr href
                                   ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   Components::RemoveFailure))
{
  ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->lock_);

  if (this->home_set_.object_in_set (href) == 0)
    ACE_THROW (CORBA::BAD_PARAM ());

  // @@ Finalizing home... how?  Removing all the components, but how?
  // It looks like the component home will also need to keep a record
  // of all the components it creates.

  this->container_->ciao_uninstall_home (href
                                         ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  // @@ Still need to remove the home if the previous operation fails?
  if (this->home_set_.remove (href) == -1)
    ACE_THROW (::Components::RemoveFailure ());
}

::Components::CCMHomes *
CIAO::Container_Impl::get_homes (ACE_ENV_SINGLE_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);

  Components::CCMHomes_var retval;

  ACE_NEW_THROW_EX (retval.out (),
                    Components::CCMHomes (),
                    CORBA::INTERNAL ());
  ACE_CHECK_RETURN (0);

  CORBA::ULong len = this->home_set_.size ();
  retval->length (len);          // resize

#if 0
  // TAO is broken here.  Both <replace>, <get_buffer> and friends are missing.
  this->home_set_.copy (len, retval->get_buffer (0));
#else
  for (CORBA::ULong i = 0; i < len; ++i)
    {
      retval[i] = this->home_set_.at (i);
    }
#endif

  return retval._retn ();
}

void
CIAO::Container_Impl::remove (ACE_ENV_SINGLE_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   Components::RemoveFailure))
{
  // @@ Need to remove all CCMHome

  //  ACE_THROW (CORBA::NO_IMPLEMENT ());

  ACE_DEBUG ((LM_DEBUG, "CIAO::Container_Impl::remove\n"));
}

void
CIAO::Container_Impl::parse_config_values (const char *id,
                                           const Components::ConfigValues &options,
                                           struct home_installation_info &component_install_info
                                           ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   Components::Deployment::UnknownImplId,
                   Components::Deployment::ImplEntryPointNotFound,
                   Components::InvalidConfiguration))
{
  CORBA::String_var servant_uuid;

  for (CORBA::ULong i = 0; i < options.length (); ++i)
    {
      CORBA::String_var *info;
      const char *str_in = 0;

      // @@ The following code need cleaning up.
      if (ACE_OS::strcmp (options[i]->name (), "CIAO-servant-UUID") == 0)
        info = &servant_uuid;
      else if (ACE_OS::strcmp (options[i]->name (), "CIAO-servant-entrypt") == 0)
        info = &component_install_info.servant_entrypt_;
      else
        {
          Components::InvalidConfiguration exc;
          exc.name = CORBA::string_dup (options[i]->name ());
          exc.reason = Components::UnknownConfigValueName;
          ACE_THROW (exc);
        }

      if (options[i]->value () >>= str_in)
        {
          *info = CORBA::string_dup (str_in);
#if 0
          ACE_DEBUG ((LM_DEBUG, "*parse_config_values got (%s) = %s\n",
                      options[i]->name (),
                      str_in));
#endif /* 0 */
        }
      else
        {
          Components::InvalidConfiguration exc;
          exc.name = CORBA::string_dup (options[i]->name ());
          exc.reason = Components::InvalidConfigValueType;
          ACE_THROW (exc);
        }
    }

  component_install_info.executor_dll_ =
    this->installation_->get_implementation (id
                                             ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  component_install_info.servant_dll_ =
    this->installation_->get_implementation (servant_uuid.in ()
                                             ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  if (component_install_info.executor_dll_.in () == 0 ||
      component_install_info.servant_dll_.in () == 0 ||
      component_install_info.servant_entrypt_.in () == 0)
    {
      Components::InvalidConfiguration exc;
      // The following should really be the exact missing configvalue name:
      exc.name = CORBA::string_dup ("home_installation_info");
      exc.reason = Components::ConfigValueRequired;
      ACE_THROW (exc);
    }
}