summaryrefslogtreecommitdiff
path: root/trunk/CIAO/tools/Config_Handlers/DP_Handler.cpp
blob: c5ff32d9c3504893a1e27113db6ab6069ad243ac (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
// $Id$

#include "DP_Handler.h"
#include "ace/UUID.h"
#include "DAnCE/Deployment/Deployment_DataC.h"

#include "CCD_Handler.h"
#include "ADD_Handler.h"
#include "MDD_Handler.h"
#include "IDD_Handler.h"
#include "ID_Handler.h"
#include "Property_Handler.h"
#include "cdp.hpp"
#include "RT-CCM/SRD_Handler.h"
#include "RT-CCM/CIAOServerResources.hpp"
#include "CIAO_Events/CIAOEvents_Handler.h"
#include "CIAO_Events/CIAOEvents.hpp"

#include "PCD_Handler.h"

ACE_RCSID (Config_Handlers,
           DP_Handler,
           "$Id$")

  namespace CIAO
  {
    namespace Config_Handlers
    {
      DP_Handler::DP_Handler (DeploymentPlan &dp)
        :   xsc_dp_ (0)
        , idl_dp_ (0)
        , retval_ (true)
      {
        if (!this->resolve_plan (dp))
          throw;
      }

      DP_Handler::DP_Handler (const ::Deployment::DeploymentPlan &plan)
        : xsc_dp_ (new DeploymentPlan),
          idl_dp_ (0),
          retval_ (0)
      {
        if (!this->build_xsc (plan))
          throw;
      }

      DP_Handler::~DP_Handler (void)
        throw ()
      {
      }

      DeploymentPlan const *
      DP_Handler::xsc (void) const
        throw (DP_Handler::NoPlan)
      {
        if (this->retval_ && this->xsc_dp_.get () != 0)
          return this->xsc_dp_.get ();

        throw NoPlan ();
      }

      DeploymentPlan *
      DP_Handler::xsc (void)
        throw (DP_Handler::NoPlan)
      {
        if (this->retval_ && this->xsc_dp_.get () != 0)
          return this->xsc_dp_.release ();

        throw NoPlan ();
      }

      ::Deployment::DeploymentPlan const *
      DP_Handler::plan (void) const
        throw (DP_Handler::NoPlan)
      {
        if (this->retval_ && this->idl_dp_.get () != 0)
          return this->idl_dp_.get ();

        throw NoPlan ();
      }

      ::Deployment::DeploymentPlan *
      DP_Handler::plan (void)
        throw (DP_Handler::NoPlan)

      {
        if (this->retval_ && this->idl_dp_.get () != 0)
          return this->idl_dp_.release ();

        throw NoPlan ();
      }

      bool
      DP_Handler::resolve_plan (DeploymentPlan &xsc_dp)
      {
        CIAO_TRACE ("DP_Handler::resolve_plan");

        ::Deployment::DeploymentPlan *tmp =
            new Deployment::DeploymentPlan;

        this->idl_dp_.reset (tmp);

        // Read in the label, if present, since minoccurs = 0
        if (xsc_dp.label_p ())
          {
            this->idl_dp_->label =
              CORBA::string_dup (xsc_dp.label ().c_str ());
          }

        // Read in the UUID, if present
        if (xsc_dp.UUID_p ())
          {
            this->idl_dp_->UUID =
              CORBA::string_dup (xsc_dp.UUID ().c_str ());
          }

        // Similar thing for dependsOn
        for (DeploymentPlan::dependsOn_const_iterator dstart = xsc_dp.begin_dependsOn ();
             dstart != xsc_dp.end_dependsOn ();
             ++dstart)
          {
            CORBA::ULong len = this->idl_dp_->dependsOn.length ();
            this->idl_dp_->dependsOn.length (len + 1);
            ID_Handler::get_ImplementationDependency (*dstart,
                                                      this->idl_dp_->dependsOn [len]);

          }

        // ... An the property stuff
        for (DeploymentPlan::infoProperty_const_iterator pstart = xsc_dp.begin_infoProperty ();
             pstart != xsc_dp.end_infoProperty ();
             ++pstart)
          {
            CORBA::ULong len =
              this->idl_dp_->infoProperty.length ();

            this->idl_dp_->infoProperty.length (len + 1);

            if (pstart->name () == "CIAOServerResources")
              {
                /*
                 * Hook for RT-CCM
                 */


                ACE_DEBUG ((LM_DEBUG,
                            "Importing ServerResources...\n"));

                // Parse the SR document
                SRD_Handler srd_handler (pstart->value ().value ().begin_string ()->c_str ());

                // Populate the property
                this->idl_dp_->infoProperty [len].name = pstart->name ().c_str ();
                this->idl_dp_->infoProperty [len].value <<= *(srd_handler.srd_idl ());
              }
            else if (pstart->name () == "CIAOEvents")
              {
                /*
                * Hook for EVENTS
                */

                ACE_DEBUG ((LM_DEBUG,
                            "Importing CIAOEvents...\n"));

                // Parse the SR document
                CIAOEvents_Handler event_handler (pstart->value ().value ().begin_string ()->c_str ());

                // Populate the property
                this->idl_dp_->infoProperty [len].name = pstart->name ().c_str ();
                this->idl_dp_->infoProperty [len].value <<= *(event_handler.esd_idl ());
              }
            else
              {
                Property_Handler::handle_property (*pstart,
                                                this->idl_dp_->infoProperty [len]);
              }
          }

        // Read in the realizes, if present
        if (xsc_dp.realizes_p ())
          {
            CCD_Handler::component_interface_descr (
                                                    xsc_dp.realizes (),
                                                    this->idl_dp_->realizes);
          }

        ADD_Handler::artifact_deployment_descrs (xsc_dp,
                                                 this->idl_dp_->artifact);

        MDD_Handler::mono_deployment_descriptions (xsc_dp,
                                                   this->idl_dp_->implementation);

        IDD_Handler::instance_deployment_descrs (xsc_dp,
                                                 this->idl_dp_->instance);

        this->idl_dp_->connection.length (xsc_dp.count_connection ());
        std::for_each (xsc_dp.begin_connection (),
                       xsc_dp.end_connection (),
                       PCD_Functor (this->idl_dp_->connection));

        //PCD_Handler::get_PlanConnectionDescription (xsc_dp, this->idl_dp_->connection);

        return true;
      }

      bool
      DP_Handler::build_xsc (const ::Deployment::DeploymentPlan &plan)
      {
        CIAO_TRACE ("DP_Handler::build_xsc");

        // Initialize the UUID generator.
        ACE_Utils::UUID_GENERATOR::instance ()->init ();

        // Clear IDREF tables
        IDD_Handler::IDREF.unbind_refs ();
        MDD_Handler::IDREF.unbind_refs ();
        ADD_Handler::IDREF.unbind_refs ();


        size_t len; //Used for checking the length of struct data members

        // Read in the label, if present, since minoccurs = 0
        if (plan.label != 0)
          {
            XMLSchema::string< char > i((plan.label));
            this->xsc_dp_->label(i);
          }

        // Read in the UUID, if present
        if (plan.UUID != 0)
          {
            XMLSchema::string< char > j((plan.UUID));
            this->xsc_dp_->UUID(j);
          }

        // Similar thing for dependsOn
        len = plan.dependsOn.length();
        for (size_t j = 0;
             j < len;
             ++j)
          {
            this->xsc_dp_->add_dependsOn(
                                         ID_Handler::impl_dependency(
                                                                     plan.dependsOn[j]));
          }

        // ... And the property stuff
        len = plan.infoProperty.length();
        for (size_t q = 0;
             q < len;
             q++)
          {
            if (ACE_OS::strcmp (plan.infoProperty[q].name.in (),
                                "CIAOServerResources") == 0)
              {
                ACE_ERROR ((LM_ERROR,
                            "(%P|%t) DP_Handler: Dumping of ServerResources not currently supported."));
                continue;
              }

            this->xsc_dp_->add_infoProperty (
                                             Property_Handler::get_property (
                                                                             plan.infoProperty[q]));
          }


        // We are assuming there is a realizes for the moment
        // @@ We may want to change this at a later date by creating a sequence of
        // @@ ComponentInterfaceDescriptions in the DeploymentPlan in ../DAnCE/Deployment/Deployment_Data.idl
        // @@ so we can check for length
        this->xsc_dp_->realizes(CCD_Handler::component_interface_descr(plan.realizes));
        if (!this->xsc_dp_->realizes_p())
          {
            ACE_ERROR ((LM_ERROR,
                        "(%P|%t) DP_Handler: "
                        "Error parsing Component Interface Descriptor."));
            return false;
          }

        //Take care of the artifact(s) if they exist
        len = plan.artifact.length();
        for(size_t k = 0;
            k < len;
            k++)
          {
            this->xsc_dp_->add_artifact (
                                         ADD_Handler::artifact_deployment_descr (
                                                                                 plan.artifact[k]));
          }

        //Take care of the implementation(s) if they exist
        len = plan.implementation.length();
        for(size_t l = 0;
            l < len;
            l++)
          {
            this->xsc_dp_->add_implementation (
                                               MDD_Handler::mono_deployment_description (
                                                                                         plan.implementation[l]));
          }

        //Ditto for the instance(s)
        len = plan.instance.length();
        for(size_t m = 0;
            m < len;
            m++)
          {
            this->xsc_dp_->add_instance (
                                         IDD_Handler::instance_deployment_descr (
                                                                                 plan.instance[m]));
          }

        //Finally, take care of the Connection Planning
        len = plan.connection.length();
        for(size_t n = 0; n < len; n++)
          {
            this->xsc_dp_->add_connection (PCD_Handler::get_PlanConnectionDescription (
                                                                                  plan.connection[n]));
          }

        retval_ = true;
        return true;
      }
    }
  }