RTI Routing Service  Version 6.0.1
 All Data Structures Files Functions Typedefs Enumerations Enumerator Groups Pages
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 
20 namespace 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  memcpy(&(TO_VECTOR[0]), &(FROM_VECTOR)[0], sizeof(void*) * (FROM_VECTOR).size());
60 
61 
62 template <typename OwnerType, typename ForwarderType>
63 struct ScopedForwarder {
64 
65  ScopedForwarder(
66  OwnerType *owner,
67  ForwarderType *forwarder,
68  RTI_RoutingServiceEnvironment *environment)
69  :owner_(owner), forwarder_(forwarder), environment_(environment)
70  {
71  }
72 
73  void release()
74  {
75  forwarder_ = NULL;
76  }
77 
78  ~ScopedForwarder()
79  {
80  if (forwarder_ != NULL) {
81  ForwarderType::delete_native(owner_, forwarder_->native(), environment_);
82  }
83  }
84 
85 private:
86  OwnerType *owner_;
87  ForwarderType *forwarder_;
88  RTI_RoutingServiceEnvironment *environment_;
89 
90 };
91 
92 
93 } } }
94 
95 
96 #endif // RTI_ROUTING_DETAIL_FORWARDER_UTILS_UTILS_HPP_

RTI Routing Service Version 6.0.1 Copyright © Sun Nov 17 2019 Real-Time Innovations, Inc