summaryrefslogtreecommitdiff
path: root/ciao/ComponentServer/CIAO_Container_Impl.cpp
blob: 20752532008f95c2078cf30dee5114aa7416261b (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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
// $Id$
#include "CIAO_Container_Impl.h"

#include "ace/Log_Msg.h"
#include "ccm/CCM_HomeC.h"
#include "CIAO_PropertiesC.h"
#include "CIAO_CS_ClientC.h"
#include "Client_init.h"
#include "ciao/Logger/Log_Macros.h"

namespace CIAO
{
  namespace Deployment
  {
    // Constructor
    CIAO_Container_i::CIAO_Container_i (const Components::ConfigValues &config,
                                        const Static_Config_EntryPoints_Maps *static_entrypts,
                                        const char *name,
                                        const CORBA::PolicyList *policies,
                                        Components::Deployment::ComponentInstallation_ptr ci,
                                        CORBA::ORB_ptr orb,
                                        PortableServer::POA_ptr poa)
      : orb_ (CORBA::ORB::_duplicate (orb)),
        poa_ (PortableServer::POA::_duplicate (poa)),
        config_ (config.length ()),
        static_entrypts_maps_ (static_entrypts),
        ci_ (Components::Deployment::ComponentInstallation::_duplicate (ci))
    {
      CIAO_TRACE("CIAO_Container_i::CIAO_Container_i");

      for (CORBA::ULong i = 0; i < config.length (); ++i)
        {
          this->config_[i] = config[i];
        }

      try
        {
          if (this->static_entrypts_maps_ == 0)
            {
              CIAO_DEBUG (6, (LM_DEBUG, CLINFO "CIAO_Container_i: creating Session container with dynamic linkage\n"));
              this->container_ = new CIAO::Session_Container (this->orb_.in (), this->poa_.in (), this, false,
                                                              0, name, policies);
            }
          else
            {
              CIAO_DEBUG (6, (LM_DEBUG, CLINFO "CIAO_Container_i: creating Session container with static linkage\n"));
              this->container_ = new CIAO::Session_Container (this->orb_.in (), this->poa_.in (), this, true,
                                                              this->static_entrypts_maps_,
                                                              name, policies);
            }
        }
      catch (...)
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO "CIAO_Container_i::CIAO_Container_i - "
                      "Caught exception while allocating container implementation\n"));
          throw;
        }
    }


    // Destructor
    CIAO_Container_i::~CIAO_Container_i (void)
    {
      CIAO_TRACE("CIAO_Container_i::~CIAO_Container_i");
    }

    ::Components::CCMObject_ptr
    CIAO_Container_i::install_component (const char * id,
                                         const char * entrypt,
                                         const ::Components::ConfigValues & config)
    {
      CIAO_TRACE("CIAO_Container_i::install_component");

      if (!id)
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO "CIAO_Container_i::install_component - "
                       "No home ID provided\n"));
          throw ::Components::Deployment::InvalidConfiguration ();
        }

      Components::CCMObject_var comp;

      if (this->component_map_.find (id, comp) == 0)
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO "CIAO_Container_i::install_component - "
                       "Component with id %C already installed, aborting\n",
                       id));
          throw Components::CreateFailure ();
        }

      if (!entrypt)
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO "CIAO_Container_i::install_component - "
                      "No executor entrypoint found.\n"));
          throw ::Components::Deployment::InvalidConfiguration ();
        }

      CIAO_DEBUG (6, (LM_INFO, CLINFO "CIAO_Container_i::install_component - "
                   "Attempting to install home with id [%C]\n",
                   id));

      CIAO_DEBUG (9, (LM_TRACE, CLINFO
                  "CIAO_Container_i::install_component - "
                  "Extracting ConfigValues from sequence of length [%u]\n",
                  config.length ()));

      CIAO::Utility::CONFIGVALUE_MAP cm;
      CIAO::Utility::build_config_values_map (cm, config);
      CORBA::Any val;

      const char *tmp = 0;
      CORBA::String_var exec_art, svnt_art, svnt_entry;

      if (cm.find (SVNT_ENTRYPT, val) == 0)
        {
          val >>= tmp;
          svnt_entry = tmp;
          CIAO_DEBUG (9, (LM_TRACE, CLINFO
                       "CIAO_Container_i::install_component - "
                       "Found Servant entrypoint %C\n", svnt_entry.in ()));
        }
      else
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO
                       "CIAO_Container_i::install_component - "
                       "Error: No Servant entrypoint provided, aborting installation\n"));
          throw Components::InvalidConfiguration ();
        }

      if (cm.find (SVNT_ARTIFACT, val) == 0)
        {
          val >>= tmp;
          svnt_art = this->ci_->get_implementation (tmp);
          CIAO_DEBUG (9, (LM_TRACE, CLINFO
                       "CIAO_Container_i::install_component - "
                       "Found Servant artifact %C\n", svnt_art.in ()));
        }
      else
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO
                       "CIAO_Container_i::install_component - "
                       "Error: No Servant artifact provided, aborting installation\n"));
          throw Components::InvalidConfiguration ();
        }


      if (cm.find (EXEC_ARTIFACT, val) == 0)
        {
          val >>= tmp;
          exec_art = this->ci_->get_implementation (tmp);
          CIAO_DEBUG (9, (LM_TRACE, CLINFO
                       "CIAO_Container_i::install_component - "
                       "Found executor artifact: %C\n", exec_art.in ()));
        }
      else
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO
                       "CIAO_Container_i::install_component - "
                       "Error: No Executor artifact provided, aborting installation\n"));
        }

      CIAO_DEBUG (9, (LM_TRACE, CLINFO
                  "CIAO_Container_i::install_component - "
                  "Extraction resulted in map of [%u] values\n", cm.current_size ()));

      comp = this->container_->install_component (exec_art,
                                                  entrypt,
                                                  svnt_art,
                                                  svnt_entry,
                                                  id);

      if (this->component_map_.bind (id,
                                     Components::CCMObject::_duplicate (comp.in ())) == -1)
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO
                       "CIAO_Container_i::install_component - "
                       "Unable to bind componnet into component map\n"));
        }

      return comp._retn ();
    }

    void
    CIAO_Container_i::remove_component (::Components::CCMObject_ptr cref)
    {
      CIAO_TRACE("CIAO_Container_i::remove_component");

      Component_Iterator i = this->component_map_.begin ();
      while (!i.done ())
        {
          if (i->item ()->_is_equivalent (cref))
            {
              CIAO_DEBUG (9, (LM_TRACE, CLINFO "CIAO_Container_i::remove_component - "
                           "Successfully found matching component\n"));
              break;
            }
          i.advance ();
        }

      if (i.done ())
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO "CIAO_Container_i::remove_component - "
                       "Unable to find matching component managed by this container, throwing RemoveFailure\n"));
          throw Components::RemoveFailure ();
        }

      if (!CORBA::is_nil (this->container_.in ()))
        {
          CIAO_DEBUG (9, (LM_TRACE, CLINFO "CIAO_Container_i::remove_component - "
                       "Invoking remove on the container impl for component %C.\n",
                       i->key ().c_str ()));
          this->container_->uninstall_component (cref);
          CIAO_DEBUG (6, (LM_INFO, CLINFO "CIAO_Container_i::remove_component - "
                       "Successfully removed component %C\n",
                       i->key ().c_str ()));
        }

      if (this->component_map_.unbind (i->key ()) != 0)
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO "CIAO_Container_i::remove_component - "
                       "Unable to unbind removed component with id %C from component map\n",
                       i->key ().c_str ()));
        }
    }

    ::Components::CCMObjectSeq *
    CIAO_Container_i::get_components (void)
    {
      CIAO_TRACE("CIAO_Container_i::get_components");
      throw CORBA::NO_IMPLEMENT ();
    }

    ::Components::ConfigValues *
    CIAO_Container_i::configuration (void)
    {
      CIAO_TRACE("CIAO_Container_i::configuration");
      throw CORBA::NO_IMPLEMENT ();
    }

    ::Components::Deployment::ComponentServer_ptr
    CIAO_Container_i::get_component_server (void)
    {
      CIAO_TRACE("CIAO_Container_i::get_component_server");
      throw CORBA::NO_IMPLEMENT ();
    }

    ::Components::CCMHome_ptr
    CIAO_Container_i::install_home (const char * id,
                                    const char * entrypt,
                                    const ::Components::ConfigValues & config)
    {
      CIAO_TRACE("CIAO_Container_i::install_home");

      if (!id)
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO "CIAO_Container_i::install_home - "
                      "No home ID provided\n"));
          throw ::Components::Deployment::InvalidConfiguration ();
        }

      Components::CCMHome_var home;

      if (this->home_map_.find (id, home) == 0)
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO "CIAO_Container_i::install_home - "
                       "Home with id %C already installed, aborting\n",
                       id));
          throw Components::CreateFailure ();
        }

      if (!entrypt)
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO "CIAO_Container_i::install_home - "
                      "No executor entrypoint found.\n"));
          throw ::Components::Deployment::InvalidConfiguration ();
        }

      CIAO_DEBUG (6, (LM_INFO, CLINFO "CIAO_Container_i::install_home - "
      "Attempting to install home with id [%C]\n", id));

      CIAO_DEBUG (9, (LM_TRACE, CLINFO
                  "CIAO_Container_i::install_home - "
                  "Extracting ConfigValues from sequence of length [%u]\n",
                  config.length ()));

      CIAO::Utility::CONFIGVALUE_MAP cm;
      CIAO::Utility::build_config_values_map (cm, config);
      CORBA::Any val;

      const char *tmp = 0;
      CORBA::String_var exec_art, svnt_art, svnt_entry;
      if (cm.find (SVNT_ENTRYPT, val) == 0)
        {
          val >>= tmp;
          svnt_entry = tmp;
          CIAO_DEBUG (9, (LM_TRACE, CLINFO
                       "CIAO_Container_i::install_home - "
                       "Found Servant entrypoint %C\n", svnt_entry.in ()));
        }
      else
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO
                       "CIAO_Container_i::install_home - "
                       "Error: No Servant entrypoint provided, aborting installation\n"));
          throw Components::InvalidConfiguration ();
        }

      if (cm.find (SVNT_ARTIFACT, val) == 0)
        {
          val >>= tmp;
          svnt_art = this->ci_->get_implementation (tmp);
          CIAO_DEBUG (9, (LM_TRACE, CLINFO
                       "CIAO_Container_i::install_home - "
                       "Found Servant artifact %C\n", svnt_art.in ()));
        }
      else
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO
                       "CIAO_Container_i::install_home - "
                       "Error: No Servant artifact provided, aborting installation\n"));
          throw Components::InvalidConfiguration ();
        }


      if (cm.find (EXEC_ARTIFACT, val) == 0)
        {
          val >>= tmp;
          exec_art = this->ci_->get_implementation (tmp);
          CIAO_DEBUG (9, (LM_TRACE, CLINFO
                       "CIAO_Container_i::install_home - "
                       "Found executor artifact: %C\n", exec_art.in ()));
        }
      else
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO
                       "CIAO_Container_i::install_home - "
                       "Error: No Executor artifact provided, aborting installation\n"));
        }

      CIAO_DEBUG (9, (LM_TRACE, CLINFO
                  "CIAO_Container_i::install_home - "
                  "Extraction resulted in map of [%u] values\n", cm.current_size ()));


      // extract config values here...

      //CIAO_DEBUG (6, (LM_DEBUG, CLINFO "CIAO_Container_i::install_home - ",
      //"Executor entrypoint [%C], servant entrypoint [%C], servant library [%C]\n",
      //entrypt, svnt_entrypt.in (), svnt_library.in ()));

      home = this->container_->install_home (exec_art,
                                             entrypt,
                                             svnt_art,
                                             svnt_entry,
                                             id);

      if (this->home_map_.bind (id,
                                Components::CCMHome::_duplicate (home.in ())) == -1)
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO
                       "CIAO_Container_i::install_home - "
                       "Unable to bind home into home map\n"));
        }

      return  home._retn ();
    }

    void
    CIAO_Container_i::remove_home (::Components::CCMHome_ptr href)
    {
      CIAO_TRACE("CIAO_Container_i::remove_home");

      Home_Iterator i = this->home_map_.begin ();
      while (!i.done ())
        {
          if (i->item ()->_is_equivalent (href))
            {
              CIAO_DEBUG (9, (LM_TRACE, CLINFO "CIAO_Container_i::remove_home - "
                           "Successfully found matching home\n"));
              break;
            }
          i.advance ();
        }

      if (i.done ())
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO "CIAO_Container_i::remove_home - "
                       "Unable to find matching home managed by this container, throwing RemoveFailure\n"));
          throw Components::RemoveFailure ();
        }

      CIAO_DEBUG (9, (LM_TRACE, CLINFO "CIAO_Container_i::remove_home - "
                   "Invoking remove on the container impl for home %C.\n",
                   i->key ().c_str ()));
      this->container_->uninstall_home (href);
      CIAO_DEBUG (6, (LM_INFO, CLINFO "CIAO_Container_i::remove_home - "
                   "Successfully removed home %C\n",
                   i->key ().c_str ()));

      if (this->home_map_.unbind (i->key ()) != 0)
        {
          CIAO_ERROR (1, (LM_ERROR, CLINFO "CIAO_Container_i::remove_home - "
                       "Unable to unbind removed home with id %C from home map\n",
                       i->key ().c_str ()));
        }
    }

    ::Components::CCMHomes *
    CIAO_Container_i::get_homes (void)
    {
      CIAO_TRACE("CIAO_Container_i::get_homes");

      ::Components::CCMHomes *tmp_homes = 0;

      ACE_NEW_THROW_EX (tmp_homes,
                        ::Components::CCMHomes (this->home_map_.current_size ()),
                        CORBA::NO_MEMORY ());

      ::Components::CCMHomes_var retval (tmp_homes);
      retval->length (this->home_map_.current_size ());
      Home_Iterator i = this->home_map_.begin ();
      CORBA::ULong pos = 0;
      while (!i.done ())
        {
          retval[pos++] = ::Components::CCMHome::_duplicate (i->item ().in ());
          i.advance ();
        }

      return retval._retn ();
    }

    void
    CIAO_Container_i::remove (void)
    {
      CIAO_TRACE("CIAO_Container_i::remove");

      if (this->home_map_.current_size () != 0 ||
          this->component_map_.current_size () != 0)
        {
          CIAO_ERROR (1, (LM_WARNING, CLINFO "CIAO_Container_i::remove - "
                       "Attempting to remove container that still has %u homes and %u components installed\n",
                       this->home_map_.current_size (),
                       this->component_map_.current_size ()));
        }
    }

    void
    CIAO_Container_i::activate_component (::Components::CCMObject_ptr comp)
    {
      CIAO_TRACE ("CIAO_Container_i::activate_component");

      this->container_->activate_component (comp);
    }


    void
    CIAO_Container_i::passivate_component (::Components::CCMObject_ptr comp)
    {
      CIAO_TRACE ("CIAO_Container_i::passivate_component");

      this->container_->passivate_component (comp);
    }

    PortableServer::POA_ptr
    CIAO_Container_i::_default_POA (void)
    {
      CIAO_TRACE ("CIAO_Container_i::_default_POA");
      return PortableServer::POA::_duplicate (this->poa_.in ());
    }

    void CIAO_Container_i::connect_local_facet (::Components::CCMObject_ptr provider,
                                                const char * provider_port,
                                                ::Components::CCMObject_ptr user,
                                                const char * user_port)
    {
      CIAO_TRACE ("CIAO_Container_i::connect_local_facet");
      this->container_->connect_local_facet (provider, provider_port, user, user_port);

    }

    void CIAO_Container_i::disconnect_local_facet (::Components::CCMObject_ptr provider,
                                                   const char * provider_port,
                                                   ::Components::CCMObject_ptr user,
                                                   const char * user_port)
    {
      CIAO_TRACE ("CIAO_Container_i::connect_local_facet");
      this->container_->disconnect_local_facet (provider, provider_port, user, user_port);
    }
  }
}