Skip to content

Commit

Permalink
Add create_sample and create_dynamic_sample
Browse files Browse the repository at this point in the history
  • Loading branch information
iguessthislldo committed Nov 29, 2023
1 parent e22eac1 commit cb2715d
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 62 deletions.
49 changes: 48 additions & 1 deletion dds/DCPS/TypeSupportImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ class OpenDDS_Dcps_Export TypeSupportImpl
};

template <typename NativeType>
class TypeSupportImpl_T : public TypeSupportImpl {
class TypeSupportImpl_T
: public virtual LocalObject<typename DDSTraits<NativeType>::TypeSupportType>
, public TypeSupportImpl
{
public:
typedef DDSTraits<NativeType> TraitsType;
typedef MarshalTraits<NativeType> MarshalTraitsType;
Expand Down Expand Up @@ -218,6 +221,50 @@ class TypeSupportImpl_T : public TypeSupportImpl {
get_type_from_type_lookup_service();
return TypeSupportImpl::get_type();
}

/// The IDL is `NativeType create_sample(DDS::DynamicData src)`, but in the
/// C++ mapping this can return NativeType* or just NativeType depending on if
/// the type is "variable length". If it has something like a sequence then
/// it's variable length and returns a pointer else it's fixed and returns on
/// the stack. opendds_idl will wrap this in the correct form.
bool create_sample(NativeType* dest, DDS::DynamicData_ptr src)
{
OpenDDS::DCPS::set_default(*dest);
# if OPENDDS_HAS_DYNAMIC_DATA_ADAPTOR
DDS::DynamicData_var dest_dd = get_dynamic_data_adapter<NativeType>(get_type(), dest);
const DDS::ReturnCode_t rc = XTypes::copy(dest_dd, src);
if (rc == DDS::RETCODE_OK) {
return true;
}
if (log_level >= LogLevel::Warning) {
ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: TypeSupportImpl_T::create_sample: "
"failed to copy from DynamicData: %C\n", retcode_to_string(rc)));
}
# else
ACE_UNUSED_ARG(dest);
ACE_UNUSED_ARG(src);
# endif
return false;
}

DDS::DynamicData_ptr create_dynamic_sample(const NativeType& src)
{
# if OPENDDS_HAS_DYNAMIC_DATA_ADAPTOR
DDS::DynamicData_var dest_dd = DDS::DynamicDataFactory::get_instance()->create_data(type_);
DDS::DynamicData_var src_dd = get_dynamic_data_adapter<NativeType>(get_type(), &src);
const DDS::ReturnCode_t rc = XTypes::copy(dest_dd, src_dd);
if (rc == DDS::RETCODE_OK) {
return dest_dd._retn();
}
if (log_level >= LogLevel::Notice) {
ACE_ERROR((LM_NOTICE, "(%P|%t) NOTICE: TypeSupportImpl_T::create_dynamic_sample: "
"failed to copy to DynamicData: %C\n", retcode_to_string(rc)));
}
# else
ACE_UNUSED_ARG(src);
# endif
return 0;
}
#endif
};

Expand Down
4 changes: 4 additions & 0 deletions dds/idl/IDLTemplate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ typedef sequence<<%SCOPED%>> <%TYPE%><%SEQ%>;
* this interface.
*/
local interface <%TYPE%>TypeSupport : OpenDDS::DCPS::TypeSupport {
#ifndef OPENDDS_SAFETY_PROFILE
<%SCOPED%> create_sample(in ::DDS::DynamicData src);
::DDS::DynamicData create_dynamic_sample(in <%SCOPED%> src);
#endif

::DDS::ReturnCode_t encode_to_string(in <%SCOPED%> sample, out string encoded, in OpenDDS::DCPS::RepresentationFormat format);
::DDS::ReturnCode_t encode_to_bytes(in <%SCOPED%> sample, out ::DDS::OctetSeq encoded, in OpenDDS::DCPS::RepresentationFormat format);
Expand Down
Loading

0 comments on commit cb2715d

Please sign in to comment.