OpenDDS  Snapshot(2023/04/28-20:55)
DataWriterImpl_T.h
Go to the documentation of this file.
1 /*
2  * Distributed under the OpenDDS License.
3  * See: http://www.opendds.org/license.html
4  */
5 
6 #ifndef OPENDDS_DCPS_DATAWRITERIMPL_T_H
7 #define OPENDDS_DCPS_DATAWRITERIMPL_T_H
8 
9 #include "Sample.h"
10 #include "PublicationInstance.h"
11 #include "DataWriterImpl.h"
12 #include "Util.h"
13 #include "TypeSupportImpl.h"
14 #include "dcps_export.h"
15 #include "SafetyProfileStreams.h"
16 #include "DCPS_Utils.h"
17 
18 #ifdef OPENDDS_SECURITY
19 # include <dds/DdsSecurityCoreC.h>
20 #endif
21 
23 
24 namespace OpenDDS {
25 namespace DCPS {
26 
27 /**
28  * Servant for DataWriter interface of the MessageType data type.
29  *
30  * See the DDS specification, OMG formal/2015-04-10, for a description of
31  * this interface.
32  */
33 template <typename MessageType>
34 class
35 #if ( __GNUC__ == 4 && __GNUC_MINOR__ == 1)
37 #endif
40 , public virtual DataWriterImpl
41 {
42 public:
44  {
45  }
46 
48  {
49  }
50 
51  DDS::InstanceHandle_t register_instance(const MessageType& instance)
52  {
53  return register_instance_w_timestamp(instance, SystemTimePoint::now().to_dds_time());
54  }
55 
57  const MessageType& instance, const DDS::Time_t& timestamp)
58  {
59  const SampleType sample(instance, Sample::KeyOnly);
60  return DataWriterImpl::register_instance_w_timestamp(sample, timestamp);
61  }
62 
63  DDS::ReturnCode_t unregister_instance(const MessageType& instance, DDS::InstanceHandle_t handle)
64  {
65  return unregister_instance_w_timestamp(instance, handle, SystemTimePoint::now().to_dds_time());
66  }
67 
69  const MessageType& instance_data,
70  DDS::InstanceHandle_t instance_handle,
71  const DDS::Time_t& timestamp)
72  {
73  const SampleType sample(instance_data, Sample::KeyOnly);
74  return DataWriterImpl::unregister_instance_w_timestamp(sample, instance_handle, timestamp);
75  }
76 
77  //WARNING: If the handle is non-nil and the instance is not registered
78  // then this operation may cause an access violation.
79  // This lack of safety helps performance.
80  DDS::ReturnCode_t write(const MessageType& instance_data, DDS::InstanceHandle_t handle)
81  {
82  return write_w_timestamp(instance_data, handle, SystemTimePoint::now().to_dds_time());
83  }
84 
85  //WARNING: If the handle is non-nil and the instance is not registered
86  // then this operation may cause an access violation.
87  // This lack of safety helps performance.
89  const MessageType& instance_data,
90  DDS::InstanceHandle_t handle,
91  const DDS::Time_t& source_timestamp)
92  {
93  const SampleType sample(instance_data);
94  return DataWriterImpl::write_w_timestamp(sample, handle, source_timestamp);
95  }
96 
97  DDS::ReturnCode_t dispose(const MessageType& instance_data, DDS::InstanceHandle_t instance_handle)
98  {
99  return dispose_w_timestamp(instance_data, instance_handle, SystemTimePoint::now().to_dds_time());
100  }
101 
103  const MessageType& instance_data,
104  DDS::InstanceHandle_t instance_handle,
105  const DDS::Time_t& source_timestamp)
106  {
107  const SampleType sample(instance_data, Sample::KeyOnly);
108  return DataWriterImpl::dispose_w_timestamp(sample, instance_handle, source_timestamp);
109  }
110 
111  DDS::ReturnCode_t get_key_value(MessageType& key_holder, DDS::InstanceHandle_t handle)
112  {
113  Sample_rch sample;
114  const DDS::ReturnCode_t rc = DataWriterImpl::get_key_value(sample, handle);
115  if (sample) {
116  key_holder = dynamic_rchandle_cast<SampleType>(sample)->data();
117  }
118  return rc;
119  }
120 
121  DDS::InstanceHandle_t lookup_instance(const MessageType& instance_data)
122  {
123  const SampleType sample(instance_data, Sample::KeyOnly);
124  return DataWriterImpl::lookup_instance(sample);
125  }
126 
127 private:
129 
130  // A class, normally provided by an unit test, that needs access to
131  // private methods/members.
132  friend class ::DDS_TEST;
133 };
134 
135 } // namespace DCPS
136 } // namepsace OpenDDS
137 
139 
140 #endif /* OPENDDS_DDS_DCPS_DATAWRITERIMPL_T_H */
DDS::ReturnCode_t get_key_value(Sample_rch &sample, DDS::InstanceHandle_t handle)
DDS::ReturnCode_t dispose(const MessageType &instance_data, DDS::InstanceHandle_t instance_handle)
::DDS::InstanceHandle_t register_instance_w_timestamp(in<%SCOPED%> instance, in ::DDS::Time_t timestamp)
DDS::ReturnCode_t write_w_timestamp(const MessageType &instance_data, DDS::InstanceHandle_t handle, const DDS::Time_t &source_timestamp)
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
DDS::InstanceHandle_t lookup_instance(const Sample &sample)
DDS::InstanceHandle_t register_instance(const MessageType &instance)
static TimePoint_T< SystemClock > now()
Definition: TimePoint_T.inl:41
DDS::InstanceHandle_t lookup_instance(const MessageType &instance_data)
DDS::ReturnCode_t unregister_instance_w_timestamp(const MessageType &instance_data, DDS::InstanceHandle_t instance_handle, const DDS::Time_t &timestamp)
Implements the OpenDDS::DCPS::DataWriterRemote interfaces and DDS::DataWriter interfaces.
DDS::ReturnCode_t get_key_value(MessageType &key_holder, DDS::InstanceHandle_t handle)
DDS::ReturnCode_t unregister_instance(const MessageType &instance, DDS::InstanceHandle_t handle)
::DDS::ReturnCode_t write_w_timestamp(in<%SCOPED%> instance_data, in ::DDS::InstanceHandle_t handle, in ::DDS::Time_t source_timestamp)
DDS::ReturnCode_t dispose_w_timestamp(const Sample &sample, DDS::InstanceHandle_t instance_handle, const DDS::Time_t &source_timestamp)
DDS::InstanceHandle_t register_instance_w_timestamp(const Sample &sample, const DDS::Time_t &timestamp)
DDS::ReturnCode_t dispose_w_timestamp(const MessageType &instance_data, DDS::InstanceHandle_t instance_handle, const DDS::Time_t &source_timestamp)
HANDLE_TYPE_NATIVE InstanceHandle_t
Definition: DdsDcpsCore.idl:51
DDS::ReturnCode_t write_w_timestamp(const Sample &sample, DDS::InstanceHandle_t handle, const DDS::Time_t &source_timestamp)
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
::DDS::ReturnCode_t unregister_instance_w_timestamp(in<%SCOPED%> instance, in ::DDS::InstanceHandle_t handle, in ::DDS::Time_t timestamp)
DDS::ReturnCode_t write(const MessageType &instance_data, DDS::InstanceHandle_t handle)
DDS::InstanceHandle_t register_instance_w_timestamp(const MessageType &instance, const DDS::Time_t &timestamp)
RcHandle< T > dynamic_rchandle_cast(const RcHandle< U > &h)
Definition: RcHandle_T.h:214
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
Sample_T< MessageType > SampleType
DDS::ReturnCode_t unregister_instance_w_timestamp(const Sample &sample, DDS::InstanceHandle_t instance_handle, const DDS::Time_t &timestamp)
::DDS::ReturnCode_t dispose_w_timestamp(in<%SCOPED%> instance_data, in ::DDS::InstanceHandle_t instance_handle, in ::DDS::Time_t source_timestamp)