TopicsPlugin.cxx 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  1. /*
  2. WARNING: THIS FILE IS AUTO-GENERATED. DO NOT MODIFY.
  3. This file was generated from Topics.idl using "rtiddsgen".
  4. The rtiddsgen tool is part of the RTI Connext distribution.
  5. For more information, type 'rtiddsgen -help' at a command shell
  6. or consult the RTI Connext manual.
  7. */
  8. #include <string.h>
  9. #ifndef ndds_cpp_h
  10. #include "ndds/ndds_cpp.h"
  11. #endif
  12. #ifndef osapi_type_h
  13. #include "osapi/osapi_type.h"
  14. #endif
  15. #ifndef osapi_heap_h
  16. #include "osapi/osapi_heap.h"
  17. #endif
  18. #ifndef osapi_utility_h
  19. #include "osapi/osapi_utility.h"
  20. #endif
  21. #ifndef cdr_type_h
  22. #include "cdr/cdr_type.h"
  23. #endif
  24. #ifndef cdr_type_object_h
  25. #include "cdr/cdr_typeObject.h"
  26. #endif
  27. #ifndef cdr_encapsulation_h
  28. #include "cdr/cdr_encapsulation.h"
  29. #endif
  30. #ifndef cdr_stream_h
  31. #include "cdr/cdr_stream.h"
  32. #endif
  33. #include "xcdr/xcdr_interpreter.h"
  34. #include "xcdr/xcdr_stream.h"
  35. #ifndef cdr_log_h
  36. #include "cdr/cdr_log.h"
  37. #endif
  38. #ifndef pres_typePlugin_h
  39. #include "pres/pres_typePlugin.h"
  40. #endif
  41. #include "dds_c/dds_c_typecode_impl.h"
  42. #define RTI_CDR_CURRENT_SUBMODULE RTI_CDR_SUBMODULE_MASK_STREAM
  43. #include <new>
  44. #include "TopicsPlugin.h"
  45. /* ----------------------------------------------------------------------------
  46. * Type TopicSample_SomeBytes
  47. * -------------------------------------------------------------------------- */
  48. /* -----------------------------------------------------------------------------
  49. Support functions:
  50. * -------------------------------------------------------------------------- */
  51. TopicSample_SomeBytes*
  52. TopicSample_SomeBytesPluginSupport_create_data_w_params(
  53. const struct DDS_TypeAllocationParams_t * alloc_params)
  54. {
  55. TopicSample_SomeBytes *sample = NULL;
  56. sample = new (std::nothrow) TopicSample_SomeBytes ;
  57. if (sample == NULL) {
  58. return NULL;
  59. }
  60. if (!TopicSample_SomeBytes_initialize_w_params(sample,alloc_params)) {
  61. delete sample;
  62. sample=NULL;
  63. }
  64. return sample;
  65. }
  66. TopicSample_SomeBytes *
  67. TopicSample_SomeBytesPluginSupport_create_data_ex(RTIBool allocate_pointers)
  68. {
  69. TopicSample_SomeBytes *sample = NULL;
  70. sample = new (std::nothrow) TopicSample_SomeBytes ;
  71. if(sample == NULL) {
  72. return NULL;
  73. }
  74. if (!TopicSample_SomeBytes_initialize_ex(sample,allocate_pointers, RTI_TRUE)) {
  75. delete sample;
  76. sample=NULL;
  77. }
  78. return sample;
  79. }
  80. TopicSample_SomeBytes *
  81. TopicSample_SomeBytesPluginSupport_create_data(void)
  82. {
  83. return TopicSample_SomeBytesPluginSupport_create_data_ex(RTI_TRUE);
  84. }
  85. void
  86. TopicSample_SomeBytesPluginSupport_destroy_data_w_params(
  87. TopicSample_SomeBytes *sample,
  88. const struct DDS_TypeDeallocationParams_t * dealloc_params) {
  89. TopicSample_SomeBytes_finalize_w_params(sample,dealloc_params);
  90. delete sample;
  91. sample=NULL;
  92. }
  93. void
  94. TopicSample_SomeBytesPluginSupport_destroy_data_ex(
  95. TopicSample_SomeBytes *sample,RTIBool deallocate_pointers) {
  96. TopicSample_SomeBytes_finalize_ex(sample,deallocate_pointers);
  97. delete sample;
  98. sample=NULL;
  99. }
  100. void
  101. TopicSample_SomeBytesPluginSupport_destroy_data(
  102. TopicSample_SomeBytes *sample) {
  103. TopicSample_SomeBytesPluginSupport_destroy_data_ex(sample,RTI_TRUE);
  104. }
  105. RTIBool
  106. TopicSample_SomeBytesPluginSupport_copy_data(
  107. TopicSample_SomeBytes *dst,
  108. const TopicSample_SomeBytes *src)
  109. {
  110. return TopicSample_SomeBytes_copy(dst,(const TopicSample_SomeBytes*) src);
  111. }
  112. void
  113. TopicSample_SomeBytesPluginSupport_print_data(
  114. const TopicSample_SomeBytes *sample,
  115. const char *desc,
  116. unsigned int indent_level)
  117. {
  118. RTICdrType_printIndent(indent_level);
  119. if (desc != NULL) {
  120. RTILog_debug("%s:\n", desc);
  121. } else {
  122. RTILog_debug("\n");
  123. }
  124. if (sample == NULL) {
  125. RTILog_debug("NULL\n");
  126. return;
  127. }
  128. if (DDS_OctetSeq_get_contiguous_bufferI(sample) != NULL) {
  129. RTICdrType_printArray(
  130. DDS_OctetSeq_get_contiguous_bufferI(sample),
  131. DDS_OctetSeq_get_length(sample),
  132. RTI_CDR_OCTET_SIZE,
  133. (RTICdrTypePrintFunction)RTICdrType_printOctet,
  134. "", indent_level + 1);
  135. } else {
  136. RTICdrType_printPointerArray(
  137. DDS_OctetSeq_get_discontiguous_bufferI(sample),
  138. DDS_OctetSeq_get_length(sample ),
  139. (RTICdrTypePrintFunction)RTICdrType_printOctet,
  140. "", indent_level + 1);
  141. }
  142. }
  143. /* ----------------------------------------------------------------------------
  144. Callback functions:
  145. * ---------------------------------------------------------------------------- */
  146. RTIBool
  147. TopicSample_SomeBytesPlugin_copy_sample(
  148. PRESTypePluginEndpointData endpoint_data,
  149. TopicSample_SomeBytes *dst,
  150. const TopicSample_SomeBytes *src)
  151. {
  152. if (endpoint_data) {} /* To avoid warnings */
  153. return TopicSample_SomeBytesPluginSupport_copy_data(dst,src);
  154. }
  155. /* ----------------------------------------------------------------------------
  156. (De)Serialize functions:
  157. * ------------------------------------------------------------------------- */
  158. unsigned int
  159. TopicSample_SomeBytesPlugin_get_serialized_sample_max_size(
  160. PRESTypePluginEndpointData endpoint_data,
  161. RTIBool include_encapsulation,
  162. RTIEncapsulationId encapsulation_id,
  163. unsigned int current_alignment);
  164. unsigned int
  165. TopicSample_SomeBytesPlugin_get_serialized_sample_max_size(
  166. PRESTypePluginEndpointData endpoint_data,
  167. RTIBool include_encapsulation,
  168. RTIEncapsulationId encapsulation_id,
  169. unsigned int current_alignment)
  170. {
  171. unsigned int size;
  172. RTIBool overflow = RTI_FALSE;
  173. size = PRESTypePlugin_interpretedGetSerializedSampleMaxSize(
  174. endpoint_data,&overflow,include_encapsulation,encapsulation_id,current_alignment);
  175. if (overflow) {
  176. size = RTI_CDR_MAX_SERIALIZED_SIZE;
  177. }
  178. return size;
  179. }
  180. /* --------------------------------------------------------------------------------------
  181. Key Management functions:
  182. * -------------------------------------------------------------------------------------- */
  183. PRESTypePluginKeyKind
  184. TopicSample_SomeBytesPlugin_get_key_kind(void)
  185. {
  186. return PRES_TYPEPLUGIN_NO_KEY;
  187. }
  188. unsigned int
  189. TopicSample_SomeBytesPlugin_get_serialized_key_max_size(
  190. PRESTypePluginEndpointData endpoint_data,
  191. RTIBool include_encapsulation,
  192. RTIEncapsulationId encapsulation_id,
  193. unsigned int current_alignment)
  194. {
  195. unsigned int size;
  196. RTIBool overflow = RTI_FALSE;
  197. size = PRESTypePlugin_interpretedGetSerializedKeyMaxSize(
  198. endpoint_data,&overflow,include_encapsulation,encapsulation_id,current_alignment);
  199. if (overflow) {
  200. size = RTI_CDR_MAX_SERIALIZED_SIZE;
  201. }
  202. return size;
  203. }
  204. unsigned int
  205. TopicSample_SomeBytesPlugin_get_serialized_key_max_size_for_keyhash(
  206. PRESTypePluginEndpointData endpoint_data,
  207. RTIEncapsulationId encapsulation_id,
  208. unsigned int current_alignment)
  209. {
  210. unsigned int size;
  211. RTIBool overflow = RTI_FALSE;
  212. size = PRESTypePlugin_interpretedGetSerializedKeyMaxSizeForKeyhash(
  213. endpoint_data,
  214. &overflow,
  215. encapsulation_id,
  216. current_alignment);
  217. if (overflow) {
  218. size = RTI_CDR_MAX_SERIALIZED_SIZE;
  219. }
  220. return size;
  221. }
  222. /* ------------------------------------------------------------------------
  223. * Plug-in Installation Methods
  224. * ------------------------------------------------------------------------ */
  225. /* ----------------------------------------------------------------------------
  226. * Type TopicSample_Message
  227. * -------------------------------------------------------------------------- */
  228. /* -----------------------------------------------------------------------------
  229. Support functions:
  230. * -------------------------------------------------------------------------- */
  231. TopicSample_Message*
  232. TopicSample_MessagePluginSupport_create_data_w_params(
  233. const struct DDS_TypeAllocationParams_t * alloc_params)
  234. {
  235. TopicSample_Message *sample = NULL;
  236. sample = new (std::nothrow) TopicSample_Message ;
  237. if (sample == NULL) {
  238. return NULL;
  239. }
  240. if (!TopicSample_Message_initialize_w_params(sample,alloc_params)) {
  241. delete sample;
  242. sample=NULL;
  243. }
  244. return sample;
  245. }
  246. TopicSample_Message *
  247. TopicSample_MessagePluginSupport_create_data_ex(RTIBool allocate_pointers)
  248. {
  249. TopicSample_Message *sample = NULL;
  250. sample = new (std::nothrow) TopicSample_Message ;
  251. if(sample == NULL) {
  252. return NULL;
  253. }
  254. if (!TopicSample_Message_initialize_ex(sample,allocate_pointers, RTI_TRUE)) {
  255. delete sample;
  256. sample=NULL;
  257. }
  258. return sample;
  259. }
  260. TopicSample_Message *
  261. TopicSample_MessagePluginSupport_create_data(void)
  262. {
  263. return TopicSample_MessagePluginSupport_create_data_ex(RTI_TRUE);
  264. }
  265. void
  266. TopicSample_MessagePluginSupport_destroy_data_w_params(
  267. TopicSample_Message *sample,
  268. const struct DDS_TypeDeallocationParams_t * dealloc_params) {
  269. TopicSample_Message_finalize_w_params(sample,dealloc_params);
  270. delete sample;
  271. sample=NULL;
  272. }
  273. void
  274. TopicSample_MessagePluginSupport_destroy_data_ex(
  275. TopicSample_Message *sample,RTIBool deallocate_pointers) {
  276. TopicSample_Message_finalize_ex(sample,deallocate_pointers);
  277. delete sample;
  278. sample=NULL;
  279. }
  280. void
  281. TopicSample_MessagePluginSupport_destroy_data(
  282. TopicSample_Message *sample) {
  283. TopicSample_MessagePluginSupport_destroy_data_ex(sample,RTI_TRUE);
  284. }
  285. RTIBool
  286. TopicSample_MessagePluginSupport_copy_data(
  287. TopicSample_Message *dst,
  288. const TopicSample_Message *src)
  289. {
  290. return TopicSample_Message_copy(dst,(const TopicSample_Message*) src);
  291. }
  292. void
  293. TopicSample_MessagePluginSupport_print_data(
  294. const TopicSample_Message *sample,
  295. const char *desc,
  296. unsigned int indent_level)
  297. {
  298. RTICdrType_printIndent(indent_level);
  299. if (desc != NULL) {
  300. RTILog_debug("%s:\n", desc);
  301. } else {
  302. RTILog_debug("\n");
  303. }
  304. if (sample == NULL) {
  305. RTILog_debug("NULL\n");
  306. return;
  307. }
  308. if (sample->msgname==NULL) {
  309. RTICdrType_printString(
  310. NULL,"msgname", indent_level + 1);
  311. } else {
  312. RTICdrType_printString(
  313. sample->msgname,"msgname", indent_level + 1);
  314. }
  315. RTICdrType_printLong(
  316. &sample->counter, "counter", indent_level + 1);
  317. RTICdrType_printLongLong(
  318. &sample->sendtime, "sendtime", indent_level + 1);
  319. TopicSample_SomeBytesPluginSupport_print_data(
  320. (const TopicSample_SomeBytes*) &sample->xdata, "xdata", indent_level + 1);
  321. }
  322. /* ----------------------------------------------------------------------------
  323. Callback functions:
  324. * ---------------------------------------------------------------------------- */
  325. PRESTypePluginParticipantData
  326. TopicSample_MessagePlugin_on_participant_attached(
  327. void *registration_data,
  328. const struct PRESTypePluginParticipantInfo *participant_info,
  329. RTIBool top_level_registration,
  330. void *container_plugin_context,
  331. RTICdrTypeCode *type_code)
  332. {
  333. struct RTIXCdrInterpreterPrograms *programs = NULL;
  334. struct PRESTypePluginDefaultParticipantData *pd = NULL;
  335. struct RTIXCdrInterpreterProgramsGenProperty programProperty =
  336. RTIXCdrInterpreterProgramsGenProperty_INITIALIZER;
  337. if (registration_data) {} /* To avoid warnings */
  338. if (participant_info) {} /* To avoid warnings */
  339. if (top_level_registration) {} /* To avoid warnings */
  340. if (container_plugin_context) {} /* To avoid warnings */
  341. if (type_code) {} /* To avoid warnings */
  342. pd = (struct PRESTypePluginDefaultParticipantData *)
  343. PRESTypePluginDefaultParticipantData_new(participant_info);
  344. programProperty.generateV1Encapsulation = RTI_XCDR_TRUE;
  345. programProperty.generateV2Encapsulation = RTI_XCDR_TRUE;
  346. programProperty.resolveAlias = RTI_XCDR_TRUE;
  347. programProperty.inlineStruct = RTI_XCDR_TRUE;
  348. programProperty.optimizeEnum = RTI_XCDR_TRUE;
  349. programs = DDS_TypeCodeFactory_assert_programs_in_global_list(
  350. DDS_TypeCodeFactory_get_instance(),
  351. TopicSample_Message_get_typecode(),
  352. &programProperty,
  353. RTI_XCDR_PROGRAM_MASK_TYPEPLUGIN);
  354. if (programs == NULL) {
  355. PRESTypePluginDefaultParticipantData_delete(
  356. (PRESTypePluginParticipantData) pd);
  357. return NULL;
  358. }
  359. pd->programs = programs;
  360. return (PRESTypePluginParticipantData)pd;
  361. }
  362. void
  363. TopicSample_MessagePlugin_on_participant_detached(
  364. PRESTypePluginParticipantData participant_data)
  365. {
  366. if (participant_data != NULL) {
  367. struct PRESTypePluginDefaultParticipantData *pd =
  368. (struct PRESTypePluginDefaultParticipantData *)participant_data;
  369. if (pd->programs != NULL) {
  370. DDS_TypeCodeFactory_remove_programs_from_global_list(
  371. DDS_TypeCodeFactory_get_instance(),
  372. pd->programs);
  373. pd->programs = NULL;
  374. }
  375. PRESTypePluginDefaultParticipantData_delete(participant_data);
  376. }
  377. }
  378. PRESTypePluginEndpointData
  379. TopicSample_MessagePlugin_on_endpoint_attached(
  380. PRESTypePluginParticipantData participant_data,
  381. const struct PRESTypePluginEndpointInfo *endpoint_info,
  382. RTIBool top_level_registration,
  383. void *containerPluginContext)
  384. {
  385. PRESTypePluginEndpointData epd = NULL;
  386. unsigned int serializedSampleMaxSize = 0;
  387. if (top_level_registration) {} /* To avoid warnings */
  388. if (containerPluginContext) {} /* To avoid warnings */
  389. if (participant_data == NULL) {
  390. return NULL;
  391. }
  392. epd = PRESTypePluginDefaultEndpointData_new(
  393. participant_data,
  394. endpoint_info,
  395. (PRESTypePluginDefaultEndpointDataCreateSampleFunction)
  396. TopicSample_MessagePluginSupport_create_data,
  397. (PRESTypePluginDefaultEndpointDataDestroySampleFunction)
  398. TopicSample_MessagePluginSupport_destroy_data,
  399. NULL , NULL );
  400. if (epd == NULL) {
  401. return NULL;
  402. }
  403. if (endpoint_info->endpointKind == PRES_TYPEPLUGIN_ENDPOINT_WRITER) {
  404. serializedSampleMaxSize = TopicSample_MessagePlugin_get_serialized_sample_max_size(
  405. epd,RTI_FALSE,RTI_CDR_ENCAPSULATION_ID_CDR_BE,0);
  406. PRESTypePluginDefaultEndpointData_setMaxSizeSerializedSample(epd, serializedSampleMaxSize);
  407. if (PRESTypePluginDefaultEndpointData_createWriterPool(
  408. epd,
  409. endpoint_info,
  410. (PRESTypePluginGetSerializedSampleMaxSizeFunction)
  411. TopicSample_MessagePlugin_get_serialized_sample_max_size, epd,
  412. (PRESTypePluginGetSerializedSampleSizeFunction)
  413. PRESTypePlugin_interpretedGetSerializedSampleSize,
  414. epd) == RTI_FALSE) {
  415. PRESTypePluginDefaultEndpointData_delete(epd);
  416. return NULL;
  417. }
  418. }
  419. return epd;
  420. }
  421. void
  422. TopicSample_MessagePlugin_on_endpoint_detached(
  423. PRESTypePluginEndpointData endpoint_data)
  424. {
  425. PRESTypePluginDefaultEndpointData_delete(endpoint_data);
  426. }
  427. void
  428. TopicSample_MessagePlugin_return_sample(
  429. PRESTypePluginEndpointData endpoint_data,
  430. TopicSample_Message *sample,
  431. void *handle)
  432. {
  433. TopicSample_Message_finalize_optional_members(sample, RTI_TRUE);
  434. PRESTypePluginDefaultEndpointData_returnSample(
  435. endpoint_data, sample, handle);
  436. }
  437. RTIBool
  438. TopicSample_MessagePlugin_copy_sample(
  439. PRESTypePluginEndpointData endpoint_data,
  440. TopicSample_Message *dst,
  441. const TopicSample_Message *src)
  442. {
  443. if (endpoint_data) {} /* To avoid warnings */
  444. return TopicSample_MessagePluginSupport_copy_data(dst,src);
  445. }
  446. /* ----------------------------------------------------------------------------
  447. (De)Serialize functions:
  448. * ------------------------------------------------------------------------- */
  449. unsigned int
  450. TopicSample_MessagePlugin_get_serialized_sample_max_size(
  451. PRESTypePluginEndpointData endpoint_data,
  452. RTIBool include_encapsulation,
  453. RTIEncapsulationId encapsulation_id,
  454. unsigned int current_alignment);
  455. RTIBool
  456. TopicSample_MessagePlugin_serialize_to_cdr_buffer_ex(
  457. char *buffer,
  458. unsigned int *length,
  459. const TopicSample_Message *sample,
  460. DDS_DataRepresentationId_t representation)
  461. {
  462. RTIEncapsulationId encapsulationId = RTI_CDR_ENCAPSULATION_ID_INVALID;
  463. struct RTICdrStream stream;
  464. struct PRESTypePluginDefaultEndpointData epd;
  465. RTIBool result;
  466. struct PRESTypePluginDefaultParticipantData pd;
  467. struct RTIXCdrTypePluginProgramContext defaultProgramConext =
  468. RTIXCdrTypePluginProgramContext_INTIALIZER;
  469. struct PRESTypePlugin plugin;
  470. if (length == NULL) {
  471. return RTI_FALSE;
  472. }
  473. RTIOsapiMemory_zero(&epd, sizeof(struct PRESTypePluginDefaultEndpointData));
  474. epd.programContext = defaultProgramConext;
  475. epd._participantData = &pd;
  476. epd.typePlugin = &plugin;
  477. epd.programContext.endpointPluginData = &epd;
  478. plugin.typeCode = (struct RTICdrTypeCode *)
  479. TopicSample_Message_get_typecode();
  480. pd.programs = TopicSample_MessagePlugin_get_programs();
  481. if (pd.programs == NULL) {
  482. return RTI_FALSE;
  483. }
  484. encapsulationId = DDS_TypeCode_get_native_encapsulation(
  485. (DDS_TypeCode *) plugin.typeCode,
  486. representation);
  487. if (encapsulationId == RTI_CDR_ENCAPSULATION_ID_INVALID) {
  488. return RTI_FALSE;
  489. }
  490. epd._maxSizeSerializedSample =
  491. TopicSample_MessagePlugin_get_serialized_sample_max_size(
  492. (PRESTypePluginEndpointData)&epd,
  493. RTI_TRUE,
  494. encapsulationId,
  495. 0);
  496. if (buffer == NULL) {
  497. *length =
  498. PRESTypePlugin_interpretedGetSerializedSampleSize(
  499. (PRESTypePluginEndpointData)&epd,
  500. RTI_TRUE,
  501. encapsulationId,
  502. 0,
  503. sample);
  504. if (*length == 0) {
  505. return RTI_FALSE;
  506. }
  507. return RTI_TRUE;
  508. }
  509. RTICdrStream_init(&stream);
  510. RTICdrStream_set(&stream, (char *)buffer, *length);
  511. result = PRESTypePlugin_interpretedSerialize(
  512. (PRESTypePluginEndpointData)&epd,
  513. sample,
  514. &stream,
  515. RTI_TRUE,
  516. encapsulationId,
  517. RTI_TRUE,
  518. NULL);
  519. *length = RTICdrStream_getCurrentPositionOffset(&stream);
  520. return result;
  521. }
  522. RTIBool
  523. TopicSample_MessagePlugin_serialize_to_cdr_buffer(
  524. char *buffer,
  525. unsigned int *length,
  526. const TopicSample_Message *sample)
  527. {
  528. return TopicSample_MessagePlugin_serialize_to_cdr_buffer_ex(
  529. buffer,
  530. length,
  531. sample,
  532. DDS_AUTO_DATA_REPRESENTATION);
  533. }
  534. RTIBool
  535. TopicSample_MessagePlugin_deserialize_from_cdr_buffer(
  536. TopicSample_Message *sample,
  537. const char * buffer,
  538. unsigned int length)
  539. {
  540. struct RTICdrStream stream;
  541. struct PRESTypePluginDefaultEndpointData epd;
  542. struct RTIXCdrTypePluginProgramContext defaultProgramConext =
  543. RTIXCdrTypePluginProgramContext_INTIALIZER;
  544. struct PRESTypePluginDefaultParticipantData pd;
  545. struct PRESTypePlugin plugin;
  546. epd.programContext = defaultProgramConext;
  547. epd._participantData = &pd;
  548. epd.typePlugin = &plugin;
  549. epd.programContext.endpointPluginData = &epd;
  550. plugin.typeCode = (struct RTICdrTypeCode *)
  551. TopicSample_Message_get_typecode();
  552. pd.programs = TopicSample_MessagePlugin_get_programs();
  553. if (pd.programs == NULL) {
  554. return RTI_FALSE;
  555. }
  556. epd._assignabilityProperty.acceptUnknownEnumValue = RTI_XCDR_TRUE;
  557. epd._assignabilityProperty.acceptUnknownUnionDiscriminator = RTI_XCDR_TRUE;
  558. RTICdrStream_init(&stream);
  559. RTICdrStream_set(&stream, (char *)buffer, length);
  560. TopicSample_Message_finalize_optional_members(sample, RTI_TRUE);
  561. return PRESTypePlugin_interpretedDeserialize(
  562. (PRESTypePluginEndpointData)&epd, sample,
  563. &stream, RTI_TRUE, RTI_TRUE,
  564. NULL);
  565. }
  566. #ifndef NDDS_STANDALONE_TYPE
  567. DDS_ReturnCode_t
  568. TopicSample_MessagePlugin_data_to_string(
  569. const TopicSample_Message *sample,
  570. char *str,
  571. DDS_UnsignedLong *str_size,
  572. const struct DDS_PrintFormatProperty *property)
  573. {
  574. DDS_DynamicData *data = NULL;
  575. char *buffer = NULL;
  576. unsigned int length = 0;
  577. struct DDS_PrintFormat printFormat;
  578. DDS_ReturnCode_t retCode = DDS_RETCODE_ERROR;
  579. if (sample == NULL) {
  580. return DDS_RETCODE_BAD_PARAMETER;
  581. }
  582. if (str_size == NULL) {
  583. return DDS_RETCODE_BAD_PARAMETER;
  584. }
  585. if (property == NULL) {
  586. return DDS_RETCODE_BAD_PARAMETER;
  587. }
  588. if (!TopicSample_MessagePlugin_serialize_to_cdr_buffer(
  589. NULL,
  590. &length,
  591. sample)) {
  592. return DDS_RETCODE_ERROR;
  593. }
  594. RTIOsapiHeap_allocateBuffer(&buffer, length, RTI_OSAPI_ALIGNMENT_DEFAULT);
  595. if (buffer == NULL) {
  596. return DDS_RETCODE_ERROR;
  597. }
  598. if (!TopicSample_MessagePlugin_serialize_to_cdr_buffer(
  599. buffer,
  600. &length,
  601. sample)) {
  602. RTIOsapiHeap_freeBuffer(buffer);
  603. return DDS_RETCODE_ERROR;
  604. }
  605. data = DDS_DynamicData_new(
  606. TopicSample_Message_get_typecode(),
  607. &DDS_DYNAMIC_DATA_PROPERTY_DEFAULT);
  608. if (data == NULL) {
  609. RTIOsapiHeap_freeBuffer(buffer);
  610. return DDS_RETCODE_ERROR;
  611. }
  612. retCode = DDS_DynamicData_from_cdr_buffer(data, buffer, length);
  613. if (retCode != DDS_RETCODE_OK) {
  614. RTIOsapiHeap_freeBuffer(buffer);
  615. DDS_DynamicData_delete(data);
  616. return retCode;
  617. }
  618. retCode = DDS_PrintFormatProperty_to_print_format(
  619. property,
  620. &printFormat);
  621. if (retCode != DDS_RETCODE_OK) {
  622. RTIOsapiHeap_freeBuffer(buffer);
  623. DDS_DynamicData_delete(data);
  624. return retCode;
  625. }
  626. retCode = DDS_DynamicDataFormatter_to_string_w_format(
  627. data,
  628. str,
  629. str_size,
  630. &printFormat);
  631. if (retCode != DDS_RETCODE_OK) {
  632. RTIOsapiHeap_freeBuffer(buffer);
  633. DDS_DynamicData_delete(data);
  634. return retCode;
  635. }
  636. RTIOsapiHeap_freeBuffer(buffer);
  637. DDS_DynamicData_delete(data);
  638. return DDS_RETCODE_OK;
  639. }
  640. #endif
  641. unsigned int
  642. TopicSample_MessagePlugin_get_serialized_sample_max_size(
  643. PRESTypePluginEndpointData endpoint_data,
  644. RTIBool include_encapsulation,
  645. RTIEncapsulationId encapsulation_id,
  646. unsigned int current_alignment)
  647. {
  648. unsigned int size;
  649. RTIBool overflow = RTI_FALSE;
  650. size = PRESTypePlugin_interpretedGetSerializedSampleMaxSize(
  651. endpoint_data,&overflow,include_encapsulation,encapsulation_id,current_alignment);
  652. if (overflow) {
  653. size = RTI_CDR_MAX_SERIALIZED_SIZE;
  654. }
  655. return size;
  656. }
  657. /* --------------------------------------------------------------------------------------
  658. Key Management functions:
  659. * -------------------------------------------------------------------------------------- */
  660. PRESTypePluginKeyKind
  661. TopicSample_MessagePlugin_get_key_kind(void)
  662. {
  663. return PRES_TYPEPLUGIN_NO_KEY;
  664. }
  665. RTIBool TopicSample_MessagePlugin_deserialize_key(
  666. PRESTypePluginEndpointData endpoint_data,
  667. TopicSample_Message **sample,
  668. RTIBool * drop_sample,
  669. struct RTICdrStream *stream,
  670. RTIBool deserialize_encapsulation,
  671. RTIBool deserialize_key,
  672. void *endpoint_plugin_qos)
  673. {
  674. RTIBool result;
  675. if (drop_sample) {} /* To avoid warnings */
  676. stream->_xTypesState.unassignable = RTI_FALSE;
  677. result= PRESTypePlugin_interpretedDeserializeKey(
  678. endpoint_data, (sample != NULL)?*sample:NULL, stream,
  679. deserialize_encapsulation, deserialize_key, endpoint_plugin_qos);
  680. if (result) {
  681. if (stream->_xTypesState.unassignable) {
  682. result = RTI_FALSE;
  683. }
  684. }
  685. return result;
  686. }
  687. unsigned int
  688. TopicSample_MessagePlugin_get_serialized_key_max_size(
  689. PRESTypePluginEndpointData endpoint_data,
  690. RTIBool include_encapsulation,
  691. RTIEncapsulationId encapsulation_id,
  692. unsigned int current_alignment)
  693. {
  694. unsigned int size;
  695. RTIBool overflow = RTI_FALSE;
  696. size = PRESTypePlugin_interpretedGetSerializedKeyMaxSize(
  697. endpoint_data,&overflow,include_encapsulation,encapsulation_id,current_alignment);
  698. if (overflow) {
  699. size = RTI_CDR_MAX_SERIALIZED_SIZE;
  700. }
  701. return size;
  702. }
  703. unsigned int
  704. TopicSample_MessagePlugin_get_serialized_key_max_size_for_keyhash(
  705. PRESTypePluginEndpointData endpoint_data,
  706. RTIEncapsulationId encapsulation_id,
  707. unsigned int current_alignment)
  708. {
  709. unsigned int size;
  710. RTIBool overflow = RTI_FALSE;
  711. size = PRESTypePlugin_interpretedGetSerializedKeyMaxSizeForKeyhash(
  712. endpoint_data,
  713. &overflow,
  714. encapsulation_id,
  715. current_alignment);
  716. if (overflow) {
  717. size = RTI_CDR_MAX_SERIALIZED_SIZE;
  718. }
  719. return size;
  720. }
  721. struct RTIXCdrInterpreterPrograms *TopicSample_MessagePlugin_get_programs()
  722. {
  723. return ::rti::xcdr::get_cdr_serialization_programs<
  724. TopicSample_Message,
  725. true, true, true>();
  726. }
  727. /* ------------------------------------------------------------------------
  728. * Plug-in Installation Methods
  729. * ------------------------------------------------------------------------ */
  730. struct PRESTypePlugin *TopicSample_MessagePlugin_new(void)
  731. {
  732. struct PRESTypePlugin *plugin = NULL;
  733. const struct PRESTypePluginVersion PLUGIN_VERSION =
  734. PRES_TYPE_PLUGIN_VERSION_2_0;
  735. RTIOsapiHeap_allocateStructure(
  736. &plugin, struct PRESTypePlugin);
  737. if (plugin == NULL) {
  738. return NULL;
  739. }
  740. plugin->version = PLUGIN_VERSION;
  741. /* set up parent's function pointers */
  742. plugin->onParticipantAttached =
  743. (PRESTypePluginOnParticipantAttachedCallback)
  744. TopicSample_MessagePlugin_on_participant_attached;
  745. plugin->onParticipantDetached =
  746. (PRESTypePluginOnParticipantDetachedCallback)
  747. TopicSample_MessagePlugin_on_participant_detached;
  748. plugin->onEndpointAttached =
  749. (PRESTypePluginOnEndpointAttachedCallback)
  750. TopicSample_MessagePlugin_on_endpoint_attached;
  751. plugin->onEndpointDetached =
  752. (PRESTypePluginOnEndpointDetachedCallback)
  753. TopicSample_MessagePlugin_on_endpoint_detached;
  754. plugin->copySampleFnc =
  755. (PRESTypePluginCopySampleFunction)
  756. TopicSample_MessagePlugin_copy_sample;
  757. plugin->createSampleFnc =
  758. (PRESTypePluginCreateSampleFunction)
  759. TopicSample_MessagePlugin_create_sample;
  760. plugin->destroySampleFnc =
  761. (PRESTypePluginDestroySampleFunction)
  762. TopicSample_MessagePlugin_destroy_sample;
  763. plugin->finalizeOptionalMembersFnc =
  764. (PRESTypePluginFinalizeOptionalMembersFunction)
  765. TopicSample_Message_finalize_optional_members;
  766. plugin->serializeFnc =
  767. (PRESTypePluginSerializeFunction) PRESTypePlugin_interpretedSerialize;
  768. plugin->deserializeFnc =
  769. (PRESTypePluginDeserializeFunction) PRESTypePlugin_interpretedDeserializeWithAlloc;
  770. plugin->getSerializedSampleMaxSizeFnc =
  771. (PRESTypePluginGetSerializedSampleMaxSizeFunction)
  772. TopicSample_MessagePlugin_get_serialized_sample_max_size;
  773. plugin->getSerializedSampleMinSizeFnc =
  774. (PRESTypePluginGetSerializedSampleMinSizeFunction)
  775. PRESTypePlugin_interpretedGetSerializedSampleMinSize;
  776. plugin->getDeserializedSampleMaxSizeFnc = NULL;
  777. plugin->getSampleFnc =
  778. (PRESTypePluginGetSampleFunction)
  779. TopicSample_MessagePlugin_get_sample;
  780. plugin->returnSampleFnc =
  781. (PRESTypePluginReturnSampleFunction)
  782. TopicSample_MessagePlugin_return_sample;
  783. plugin->getKeyKindFnc =
  784. (PRESTypePluginGetKeyKindFunction)
  785. TopicSample_MessagePlugin_get_key_kind;
  786. /* These functions are only used for keyed types. As this is not a keyed
  787. type they are all set to NULL
  788. */
  789. plugin->serializeKeyFnc = NULL ;
  790. plugin->deserializeKeyFnc = NULL;
  791. plugin->getKeyFnc = NULL;
  792. plugin->returnKeyFnc = NULL;
  793. plugin->instanceToKeyFnc = NULL;
  794. plugin->keyToInstanceFnc = NULL;
  795. plugin->getSerializedKeyMaxSizeFnc = NULL;
  796. plugin->instanceToKeyHashFnc = NULL;
  797. plugin->serializedSampleToKeyHashFnc = NULL;
  798. plugin->serializedKeyToKeyHashFnc = NULL;
  799. #ifdef NDDS_STANDALONE_TYPE
  800. plugin->typeCode = NULL;
  801. #else
  802. plugin->typeCode = (struct RTICdrTypeCode *)TopicSample_Message_get_typecode();
  803. #endif
  804. plugin->languageKind = PRES_TYPEPLUGIN_CPP_LANG;
  805. /* Serialized buffer */
  806. plugin->getBuffer =
  807. (PRESTypePluginGetBufferFunction)
  808. TopicSample_MessagePlugin_get_buffer;
  809. plugin->returnBuffer =
  810. (PRESTypePluginReturnBufferFunction)
  811. TopicSample_MessagePlugin_return_buffer;
  812. plugin->getBufferWithParams = NULL;
  813. plugin->returnBufferWithParams = NULL;
  814. plugin->getSerializedSampleSizeFnc =
  815. (PRESTypePluginGetSerializedSampleSizeFunction)
  816. PRESTypePlugin_interpretedGetSerializedSampleSize;
  817. plugin->getWriterLoanedSampleFnc = NULL;
  818. plugin->returnWriterLoanedSampleFnc = NULL;
  819. plugin->returnWriterLoanedSampleFromCookieFnc = NULL;
  820. plugin->validateWriterLoanedSampleFnc = NULL;
  821. plugin->setWriterLoanedSampleSerializedStateFnc = NULL;
  822. plugin->endpointTypeName = TopicSample_MessageTYPENAME;
  823. plugin->isMetpType = RTI_FALSE;
  824. return plugin;
  825. }
  826. void
  827. TopicSample_MessagePlugin_delete(struct PRESTypePlugin *plugin)
  828. {
  829. RTIOsapiHeap_freeStructure(plugin);
  830. }
  831. #undef RTI_CDR_CURRENT_SUBMODULE