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
|
// $Id$
#include "dds4ccm/impl/Utils.h"
#include "dds4ccm/impl/logger/Log_Macros.h"
#include "ace/Reactor.h"
namespace CIAO
{
namespace DDS4CCM
{
template <typename CCM_TYPE, typename TYPED_DDS_READER, typename SEQ_TYPE, DDS4CCM_LISTENER_READ_TAKE LRT>
DataReaderListenerBase_T<CCM_TYPE, TYPED_DDS_READER, SEQ_TYPE, LRT>::DataReaderListenerBase_T (
typename CCM_TYPE::data_listener_type::_ptr_type listener,
::CCM_DDS::PortStatusListener_ptr port_status_listener,
::CCM_DDS::DataListenerControl_ptr control,
ACE_Reactor * reactor,
ConditionManager& condition_manager)
: PortStatusListener (port_status_listener, reactor) ,
listener_ (CCM_TYPE::data_listener_type::_duplicate (listener)),
control_ (::CCM_DDS::DataListenerControl::_duplicate (control)),
condition_manager_ (condition_manager)
{
DDS4CCM_TRACE ("DataReaderListenerBase_T::DataReaderListenerBase_T");
}
template <typename CCM_TYPE, typename TYPED_DDS_READER, typename SEQ_TYPE, DDS4CCM_LISTENER_READ_TAKE LRT>
DataReaderListenerBase_T<CCM_TYPE, TYPED_DDS_READER, SEQ_TYPE, LRT>::~DataReaderListenerBase_T (void)
{
DDS4CCM_TRACE ("DataReaderListenerBase_T::~DataReaderListenerBase_T");
}
template <typename CCM_TYPE, typename TYPED_DDS_READER, typename SEQ_TYPE, DDS4CCM_LISTENER_READ_TAKE LRT>
void
DataReaderListenerBase_T<CCM_TYPE, TYPED_DDS_READER, SEQ_TYPE, LRT>::on_data_available (
::DDS::DataReader_ptr rdr)
{
DDS4CCM_TRACE ("DataReaderListenerBase_T::on_data_available");
if (!::CORBA::is_nil (rdr) &&
this->control_->mode () != ::CCM_DDS::NOT_ENABLED)
{
if (this->reactor_)
{
DataReaderHandler_type * rh = 0;
ACE_NEW (rh, DataReaderHandler_type (this, rdr));
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 ("DataReaderListener_T::on_data_available - ")
ACE_TEXT ("failed to use reactor.\n")));
}
}
else
{
this->on_data_available_i (rdr);
}
}
}
template <typename CCM_TYPE, typename TYPED_DDS_READER, typename SEQ_TYPE>
::DDS::ReturnCode_t
DataReaderListener_T<CCM_TYPE, TYPED_DDS_READER, SEQ_TYPE, CIAO::DDS4CCM::DDS4CCM_TAKE>::get_data_i (
typename TYPED_DDS_READER::_ptr_type reader,
::DDS::QueryCondition_ptr qc,
SEQ_TYPE &data,
::DDS::SampleInfoSeq &sample_info,
::CORBA::Long max_samples)
{
DDS4CCM_TRACE ("DataReaderListener_T::get_data_i");
::DDS::ReturnCode_t result = ::DDS::RETCODE_OK;
if (! ::CORBA::is_nil (qc))
{
::DDS::ReadCondition_var rd = ::DDS::ReadCondition::_narrow (qc);
result = reader->take_w_condition (data,
sample_info,
max_samples,
rd.in ());
}
else
{
result = reader->take (data,
sample_info,
max_samples,
::DDS::NOT_READ_SAMPLE_STATE,
::DDS::NEW_VIEW_STATE | ::DDS::NOT_NEW_VIEW_STATE,
::DDS::ANY_INSTANCE_STATE);
}
return result;
}
template <typename CCM_TYPE, typename TYPED_DDS_READER, typename SEQ_TYPE>
::DDS::ReturnCode_t
DataReaderListener_T<CCM_TYPE, TYPED_DDS_READER, SEQ_TYPE, CIAO::DDS4CCM::DDS4CCM_READ>::get_data_i (
typename TYPED_DDS_READER::_ptr_type reader,
::DDS::QueryCondition_ptr qc,
SEQ_TYPE &data,
::DDS::SampleInfoSeq &sample_info,
::CORBA::Long max_samples)
{
DDS4CCM_TRACE ("DataReaderListener_T::get_data_i");
::DDS::ReturnCode_t result = ::DDS::RETCODE_OK;
if (! ::CORBA::is_nil (qc))
{
::DDS::ReadCondition_var rd = ::DDS::ReadCondition::_narrow (qc);
result = reader->read_w_condition (data,
sample_info,
max_samples,
rd.in ());
}
else
{
result = reader->read (data,
sample_info,
max_samples,
::DDS::NOT_READ_SAMPLE_STATE,
::DDS::NEW_VIEW_STATE | ::DDS::NOT_NEW_VIEW_STATE,
::DDS::ANY_INSTANCE_STATE);
}
return result;
}
template <typename CCM_TYPE, typename TYPED_DDS_READER, typename SEQ_TYPE, DDS4CCM_LISTENER_READ_TAKE LRT>
void
DataReaderListenerBase_T<CCM_TYPE, TYPED_DDS_READER, SEQ_TYPE, LRT>::on_data_available_i (
::DDS::DataReader_ptr rdr)
{
DDS4CCM_TRACE ("DataReaderListenerBase_T::on_data_available_i");
if (::CORBA::is_nil (rdr))
{
DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
ACE_TEXT ("DataReaderListenerBase_T::on_data_available_i - ")
ACE_TEXT ("No datareader received.\n")));
return;
}
::CCM_DDS::ListenerMode const mode = this->control_->mode ();
if (mode == ::CCM_DDS::NOT_ENABLED)
{
return;
}
typename TYPED_DDS_READER::_var_type reader;
reader = TYPED_DDS_READER::_narrow (rdr);
if (::CORBA::is_nil (reader.in ()))
{
DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
ACE_TEXT ("DataReaderListenerBase_T::on_data_available_i - ")
ACE_TEXT ("Failed to narrow DataReader to a type ")
ACE_TEXT ("specific DataReader.\n")));
return;
}
try
{
SEQ_TYPE data;
::DDS::SampleInfoSeq sample_info;
::CORBA::Long max_samples = 0;
mode == ::CCM_DDS::ONE_BY_ONE
? max_samples = ::DDS::LENGTH_UNLIMITED
: this->control_->max_delivered_data() == 0
? max_samples = ::DDS::LENGTH_UNLIMITED
: max_samples = this->control_->max_delivered_data ();
::DDS::QueryCondition_var qc =
this->condition_manager_.get_querycondition_listener ();
::DDS::ReturnCode_t const result =
this->get_data_i (reader, qc.in (), data, sample_info, max_samples);
DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_DDS_STATUS, (LM_INFO, DDS4CCM_INFO
ACE_TEXT ("DataReaderListenerBase_T::on_data_available_i - ")
ACE_TEXT ("Get data returned %C.\n"),
translate_retcode (result)));
if (result == ::DDS::RETCODE_OK)
{
if (mode == ::CCM_DDS::ONE_BY_ONE)
{
for (::CORBA::ULong i = 0; i < data.length (); ++i)
{
if (sample_info[i].valid_data)
{
::CCM_DDS::ReadInfo info;
info <<= sample_info[i];
this->listener_->on_one_data (data[i], info);
}
}
}
else
{
CORBA::ULong nr_of_samples = 0;
for (::CORBA::ULong i = 0 ; i < sample_info.length(); i++)
{
if (sample_info[i].valid_data)
{
++nr_of_samples;
}
}
if (nr_of_samples > 0)
{
SEQ_TYPE inst_seq (nr_of_samples);
::CCM_DDS::ReadInfoSeq infoseq (nr_of_samples);
infoseq.length (nr_of_samples);
inst_seq.length (nr_of_samples);
// Copy the valid samples
CORBA::ULong ix = 0;
for (::CORBA::ULong i = 0 ; i < sample_info.length(); i++)
{
if(sample_info[i].valid_data)
{
infoseq[ix] <<= sample_info[i];
inst_seq[ix] = data[i];
++ix;
}
}
this->listener_->on_many_data (inst_seq, infoseq);
}
}
}
// Return the loan
DDS::ReturnCode_t const retval = reader->return_loan (data, sample_info);
if (retval != ::DDS::RETCODE_OK)
{
DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
ACE_TEXT ("DataReaderListenerBase_T::on_data_available_i - ")
ACE_TEXT ("Error returning loan to DDS - <%C>\n"),
translate_retcode (retval)));
// No exception here since this the DDS vendor doesn't expect this.
// It will likely causes a crash in their implementation
}
}
catch (const ::CORBA::BAD_INV_ORDER& ex)
{
DDS4CCM_PRINT_DEBUG_CORBA_EXCEPTION (
DDS4CCM_LOG_LEVEL_ACTION,
ex,
"DataReaderListenerBase_T::on_data_available_i");
}
catch (const ::CORBA::Exception& ex)
{
DDS4CCM_PRINT_CORBA_EXCEPTION (
DDS4CCM_LOG_LEVEL_ERROR,
ex,
"DataReaderListenerBase_T::on_data_available_i");
}
catch (...)
{
DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
ACE_TEXT ("DataReaderListener_T::on_data_available_i - ")
ACE_TEXT ("Unexpected exception caught\n")));
}
}
template <typename CCM_TYPE, typename TYPED_DDS_READER, typename SEQ_TYPE, DDS4CCM_LISTENER_READ_TAKE LRT>
::DDS::StatusMask
DataReaderListenerBase_T<CCM_TYPE, TYPED_DDS_READER, SEQ_TYPE, LRT>::get_mask (
typename CCM_TYPE::data_listener_type::_ptr_type listener,
::CCM_DDS::PortStatusListener_ptr status)
{
DDS4CCM_TRACE ("DataReaderListenerBase_T::get_mask");
::DDS::StatusMask mask = 0;
if (! ::CORBA::is_nil (listener) ||
DDS4CCM_debug_level >= DDS4CCM_LOG_LEVEL_DDS_STATUS)
{
mask = ::DDS::DATA_AVAILABLE_STATUS;
mask |= ::CIAO::DDS4CCM::PortStatusListener::get_mask (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
"DataReaderListenerBase_T::get_mask - "
"Mask becomes %C\n",
msk.c_str ()));
}
return mask;
}
}
}
|