OpenSplice ISO C++ 2 FACE API  v6.x
OpenSplice Future Airborne Capability Environment (FACE) ISO C++ 2 API
DataListener.hpp
Go to the documentation of this file.
1 /*
2  * Vortex OpenSplice
3  *
4  * This software and documentation are Copyright 2006 to 2021 ADLINK
5  * Technology Limited, its affiliated companies and licensors. All rights
6  * reserved.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #ifndef VORTEX_FACE_DATALISTENER_HPP_
22 #define VORTEX_FACE_DATALISTENER_HPP_
23 
24 #include "Vortex_FACE.hpp"
26 
27 namespace Vortex {
28 namespace FACE {
29 
30 template <typename TYPE>
31 class DataListener : public virtual dds::sub::NoOpDataReaderListener<TYPE>
32 {
33 public:
35 
36  DataListener(const std::string &tn,
37  const std::string &cn,
38  typename ::FACE::Read_Callback<TYPE>::send_event cb) :
39  typeName(tn),
40  connectionName(cn),
41  transactionId(0),
42  callback(cb)
43  {
44  }
45 
46  virtual ~DataListener() {}
47 
48 protected:
49  virtual void on_data_available (dds::sub::DataReader<TYPE>& reader)
50  {
52  try {
53  typename dds::sub::LoanedSamples<TYPE> samples = reader.take();
54  typename dds::sub::LoanedSamples<TYPE>::const_iterator sample;
55  for (sample = samples.begin(); sample != samples.end(); ++sample) {
56  TYPE data = sample->data();
57  const dds::sub::SampleInfo& info = sample->info();
58  if (info.valid()) {
59  this->callback(transactionId++,
60  data,
61  0,
62  0,
63  dummyMask,
64  status);
65  if (status != ::FACE::NO_ERROR) {
66  FACE_REPORT_ERROR(status, "This was returned by the callback for '%s'<%s> (we can not handle that).", this->connectionName.c_str(), this->typeName.c_str());
67  }
68  }
69  }
70  } catch (const dds::core::Exception& e) {
72  } catch (...) {
73  FACE_REPORT_ERROR(::FACE::NO_ACTION, "Data take for '%s'<%s> callback", this->connectionName.c_str(), this->typeName.c_str());
74  assert(false);
75  }
76  }
77 
78 private:
79  std::string typeName;
80  std::string connectionName;
81  ::FACE::WAITSET_TYPE dummyMask;
82  ::FACE::TRANSACTION_ID_TYPE transactionId;
83  typename ::FACE::Read_Callback<TYPE>::send_event callback;
84 };
85 
86 }; /* namespace FACE */
87 }; /* namespace Vortex */
88 
89 
90 #endif /* VORTEX_FACE_DATALISTENER_HPP_ */
Vortex::FACE::smart_ptr_traits< DataListener< TYPE > >::shared_ptr shared_ptr
RETURN_CODE_TYPE
Definition: FACE_common.h:54
#define FACE_REPORT_ERROR(code,...)
DataListener(const std::string &tn, const std::string &cn, typename ::FACE::Read_Callback< TYPE >::send_event cb)
int64_t TRANSACTION_ID_TYPE
VORTEX_FACE_API ::FACE::RETURN_CODE_TYPE exceptionToReturnCode(const dds::core::Exception &e)
dds::core::array< bool, 32 > WAITSET_TYPE