summaryrefslogtreecommitdiff
path: root/SA_POP/Converter.cpp
blob: 02353142f86d0992df9ea02e01ef4256a44fc381 (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
#include "Converter.h"
namespace CIAO
{

  namespace RACE
  {

    Converter::Converter (int argc, char **argv)
      : iia_name_ ("RACE::InteractiveInput"),
        history_ (false)
    {
      try
        {
          this->orb_ = CORBA::ORB_init (argc, argv, "");
          // Resolve naming service
          CORBA::Object_var ns_tmp =
            this->orb_->resolve_initial_references ("NameService");
          ::CosNaming::NamingContext_var ns =
              ::CosNaming::NamingContext::_narrow (ns_tmp.in ());
          ::CosNaming::Name ns_name;
          CORBA::ULong i = 0;
          ACE_Tokenizer tok (this->iia_name_.rep ());
          tok.delimiter_replace (':', 0);
          tok.delimiter_replace ('/', 0);
          char *name_element = 0;
          while ((name_element = tok.next ()) != 0)
            {
              ns_name.length (ns_name.length () + 1);
              ns_name[i].id = CORBA::string_dup (name_element);
              ++i;
            }

          /// now try to resolve the reference to the IIA.
          CORBA::Object_var iia_tmp = ns->resolve (ns_name);
          this->iia_ =
            ::CIAO::RACE::Interactive_Input_Adapter::_narrow (iia_tmp.in ());

          this->plan_gen_.init (this->orb_);

        }
      catch (CORBA::Exception &ex)
        {
          ACE_PRINT_EXCEPTION (ex, "Error in initializing the Injector!\n");
        }

    }

    Converter::~Converter ()
    {}


    int
    Converter::convert (OperationalString &op_string,
                        ::Deployment::DeploymentPlan &plan)
    {
      plan.label = op_string.name;

      plan.UUID = op_string.UUID;

      plan.connection = op_string.dataLinks;

      plan.infoProperty = op_string.properties;

      int position;

      for (CORBA::ULong itr = 0; itr < op_string.instances.length (); ++itr)
        {
          ::CIAO::RACE::InstanceDescription op_instance =
            op_string.instances [itr];
          if (this->plan_gen_.generate_plan
              (plan,
               op_instance.suggestedImpl.in (),
               position))
            {
              ::Deployment::InstanceDeploymentDescription instance;
              instance.name = op_instance.name;
              instance.node = CORBA::string_dup ("Satellite");
              instance.implementationRef = position;
              instance.configProperty = op_instance.configProperty;
              CORBA::ULong cur_len = plan.instance.length ();
              plan.instance.length (cur_len+1);
              plan.instance [cur_len] = instance;

            }
          else
            {
              ACE_ERROR ((LM_ERROR, "Given suggested type is not available "
                          "in the Repoman!!\n Bailing out....\n"));
              return -1;
            }
        }

      return 0;
    }

    int
    Converter::deploy_plan (::Deployment::DeploymentPlan &plan)
    {
      CIAO::RACE::Metadata_var metadata = new OBV_CIAO::RACE::Metadata;

      try
        {

          if (this->history_)
            {
              metadata->command (::CIAO::RACE::TEARDOWN);
              metadata->plan (this->previous_);
              this->iia_->get_consumer_meta_data ()->push_Metadata (metadata.in ());
            }

          metadata->command (::CIAO::RACE::DEPLOY);
          metadata->plan (plan);
          this->iia_->get_consumer_meta_data ()->push_Metadata (metadata.in ());
          this->history_ = true;
          this->previous_ = plan;
        }
      catch (CORBA::Exception &ex)
        {
          ACE_PRINT_EXCEPTION (ex, "Exception caught\n");
          return -1;
        }

      catch (...)
        {
          ACE_ERROR ((LM_ERROR, "(%P|%t) Injector: Unknown exception\n"));
          return -1;
        }

      return 0;
    }

  }
}