OpenDDS  Snapshot(2023/04/28-20:55)
TypeSupportImpl.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_TYPESUPPORTIMPL_H
7 #define OPENDDS_DCPS_TYPESUPPORTIMPL_H
8 
9 #include "dcps_export.h"
10 #include "Definitions.h"
11 #include "LocalObject.h"
12 #include "Serializer.h"
13 #include "SafetyProfileStreams.h"
14 #include "XTypes/TypeObject.h"
16 
17 #include <dds/DdsDynamicDataC.h>
18 #include <dds/DdsDcpsTypeSupportExtC.h>
19 
20 #ifndef ACE_LACKS_PRAGMA_ONCE
21 # pragma once
22 #endif
23 
25 
26 namespace OpenDDS {
27 namespace DCPS {
28 
29 class MetaStruct;
30 
31 template <typename Message> struct DDSTraits;
32 
33 template <typename Message> struct MarshalTraits;
34 
36 public:
38  : bounded_(false)
39  , bound_(0)
40  {
41  }
42 
43  SerializedSizeBound(size_t bound)
44  : bounded_(true)
45  , bound_(bound)
46  {
47  }
48 
49  operator bool() const
50  {
51  return bounded_;
52  }
53 
54  size_t get() const
55  {
56  OPENDDS_ASSERT(bounded_);
57  return bound_;
58  }
59 
61  {
62  return bounded_ ? to_dds_string(bound_) : "<unbounded>";
63  }
64 
65 private:
66  bool bounded_;
67  size_t bound_;
68 };
69 
71  : public virtual LocalObject<TypeSupport> {
72 public:
74 
75 #ifndef OPENDDS_SAFETY_PROFILE
76  explicit TypeSupportImpl(DDS::DynamicType_ptr type)
77  : type_(DDS::DynamicType::_duplicate(type))
78  {
79  }
80 #endif
81 
82  virtual ~TypeSupportImpl();
83 
84 #ifndef OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE
85  virtual const MetaStruct& getMetaStructForType() const = 0;
86 #endif
87 
88  virtual DDS::ReturnCode_t register_type(DDS::DomainParticipant_ptr participant,
89  const char* type_name);
90 
91  virtual DDS::ReturnCode_t unregister_type(DDS::DomainParticipant_ptr participant,
92  const char* type_name);
93 
94  virtual const char* name() const = 0;
95 
96  /// NOTE: This one implements the IDL TypeSupport method so it returns a CORBA String
97  /// that the caller must take ownership of.
98  virtual char* get_type_name();
99 
100 #ifndef OPENDDS_SAFETY_PROFILE
101  virtual DDS::DynamicType_ptr get_type() const
102  {
103  return DDS::DynamicType::_duplicate(type_);
104  }
105 
106  // IDL local interface uses non-const memebers
107  DDS::DynamicType_ptr get_type()
108  {
109  return DDS::DynamicType::_duplicate(type_);
110  }
111 #endif
112 
113  virtual size_t key_count() const = 0;
114  virtual bool is_dcps_key(const char* fieldname) const = 0;
115 
117  {
118  return key_count();
119  }
120 
121  virtual SerializedSizeBound serialized_size_bound(const Encoding& encoding) const = 0;
122  virtual SerializedSizeBound key_only_serialized_size_bound(const Encoding& encoding) const = 0;
123 
124  /// Returns the extensibility of just the topic type.
125  virtual Extensibility base_extensibility() const = 0;
126  /// Between the topic type and its nested types, return the extensibility
127  /// that is furthest right in (final, appenable, mutable).
128  virtual Extensibility max_extensibility() const = 0;
129 
130  virtual const XTypes::TypeIdentifier& getMinimalTypeIdentifier() const = 0;
131  virtual const XTypes::TypeMap& getMinimalTypeMap() const = 0;
132  virtual const XTypes::TypeIdentifier& getCompleteTypeIdentifier() const = 0;
133  virtual const XTypes::TypeMap& getCompleteTypeMap() const = 0;
134 
135  void to_type_info(XTypes::TypeInformation& type_info) const;
137  {
138  return 0;
139  }
140 
141  void add_types(const XTypes::TypeLookupService_rch& tls) const;
142 
143  RepresentationFormat* make_format(DDS::DataRepresentationId_t representation);
144 
145 protected:
146 #ifndef OPENDDS_SAFETY_PROFILE
147  void get_type_from_type_lookup_service();
148 
149  DDS::DynamicType_var type_;
150 #endif
151 
152 private:
154 
155  void to_type_info_i(XTypes::TypeIdentifierWithDependencies& ti_with_deps,
156  const XTypes::TypeIdentifier& ti,
157  const XTypes::TypeMap& type_map) const;
158 
159  void populate_dependencies_i(const XTypes::TypeLookupService_rch& tls,
160  XTypes::EquivalenceKind ek) const;
161 
162 #ifndef OPENDDS_SAFETY_PROFILE
164 #endif
165 
167 };
168 
169 template <typename NativeType>
171 public:
174 
175  const char* name() const
176  {
177  return TraitsType::type_name();
178  }
179 
180  size_t key_count() const
181  {
182  return TraitsType::key_count();
183  }
184 
185  bool is_dcps_key(const char* fieldname) const
186  {
187  return TraitsType::is_key(fieldname);
188  }
189 
191  {
192  MarshalTraitsType::representations_allowed_by_type(seq);
193  }
194 
196  {
198  }
199 
201  {
202  return MarshalTraitsType::max_extensibility_level();
203  }
204 
206  {
207  return MarshalTraitsType::serialized_size_bound(encoding);
208  }
209 
211  {
212  return MarshalTraitsType::key_only_serialized_size_bound(encoding);
213  }
214 
215 #ifndef OPENDDS_SAFETY_PROFILE
216  DDS::DynamicType_ptr get_type()
217  {
218  get_type_from_type_lookup_service();
219  return TypeSupportImpl::get_type();
220  }
221 #endif
222 };
223 
224 template <typename T>
227  : ts_(new T)
228  {
229  ts_->register_type(0, "");
230  }
231 
233  {
234  T* const t = dynamic_cast<T*>(ts_.in());
235  ts_->unregister_type(0, t ? t->name() : 0);
236  }
237 
238  typename T::_var_type ts_;
239 };
240 
241 } // namespace DCPS
242 } // namespace OpenDDS
243 
245 
246 #endif
SerializedSizeBound serialized_size_bound(const Encoding &encoding) const
bool is_key(DDS::DynamicType_ptr type, const char *field)
MarshalTraits< NativeType > MarshalTraitsType
const XTypes::TypeIdentifier & getCompleteTypeIdentifier()
Extensibility base_extensibility() const
Returns the extensibility of just the topic type.
const XTypes::TypeMap & getMinimalTypeMap()
DDSTraits< NativeType > TraitsType
Extensibility max_extensibility() const
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
String to_dds_string(unsigned short to_convert)
#define OPENDDS_DELETED_COPY_MOVE_CTOR_ASSIGN(CLASS)
Definition: Definitions.h:35
DDS::DynamicType_ptr get_type()
#define OPENDDS_ASSERT(C)
Definition: Definitions.h:72
TypeSupportImpl(DDS::DynamicType_ptr type)
sequence< DataRepresentationId_t > DataRepresentationIdSeq
XTypes::TypeLookupService_rch type_lookup_service_
T * _duplicate(T *st)
static const ACE_CDR::Long TYPE_INFO_DEPENDENT_COUNT_NOT_PROVIDED
#define OPENDDS_STRING
SerializedSizeBound key_only_serialized_size_bound(const Encoding &encoding) const
virtual DDS::DynamicType_ptr get_type() const
const XTypes::TypeMap & getCompleteTypeMap()
The End User API.
DDS::DynamicType_ptr get_type()
const char *const name
Definition: debug.cpp:60
ACE_INT32 Long
ACE_CDR::Octet EquivalenceKind
Definition: TypeObject.h:204
const XTypes::TypeIdentifier & getMinimalTypeIdentifier()
void representations_allowed_by_type(DDS::DataRepresentationIdSeq &seq)
virtual const XTypes::TypeInformation * preset_type_info() const
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
OPENDDS_STRING to_string() const
bool is_dcps_key(const char *fieldname) const
short DataRepresentationId_t
DDS::ReturnCode_t max_extensibility(DDS::DynamicType_ptr type, DCPS::Extensibility &ext)
const DCPS::Encoding encoding(DCPS::Encoding::KIND_UNALIGNED_CDR, DCPS::ENDIAN_BIG)
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
DDS::ReturnCode_t key_count(DDS::DynamicType_ptr type, size_t &count)
extensibility(MUTABLE) struct TypeLookup_getTypes_In
Definition: TypeLookup.idl:29