summaryrefslogtreecommitdiff
path: root/CIAO/connectors/dds4ccm/impl/PortStatusListener.cpp
blob: 66c8808f0629f437d5a13155b8ea6810fd76cae0 (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
#include "dds4ccm/impl/PortStatusListener.h"
#include "dds4ccm/impl/Utils.h"
#include "dds4ccm/impl/logger/Log_Macros.h"
#include "dds4ccm/impl/DDSCallbackStatusHandler.h"
#include "tao/ORB_Core.h"
#include "ace/Reactor.h"

namespace CIAO
{
  namespace DDS4CCM
  {
    PortStatusListener::PortStatusListener (
        ::CCM_DDS::PortStatusListener_ptr port_status_listener,
         ACE_Reactor* reactor)
    : port_status_listener_ (::CCM_DDS::PortStatusListener::_duplicate (port_status_listener)),
      reactor_ (reactor)
    {
      DDS4CCM_TRACE ("CIAO::DDS4CCM::PortStatusListener::PortStatusListener");
    }

    PortStatusListener::~PortStatusListener (void)
    {
      DDS4CCM_TRACE ("CIAO::DDS4CCM::PortStatusListener::~PortStatusListener");
    }

    void
    PortStatusListener::on_requested_deadline_missed (
        ::DDS::DataReader_ptr the_reader,
         const ::DDS::RequestedDeadlineMissedStatus & status)
    {
      DDS4CCM_TRACE ("CIAO::DDS4CCM::PortStatusListener::on_requested_deadline_missed");

      DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_DDS_STATUS, (LM_DEBUG, DDS4CCM_INFO
          ACE_TEXT ("PortStatusListener::on_requested_deadline_missed: ")
          ACE_TEXT ("total count <%d> - total change <%d> - ")
          ACE_TEXT ("last instance") DDS_INSTANCE_HANDLE_FORMAT_SPECIFIER
          ACE_TEXT ("\n"),
          status.total_count, status.total_count_change,
          DDS_INSTANCE_HANDLE_LOG (status.last_instance_handle)));

      if (! ::CORBA::is_nil (this->port_status_listener_))
        {
          try
            {
              if (this->reactor_)
                {
                  ::CIAO::DDS4CCM::OnRequestedDeadlineMissedHandler* rh = 0;
                  ACE_NEW (rh,
                      ::CIAO::DDS4CCM::OnRequestedDeadlineMissedHandler (
                            this->port_status_listener_.in (), the_reader, status));
                  ACE_Event_Handler_var safe_handler (rh);
                  if (this->reactor_->notify (rh) != 0)
                    {
                      DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                          ACE_TEXT ("PortStatusListener::on_requested_deadline_missed: ")
                          ACE_TEXT ("failed to use reactor.\n")));
                    }
                }
              else
                {
                  this->port_status_listener_->on_requested_deadline_missed (the_reader, status);
                }
            }
          catch (const ::CORBA::BAD_INV_ORDER& ex)
            {
              DDS4CCM_PRINT_DEBUG_CORBA_EXCEPTION (
                                      DDS4CCM_LOG_LEVEL_ACTION,
                                      ex,
                                      "PortStatusListener::on_requested_deadline_missed");
            }
          catch (const ::CORBA::Exception& ex)
            {
              DDS4CCM_PRINT_CORBA_EXCEPTION (
                  DDS4CCM_LOG_LEVEL_ERROR,
                  ex,
                  "PortStatusListener::on_requested_deadline_missed");
            }
          catch (...)
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                  "PortStatusListener::on_requested_deadline_missed - "
                  "Unexpected exception caught\n"));
            }
        }
      else
        {
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
              ACE_TEXT ("PortStatusListener::on_requested_deadline_missed: ")
          ACE_TEXT ("No portstatus listener installed\n")));
        }
    }

    void
    PortStatusListener::on_sample_lost (
        ::DDS::DataReader_ptr the_reader,
         const ::DDS::SampleLostStatus & status)
    {
      DDS4CCM_TRACE ("CIAO::DDS4CCM::PortStatusListener::on_sample_lost");

      DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_DDS_STATUS, (LM_DEBUG, DDS4CCM_INFO
          ACE_TEXT ("PortStatusListener::on_sample_lost: ")
      ACE_TEXT ("total count <%d> - total change <%d>\n"),
      status.total_count, status.total_count_change));

      if (! ::CORBA::is_nil (this->port_status_listener_.in ()))
        {
          try
            {
              if (this->reactor_)
                {
                  ::CIAO::DDS4CCM::OnSampleLostHandler* rh = 0;
                  ACE_NEW (rh,
                      ::CIAO::DDS4CCM::OnSampleLostHandler (
                          this->port_status_listener_.in (),
                          the_reader,
                          status));
                  ACE_Event_Handler_var safe_handler (rh);
                  if (this->reactor_->notify (rh) != 0)
                    {
                      DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                          ACE_TEXT ("PortStatusListener::on_sample_lost: ")
                      ACE_TEXT ("failed to use reactor.\n")));
                    }
                }
              else
                {
                  this->port_status_listener_->on_sample_lost (the_reader, status);
                }
            }
          catch (const ::CORBA::BAD_INV_ORDER& ex)
            {
              DDS4CCM_PRINT_DEBUG_CORBA_EXCEPTION (
                                      DDS4CCM_LOG_LEVEL_ACTION,
                                      ex,
                                      "PortStatusListener::on_sample_lost");
            }
          catch (const ::CORBA::Exception& ex)
            {
              DDS4CCM_PRINT_CORBA_EXCEPTION (
                  DDS4CCM_LOG_LEVEL_ERROR,
                  ex,
                  "PortStatusListener::on_sample_lost");
            }
          catch (...)
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                  "PortStatusListener::on_sample_lost - "
                  "Unexpected exception caught\n"));
            }
        }
      else
        {
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG,
              ACE_TEXT ("PortStatusListener::on_sample_lost: ")
              ACE_TEXT ("No portstatus listener installed\n")));
        }
    }

    void
    PortStatusListener::on_requested_incompatible_qos (
        ::DDS::DataReader_ptr ,
         const ::DDS::RequestedIncompatibleQosStatus & )
    {
      DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
          "PortStatusListener::on_requested_incompatible_qos - "
          "Unexpected callback occurred\n"));
    }

    void
    PortStatusListener::on_sample_rejected (
        ::DDS::DataReader_ptr ,
         const ::DDS::SampleRejectedStatus & )
    {
      DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
          "PortStatusListener::on_sample_rejected - "
          "Unexpected callback occurred\n"));
    }

    void
    PortStatusListener::on_liveliness_changed (
        ::DDS::DataReader_ptr ,
         const ::DDS::LivelinessChangedStatus & )
    {
      DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
          "PortStatusListener::on_liveliness_changed - "
          "Unexpected callback occurred\n"));
    }

    void
    PortStatusListener::on_data_available (::DDS::DataReader_ptr )
    {
      DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
          "PortStatusListener::on_data_available - "
          "Unexpected callback occurred\n"));
    }

    void
    PortStatusListener::on_subscription_matched (
        ::DDS::DataReader_ptr ,
         const ::DDS::SubscriptionMatchedStatus & )
    {
      DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
          "PortStatusListener::on_subscription_matched - "
          "Unexpected callback occurred\n"));
    }

    ::DDS::StatusMask
    PortStatusListener::get_mask (
         ::CCM_DDS::PortStatusListener_ptr psl)
    {
      DDS4CCM_TRACE ("CIAO::DDS4CCM::PortStatusListener::get_mask");

      ::DDS::StatusMask mask = 0;
      if (! ::CORBA::is_nil (psl) ||
          DDS4CCM_debug_level >= DDS4CCM_LOG_LEVEL_DDS_STATUS)
        {
          mask = ::DDS::REQUESTED_DEADLINE_MISSED_STATUS |
                 ::DDS::SAMPLE_LOST_STATUS;
        }

      if (DDS4CCM_debug_level >= DDS4CCM_LOG_LEVEL_DDS_STATUS)
        {
          ACE_CString msk;
          translate_statusmask (msk, mask);
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_DDS_STATUS, (LM_DEBUG, DDS4CCM_INFO
              "PortStatusListener::get_mask - "
              "Mask becomes %C\n",
              msk.c_str ()));
        }
      return mask;
    }
  }
}