summaryrefslogtreecommitdiff
path: root/modules/CIAO/RACE/Input_Adapters/LocationUpdater/PlanUpdater.cpp
blob: 939d015c817260dfe1d9807081251d655ca9b020 (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
/* -*- C++ -*- */

//========================================================================
/*
 *  file  PlanUpdater.cpp
 *
 *  $Id$
 *
 *  This file contains the implementation of the PackageConfiguration
 *  Visitor class PlanUpdater which derives from PCVisitorBase and attempts
 *  to update the location fields in the received DeploymentPlan to reflect
 *  the locations of the implementation artifacts as outlined in the
 *  PackageConfiguration which are downloadable via HTTP. Each Visit
 *  function focuses on the functionality necessary to process the
 *  PackageConfiguration element which is passed to it as an argument
 *  and on dispatching the next sequence of calls in the correct order!
 *
 *  author Stoyan Paunov <spaunov@isis.vanderbilt.edu
 */
//========================================================================

#include "PCVisitorBase.h"
#include "PlanUpdater.h"

#include "ace/OS_Memory.h"         //for ACE_NEW* macros
#include "ace/SString.h"           //for ACE_CString

#include "ciao/DeploymentC.h"
#include "ciao/Deployment_DataC.h"
#include "ciao/Packaging_DataC.h"

#include "Config_Handlers/DnC_Dump.h"

//#include <iostream>
//using namespace std;

  //Constructor
  PlanUpdater::PlanUpdater (Deployment::DeploymentPlan &plan,
                        Deployment::PackageConfiguration &pc)
    : PCVisitorBase (),
      plan_ (plan),
      pc_ (pc),
      status_ (true)
  {
  }

  //entry point for the protected visitor to get it do start
  //the visitation process
  bool PlanUpdater::Visit ()
  {
    Accept (*this, this->pc_);

    return this->status_;

  }

  // A whole slew of overloaded routines for different IDL
  // data types part of the PackageConfiguration.


  void PlanUpdater::Visit (Deployment::PackageConfiguration &pc)
  {
    //visit the ComponentPackageDescription
    if (pc.basePackage.length ())
    {
      //currently no support for that anywhere
      //for (size_t r = 0; r = pc.selectRequirement.length (); ++r);

      Accept (*this, pc.basePackage);
    }
    else
      ACE_DEBUG ((LM_WARNING,
                 "[PlanUpdater - PackageConfiguration] We currently "
                 "do NOT support package references, specializedConfigs",
                 "or imports!\n"));
  }

  //!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!

  //ComponentPackageDescription descendents

  void PlanUpdater::Visit (Deployment::ComponentPackageDescription &cpd)
  {
    //do not need to visit the interface
    //Accept (*this, cpd.realizes);

    //visit the implementations
    Accept (*this, cpd.implementation);
  }


  void PlanUpdater::Visit (Deployment::ComponentInterfaceDescription &cid)
  {
    //Might want to populate this too once PICML starts supporting it
  }


  void PlanUpdater::Visit (Deployment::PackagedComponentImplementation &pci)
  {
    //visit the referencedImplementationArtifact
    Accept (*this, pci.referencedImplementation);
  }


  void PlanUpdater::Visit (Deployment::ComponentImplementationDescription &cid)
  {
    if (cid.assemblyImpl.length ())
       //visit the component assembly
       Accept (*this, cid.assemblyImpl);
    else
       //visit the monolithic component
       Accept (*this, cid.monolithicImpl);
  }


  void PlanUpdater::Visit (Deployment::ComponentAssemblyDescription &cad)
  {
    //visit the SubcomponentInstantiationDescription
    Accept (*this, cad.instance);

    //do not need to visit the connections
    //Accept (*this, cad.connection);
  }


  void PlanUpdater::Visit (Deployment::SubcomponentInstantiationDescription &sid)
  {
    //visit the ComponentPackageDescription (again)
    if (sid.basePackage.length ())
      //visit the base package in the subcomponent
      Accept (*this, sid.basePackage);
    else
      ACE_DEBUG ((LM_WARNING,
                  "[PlanUpdater - SubcomponentInstantiationDescription] ",
                  "We currently do NOT support package references, ",
                  "specializedConfigs or imports!\n"));
  }


  void PlanUpdater::Visit (Deployment::MonolithicImplementationDescription &mid)
  {
    //NOTE: There are usually 3 NamedImplementationArtifacts per
    //MonolithicImplementationDescription *_stub, *_svnt & *_exec

    //visit the NamedImplementationArtifacts
    Accept (*this, mid.primaryArtifact);
  }


  void PlanUpdater::Visit (Deployment::NamedImplementationArtifact &nia)
  {
    //visit the actual ImplementationArtifactDescriptor
    Accept (*this, nia.referencedArtifact);
  }


  //This function attempts to update the location of the artifact deployment
  //descriptions to reflect the once in the RepositoryManager.
  //
  //Not sure what the input is here! I am assuming that the
  //location came from the descriptor files, so it just holds
  //the name of the library. If this code evolves, we will need to
  //update the string matching mechanism with a more complicated one.


  void PlanUpdater::Visit (Deployment::ImplementationArtifactDescription &iad)
  {
    //some heavy lifting here!
    static size_t iters = 0;
    ++iters;
    ACE_CString iad_loc (iad.location[0]);

    size_t add_len = this->plan_.artifact.length ();

    for (size_t i = 0; i < add_len; ++i)
    {
      Deployment::ArtifactDeploymentDescription& add = this->plan_.artifact[i];

      //NOTE: Right now we only populate location[0]
      //When this evolves, check needs to evolve as well.
      ACE_CString add_loc (add.location[0]);

      //check if the add location has already been updated
      if (ACE_OS::strstr (add_loc.c_str (), "http://"))//, add_loc.length ()))
        continue;

      //check for a match and update the location
      if (ACE_OS::strstr (iad_loc.c_str (), add_loc.c_str ()))//, iad_loc.length ()))
      {
        //if there is a match substitute one for the other
        add.location[0] = CORBA::string_dup (iad_loc.c_str ());

        //ACE_OS::printf ("Matching %s with %s\n",
        //                 iad_loc.c_str (),
        //                 add_loc.c_str ());

      }

    }
  }

  //!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!

  //ComponentPackageReference descendents

  void PlanUpdater::Visit (Deployment::ComponentPackageReference &cpr)
  {
    //not implemented
  }

  //!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!

  //properties

  void PlanUpdater::Visit (Deployment::AssemblyPropertyMapping &apm)
  {
    //not needed
  }


  void PlanUpdater::Visit (Deployment::Property &property)
  {
     //not needed
  }


  //requirements & capabilities

  void PlanUpdater::Visit (Deployment::Requirement &requirement)
  {
    //not needed
  }


  void PlanUpdater::Visit (Deployment::Capability &capability)
  {
    //not needed
  }


  void PlanUpdater::Visit (Deployment::ImplementationRequirement &ir)
  {
    //not needed
  }


  void PlanUpdater::Visit (Deployment::ImplementationDependency &id)
  {
    //not needed
  }

  //ports and connections

  void PlanUpdater::Visit (Deployment::AssemblyConnectionDescription &acd)
  {
    //not needed
  }


  void PlanUpdater::Visit (Deployment::SubcomponentPortEndpoint &spe)
  {
    //not needed
  }


  void PlanUpdater::Visit (Deployment::ComponentExternalPortEndpoint &cepe)
  {
    //not needed
  }