summaryrefslogtreecommitdiff
path: root/modules/CIAO/tools/Config_Handlers/DD_Handler.cpp
blob: d6de22ee29ee8b8b1bbf61f200e715353fc12587 (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
// $Id$

#include "Utils/XML_Helper.h"
#include "SatisfierProperty_Handler.h"
#include "DD_Handler.h"
#include "Any_Handler.h"
#include "Deployment.hpp"
#include "ciao/Deployment_TargetDataC.h"
#include "CIAO_common.h"

using namespace std;

namespace CIAO
{
  namespace Config_Handlers
  {
    DD_Handler::DD_Handler (const ACE_TCHAR *file) :
      idl_domain_(0),
      domain_ (0),
      retval_ (false)
    {
      CIAO_TRACE("DP_PCD_Handler::constructor");
      XML_Helper helper;

      if (CIAO::debug_level () > 9)
        {
          ACE_DEBUG ((LM_DEBUG , "inside DD_Handler"));
        }


      XERCES_CPP_NAMESPACE::DOMDocument *dom =
        helper.create_dom (file);

      if (CIAO::debug_level () > 9)
        {
          ACE_DEBUG ((LM_DEBUG , "after create dom"));
        }

      if (!dom)
        throw DD_Handler::NoDomain ();

      Domain *dm =
        new Domain (domain (dom));

      //      Domain d = domain (dom);

      if (CIAO::debug_level () > 9)
        {
          ACE_DEBUG ((LM_DEBUG , "dom"));
        }


      this->domain_.reset (dm);

      if (CIAO::debug_level () > 9)
        {
          ACE_DEBUG ((LM_DEBUG , "after reset"));
        }

      if (!this->build_domain ())
        throw NoDomain ();
    }

    DD_Handler::DD_Handler (Domain *dmn):
      idl_domain_(0),
      domain_(dmn),
      retval_(false)
    {
      CIAO_TRACE("DP_PCD_Handler::constructor - Domain");
      if(!this->build_domain ())
        throw NoDomain ();
    }

    DD_Handler::DD_Handler (::Deployment::Domain *dmn):
      idl_domain_(dmn),
      domain_(0),
      retval_(false)
    {
      if(!this->build_xsc())
        throw NoDomain ();
    }

    DD_Handler::~DD_Handler (void)
    {
    }

    bool
    DD_Handler::build_domain ()
    {
      CIAO_TRACE("DP_PCD_Handler::build_domain");
      this->idl_domain_.reset ( new ::Deployment::Domain );

      // Read in the name
      // Check if the label is there or not
      if (domain_->label_p ())
        this->idl_domain_->label =
          CORBA::string_dup (domain_->label ().c_str ());

      if (domain_->UUID_p ())
        this->idl_domain_->UUID =
          CORBA::string_dup (domain_->UUID ().c_str ());

      CORBA::ULong len = domain_->count_node ();
      this->idl_domain_->node.length (len);

      if (CIAO::debug_level () > 9)
        {
          ACE_DEBUG ((LM_DEBUG , "The node length is [%d]\n",len));
        }

      //Resource _resource;
      int i =0;
      for (Domain::node_const_iterator iter = domain_->begin_node ();
           iter != domain_->end_node ();
           ++iter,++i
           )
        {
          // Node* thisNode = (Node*)iter;
          this->idl_domain_->node[i].name =
            CORBA::string_dup (iter->name ().c_str ());

          if (iter->label_p ())
            this->idl_domain_->node[i].label =
              CORBA::string_dup (iter->label ().c_str ());

          // length is hard-coded for now ...
          // here iterate over the resources ...
          CORBA::ULong res_len = iter->count_resource ();
          this->idl_domain_->node[i].resource.length (res_len);

          int res_id=0;
          // FOR EACH RESOURCE ....
          for (Node::resource_const_iterator res_iter = iter->begin_resource ();
               res_iter != iter->end_resource ();
               res_iter++, res_id++)
            {

              this->idl_domain_->node[i].resource[res_id].name =
                CORBA::string_dup (res_iter->name ().c_str ());

              CORBA::ULong resource_type_len = res_iter->count_resourceType ();
              this->idl_domain_->node[i].resource[res_id].resourceType.length (resource_type_len);

              int res_type_id =0;

              // FOR EACH RESOURCE TYPE
              for (Resource::resourceType_const_iterator res_type_iter =
                     res_iter->begin_resourceType ();
                   res_type_iter != res_iter->end_resourceType ();
                   res_type_iter++, res_type_id++)
                {
                  this->idl_domain_->node[i].resource[res_id].resourceType[res_type_id] =
                    CORBA::string_dup (res_type_iter->c_str ());
                }

              CORBA::ULong property_len = res_iter->count_property ();
              this->idl_domain_->node[i].resource[res_id].property.length (property_len);

              //              int property_id =0;

              std::for_each (res_iter->begin_property (),
                             res_iter->end_property (),
                             SatisfierProperty_Functor (this->idl_domain_->node[i].resource[res_id].property));

              /*
              //FOR EACH PROPERTY
              for (Resource::property_const_iterator property_iter =
              res_iter->begin_property ();
              property_iter != res_iter->end_property ();
              property_iter++, property_id++)
              {
              this->idl_domain_->node[i].resource[res_id].property[property_id ].name =
              CORBA::string_dup (property_iter->name ().c_str ());


              this->idl_domain_->node[i].resource[res_id].property[property_id].kind =
              ::Deployment::Quantity;

              Any the_any = property_iter->value ();
              CORBA::Any a_corba_any;
              Any_Handler::extract_into_any (the_any , a_corba_any);
              this->idl_domain_->node[i].resource[res_id].property[property_id].value
              = a_corba_any;
              }
              */
            }
        }

      return true;

    }

    bool
    DD_Handler::build_xsc ()
    {
      return true;
    }

    ::Deployment::Domain const *
    DD_Handler::domain_idl () const
      throw (DD_Handler::NoDomain)
    {
      if(!this->idl_domain_.get())
        throw NoDomain ();

      //else
      return this->idl_domain_.get();
    }

    ::Deployment::Domain *
    DD_Handler::domain_idl ()
      throw (DD_Handler::NoDomain)
    {
      if(!this->idl_domain_.get())
        throw NoDomain();

      //else
      return this->idl_domain_.release();
    }

    Domain const *
    DD_Handler::domain_xsc () const
      throw (DD_Handler::NoDomain)
    {
      if(!this->domain_.get())
        throw NoDomain ();

      //else
      return this->domain_.get();
    }

    Domain *
    DD_Handler::domain_xsc ()
      throw (DD_Handler::NoDomain)
    {
      if(!this->domain_.get())
        throw NoDomain ();

      //else
      return this->domain_.release();
    }
  }
}