Updated: April 19, 2023 |
After fully implementing our custom data types, we must do some extra work to make them visible to the PiPS framework. Because the framework is written in C, the C++ Fast RTPS type implementation must be wrapped and exposed with C linkage.
DataBufferType DataBufferType::m_impl; TypeImpl* DataBufferType::Impl() { return &m_impl; }
extern "C" { fastrtps_type_impl_t* fastrtps_databuffer_impl( void ) { return DataBufferType::Impl(); } }
extern "C" { fastrtps_type_impl_t* fastrtps_keyeddatabuffer_impl( void ) { return KeyedDataBufferType::Impl(); } }
extern fastrtps_type_impl_t* fastrtps_databuffer_impl( void ); extern fastrtps_type_impl_t* fastrtps_keyeddatabuffer_impl( void ); static fastrtps_type_t fastrtps_databuffer_plugin = { .name = "DataBuffer", .impl = fastrtps_databuffer_impl, }; pips_type_t* fastrtps_databuffer_type = &fastrtps_databuffer_plugin.as_pips_type; static fastrtps_type_t fastrtps_keyeddatabuffer_plugin = { .name = "KeyedDataBuffer", .impl = fastrtps_keyeddatabuffer_impl, }; pips_type_t* fastrtps_keyeddatabuffer_type = &fastrtps_keyeddatabuffer_plugin.as_pips_type; int fastrtps_type_load( fastrtps_provider_t* provider, void* handle ) { int rc = -1; if ( !handle ) { errno = ENODEV; } else { if ( !fastrtps_databuffer_plugin.handle ) { rc = fastrtps_provider_register_type( provider, &fastrtps_databuffer_plugin.as_pips_type ); if ( 0 == rc ) { fastrtps_databuffer_plugin.handle = handle; } } if ( (EOK == rc) && !fastrtps_keyeddatabuffer_plugin.handle ) { rc = fastrtps_provider_register_type( provider, &fastrtps_keyeddatabuffer_plugin.as_pips_type ); if ( 0 == rc ) { fastrtps_keyeddatabuffer_plugin.handle = handle; } } } return rc; }
"typedefs":{ "QNMP":[], - "FASTRTPS":[], + "FASTRTPS":[ "fastrtps-databuffer.so" ], },
const char* extra_options = "typedef=fastrtps-databuffer.so"; pips_provider_t* provider = pips_get_provider( "FASTRTPS" ); pips_init_provider( provider, NULL, extra_options );