RTI Routing Service Version 7.6.0
ForwarderUtils.hpp
1/*
2 * (c) Copyright, Real-Time Innovations, 2017.
3 * All rights reserved.
4 *
5 * No duplications, whole or partial, manual or electronic, may be made
6 * without express written permission. Any such copies, or
7 * revisions thereof, must display this notice unaltered.
8 * This code contains trade secrets of Real-Time Innovations, Inc.
9 */
10
11#ifndef RTI_ROUTING_DETAIL_FORWARDER_UTILS_UTILS_HPP_
12#define RTI_ROUTING_DETAIL_FORWARDER_UTILS_UTILS_HPP_
13
14#include <map>
15
16#include <dds/topic/Topic.hpp>
17#include <rti/core/Exception.hpp>
18#include <routingservice/routingservice_infrastructure.h>
19
20namespace rti { namespace routing { namespace detail {
21
22#define RTI_ROUTING_THROW_ON_NULL(pointer) \
23 if ((pointer) == NULL) { \
24 throw dds::core::Error("invalid return of NULL"); \
25 }
26
27#define RTI_ROUTING_THROW_ON_ENV_ERROR(NATIVE_ENV) \
28 if (RTI_RoutingServiceEnvironment_error_occurred((NATIVE_ENV))) { \
29 dds::core::Error rex( \
30 RTI_RoutingServiceEnvironment_get_error_message((NATIVE_ENV))); \
31 RTI_RoutingServiceEnvironment_clear_error((NATIVE_ENV)); \
32 throw rex; \
33 }
34
35#define RTI_ROUTING_SAMPLE_VECTOR_COPY_FROM_NATIVE( \
36 VECTOR, \
37 NATIVE_ARRAY, \
38 ARRAY_LENGTH) \
39 (VECTOR).resize((ARRAY_LENGTH)); \
40 memcpy(&((VECTOR)[0]), \
41 (NATIVE_ARRAY), \
42 sizeof (void*) * (ARRAY_LENGTH));
43
44#define RTI_ROUTING_SAMPLE_VECTOR_COPY_FROM_NATIVE_W_OFFSET( \
45 VECTOR, \
46 NATIVE_ARRAY, \
47 OFFSET, \
48 ARRAY_LENGTH) \
49 (VECTOR).resize((ARRAY_LENGTH) + (OFFSET)); \
50 memcpy(&((VECTOR)[OFFSET]), \
51 (NATIVE_ARRAY), \
52 sizeof (void*) * (ARRAY_LENGTH));
53
54
55#define RTI_ROUTING_SAMPLE_VECTOR_COPY_PTRS( \
56 TO_VECTOR, \
57 FROM_VECTOR) \
58 (TO_VECTOR).resize((FROM_VECTOR).size()); \
59 if ((FROM_VECTOR).size() > 0) { \
60 memcpy( \
61 &(TO_VECTOR[0]), \
62 &(FROM_VECTOR)[0], \
63 sizeof(void*) * (FROM_VECTOR).size()); \
64 }
65
66
67template <typename OwnerType, typename ForwarderType>
68struct ScopedForwarder {
69
70 ScopedForwarder(
71 OwnerType *owner,
72 ForwarderType *forwarder,
73 RTI_RoutingServiceEnvironment *environment)
74 :owner_(owner), forwarder_(forwarder), environment_(environment)
75 {
76 }
77
78 void release()
79 {
80 forwarder_ = NULL;
81 }
82
83 ~ScopedForwarder()
84 {
85 if (forwarder_ != NULL) {
86 ForwarderType::delete_native(
87 owner_,
88 forwarder_->native(),
89 environment_);
90 }
91 }
92
93private:
94
95 OwnerType *owner_;
96 ForwarderType *forwarder_;
97 RTI_RoutingServiceEnvironment *environment_;
98
99};
100
101
102} } }
103
104
105#endif // RTI_ROUTING_DETAIL_FORWARDER_UTILS_UTILS_HPP_