RTI Routing Service  Version 6.0.0
 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_ForwarderType_UTILS_HPP_
12 #define RTI_ROUTING_DETAIL_ForwarderType_UTILS_HPP_
13 
14 #include <map>
15 
16 #include <rti/core/Exception.hpp>
17 #include <routingservice/routingservice_infrastructure.h>
18 
19 #define RTI_ROUTING_THROW_ON_NULL(pointer) \
20  if ((pointer) == NULL) { \
21  throw dds::core::Error("invalid return of NULL"); \
22  }
23 
24 #define RTI_ROUTING_THROW_ON_ENV_ERROR(NATIVE_ENV) \
25  if (RTI_RoutingServiceEnvironment_error_occurred((NATIVE_ENV))) { \
26  dds::core::Error rex( \
27  RTI_RoutingServiceEnvironment_get_error_message((NATIVE_ENV))); \
28  RTI_RoutingServiceEnvironment_clear_error((NATIVE_ENV)); \
29  throw rex; \
30  }
31 
32 #define RTI_ROUTING_SAMPLE_VECTOR_COPY_FROM_NATIVE( \
33  VECTOR, \
34  NATIVE_ARRAY, \
35  ARRAY_LENGTH) \
36  (VECTOR).resize((ARRAY_LENGTH)); \
37  memcpy(&((VECTOR)[0]), \
38  (NATIVE_ARRAY), \
39  sizeof (void*) * (ARRAY_LENGTH));
40 
41 #define RTI_ROUTING_SAMPLE_VECTOR_COPY_PTRS( \
42  TO_VECTOR, \
43  FROM_VECTOR) \
44  (TO_VECTOR).resize((FROM_VECTOR).size()); \
45  memcpy(&(TO_VECTOR[0]), &(FROM_VECTOR)[0], sizeof(void*) * (FROM_VECTOR).size());
46 
47 
48 template <typename OwnerType, typename ForwarderType>
49 struct ScopedForwarder {
50 
51  ScopedForwarder(
52  OwnerType *owner,
53  ForwarderType *forwarder,
54  RTI_RoutingServiceEnvironment *environment)
55  :owner_(owner), forwarder_(forwarder), environment_(environment)
56  {
57  }
58 
59  void release()
60  {
61  forwarder_ = NULL;
62  }
63 
64  ~ScopedForwarder()
65  {
66  if (forwarder_ != NULL) {
67  ForwarderType::delete_native(owner_, forwarder_->native(), environment_);
68  }
69  }
70 
71 private:
72  OwnerType *owner_;
73  ForwarderType *forwarder_;
74  RTI_RoutingServiceEnvironment *environment_;
75 
76 };
77 
78 
79 #endif // RTI_ROUTING_DETAIL_ForwarderType_UTILS_HPP_

RTI Routing Service Version 6.0.0 Copyright © Sun Mar 3 2019 Real-Time Innovations, Inc