summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/IFRService/IFR_Service_Utils_T.cpp
blob: 07a898a774c256896e026746303c02cb5f095b89 (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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
// $Id$

#ifndef TAO_IFR_SERVICE_UTILS_T_CPP
#define TAO_IFR_SERVICE_UTILS_T_CPP

#include "orbsvcs/IFRService/IFR_Service_Utils_T.h"
#include "orbsvcs/IFRService/IFR_Service_Utils.h"
#include "orbsvcs/IFRService/Repository_i.h"

#include "ace/SString.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

template<typename T>
void
TAO_IFR_Generic_Utils<T>::destroy_special (const char *section_name,
                                           TAO_Repository_i *repo,
                                           ACE_Configuration_Section_Key &key)
{
  ACE_Configuration_Section_Key sub_key;
  int status =
    repo->config ()->open_section (key,
                                   section_name,
                                   0,
                                   sub_key);

  if (status != 0)
    {
      /// Nothing to destroy.
      return;
    }

  CORBA::ULong count = 0;
  repo->config ()->get_integer_value (sub_key,
                                      "count",
                                      count);

  char *stringified = 0;
  ACE_Configuration_Section_Key special_key;
  ACE_TString holder;

  for (CORBA::ULong i = 0; i < count; ++i)
    {
      stringified = TAO_IFR_Service_Utils::int_to_string (i);
      repo->config ()->open_section (sub_key,
                                     stringified,
                                     0,
                                     special_key);
      T impl (repo);
      impl.section_key (special_key);
      impl.destroy_i ();
    }
}

template<typename T>
void
TAO_IFR_Generic_Utils<T>::set_initializers (
    const T &initializers,
    ACE_Configuration *config,
    ACE_Configuration_Section_Key &key
  )
{
  CORBA::ULong length = initializers.length ();

  if (length == 0)
    {
      return;
    }

  ACE_Configuration_Section_Key initializers_key;
  config->open_section (key,
                        "initializers",
                        1,
                        initializers_key);
  config->set_integer_value (initializers_key,
                             "count",
                             length);

  CORBA::ULong arg_count = 0;
  char *arg_path = 0;
  ACE_Configuration_Section_Key initializer_key;
  ACE_Configuration_Section_Key params_key;
  ACE_Configuration_Section_Key arg_key;

  for (CORBA::ULong i = 0; i < length; ++i)
    {
      char *stringified = TAO_IFR_Service_Utils::int_to_string (i);
      config->open_section (initializers_key,
                            stringified,
                            1,
                            initializer_key);
      config->set_string_value (initializer_key,
                                "name",
                                initializers[i].name.in ());

      arg_count = initializers[i].members.length ();

      if (arg_count > 0)
        {
          config->open_section (initializer_key,
                                "params",
                                1,
                                params_key);
          config->set_integer_value (params_key,
                                     "count",
                                     arg_count);

          for (CORBA::ULong j = 0; j < arg_count; ++j)
            {
              char *stringified =
                TAO_IFR_Service_Utils::int_to_string (j);
              config->open_section (params_key,
                                    stringified,
                                    1,
                                    arg_key);
              config->set_string_value (
                  arg_key,
                  "arg_name",
                  initializers[i].members[j].name.in ()
                );
              arg_path =
                TAO_IFR_Service_Utils::reference_to_path (
                    initializers[i].members[j].type_def.in ()
                  );
              config->set_string_value (arg_key,
                                        "arg_path",
                                        arg_path);
            }
        }
    }
}

template<typename T_desc, typename T_impl>
void
TAO_IFR_Desc_Utils<T_desc,T_impl>::fill_desc_begin (
    T_desc &desc,
    TAO_Repository_i *repo,
    ACE_Configuration_Section_Key &key
  )
{
  T_impl impl (repo);
  impl.section_key (key);

  desc.name = impl.name_i ();

  desc.id = impl.id_i ();

  ACE_TString holder;
  repo->config ()->get_string_value (key,
                                     "container_id",
                                     holder);
  desc.defined_in = holder.fast_rep ();

  desc.version = impl.version_i ();
}

template<typename T_strseq>
void
TAO_IFR_Strseq_Utils<T_strseq> ::fill_string_seq (
    const char *section_name,
    ACE_Configuration *config,
    ACE_Configuration_Section_Key &key,
    T_strseq &seq
  )
{
  ACE_Configuration_Section_Key section_key;
  int status = config->open_section (key,
                                     section_name,
                                     0,
                                     section_key);

  if (status != 0)
    {
      seq.length (0);
      return;
    }

  CORBA::ULong count = 0;
  config->get_integer_value (section_key,
                             "count",
                             count);
  seq.length (count);
  char *stringified = 0;
  ACE_TString holder;

  for (CORBA::ULong i = 0; i < count; ++i)
    {
      stringified = TAO_IFR_Service_Utils::int_to_string (i);
      config->get_string_value (section_key,
                                stringified,
                                holder);
      seq[i] = holder.fast_rep ();
    }
}

template<typename T_desc_seq>
void
TAO_Port_Desc_Seq_Utils<T_desc_seq>::port_descriptions (
    T_desc_seq &desc_seq,
    ACE_Configuration *config,
    ACE_Configuration_Section_Key &key,
    const char *sub_section
  )
{
  ACE_Configuration_Section_Key sub_key;
  int status = config->open_section (key,
                                     sub_section,
                                     0,
                                     sub_key);

  if (status != 0)
    {
      desc_seq.length (0);
      return;
    }

  CORBA::ULong count = 0;
  config->get_integer_value (sub_key,
                             "count",
                             count);
  desc_seq.length (count);
  ACE_Configuration_Section_Key desc_key;
  char *stringified = 0;
  ACE_TString holder;

  for (CORBA::ULong i = 0; i < count; ++i)
    {
      stringified = TAO_IFR_Service_Utils::int_to_string (i);
      config->open_section (sub_key,
                            stringified,
                            0,
                            desc_key);

      config->get_string_value (desc_key,
                                "name",
                                holder);
      desc_seq[i].name = holder.c_str ();

      config->get_string_value (desc_key,
                                "id",
                                holder);
      desc_seq[i].id = holder.c_str ();

      /// Seems to me that this field should refer to the component
      /// where the port is defined - NOT where the base type is defined.
      config->get_string_value (key,
                                "id",
                                holder);
      desc_seq[i].defined_in = holder.c_str ();

      config->get_string_value (desc_key,
                                "version",
                                holder);
      desc_seq[i].version = holder.c_str ();

      config->get_string_value (desc_key,
                                "base_type",
                                holder);
      TAO_Port_Desc_Seq_Utils<T_desc_seq>::port_base_type (desc_seq,
                                                           holder,
                                                           i);

      TAO_Port_Desc_Seq_Utils<T_desc_seq>::get_is_multiple (desc_seq,
                                                            config,
                                                            desc_key,
                                                            i);
    }
}

template<typename T_desc_seq>
void
TAO_Port_Desc_Seq_Utils<T_desc_seq>::get_is_multiple (
    T_desc_seq & /* desc_seq */,
    ACE_Configuration * /* config */,
    ACE_Configuration_Section_Key & /* key */,
    CORBA::ULong /* index */
  )
{
  // All types except UsesDescription have no is_multiple member.
}

template<typename T_desc_seq>
void
TAO_Port_Desc_Seq_Utils<T_desc_seq>::port_base_type (T_desc_seq &desc_seq,
                                                     ACE_TString &holder,
                                                     CORBA::ULong index)
{
  desc_seq[index].interface_type = holder.fast_rep ();
}

template<typename T>
T *
TAO_Port_Utils<T>::create_entry (const char *id,
                                 const char *name,
                                 const char *version,
                                 const char *sub_section,
                                 CORBA::Container_ptr port_base_type,
                                 CORBA::Boolean is_multiple,
                                 TAO_Repository_i *repo,
                                 CORBA::DefinitionKind port_kind,
                                 ACE_Configuration_Section_Key &key)
{
  TAO_Container_i::tmp_name_holder (name);
  ACE_Configuration_Section_Key new_key;
  ACE_TString path =
    TAO_IFR_Service_Utils::create_common (CORBA::dk_Component,
                                          port_kind,
                                          key,
                                          new_key,
                                          repo,
                                          id,
                                          name,
                                          &TAO_Container_i::same_as_tmp_name,
                                          version,
                                          sub_section);

  const char *tmp =
    TAO_IFR_Service_Utils::reference_to_path (port_base_type);

  ACE_Configuration_Section_Key base_type_key;
  repo->config ()->expand_path (repo->root_key (),
                                tmp,
                                base_type_key,
                                0);

  ACE_TString holder;
  repo->config ()->get_string_value (base_type_key,
                                     "id",
                                     holder);

  repo->config ()->set_string_value (
                       new_key,
                       "base_type",
                       holder);

  TAO_Port_Utils<T>::set_is_multiple (is_multiple,
                                      repo->config (),
                                      new_key);

  CORBA::Object_var obj =
    TAO_IFR_Service_Utils::path_to_ir_object (path,
                                              repo);

  return T::_narrow (obj.in ());
}

#if defined (__BORLANDC__) && (__BORLANDC__ <= 0x592)
// Borland gives warnings about argument not used on the construct as used
// for the other compilers. This has been reported to Borland, adding
// a workaround to suppress these warnings so that the real important ones
// are not missed.
template<typename T>
void
TAO_Port_Utils<T>::set_is_multiple (CORBA::Boolean is_multiple,
                                    ACE_Configuration * config,
                                    ACE_Configuration_Section_Key &key)
{
  ACE_UNUSED_ARG (is_multiple);
  ACE_UNUSED_ARG (config);
  ACE_UNUSED_ARG (key);
  // Do nothing for everything except UsesDef.
}
#else
template<typename T>
void
TAO_Port_Utils<T>::set_is_multiple (CORBA::Boolean /* is_multiple */,
                                    ACE_Configuration * /* config */,
                                    ACE_Configuration_Section_Key & /* key */)
{
  // Do nothing for everything except UsesDef.
}
#endif

TAO_END_VERSIONED_NAMESPACE_DECL

#endif /* TAO_IFR_SERVICE_UTILS_T_CPP */