summaryrefslogtreecommitdiff
path: root/modules/CIAO/ciao/Deployment/Handlers/Container_Handler.cpp
blob: d27dab97c659135aab9d8a55381b4d60d29c539b (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
// $Id$

#include "Container_Handler.h"
#include "ciao/Logger/Log_Macros.h"
#include "ciao/Containers/Session/Session_Container.h"
#include "ciao/ComponentServer/Server_init.h"

#include "CIAO_State.h"

namespace CIAO
{
  Container_Handler_i::Container_Handler_i (const DAnCE::Utility::PROPERTY_MAP &,
                                            CORBA::ORB_ptr orb,
                                            PortableServer::POA_ptr poa)
    : orb_ (CORBA::ORB::_duplicate (orb)),
      poa_ (PortableServer::POA::_duplicate (poa))
            
  {
    CIAO_TRACE ("Container_Handler_i::Container_Handler_i");
    CIAO::Server_init (orb_);
    
    // For the time being, we are going to go ahead and construct a container.
    ::Deployment::DeploymentPlan plan;
    plan.instance.length (1);
    plan.instance[0].name = "";
    
    ::CORBA::Any_var any;
    this->install_instance (plan, 0, any.out ());
  }
  
  // Destructor 
  Container_Handler_i::~Container_Handler_i (void)
  {
    CIAO_TRACE ("Container_Handler_i::~Container_Handler_i");
    
    try
      {
        // For the time being, we are going to go ahead and delete the default container
        ::Deployment::DeploymentPlan plan;
        plan.instance.length (1);
        plan.instance[0].name = "";
        
        CORBA::Any any;
        this->remove_instance (plan, 0, any);
      }
    catch (...)
      { //swallow
      }
  }
    
    
  char * 
  Container_Handler_i::instance_type (void)
  {
    CIAO_TRACE ("Container_Handler_i::instance_type");
    return CORBA::string_dup ("edu.dre.vanderbilt.dre.DAnCE.CCM.Container");
  }
  
    
  void
  Container_Handler_i::install_instance (const ::Deployment::DeploymentPlan &plan,
                                         ::CORBA::ULong instanceRef,
                                         ::CORBA::Any_out instance_reference)
  {
    CIAO_TRACE ("Container_Handler_i::install_instance");
    
    CIAO::Session_Container *cont (0);
    const char *name (plan.instance[instanceRef].name.in ());
    CORBA::PolicyList policies (0);
    
    CIAO_DEBUG (6, (LM_DEBUG, CLINFO 
                    "Container_Handler_i::install_instance - "
                    "Creating container with id %C\n",
                    name));
    ACE_NEW_THROW_EX (cont,
                      CIAO::Session_Container (this->orb_,
                                               this->poa_,
                                               0 /* not needed */,
                                               false /* we're always dynanic for the moment */,
                                               0, /*always dynanic */
                                               name,
                                               0 /* no additional policies at this moment */),
                      CORBA::NO_MEMORY ());
    
    CIAO_DEBUG (8, (LM_DEBUG, CLINFO 
                    "Container_Handler_i::install_instance - "
                    "Container <%C> successfully created\n",
                    name));

    CIAO::Container_var container_ref (cont);

    DEPLOYMENT_STATE::instance ()->add_container (name,
                                                  cont);
    
    ::CORBA::Any_ptr outref;
    ACE_NEW_THROW_EX (outref,
                      ::CORBA::Any (),
                      CORBA::NO_MEMORY ());
    
    (*outref) <<= container_ref;
    
    instance_reference = outref;
  }
  
  void
  Container_Handler_i::activate_instance (const ::Deployment::DeploymentPlan & ,
                                     ::CORBA::ULong ,
                                     const ::CORBA::Any &)
  {
    CIAO_TRACE ("Container_Handler_i::activate_instance");
    // no activation needed.
  }

  void
  Container_Handler_i::passivate_instance (const ::Deployment::DeploymentPlan & ,
                                      ::CORBA::ULong ,
                                      const ::CORBA::Any &)
  {
    CIAO_TRACE ("Container_Handler_i::passivate_instance");
    // no passivation needed.
  }
    
  void 
  Container_Handler_i::provide_endpoint_reference (const ::Deployment::DeploymentPlan &,
                                                   ::CORBA::ULong,
                                                   ::CORBA::Any_out)
  {
    CIAO_TRACE ("Container_Handler_i::provide_endpoint_reference");
    CIAO_ERROR (1, (LM_ERROR, CLINFO 
                    "Container_Handler_i::provide_endpoint_reference - "
                    "Unable to provide any endpoints.\n"));
    throw CORBA::NO_IMPLEMENT ();
  }

  void
  Container_Handler_i::remove_instance (const ::Deployment::DeploymentPlan & plan,
                                        ::CORBA::ULong instanceRef,
                                        const ::CORBA::Any &)
  {
    CIAO_TRACE ("Container_Handler_i::remove_instance");
    
    const char *name = plan.instance[instanceRef].name.in ();

    ::CIAO::Container_var cont = 
        DEPLOYMENT_STATE::instance ()->fetch_container (name);
    
    if (!cont)
      {
        CIAO_ERROR (1, (LM_ERROR, CLINFO,
                        "Container_Handler_i::remove_instance - "
                        "Error, no contianer with id <%C>",
                        name));
        throw ::Deployment::StopError (name,
                                       "No container with ID");
      }
       
    
    CIAO_DEBUG (8, (LM_TRACE, CLINFO
                    "Container_Handler_i::remove_instance - "
                    "Removing container with Id <%C>\n",
                    name));
    
    DEPLOYMENT_STATE::instance ()->remove_container (name);
    
    CIAO_DEBUG (5, (LM_TRACE, CLINFO
                    "Container_Handler_i::remove_instance - "
                    "Container with Id <%C> removed.\n",
                    name));
  }
  
    
  void
  Container_Handler_i::connect_instance (const ::Deployment::DeploymentPlan &,
                                         ::CORBA::ULong,
                                         const ::CORBA::Any &)
  {
    CIAO_TRACE ("Container_Handler_i::connect_instance");
    
    CIAO_ERROR (1, (LM_ERROR, CLINFO
                    "Container_Handler_i::connect_instance - ",
                    "No connections allowed for containers.\n"));
    throw CORBA::NO_IMPLEMENT ();
  }
  
    
  void
  Container_Handler_i::disconnect_instance (const ::Deployment::DeploymentPlan &,
                                            ::CORBA::ULong)
  {
    CIAO_TRACE ("Container_Handler_i::disconnect_instance");
    
    CIAO_ERROR (1, (LM_ERROR, CLINFO
                    "Container_Handler_i::disconnect_instance - ",
                    "No connections allowed for containers.\n"));
    throw CORBA::NO_IMPLEMENT ();
  }
  
  void
  Container_Handler_i::instance_configured (const ::Deployment::DeploymentPlan &,
                                            ::CORBA::ULong)
  {
    CIAO_TRACE ("Container_Handler_i::instance_configured");
    // nothing to be done
  }
}