RefleX
Build DDS Applications in Modern C++ without IDL
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
generic_dw.h
Go to the documentation of this file.
1 /*********************************************************************************************
2 (c) 2005-2014 Copyright, Real-Time Innovations, Inc. All rights reserved.
3 RTI grants Licensee a license to use, modify, compile, and create derivative works
4 of the Software. Licensee has the right to distribute object form only for use with RTI
5 products. The Software is provided "as is", with no warranty of any type, including
6 any warranty for fitness for any purpose. RTI is under no obligation to maintain or
7 support the Software. RTI shall not be liable for any incidental or consequential
8 damages arising out of the use or inability to use the software.
9 **********************************************************************************************/
10 
11 #ifndef RTIREFLEX_GENERIC_DW_H
12 #define RTIREFLEX_GENERIC_DW_H
13 
14 #include "reflex/safe_typecode.h"
15 #include "reflex/auto_dd.h"
16 #include "reflex/dllexport.h"
17 #include "reflex/reflex_fwd.h"
18 #include "reflex/enable_if.h"
19 #include "reflex/type_manager.h"
20 
21 #include <memory>
22 
23 namespace reflex {
24 
25  namespace detail {
26 
28  std::shared_ptr<DDSDynamicDataWriter> initialize_writer(DDSDomainParticipant *participant,
29  const DDS_DataWriterQos & dwqos,
30  const char * topic_name,
31  const char * type_name,
32  DDSDynamicDataTypeSupport * support,
33  DDSDataWriterListener * listener,
34  DDS_DynamicDataTypeProperty_t props);
35 
36  REFLEX_DLL_EXPORT void dw_deleter(DDSDynamicDataWriter * ddWriter) throw();
37 
38  } // namespace detail
39 
43  namespace pub {
44 
49  template <class T>
51  {
52  TypeManager<T> type_manager_;
53  AutoDynamicData dd_instance_;
54  std::shared_ptr<DDSDynamicDataWriter> safe_datawriter_;
55 
56  public:
57  GenericDataWriter(DDSDomainParticipant *participant,
58  const char * topic_name,
59  const char * type_name = 0,
60  DDS_DynamicDataTypeProperty_t props =
61  DDS_DYNAMIC_DATA_TYPE_PROPERTY_DEFAULT)
62  : type_manager_(props),
63  dd_instance_(type_manager_.get_type_support()),
64  safe_datawriter_(detail::initialize_writer(
65  participant,
66  DDS_DATAWRITER_QOS_DEFAULT,
67  topic_name,
68  type_name,
69  type_manager_.get_type_support(),
70  0, /* listener */
71  props))
72  { }
73 
74  GenericDataWriter(DDSDomainParticipant *participant,
75  DDS_DataWriterQos & dwqos,
76  const char * topic_name,
77  const char * type_name = 0,
78  DDSDataWriterListener * listener = 0,
79  DDS_DynamicDataTypeProperty_t props =
80  DDS_DYNAMIC_DATA_TYPE_PROPERTY_DEFAULT)
81  : type_manager_(props),
82  dd_instance_(type_manager_.get_type_support()),
83  safe_datawriter_(detail::initialize_writer(
84  participant,
85  dwqos,
86  topic_name,
87  type_name,
88  type_manager_.get_type_support(),
89  listener,
90  props))
91  { }
92 
99  DDS_ReturnCode_t write(const T & data,
100  const DDS_InstanceHandle_t& handle = DDS_HANDLE_NIL)
101  {
102  reflex::write_dynamicdata(dd_instance_, data);
103  return safe_datawriter_->write(*dd_instance_.get(), handle);
104  }
105 
112  DDS_ReturnCode_t write_w_params(const T & data, DDS_WriteParams_t & params)
113  {
114  reflex::write_dynamicdata(dd_instance_, data);
115  return safe_datawriter_->write_w_params(*dd_instance_.get(), params);
116  }
117 
121  DDSDynamicDataWriter * underlying()
122  {
123  return safe_datawriter_.get();
124  }
125 
129  DDSDynamicDataWriter * operator -> () {
130  return underlying();
131  }
132 
136  const DDS_DynamicDataTypeProperty_t & get_properties() const
137  {
138  return type_manager_.get_properties();
139  }
140 
145  {
146  return type_manager_.get_safe_typecode();
147  }
148 
152  const DDS_TypeCode* get_typecode() const
153  {
154  return type_manager_.get_typecode();
155  }
156 
160  const DDSDynamicDataTypeSupport * get_type_support() const
161  {
162  return type_manager_.get_type_support();
163  }
164 
165  };
166 
167  } // namespace pub
168 } // namespace reflex
169 
170 #ifndef REFLEX_NO_HEADER_ONLY
171 #include "reflex/../../src/generic_dw.cxx"
172 #endif
173 
174 #endif // RTIREFLEX_GENERIC_DW_H
const DDS_DynamicDataTypeProperty_t & get_properties() const
Definition: generic_dw.h:136
void write_dynamicdata(DDS_DynamicData &dest, const T &src)
Copies source data into the destination DDS_DynamicData instance.
Definition: reflex.h:157
DDSDynamicDataWriter * operator->()
Return the underlying DDSDynamicDataWriter.
Definition: generic_dw.h:129
DDS_ReturnCode_t write(const T &data, const DDS_InstanceHandle_t &handle=DDS_HANDLE_NIL)
Publish an instance of type T.
Definition: generic_dw.h:99
const SafeTypeCode< T > & get_safe_typecode() const
Definition: generic_dw.h:144
Manage type-specific context, such as typecode, type-support, and dynamic data properties.
Definition: type_manager.h:44
GenericDataWriter(DDSDomainParticipant *participant, DDS_DataWriterQos &dwqos, const char *topic_name, const char *type_name=0, DDSDataWriterListener *listener=0, DDS_DynamicDataTypeProperty_t props=DDS_DYNAMIC_DATA_TYPE_PROPERTY_DEFAULT)
Definition: generic_dw.h:74
DDS_DynamicData * get()
Return the underlying DynamicData instance.
Definition: auto_dd.cxx:98
const DDSDynamicDataTypeSupport * get_type_support() const
Definition: generic_dw.h:160
Automatically manages the memory of a DynamicData instance.
Definition: auto_dd.h:33
DDS_ReturnCode_t write_w_params(const T &data, DDS_WriteParams_t &params)
Publish an instance of type T.
Definition: generic_dw.h:112
#define REFLEX_DLL_EXPORT
Definition: dllexport.h:35
GenericDataWriter(DDSDomainParticipant *participant, const char *topic_name, const char *type_name=0, DDS_DynamicDataTypeProperty_t props=DDS_DYNAMIC_DATA_TYPE_PROPERTY_DEFAULT)
Definition: generic_dw.h:57
A datawriter for adapted aggregate types.
Definition: generic_dw.h:50
DDSDynamicDataWriter * underlying()
Return the underlying DDSDynamicDataWriter.
Definition: generic_dw.h:121
A type-safe, exception-safe wrapper for DDS TypeCode.
Definition: reflex_fwd.h:27
const DDS_TypeCode * get_typecode() const
Definition: generic_dw.h:152