summaryrefslogtreecommitdiff
path: root/modules/CIAO/RACE/Input_Adapters/PlanGenerator/PlanGenerator_exec.cpp
blob: dd78aafb8b567634a44cec2958ee12d392079ba7 (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
// $Id$
// Author: Stoyan Paunov

#include "PlanGenerator_exec.h"
#include "ciao/CIAO_common.h"
#include "Config_Handlers/XML_File_Intf.h"
#include "Config_Handlers/Package_Handlers/PCD_Handler.h"
#include "Config_Handlers/Common.h"
#include "Config_Handlers/DnC_Dump.h"

#include "DAnCE/RepositoryManager/RepositoryManagerDaemonC.h"
#include "PlanGenerator.h"

#include <iostream>
using namespace std;


namespace CIAO
{
  namespace RACE
  {
    namespace CIDL_PlanGenerator_Impl
    {
      //==================================================================
      // Component Executor Implementation Class:
      // PlanGenerator_exec_i
      //==================================================================

      PlanGenerator_exec_i::PlanGenerator_exec_i (void)
      {
      }

      PlanGenerator_exec_i::~PlanGenerator_exec_i (void)
      {
      }

      // Supported or inherited operations.

      // Attribute operations.

      // Port operations.

      void
      PlanGenerator_exec_i::push_deployment (
        ::CIAO::RACE::Deploy_Input * ev)
      ACE_THROW_SPEC ((CORBA::SystemException))
      {
        try
        {

          //Get the IOR of the RepoMan from the naming service

          //Obtain a ref to the orb
          CORBA::ORB_ptr orb = this->context_->_ciao_the_Container ()->the_ORB ();

          //form the path to the RepoMan IOR file
          ACE_CString RepoMan_ior = ("file://");
          RepoMan_ior += ACE_OS::getenv ("CIAO_ROOT");
          RepoMan_ior += "/DAnCE/RepositoryManager/RepositoryManagerDeamon.ior";

          cout << "RepoMan ior file: " << RepoMan_ior.c_str () << endl;

          CORBA::Object_var obj =
                    orb->string_to_object (RepoMan_ior.c_str ());

          CIAO::RepositoryManagerDaemon_var rm =
                   CIAO::RepositoryManagerDaemon::_narrow (obj.in ());

          if (CORBA::is_nil (rm.in ()))
          {
            ACE_ERROR ((LM_ERROR,
                        "Unable to acquire RepositoryManagerDaemon's objref\n"));

            throw CORBA::INTERNAL ();
          }

          //now obtian the corresponding PackageConfiguration from
          //the RepositoryManager

          Deployment::PackageConfiguration* rmpc;

          try
          {
            //retrieve the curresponding PackageConfiguration
            //from the RepoMan
            rmpc = rm->findPackageByName (ev->package_name ());

            ACE_DEBUG ((LM_INFO,
                       "The package was found!\nUUID: %s\n",
                        rmpc->UUID));
          }
          catch (Deployment::NoSuchName &)
          {
            ACE_ERROR ((LM_ERROR,
                       "Error! Package not found! Location update failed!\n"));

            throw CORBA::INTERNAL ();

          }
          catch (CORBA::Exception &)
          {
            ACE_ERROR ((LM_ERROR,
                       "Error! General exception! Location update failed!\n"));

            throw CORBA::INTERNAL ();
          }

          //now create the plan

          Deployment::DeploymentPlan* plan = 0;
          ACE_NEW_THROW_EX (plan,
                            Deployment::DeploymentPlan (),
                            CORBA::INTERNAL ());

          Plan_Generator pgen (*plan, *rmpc);

          //start the generation
          pgen.Visit ();

          //So now what?
          ::Deployment::DnC_Dump::dump (*plan);

          //do not call the plan analyzer just yet
          return;

          //creat an action sequence and populate it
          ::CIAO::RACE::Plan_Actions plan_action_seq;

           /// Create a Plan_Action_seq structure of length 1.
           plan_action_seq.length (1);

           /// Now populate the Plan_Action_seq structure.
           plan_action_seq [0].command = ev->command ();
           plan_action_seq [0].plan = *plan;
           plan_action_seq [0].package = *rmpc;

           /// Now invoke the plan_analyzer.
           this->context_->get_connection_ingress  ()
               ->analyze_plan (plan_action_seq);
        }
        catch (...)
        {
          ACE_ERROR ((LM_ERROR, "Exception caught in push_deployment\n"));
        }
      }

      // Operations from Components::SessionComponent

      void
      PlanGenerator_exec_i::set_session_context (
        ::Components::SessionContext_ptr ctx)
      ACE_THROW_SPEC ((
                        ::CORBA::SystemException,
                        ::Components::CCMException))
      {
        this->context_ =
        PlanGenerator_Context::_narrow (
          ctx);

        if (this->context_ == 0)
        {
          throw CORBA::INTERNAL ();
        }
      }

      void
      PlanGenerator_exec_i::ciao_preactivate ()
      ACE_THROW_SPEC ((
                        ::CORBA::SystemException,
                        ::Components::CCMException))
      {
        // Your code here.
      }

      void
      PlanGenerator_exec_i::ciao_postactivate ()
      ACE_THROW_SPEC ((
                        ::CORBA::SystemException,
                        ::Components::CCMException))
      {
        // Your code here.
      }

      void
      PlanGenerator_exec_i::ccm_activate ()
      ACE_THROW_SPEC ((
                        ::CORBA::SystemException,
                        ::Components::CCMException))
      {
        // Your code here.
      }

      void
      PlanGenerator_exec_i::ccm_passivate ()
      ACE_THROW_SPEC ((
                        ::CORBA::SystemException,
                        ::Components::CCMException))
      {
        // Your code here.
      }

      void
      PlanGenerator_exec_i::ccm_remove ()
      ACE_THROW_SPEC ((
                        ::CORBA::SystemException,
                        ::Components::CCMException))
      {
        // Your code here.
      }

      //==================================================================
      // Home Executor Implementation Class:   PlanGenerator_Home_exec_i
      //==================================================================

      PlanGenerator_Home_exec_i::PlanGenerator_Home_exec_i (void)
      {
      }

      PlanGenerator_Home_exec_i::~PlanGenerator_Home_exec_i (void)
      {
      }

      // Supported or inherited operations.

      // Home operations.

      // Factory and finder operations.

      // Attribute operations.

      // Implicit operations.

      ::Components::EnterpriseComponent_ptr
      PlanGenerator_Home_exec_i::create ()
      ACE_THROW_SPEC ((
                        ::CORBA::SystemException,
                        ::Components::CCMException))
      {
        ::Components::EnterpriseComponent_ptr retval =
        ::Components::EnterpriseComponent::_nil ();

        ACE_NEW_THROW_EX (
          retval,
          PlanGenerator_exec_i,
          CORBA::NO_MEMORY ());

        return retval;
      }

      extern "C" PLANGENERATOR_EXEC_Export ::Components::HomeExecutorBase_ptr
      create_CIAO_RACE_PlanGenerator_Home_Impl (void)
      {
        ::Components::HomeExecutorBase_ptr retval =
        ::Components::HomeExecutorBase::_nil ();

        ACE_NEW_RETURN (
          retval,
          PlanGenerator_Home_exec_i,
          ::Components::HomeExecutorBase::_nil ());

        return retval;
      }
    }
  }
}