summaryrefslogtreecommitdiff
path: root/CIAO/DAnCE/NodeApplication/NodeApp_Configurator.cpp
blob: 8c1ffda25799efddd2b44dd446958f403120640a (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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
// $Id$

#include "NodeApp_Configurator.h"
#include "ace/Log_Msg.h"

CIAO::NodeApp_Configurator::NodeApp_Configurator (void)
  : rt_support_ (0)
{
}

CIAO::NodeApp_Configurator::~NodeApp_Configurator (void)
{
  // Not much to do.
}

void
CIAO::NodeApp_Configurator::set_rt_support (void)
{
  this->rt_support_ = 1;
}

int
CIAO::NodeApp_Configurator::create_config_managers (void)
{
  typedef CIAO::Config_Manager * (*na_intelligent_designer)(void);
  typedef CIAO::Config_Manager * (*rtna_intelligent_designer)(void);
  CIAO::Config_Manager* ptr = 0;
  CIAO::Config_Manager* rt_ptr = 0;

  int retval = this->config_dll_.open (
                  ACE_DLL_PREFIX ACE_TEXT ("CIAO_NA_Configurator"),
                  ACE_DEFAULT_SHLIB_MODE,
                  0);

  if (0 != retval)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p\n",
                         "dll.open"),
                        0);
    }

  // Cast the void* to non-pointer type first - it's not legal to
  // cast a pointer-to-object directly to a pointer-to-function.
  void *void_ptr =
    this->config_dll_.symbol (ACE_TEXT ("create_na_config_manager"));
  ptrdiff_t tmp = reinterpret_cast<ptrdiff_t> (void_ptr);

  // "id" is for na_intelligent-designer.
  na_intelligent_designer config_id =
    reinterpret_cast<na_intelligent_designer> (tmp);

  if (0 == config_id)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p",
                         "dll.symbol"),
                        0);
    }

  ptr = config_id ();

  if (0 == ptr)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "Error creating NodeApp_Configurator\n"),
                        0);
    }

  this->na_config_manager_.reset (ptr);

  if (this->rt_support_)
    {
      int rt_retval = this->config_dll_.open (
                      ACE_DLL_PREFIX ACE_TEXT ("CIAO_RTNA_Configurator"),
                      ACE_DEFAULT_SHLIB_MODE,
                      0);

      if (0 != rt_retval)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "%p\n",
                             "dll.open"),
                            0);
        }

      // Cast the void* to non-pointer type first - it's not legal to
      // cast a pointer-to-object directly to a pointer-to-function.
      void *rt_void_ptr =
        this->config_dll_.symbol (ACE_TEXT ("create_rt_config_manager"));
      ptrdiff_t rt_tmp = reinterpret_cast<ptrdiff_t> (rt_void_ptr);

      // "id" is for na_intelligent-designer.
      rtna_intelligent_designer rt_config_id =
        reinterpret_cast<rtna_intelligent_designer> (rt_tmp);

      if (0 == rt_config_id)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "%p",
                             "dll.symbol"),
                            0);
        }

      rt_ptr = rt_config_id ();

      if (0 == rt_ptr)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Error creating RTNodeApp_Configurator\n"),
                            0);
        }

      this->rt_config_manager_.reset (rt_ptr);
    }

  return 0;
}

int
CIAO::NodeApp_Configurator::pre_orb_initialize ()
{
  ACE_DEBUG ((LM_DEBUG, "NodeApp_Configurator::pre_orb_init\n"));

  (*this->na_config_manager_.get ()).pre_orb_initialize ();
  if (this->rt_support_)
    {
      (*this->rt_config_manager_.get ()).pre_orb_initialize ();
    }

  return 0;
}

int
CIAO::NodeApp_Configurator::post_orb_initialize (CORBA::ORB_ptr o)
{
  ACE_DEBUG ((LM_DEBUG, "NodeApp_Configurator::post_orb_init\n"));
  this->orb_ = CORBA::ORB::_duplicate (o);

  (*this->na_config_manager_.get ()).init (this->orb_.in ());
  if (this->rt_support_ == 1)
    {
      (*this->rt_config_manager_.get ()).init (this->orb_.in ());
    }

  (*this->na_config_manager_.get ()).post_orb_initialize (this->orb_.in ());
  if (this->rt_support_ == 1)
    {
      (*this->rt_config_manager_.get ()).post_orb_initialize (this->orb_.in ());
    }

  return 0;
}

int
CIAO::NodeApp_Configurator::init_resource_manager
(const ::Deployment::Properties &properties)
{
  for (CORBA::ULong i = 0; i < properties.length (); ++i)
    {
      if (ACE_OS::strcmp (
          "CIAOServerResources", properties[i].name.in ()) == 0)
        {
          const CIAO::DAnCE::ServerResource *svr_resource;
          if (properties[i].value >>= svr_resource)
            {
              (*this->na_config_manager_.get ()).
                      init_resources (*svr_resource);

              if (this->rt_support_ == 1)
                {
                  (*this->rt_config_manager_.get ()).
                      init_resources (*svr_resource);
                }
            }
          else
            {
              ACE_ERROR_RETURN ((LM_ERROR,
                               "ERROR: NodeApp_Configurator::"
                               "init_resource_manager unable to extract"
                               "CIAOServerResources\n"), -1);
            }
        }
    }

  return 0;
}

CORBA::PolicyList *
CIAO::NodeApp_Configurator::find_container_policies
(const ::Deployment::Properties &properties)
{
  CORBA::PolicyList *configured_policies = 0;
  CORBA::PolicyList *rt_configured_policies = 0;

  for (CORBA::ULong i = 0; i < properties.length (); ++i)
    {
      if (ACE_OS::strcmp ("ContainerPolicySet", properties[i].name) == 0)
        {
          const char *policy_name;
          if (properties[i].value >>= policy_name)
            {
              configured_policies = (*this->na_config_manager_.get ()).
                      find_policies_by_name (policy_name);

              CORBA::ULong p_length = 0;
              if (configured_policies != 0)
                {
                  p_length = configured_policies->length ();
                }

              if (this->rt_support_ == 1)
                {
                  rt_configured_policies = (*this->rt_config_manager_.get ()).
                      find_policies_by_name (policy_name);
                }

              CORBA::PolicyList_var temp_policies;
              CORBA::ULong rtp_length = 0;
              if (rt_configured_policies != 0)
                {
                  rtp_length = rt_configured_policies->length ();
                  temp_policies = rt_configured_policies;
                }
              else
                {
                  return configured_policies;
                }

              CORBA::ULong final_length = p_length + rtp_length;
              temp_policies->length (final_length);

              for (CORBA::ULong i = 0; i < p_length; ++i)
                {
                  temp_policies[i+rtp_length] =
                     CORBA::Policy::_duplicate ((*configured_policies)[i]);
                }
              return temp_policies._retn ();
            }
          else
            {
              ACE_ERROR_RETURN ((LM_ERROR,
                                 "ERROR: NodeApp_Configurator:"
                    "find_container_policies unable to extract"
                    "ContainerPolicySet\n"), 0);
            }
        }
    }
  return 0;
}

CORBA::PolicyList *
CIAO::NodeApp_Configurator::find_policies_by_name (const char *policy_name)
{
  CORBA::PolicyList *configured_policies = 0;
  CORBA::PolicyList *rt_configured_policies = 0;

  configured_policies = (*this->na_config_manager_.get ()).
          find_policies_by_name (policy_name);

  CORBA::ULong p_length = 0;
  if (configured_policies != 0)
    {
      p_length = configured_policies->length ();
    }

  if (this->rt_support_ == 1)
    {
      rt_configured_policies = (*this->rt_config_manager_.get ()).
          find_policies_by_name (policy_name);
    }

  CORBA::PolicyList_var temp_policies;
  CORBA::ULong rtp_length = 0;
  if (rt_configured_policies != 0)
    {
      rtp_length = rt_configured_policies->length ();
      temp_policies = rt_configured_policies;
    }
  else
    {
      return configured_policies;
    }

  CORBA::ULong final_length = p_length + rtp_length;
  temp_policies->length (final_length);

  for (CORBA::ULong i = 0; i < p_length; ++i)
    {
      temp_policies[i+rtp_length] =
         CORBA::Policy::_duplicate ((*configured_policies)[i]);
    }
  return temp_policies._retn ();
}

bool
CIAO::NodeApp_Configurator::policy_exists (const char *policy_set_id)
{
  bool result;
  result = (*this->na_config_manager_.get ()).
               policy_exists (policy_set_id);

  if (result == false)
    {
      if (this->rt_support_ == 1)
        {
          result = (*this->rt_config_manager_.get ()).
                         policy_exists (policy_set_id);
        }
    }
  return result;
}