summaryrefslogtreecommitdiff
path: root/TAO/CIAO/DAnCE/Config_Handlers/IDD_Handler.cpp
blob: cf94d631bcb60b67d087f1b4199630737e10e15f (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
// $Id$

#include "IDD_Handler.h"
#include "IRDD_Handler.h"
#include "MDD_Handler.h"
#include "Property_Handler.h"
#include "Any_Handler.h"
#include "Basic_Deployment_Data.hpp"
#include "ciao/Deployment_DataC.h"
#include "cdp.hpp"

namespace CIAO
{
  namespace Config_Handlers
  {
    IDREF_Base IDD_Handler::IDREF;
    bool
    IDD_Handler::instance_deployment_descrs (
        const DeploymentPlan &src,
        Deployment::InstanceDeploymentDescriptions& dest)
    {
      DeploymentPlan::instance_const_iterator idd_e =
        src.end_instance ();

      for (DeploymentPlan::instance_const_iterator idd_b =
             src.begin_instance ();
           idd_b != idd_e;
           ++idd_b)
        {
          /* @@ Can you say n^2? */
          CORBA::ULong len =
            dest.length ();
          dest.length (len + 1);

          bool retval =
            IDD_Handler::instance_deployment_descr ((*idd_b),
                                                    dest[len], len);

          if (!retval)
            return false;
        }

      return true;
    }

    bool
    IDD_Handler::instance_deployment_descr (
        const InstanceDeploymentDescription& src,
        Deployment::InstanceDeploymentDescription& dest,
        CORBA::ULong pos)
    {
      dest.name =
        src.name ().c_str ();
      dest.node =
        src.node ().c_str ();

      if (src.id_p ())
        {
          ACE_CString cstr (src.id ().c_str ());
          if (!IDD_Handler::IDREF.bind_ref (cstr, pos))
           {
             return false;
           }
        }
      else
        {
          ACE_DEBUG((LM_ERROR,
                    "(%P|%t) Warning:  IDD %s has no idref \n",
                    src.name ().c_str ()));
        }

      // We know there should be only one element
      dest.source.length (1);
      dest.source [0] =
        src.source ().c_str ();

      // @@ MAJO:This is where the MDD should be? Need to look into
      // this later.
      // ACE_DEBUG ((LM_DEBUG, "string is %s\n", 
      //            src.implementation ().id ().c_str ()));
      size_t tmp = 0;
      bool r = MDD_Handler::IDREF.find_ref 
          (src.implementation ().id ().c_str (), tmp);
      
      ACE_UNUSED_ARG (r);
      
      // @@ MAJO:  What shouold we do if find_ref fails??
      dest.implementationRef = tmp;

      InstanceDeploymentDescription::configProperty_const_iterator pend =
        src.end_configProperty ();

      for (InstanceDeploymentDescription::configProperty_const_iterator pstart =
             src.begin_configProperty ();
           pstart != pend;
           ++pstart)
        {
          // Need to improve this. This is clearly O(n^2).
          CORBA::ULong len =
            dest.configProperty.length ();

          dest.configProperty.length (len + 1);

          Property_Handler::get_property (*pstart,
                                          dest.configProperty[len]);
        }

#if 0 /* MAJO:  Handle this next round */
      InstanceDeploymentDescription::deployedResource_const_iterator drend =
        src.end_deployedResource ();

      for (InstanceDeploymentDescription::deployedResource_const_iterator drstart =
             src.begin_deployedResource ();
           drstart != drend;
           ++drstart)
        {
          const CORBA::ULong len =
            dest.deployedResource.length ();

          dest.deployedResource.length (len + 1);

          IDD_Handler::instance_resource_depl_descr (
            (*drstart),
            dest.deployedResource[len]);

        }

#endif
#if 0
     // @@ MAJO: Need to handle this in the next round
      if (desc.deployedSharedResource_p ())
        {
          CORBA::ULong length = toconfig.deployedSharedResource.length ();
          toconfig.deployedSharedResource.length (length + 1);

          this->get_InstanceResourceDeploymentDescription
            (toconfig.deployedResource[length],
             desc.deployedResource ());
        }
#endif /*if 0*/
      return true;
      // Done!
    }

    void
    IDD_Handler::instance_resource_depl_descr (
        const InstanceResourceDeploymentDescription &src,
        ::Deployment::InstanceResourceDeploymentDescription &dest
        )
    {
      // resourceUsage is an enumerated type
      switch (src.resourceUsage ().integral ())
        {
        case ResourceUsageKind::None_l:
          dest.resourceUsage = Deployment::None;
          break;

        case ResourceUsageKind::InstanceUsesResource_l:
          dest.resourceUsage = Deployment::InstanceUsesResource;
          break;

        case ResourceUsageKind::ResourceUsesInstance_l:
          dest.resourceUsage = Deployment::ResourceUsesInstance;
          break;

        case ResourceUsageKind::PortUsesResource_l:
          dest.resourceUsage = Deployment::PortUsesResource;
          break;

        case ResourceUsageKind::ResourceUsesPort_l:
          dest.resourceUsage = Deployment::ResourceUsesPort;
          break;
        }

      // requirementName and resourceName are strings
      dest.requirementName =
        src.requirementName ().c_str ();

      dest.resourceName =
        src.resourceName ().c_str ();

      Any_Handler::extract_into_any (src.resourceValue (),
                                     dest.resourceValue);

    }

    InstanceDeploymentDescription
    IDD_Handler::instance_deployment_descr (
	const Deployment::InstanceDeploymentDescription& src)
    {
	
	//Get all the string/IDREFs
	XMLSchema::string < char > name ((src.name));
	XMLSchema::string < char > node ((src.node));
	XMLSchema::string < char > source ((src.source[0]));
	ACE_CString temp;
	MDD_Handler::IDREF.find_ref(src.implementationRef, temp);
	XMLSchema::IDREF< ACE_TCHAR > implementation ((temp.c_str()));

	//Instantiate the IDD
	InstanceDeploymentDescription idd (name, node, source, implementation);

	//Get and store the configProperty(s)
	size_t total = src.configProperty.length();
	for(size_t j = 0; j < total; j++)
	{
	    idd.add_configProperty(
		Property_Handler::get_property (
		    src.configProperty[j]));
	}

	//Check if there is a deployedResource, if so store
	if(src.deployedResource.length() != 0)
	    idd.deployedResource(
		IRDD_Handler::instance_resource_deployment_descr(
		    src.deployedResource[0]));

	//Check if there is a deployedSharedResource, if so store it
	if(src.deployedSharedResource.length() != 0)
	    idd. deployedSharedResource(
		IRDD_Handler::instance_resource_deployment_descr(
		    src.deployedSharedResource[0]));

	// @@ LDS: There is no variable id in src, is this correct, does it need to be added?
	// XMLSchema::ID < char > id ((src.id));
	// idd.id(id);

	return idd;
    }	

  }
}