summaryrefslogtreecommitdiff
path: root/CIAO/connectors/dds4ccm/tests/SharedDomainParticipant/SameDatatype/Component/Component_exec.cpp
blob: 2882814085d520fd912297a5e70729baecef678b (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
// -*- C++ -*-
// $Id$

// Test whether Connector 1,2 and 3 are sharing the same DomainParticipant.
// Connector 4 should have a different DomainParticipant.
// Also test whether Connector 1 and 2 share the same topic.

#include "Component_exec.h"
#include "ciao/Logger/Log_Macros.h"

#include "Base/BaseSupport.h"

#include "dds4ccm/impl/dds/DataWriter.h"

const char * tp_name_conn_1_ = "SharedDP";
const char * tp_name_conn_2_ = "SharedDP";
const char * tp_name_conn_3_ = "SharedDP1";
const char * tp_name_conn_4_ = "StandaloneDP";

namespace CIAO_SharedDP_SharedDPComponent_Impl
{
  //============================================================
  // Component Executor Implementation Class: Component_exec_i
  //============================================================

  Component_exec_i::Component_exec_i (void)
  {
  }

  Component_exec_i::~Component_exec_i (void)
  {
  }

  void
  Component_exec_i::set_session_context (::Components::SessionContext_ptr ctx)
  {
    this->context_ =
      ::SharedDP::CCM_SharedDPComponent_Context::_narrow (ctx);

    if ( ::CORBA::is_nil (this->context_.in ()))
      {
        throw ::CORBA::INTERNAL ();
      }
  }

  void
  Component_exec_i::configuration_complete (void)
  {
  }

  void
  Component_exec_i::ccm_activate (void)
  {
    const DDS_Duration_t dur = { 1, 0 };
    try
      {
        DDS::DataWriter_var dw1 =
          this->context_->get_connection_write1_dds_entity ();
        CIAO::DDS4CCM::CCM_DDS_DataWriter_i *ccm_dds_rd1 =
           dynamic_cast <CIAO::DDS4CCM::CCM_DDS_DataWriter_i *> (dw1.in ());
        DDSDataWriter * dds_dw1 = ccm_dds_rd1->get_impl ();
        DDSPublisher * dds_p1 = dds_dw1->get_publisher ();
        this->dds_dp1_ = dds_p1->get_participant ();
        this->dds_tp1_ = this->dds_dp1_->find_topic (
                                    CORBA::string_dup (tp_name_conn_1_),
                                    dur);
      }
    catch (...)
      {
        ACE_ERROR ((LM_ERROR, "ERROR: Unable to create dds_entity for writer1\n"));
      }

    try
      {
        DDS::DataWriter_var dw2 =
          this->context_->get_connection_write2_dds_entity ();
        CIAO::DDS4CCM::CCM_DDS_DataWriter_i *ccm_dds_rd2 =
           dynamic_cast <CIAO::DDS4CCM::CCM_DDS_DataWriter_i *> (dw2.in ());
        DDSDataWriter * dds_dw2 = ccm_dds_rd2->get_impl ();
        DDSPublisher * dds_p2 = dds_dw2->get_publisher ();
        this->dds_dp2_ = dds_p2->get_participant ();
        this->dds_tp2_ = this->dds_dp2_->find_topic (
                                    CORBA::string_dup (tp_name_conn_2_),
                                    dur);
      }
    catch (...)
      {
        ACE_ERROR ((LM_ERROR, "ERROR: Unable to create dds_entity for writer2\n"));
      }

    try
      {
        DDS::DataWriter_var dw3 =
          this->context_->get_connection_write3_dds_entity ();
        CIAO::DDS4CCM::CCM_DDS_DataWriter_i *ccm_dds_rd3 =
           dynamic_cast <CIAO::DDS4CCM::CCM_DDS_DataWriter_i *> (dw3.in ());
        DDSDataWriter * dds_dw3 = ccm_dds_rd3->get_impl ();
        DDSPublisher * dds_p3 = dds_dw3->get_publisher ();
        this->dds_dp3_ = dds_p3->get_participant ();
        this->dds_tp3_ = this->dds_dp3_->find_topic (
                                    CORBA::string_dup (tp_name_conn_3_),
                                    dur);
      }
    catch (...)
      {
        ACE_ERROR ((LM_ERROR, "ERROR: Unable to create dds_entity for writer3\n"));
      }

    try
      {
        DDS::DataWriter_var dw4 =
          this->context_->get_connection_write4_dds_entity ();
        CIAO::DDS4CCM::CCM_DDS_DataWriter_i *ccm_dds_rd4 =
           dynamic_cast <CIAO::DDS4CCM::CCM_DDS_DataWriter_i *> (dw4.in ());
        DDSDataWriter * dds_dw4 = ccm_dds_rd4->get_impl ();
        DDSPublisher * dds_p4 = dds_dw4->get_publisher ();
        this->dds_dp4_ = dds_p4->get_participant ();
        this->dds_tp4_ = this->dds_dp4_->find_topic (
                                    CORBA::string_dup (tp_name_conn_4_),
                                    dur);
      }
    catch (...)
      {
        ACE_ERROR ((LM_ERROR, "ERROR: Unable to create dds_entity for writer3\n"));
      }
  }

  void
  Component_exec_i::ccm_passivate (void)
  {
    if (!this->dds_dp1_)
      ACE_ERROR ((LM_ERROR, "ERROR: DomainParticipant for Connector 1 seems to be NIL\n"));
    if (!this->dds_dp2_)
      ACE_ERROR ((LM_ERROR, "ERROR: DomainParticipant for Connector 2 seems to be NIL\n"));
    if (!this->dds_dp3_)
      ACE_ERROR ((LM_ERROR, "ERROR: DomainParticipant for Connector 3 seems to be NIL\n"));
    if (!this->dds_dp4_)
      ACE_ERROR ((LM_ERROR, "ERROR: DomainParticipant for Connector 4 seems to be NIL\n"));

    if (!this->dds_tp1_)
      ACE_ERROR ((LM_ERROR, "ERROR: Topic for Connector 1 seems to be NIL\n"));
    if (!this->dds_tp2_)
      ACE_ERROR ((LM_ERROR, "ERROR: Topic for Connector 2 seems to be NIL\n"));
    if (!this->dds_tp3_)
      ACE_ERROR ((LM_ERROR, "ERROR: Topic for Connector 3 seems to be NIL\n"));
    if (!this->dds_tp4_)
      ACE_ERROR ((LM_ERROR, "ERROR: Topic for Connector 4 seems to be NIL\n"));
  }

  void
  Component_exec_i::ccm_remove (void)
  {
    //check shared DomainParticipants
    if (this->dds_dp1_ != this->dds_dp2_)
      {
        ACE_ERROR ((LM_ERROR, "ERROR: Connector 1 and 2 don't seem to "
                              "share the same DomainParticipant\n"));
      }
    else
      {
        ACE_DEBUG ((LM_DEBUG, "Connector 1 and 2 seems to  "
                              "share the same DomainParticipant\n"));
      }
    if (this->dds_dp1_ == this->dds_dp4_)
      {
        ACE_ERROR ((LM_ERROR, "ERROR: Connector 1 and 4 seem to "
                              "share the same DomainParticipant\n"));
      }
    if (this->dds_dp2_ == this->dds_dp4_)
      {
        ACE_ERROR ((LM_ERROR, "ERROR: Connector 2 and 4 seem to "
                              "share the same DomainParticipant\n"));
      }
    if (this->dds_dp3_ == this->dds_dp4_)
      {
        ACE_ERROR ((LM_ERROR, "ERROR: Connector 3 and 4 seem to "
                              "share the same DomainParticipant\n"));
      }

    //check shared Topics
    if (this->dds_tp1_ != this->dds_tp2_)
      {
        ACE_ERROR ((LM_ERROR, "ERROR: Connector 1 and 2 don't seem to "
                              "share the same Topic\n"));
      }
    else
      {
        ACE_DEBUG ((LM_DEBUG, "Connector 1 and 2 seems to  "
                              "share the same Topic\n"));
      }
    if (this->dds_tp1_ == this->dds_tp3_)
      {
        ACE_ERROR ((LM_ERROR, "ERROR: Connector 1 and 3 seem to "
                              "share the same Topic\n"));
      }
    if (this->dds_tp1_ == this->dds_tp4_)
      {
        ACE_ERROR ((LM_ERROR, "ERROR: Connector 1 and 4 seem to "
                              "share the same Topic\n"));
      }
  }

  extern "C" COMPONENT_EXEC_Export ::Components::EnterpriseComponent_ptr
  create_Component_Impl (void)
  {
    ::Components::EnterpriseComponent_ptr retval =
      ::Components::EnterpriseComponent::_nil ();

    ACE_NEW_NORETURN (
      retval,
      Component_exec_i);

    return retval;
  }
}