summaryrefslogtreecommitdiff
path: root/trunk/CIAO/DAnCE/RepositoryManager/PC_Updater.cpp
blob: 1acd3d8c4b92ca99b1c819bc7a471f55733a2d43 (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
// $Id$

#include "ace/Log_Msg.h"
#include "DAnCE/Deployment/Deployment_DataC.h"
#include "PC_Updater.h"
#include "PC_Updater_T.h"
#include "ace/Containers_T.h"        //for ACE_Double_Linked_List

namespace
{
  const size_t TEMP_LEN = 1024;
}

using namespace PC_Updater_T;


  //PATH of glory/gory to update the locations of the IADs
  //
  //PackageConfiguration something;
  //ComponentPackageDescriptions basePackage;
  //PackagedComponentImplementations implementation;
  //ComponentImplementationDescription referencedImplementation;
  //
  //MONOLITHIC Component:
  //MonolithicImplementationDescriptions monolithicImpl;
  //NamedImplementationArtifacts primaryArtifact;
  //ImplementationArtifactDescription referencedArtifact;
  //::CORBA::StringSeq location;
  //
  //ASSEMBLY-BASED Component
  //ComponentAssemblyDescriptions assemblyImpl;
  //SubcomponentInstantiationDescriptions instance;
  //ComponentPackageDescriptions package;
  //...


  /*
   *  PC_Updater Constructors
   */

PC_Updater::PC_Updater (const char* server_path, const char* package)
: server_path_ (server_path),
  file_list_ (),
  package_ (package),
  success_ (true)
{
}


PC_Updater::PC_Updater (ACE_CString& server_path, ACE_CString& package)
: server_path_ (server_path),
  file_list_ (),
  package_ (package),
  success_ (true)
{
}

  /*
   *  PC_Updater - Destructor
   */

PC_Updater::~PC_Updater ()
{
  this->clear_list ();
}


void PC_Updater::clear_list ()
{
  while (!this->file_list_.is_empty ())
  {
    ZIP_File_Info* inf = this->file_list_.delete_head ();

    //deallocate the head of the filename list
    delete inf;
  }
}


  /*
   *  PC_Updater - Object update methods
   */


  // PackageConfiguration

  bool PC_Updater::update (::Deployment::PackageConfiguration &pc)
  {
    //get the list of files in the package and figure out the names of all necessary files
    if (!ZIP_Wrapper::file_list_info (const_cast <char*> (this->package_.c_str ()), this->file_list_))
      return false;

    update_sequence (pc.basePackage, this);

    return this->success_;
  }


  // ComponentInterfaceDescription

  void PC_Updater::update (::Deployment::ComponentInterfaceDescription &)
  {
  }

  // Requirement

  void PC_Updater::update (::Deployment::Requirement &)
  {
  }


  // ComponentExternalPortEndpoint

  void PC_Updater::update (::Deployment::ComponentExternalPortEndpoint &)
  {
  }



  // ImplementationDependency

  void PC_Updater::update (Deployment::ImplementationDependency &)
  {
  }

  // ComponentPackageReference

  void PC_Updater::update (::Deployment::ComponentPackageReference &)
  {
  }

  // SubcomponentInstantiationDescription

  void PC_Updater::update (::Deployment::SubcomponentInstantiationDescription &sid)
  {
    update_sequence (sid.basePackage, this);
  }

  // SubcomponentPortEndpoint

  void PC_Updater::update (::Deployment::SubcomponentPortEndpoint& )
  {
  }

  // AssemblyConnectionDescription

  void PC_Updater::update (::Deployment::AssemblyConnectionDescription &)
  {
  }


  // AssemblyPropertyMapping

  void
  PC_Updater::update (::Deployment::AssemblyPropertyMapping &)
  {
  }

  // ComponentAssemblyDescription

  void PC_Updater::update (::Deployment::ComponentAssemblyDescription& cad)
  {
    update_sequence (cad.instance, this);
  }

  // ImplementationArtifactDescription

  void PC_Updater::update (::Deployment::ImplementationArtifactDescription &iad)
  {
    const char* location = CORBA::string_dup (iad.location[0]);

    //create an iterator
    ACE_Double_Linked_List_Iterator<ZIP_File_Info> iter (this->file_list_);

    //find the correct path and return
    while (!iter.done ())
    {
      const char* full_path = iter.next ()->name_.c_str ();
      //weird. Need to call next to get current ?!?!

      //is it an implementation artifact?
      const char* name = ACE_OS::strstr (full_path, "implementations/");
      if (name)
      {
        //now check if the name matches
        name = ACE_OS::strstr (full_path, iad.location[0]);

        if (name)
        {
          ACE_CString loc (this->server_path_);
          loc += "/implementations/";
          loc += location;

          iad.location[0] = CORBA::string_dup (loc.c_str ());

          //cout << "Location after update: " << iad.location[0] << endl << endl;
          return;
        }
      }
      iter++;
    }

    ACE_ERROR ((LM_ERROR,
               "[PC_Updater::update] Unable to update: %s!\n",
               location));

    this->success_ = false;
  }

  // NamedImplementationArtifact

  void PC_Updater::update (::Deployment::NamedImplementationArtifact &nia)
  {
    update (nia.referencedArtifact);
  }

  // ImplementationRequirement
  void PC_Updater::update (::Deployment::ImplementationRequirement &)
  {
  }

  // MonolithicImplementationDescription
  void PC_Updater::update (::Deployment::MonolithicImplementationDescription &mid)
  {
    update_sequence (mid.primaryArtifact, this);
  }

  // Capability
  void PC_Updater::update (::Deployment::Capability &)
  {
  }

  // ComponentImplementationDescription
  void PC_Updater::update (::Deployment::ComponentImplementationDescription &cid)
  {
    update_sequence (cid.assemblyImpl, this);
    update_sequence (cid.monolithicImpl, this);
  }

  // PackagedComponentImplementation
  void PC_Updater::update (::Deployment::PackagedComponentImplementation &pci)
  {
    PC_Updater::update (pci.referencedImplementation);
  }

  // ComponentPackageDescription
  void PC_Updater::update (::Deployment::ComponentPackageDescription &comppkgdesc)
  {
    update_sequence (comppkgdesc.implementation, this);
  }


  // Property
  void PC_Updater::update (Deployment::Property& )
  {
  }