11 #ifndef RTI_ROUTING_PROCESSOR_OUTPUT_HPP_
12 #define RTI_ROUTING_PROCESSOR_OUTPUT_HPP_
14 #include <dds/core/Value.hpp>
15 #include <dds/core/SafeEnumeration.hpp>
16 #include <rti/core/NativeValueType.hpp>
17 #include <dds/pub/DataWriter.hpp>
18 #include <dds/core/xtypes/DynamicData.hpp>
20 #include "routingservice/routingservice_processor.h"
21 #include "routingservice/routingservice_adapter_new.h"
22 #include <rti/routing/adapter/StreamWriter.hpp>
24 namespace rti {
namespace routing {
namespace processor {
28 template <
typename Data,
typename Info>
class TypedOutput;
32 RTI_RoutingServiceStreamWriterExt *native,
33 RTI_RoutingServiceRoute *native_route)
36 *RTI_RoutingServiceRoute_get_output_stream_info(native_route, native));
40 std::string name_from_native_output(
41 RTI_RoutingServiceStreamWriterExt *native,
42 RTI_RoutingServiceRoute *native_route)
44 return RTI_RoutingServiceRoute_get_output_name(
49 template <
typename Data,
typename Info = dds::sub::SampleInfo>
72 RTI_RoutingServiceStreamWriterExt *native,
74 RTI_RoutingServiceRoute *native_route,
75 RTI_RoutingServiceEnvironment *native_env)
78 native_route_(native_route),
79 native_env_(native_env),
80 stream_info_(stream_info_from_native_output(native, native_route)),
81 name_(name_from_native_output(native, native_route))
95 const std::string& name()
const
117 template <
typename Data,
typename Info>
132 template <
typename Data>
148 const std::vector<SamplePtr>& sample_seq,
149 const std::vector<InfoPtr>& info_seq) RTI_FINAL
151 int count = native_->write(
152 native_->stream_writer_data,
157 RTI_ROUTING_THROW_ON_ENV_ERROR(native_env_);
161 virtual void update(
const std::map<std::string, std::string>&) RTI_FINAL
163 throw dds::core::PreconditionNotMetError(
164 "update not applicable within a Processor notification context");
168 RTI_RoutingServiceStreamWriterExt* native()
174 template <
typename Data,
typename Info>
friend class TypedOutput;
176 RTI_RoutingServiceStreamWriterExt *native_;
178 RTI_RoutingServiceRoute *native_route_;
179 RTI_RoutingServiceEnvironment *native_env_;
192 template <
typename Data,
typename Info>
212 const std::string&
name()
const;
225 void write(
const Data& sample,
const Info& info);
235 void write(
const Data& sample);
275 DDS_DataWriter *native_writer = RTI_RoutingServiceRoute_get_dds_writer(
276 output_->native_route_,
278 if (native_writer == NULL) {
279 throw dds::core::InvalidArgumentError(
280 "invalid argument: input does not hold a DDS StreamWriter");
283 typedef dds::pub::DataWriter<Data> data_writer_type;
284 return rti::core::detail::create_from_native_entity<data_writer_type>(
294 template <
typename Data,
typename Info>
295 struct create_data_from_output {
297 static Data
get(TypedOutput<Data, Info>& )
304 template <
typename Info>
305 struct create_data_from_output<dds::core::xtypes::DynamicData, Info> {
307 static dds::core::xtypes::DynamicData
get(TypedOutput<dds::core::xtypes::DynamicData, Info>& output)
309 if (output->stream_info().type_info().type_representation_kind()
310 != TypeRepresentationKind::DYNAMIC_TYPE) {
311 throw dds::core::PreconditionNotMetError(
312 "inconsistent data representation kind");
314 dds::core::xtypes::DynamicType *type_code =
315 static_cast<dds::core::xtypes::DynamicType *
> (
316 output->stream_info().type_info().type_representation());
317 return dds::core::xtypes::DynamicData(*type_code);
322 template <
typename Data,
typename Info>
323 TypedOutput<Data,Info>::TypedOutput(Output* output) : output_(output)
327 template <
typename Data,
typename Info>
330 return output_->stream_info_;
333 template <
typename Data,
typename Info>
336 return output_->name_;
339 template <
typename Data,
typename Info>
345 template <
typename Data,
typename Info>
348 const RTI_RoutingServiceSample out_samples[1] = {
349 const_cast<void *
> (
reinterpret_cast<const void *
> (&sample))
351 const RTI_RoutingServiceSampleInfo out_infos[1] = {
352 const_cast<void *
> (
reinterpret_cast<const void *
> (&info))
354 output_->native_->write(
355 output_->native_->stream_writer_data,
356 reinterpret_cast<const RTI_RoutingServiceSample *> (&out_samples),
357 reinterpret_cast<const RTI_RoutingServiceSample *> (&out_infos),
359 output_->native_env_);
360 RTI_ROUTING_THROW_ON_ENV_ERROR(output_->native_env_);
363 template <
typename Data,
typename Info>
366 const RTI_RoutingServiceSample out_samples[1] = {
367 const_cast<void *
> (
reinterpret_cast<const void *
> (&sample))
369 output_->native_->write(
370 output_->native_->stream_writer_data,
371 reinterpret_cast<const RTI_RoutingServiceSample *> (&out_samples),
374 output_->native_env_);
375 RTI_ROUTING_THROW_ON_ENV_ERROR(output_->native_env_);
378 template <
typename Data,
typename Info>
381 return create_data_from_output<Data, Info>::get(*
this);
393 typedef dds::pub::DataWriter<dds::core::xtypes::DynamicData> DynamicDataWriter;
398 #endif // RTI_ROUTING_PROCESSOR_OUTPUT_HPP_