summaryrefslogtreecommitdiff
path: root/CIAO/connectors/dds4ccm/impl/ndds/DomainParticipantFactory.cpp
blob: dc22ba31724525483b1caffdce7192bf10ba59ea (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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
// $Id$

#include "dds4ccm/impl/ndds/DomainParticipantFactory.h"
#include "dds4ccm/impl/ndds/DomainParticipant.h"
#include "dds4ccm/impl/ndds/DomainParticipantListener.h"
#include "dds4ccm/impl/ndds/convertors/DomainParticipantFactoryQos.h"
#include "dds4ccm/impl/ndds/convertors/DomainParticipantQos.h"
#include "dds4ccm/impl/ndds/Utils.h"
#include "dds4ccm/impl/Utils.h"
#include "dds4ccm/impl/logger/Log_Macros.h"
#include "dds4ccm/impl/ndds/DomainParticipantManager.h"

namespace CIAO
{
  namespace NDDS
  {
    DDS_DomainParticipantFactory_i::DDS_DomainParticipantFactory_i (void)
    {
      DDS4CCM_TRACE ("DDS_DomainParticipantFactory_i::DDS_DomainParticipantFactory_i");
    }

    DDS_DomainParticipantFactory_i::~DDS_DomainParticipantFactory_i (void)
    {
      DDS4CCM_TRACE ("DDS_DomainParticipantFactory_i::~DDS_DomainParticipantFactory_i");
    }

    ::DDS::DomainParticipant_ptr
    DDS_DomainParticipantFactory_i::create_participant (::DDS::DomainId_t domain_id,
                                                        const ::DDS::DomainParticipantQos & qos,
                                                        ::DDS::DomainParticipantListener_ptr a_listener,
                                                        ::DDS::StatusMask mask)
    {
      DDS4CCM_TRACE ("DDS_DomainParticipantFactory_i::create_participant");

      DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION_STARTING, (LM_TRACE, DDS4CCM_INFO
                    "DDS_DomainParticipantFactory_i::create_participant - "
                    "Start creating domain participant for domain <%d>\n",
                    domain_id));

      DDS_DomainParticipantListener_i *ccm_dds_dpl = 0;
      if (! ::CORBA::is_nil (a_listener))
        {
          ACE_NEW_THROW_EX (ccm_dds_dpl,
                            DDS_DomainParticipantListener_i (a_listener),
                            ::CORBA::NO_MEMORY ());
        }

      ACE_CString qos_profile = "default";

      DDSDomainParticipant *dds_dp =
        DPMANAGER->get_participant (domain_id, qos_profile.c_str ());

      if (!dds_dp)
        {
          DDS_DomainParticipantQos ccm_dds_qos;
          DDS_ReturnCode_t retcode = DDSDomainParticipantFactory::get_instance()->get_default_participant_qos (ccm_dds_qos);
          if (retcode != DDS_RETCODE_OK)
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                          "DDS_DomainParticipantFactory_i"
                          "::create_participant - "
                          "Error: Unable to retrieve default participant qos\n"));
              return ::DDS::DomainParticipant::_nil ();
            }
          ccm_dds_qos <<= qos;
          dds_dp = DDSDomainParticipantFactory::get_instance ()->
                      create_participant (domain_id,
                                          ccm_dds_qos,
                                          ccm_dds_dpl,
                                          mask);

          if (!dds_dp)
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                          "DDS_DomainParticipantFactory_i"
                          "::create_participant - "
                          "Error: Unable to create DomainParticipant for domain <%d>\n",
                          domain_id));
              delete ccm_dds_dpl;
              return ::DDS::DomainParticipant::_nil ();
            }

          ::DDS::DomainParticipant_var retval;
          ACE_NEW_THROW_EX (retval,
                            DDS_DomainParticipant_i (dds_dp),
                            ::CORBA::NO_MEMORY ());
          retcode = dds_dp->enable ();
          if (retcode != DDS_RETCODE_OK)
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                          "DDS_DomainParticipantFactory_i"
                          "::create_participant - "
                          "Error: Unable to enable the domainparticipant "
                          "for domain <%d>: <%C>\n",
                          domain_id,
                          ::CIAO::DDS4CCM::translate_retcode (retcode)));
              delete ccm_dds_dpl;
              throw ::CORBA::INTERNAL ();
            }

          if (ccm_dds_dpl)
            {
              ccm_dds_dpl->set_dds_dp (retval.in ());
            }

          DPMANAGER->add_participant (qos_profile.c_str (), dds_dp);

          return retval._retn ();
        }
      else
        {
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
                        "DDS_DomainParticipantFactory_i::create_participant - Re-using participant "
                        "for QOS profile <%C> and domain <%d>.\n",
                        qos_profile.c_str (),
                        domain_id));
          ::DDS::DomainParticipant_var retval;
          ACE_NEW_THROW_EX (retval,
                            DDS_DomainParticipant_i (dds_dp),
                            ::CORBA::NO_MEMORY ());
          return retval._retn ();
        }
    }


    ::DDS::DomainParticipant_ptr
    DDS_DomainParticipantFactory_i::create_participant_with_profile (
      ::DDS::DomainId_t domain_id,
      const char * qos_profile,
      ::DDS::DomainParticipantListener_ptr a_listener,
      ::DDS::StatusMask mask)
    {
      DDS4CCM_TRACE ("DDS_DomainParticipantFactory_i::"
                     "create_participant_with_profile");

      DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION_STARTING, (LM_TRACE, DDS4CCM_INFO
                    "DDS_DomainParticipantFactory_i::create_participant_with_profile - "
                    "Start creating domain participant: "
                    "profile <%C> - domain <%d>\n",
                    qos_profile, domain_id));
      DDS_DomainParticipantListener_i *ccm_dds_dpl = 0;
      if (! ::CORBA::is_nil (a_listener))
        {
          ACE_NEW_THROW_EX (ccm_dds_dpl,
                            DDS_DomainParticipantListener_i (a_listener),
                            ::CORBA::NO_MEMORY ());
        }

      DDSDomainParticipant *dds_dp =
        DPMANAGER->get_participant (domain_id, qos_profile);

      if (!dds_dp)
        {
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
                        "DDS_DomainParticipantFactory_i::create_participant_with_profile - "
                        "Creating participant: profile <%C> - domain <%d>\n",
                        qos_profile,
                        domain_id));

          char * lib_name = get_library_name(qos_profile);
          char * prof_name = get_profile_name(qos_profile);

          if (lib_name != 0 && prof_name != 0)
            {
              dds_dp = DDSDomainParticipantFactory::get_instance ()->
                                create_participant_with_profile (domain_id,
                                                                lib_name,
                                                                prof_name,
                                                                ccm_dds_dpl,
                                                                mask);
            }

          ACE_OS::free (lib_name);
          ACE_OS::free (prof_name);

          if (!dds_dp)
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                            "DDS_DomainParticipantFactory_i::create_participant_with_profile <%C> - "
                            "Error: Unable to create DomainParticipant for domain <%d>\n",
                            qos_profile,
                            domain_id));
              delete ccm_dds_dpl;
              return ::DDS::DomainParticipant::_nil ();
            }
          ::DDS::DomainParticipant_var retval;
          ACE_NEW_THROW_EX (retval,
                            DDS_DomainParticipant_i (dds_dp),
                            ::CORBA::NO_MEMORY ());
          DDS_ReturnCode_t retcode = dds_dp->enable ();
          if (retcode != DDS_RETCODE_OK)
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                            "DDS_DomainParticipantFactory_i::create_participant_with_profile <%C> - "
                            "Error: Unable to enable DomainParticipant for domain <%d>: <%C>\n",
                            qos_profile,
                            domain_id,
                            ::CIAO::DDS4CCM::translate_retcode (retcode)));
              delete ccm_dds_dpl;
              throw ::CORBA::INTERNAL ();
            }

          if (ccm_dds_dpl)
            {
              ccm_dds_dpl->set_dds_dp (retval.in ());
            }
          DDS_DomainParticipant_i * typed_dp =
            dynamic_cast < DDS_DomainParticipant_i *>
            (retval.in ());

          typed_dp->set_rti_entity (dds_dp);
          DPMANAGER->add_participant (qos_profile, dds_dp);
          return retval._retn ();
        }
      else
        {
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
                        "DDS_DomainParticipantFactory_i::create_participant_with_profile - Re-using "
                        "participant for QOS profile <%C> and domain <%d>.\n",
                        qos_profile,
                        domain_id));
          ::DDS::DomainParticipant_var retval;
          ACE_NEW_THROW_EX (retval,
                            DDS_DomainParticipant_i (dds_dp),
                            ::CORBA::NO_MEMORY ());
          return retval._retn ();
        }
    }

    ::DDS::ReturnCode_t
    DDS_DomainParticipantFactory_i::delete_participant (
      ::DDS::DomainParticipant_ptr a_participant)
    {
      DDS4CCM_TRACE ("DDS_DomainParticipantFactory_i::delete_participant");

      DDS_DomainParticipant_i *part =
        dynamic_cast< DDS_DomainParticipant_i * > (a_participant);

      if (!part)
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_CAST_ERROR, (LM_ERROR, DDS4CCM_INFO
                        "DDS_DomainParticipantFactory_i"
                        "::delete_participant - "
                        "Unable to cast provided object reference to servant "
                        "type, bailing.\n"));
          return DDS::RETCODE_ERROR;
        }

      DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_CAST_SUCCESSFUL, (LM_TRACE, DDS4CCM_INFO
                    "DDS_DomainParticipantFactory_i"
                    "::delete_participant - "
                    "Successfully casted provided object reference to servant type.\n"));

      ::DDS::ReturnCode_t retval = DDS::RETCODE_OK;

      if (DPMANAGER->remove_participant (part->get_rti_entity ()))
        {
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_TRACE, DDS4CCM_INFO
                    "DDS_DomainParticipantFactory_i"
                    "::delete_participant - "
                    "Going to delete participant.\n"));

          retval = DDSDomainParticipantFactory::get_instance ()->
              delete_participant (part->get_rti_entity ());

          if (retval != DDS::RETCODE_OK)
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                            "DDS_DomainParticipantFactory_i"
                            "::delete_participant - "
                            "RTI delete_participant returned non-ok error code %C\n",
                            ::CIAO::DDS4CCM::translate_retcode (retval)));
            }
          else
            {
              DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_INFO, DDS4CCM_INFO
                             "DDS_DomainParticipantFactory_i"
                             "::delete_participant - "
                             "Successfully deleted provided participant.\n"));
            }
        }
      return retval;
    }


    ::DDS::DomainParticipant_ptr
    DDS_DomainParticipantFactory_i::lookup_participant (
      ::DDS::DomainId_t domain_id)
    {
      ::DDS::DomainParticipant_var retval;
      ::DDSDomainParticipant* dp = DDSDomainParticipantFactory::get_instance ()
        ->lookup_participant (domain_id);
       ACE_NEW_THROW_EX (retval,
                         DDS_DomainParticipant_i (dp),
                         ::CORBA::NO_MEMORY ());
      return retval._retn ();
    }


    ::DDS::ReturnCode_t
    DDS_DomainParticipantFactory_i::set_default_participant_qos (
      const ::DDS::DomainParticipantQos & qos)
    {
      DDS4CCM_TRACE ("DDS_DomainParticipantFactory_i::"
        "set_default_participant_qos");
      DDS_DomainParticipantQos ccm_dds_qos;
      DDS_ReturnCode_t const retcode = DDSDomainParticipantFactory::get_instance()->get_default_participant_qos (ccm_dds_qos);
      if (retcode != DDS_RETCODE_OK)
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                      "DDS_DomainParticipantFactory_i"
                      "::set_default_participant_qos - "
                      "Error: Unable to retrieve default participant qos\n"));
          return retcode;
        }
      ccm_dds_qos <<= qos;
      return DDSDomainParticipantFactory::get_instance ()->
        set_default_participant_qos (ccm_dds_qos);
    }


    ::DDS::ReturnCode_t
    DDS_DomainParticipantFactory_i::get_default_participant_qos (
      ::DDS::DomainParticipantQos & qos)
    {
      DDS4CCM_TRACE ("DDS_DomainParticipantFactory_i::"
        "get_default_participant_qos");
      DDS_DomainParticipantQos ccm_dds_qos;
      ::DDS::ReturnCode_t retcode =
        DDSDomainParticipantFactory::get_instance ()->
          get_default_participant_qos (ccm_dds_qos);
      qos <<= ccm_dds_qos;
      return retcode;
    }

    ::DDS::ReturnCode_t
    DDS_DomainParticipantFactory_i::set_qos (
      const ::DDS::DomainParticipantFactoryQos & qos)
    {
      DDS4CCM_TRACE ("DDS_DomainParticipantFactory_i::set_qos");
      DDS_DomainParticipantFactoryQos ccm_dds_qos;
      DDS_ReturnCode_t const retcode = DDSDomainParticipantFactory::get_instance ()->get_qos (ccm_dds_qos);
      if (retcode != DDS_RETCODE_OK)
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                      "DDS_DomainParticipantFactory_i"
                      "::set_qos - "
                      "Error: Unable to retrieve participant factory qos\n"));
          return retcode;
        }
      ccm_dds_qos <<= qos;
      return DDSDomainParticipantFactory::get_instance ()->set_qos (ccm_dds_qos);
    }


    ::DDS::ReturnCode_t
    DDS_DomainParticipantFactory_i::get_qos (
      ::DDS::DomainParticipantFactoryQos & qos)
    {
      DDS4CCM_TRACE ("DDS_DomainParticipantFactory_i::get_qos");
      DDS_DomainParticipantFactoryQos ccm_dds_qos;
      ccm_dds_qos <<= qos;
      ::DDS::ReturnCode_t retcode =
        DDSDomainParticipantFactory::get_instance ()->get_qos (ccm_dds_qos);
      ccm_dds_qos <<= qos;
      return retcode;
    }


    ::DDS::ReturnCode_t
    DDS_DomainParticipantFactory_i::set_default_participant_qos_with_profile (
      const char * qos_profile)
    {
      char * lib_name = get_library_name(qos_profile);
      char * prof_name = get_profile_name(qos_profile);

      ::DDS::ReturnCode_t retcode = ::DDS::RETCODE_ERROR;
      if (lib_name != 0 && prof_name != 0)
        {
          retcode = DDSDomainParticipantFactory::get_instance ()->
            set_default_participant_qos_with_profile (lib_name, prof_name);
        }

      ACE_OS::free (lib_name);
      ACE_OS::free (prof_name);

      return retcode;
    }
  }
}