summaryrefslogtreecommitdiff
path: root/modules/CIAO/RACE/Input_Adapters/LocationUpdater/Injector.cpp
blob: 7b22e5199228cc9a3c71ccce8bb393633ab83730 (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
/**
 * @file Injector.cpp
 * @author Will Otte <wotte@dre.vanderbilt.edu>
 *
 * $Id$
 */

#include "Input_Adapters/LocationUpdater/LocationUpdaterC.h"
#include "ace/OS.h"
#include "ace/Get_Opt.h"
#include "ace/SString.h"
#include "orbsvcs/CosNamingC.h"
#include "ace/Auto_Ptr.h"

#include <iostream>
using namespace std;

namespace CIAO
{
  namespace RACE
  {
    namespace Injector
    {
      const char *package_uri = 0;
      const char *plan_uri = 0;
      const char *iia_ior_file = 0;
      const char *iia_name = "RACE::InteractiveInput";

      bool teardown = false;

      static void
      usage (const ACE_TCHAR* program)
      {
  ACE_ERROR ((LM_ERROR,
        ACE_TEXT ("Usage %s\n")
        ACE_TEXT ("-d <Flatten deployment plan URI>\n")
        ACE_TEXT ("-p <Toplevel Package URI>\n")
        ACE_TEXT ("-t <Teardown plan>\n")
        ACE_TEXT ("-k <Interactive_Input_Adaptor IOR, "
                              "use naming service if not present\n"),
                    program));
      }

      static bool
      parse_args (int argc,
      ACE_TCHAR *argv[])
      {
  ACE_Get_Opt get_opt (argc,
           argv,
           ACE_TEXT ("d:p:k:thn:"));
  int c;

  while ((c = get_opt ()) != EOF)
    {
      switch (c)
        {
        case 'd':
    plan_uri = get_opt.opt_arg ();
    break;

        case 'p':
    package_uri = get_opt.opt_arg ();
    break;

        case 'k':
    iia_ior_file = get_opt.opt_arg ();
    break;

              case 't':
                teardown = true;
    break;

              case 'n':
                iia_name = get_opt.opt_arg ();

        case 'h':
        default:
    usage (argv[0]);
    return false;
        }
    }

  return true;
      }

      CORBA::Object_ptr
      fetch_reference_naming (CORBA::ORB_ptr orb,
            const  ACE_CString &name)
      {
  ACE_ERROR ((LM_ERROR, "Resolving via nameservice...\n"));
  using namespace CosNaming;
  // Resolve naming service
  CORBA::Object_var tmp =
    orb->resolve_initial_references ("NameService");

  NamingContext_var pns =
    NamingContext::_narrow (tmp.in ());

        Name ns_name;
  CORBA::ULong i = 0;

        ACE_Tokenizer tok ( 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;
          }


  return pns->resolve (ns_name);
      }

      static int
      run_main_implementation (int argc,  ACE_TCHAR *argv[])
      {
  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv, "");

      if (!parse_args (argc, argv))
        return -1;


      // Resolve our input adapter...
      CORBA::Object_var tmp;

      cout << "resolving: " << iia_ior_file << endl;

      if (iia_ior_file != 0)
        tmp = orb->string_to_object (iia_ior_file);
      else // must be a name....
        tmp = fetch_reference_naming (orb.in (), iia_name);

      CIAO::RACE::LocationUpdater_var iia
        = CIAO::RACE::LocationUpdater::_narrow (tmp.in ());

      // Create deploy input event.
      CIAO::RACE::Deploy_Input_var input =
        new OBV_CIAO::RACE::Deploy_Input;

      input->plan_uri (plan_uri);
      input->package_uri (package_uri);

            if (teardown)
              {
                input->command (::CIAO::RACE::TEARDOWN);
              }
            else
              {
                input->command (::CIAO::RACE::DEPLOY);
              }



      // Get the consumer for the IIA
      ::CIAO::RACE::Deploy_InputConsumer_var consumer =
    iia->get_consumer_deployment ();

      // push the event
      consumer->push_Deploy_Input (input.in ());

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

      return 0;
      }
    }
  }
}

int main (int argc, ACE_TCHAR **argv)
{
  return CIAO::RACE::Injector::run_main_implementation (argc, argv);
}