void read_data (DDS_DataReaderListener *l, DDS_DataReader dr) { static DDS_DynamicDataSeq drx_sample = DDS_SEQ_INITIALIZER (void *); static DDS_SampleInfoSeq rx_info = DDS_SEQ_INITIALIZER (DDS_SampleInfo *); DDS_SampleStateMask ss = DDS_NOT_READ_SAMPLE_STATE; DDS_ViewStateMask vs = DDS_ANY_VIEW_STATE; DDS_InstanceStateMask is = DDS_ANY_INSTANCE_STATE; DDS_SampleInfo *info; DDS_ReturnCode_t error; DDS_DynamicData dd; Topic *tp; int secure = (cert_path != NULL); tp = (Topic *) l->cookie; for (;;) { error = DDS_DynamicDataReader_take (dr, &drx_sample, &rx_info, 1, ss, vs, is); if (error) { if (error != DDS_RETCODE_NO_DATA) printf ("Unable to read samples: error = %s!\r\n", DDS_error (error)); return; } if (DDS_SEQ_LENGTH (rx_info)) { info = DDS_SEQ_ITEM (rx_info, 0); if (info->valid_data) { dd = DDS_SEQ_ITEM (drx_sample, 0); if (!dd) fatal ("Empty dynamic sample!"); tp->ndata++; if (!paused) { dbg_printf ("%s: ", tp->topic_name); DDS_Debug_dump_dynamic (0, tp->ts, dd, 0, secure, 1); dbg_printf ("\r\n"); } } else if (info->instance_handle && info->instance_state != DDS_ALIVE_INSTANCE_STATE) { if (info->instance_state == DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE) tp->ndispose++; else if (info->instance_state == DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) tp->nnowriter++; if (!paused) { dd = DDS_DynamicDataFactory_create_data (tp->dtype); DDS_DynamicDataReader_get_key_value (dr, dd, info->instance_handle); dbg_printf ("%s: ", tp->topic_name); DDS_Debug_dump_dynamic (0, tp->ts, dd, 1, secure, 1); if (info->instance_state == DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE) dbg_printf (": Not alive - disposed."); else if (info->instance_state == DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) dbg_printf (": Not alive - no writers."); dbg_printf ("\r\n"); } } DDS_DynamicDataReader_return_loan (dr, &drx_sample, &rx_info); } else return; } }
static unsigned partition_set (DDS_StringSeq *ssp, Strings_t *pp, unsigned char *dst) { String_t *sp; unsigned char *start = dst; unsigned i, len; ssp->_esize = sizeof (char *); if (pp) { ssp->_maximum = ssp->_length = pp->_length; ssp->_buffer = (char **) dst; dst += pp->_length * sizeof (char *); for (i = 0; i < DDS_SEQ_LENGTH (*pp); i++) { sp = DDS_SEQ_ITEM (*pp, i); if (sp) { len = str_len (sp); memcpy (dst, str_ptr (sp), len); } else { len = 1; *dst = '\0'; } DDS_SEQ_ITEM_SET (*ssp, i, (char *) dst); dst += len; } } else ssp->_maximum = ssp->_length = 0; return (dst - start); }
static void fwd_client_on_data(const qeocore_reader_t *reader, const qeocore_data_t *data, uintptr_t userdata) { qeo_factory_t *factory = (qeo_factory_t *)userdata; qeocore_data_status_t status; org_qeo_system_Forwarder_t *fwd_data; org_qeo_system_ForwarderLocator_t fwd_locator; qeo_mgmt_client_locator_t locator; status = qeocore_data_get_status(data); if (QEOCORE_DATA == status) { fwd_data = (org_qeo_system_Forwarder_t *)qeocore_data_get_data(data); /* check locator */ if ((NULL != fwd_data) && (DDS_SEQ_LENGTH(fwd_data->locator) > 0)) { fwd_locator = DDS_SEQ_ITEM(fwd_data->locator, 0); locator.type = fwd_locator.type; locator.port = fwd_locator.port; locator.address = fwd_locator.address; client_state_machine_eval(factory, CLIENT_EVENT_FWD_DATA_RECEIVED, &locator, fwd_data->deviceId); } } else if (QEOCORE_REMOVE == status) { fwd_data = (org_qeo_system_Forwarder_t *)qeocore_data_get_data(data); if (NULL != fwd_data) { client_state_machine_eval(factory, CLIENT_EVENT_FWD_DATA_REMOVED, NULL, fwd_data->deviceId); } } }
static void my_on_data_available(const qeocore_reader_t *reader, const qeocore_data_t *data, uintptr_t userdata) { switch (qeocore_data_get_status(data)) { case QEOCORE_DATA: { qeocore_data_t *seqdata = NULL; byte_array_t array; int i, size; log_pid("reader received data"); assert(QEO_OK == qeocore_data_get_member(data, _size_id, &size)); assert(QEO_OK == qeocore_data_get_member(data, _buf_id, &seqdata)); assert(QEO_OK == qeocore_data_sequence_get(seqdata, (qeo_sequence_t *)&array, 0, QEOCORE_SIZE_UNLIMITED)); assert(size == DDS_SEQ_LENGTH(array)); assert(_test_size == DDS_SEQ_LENGTH(array)); for (i = 0; i < size; i++) { assert(DDS_SEQ_ITEM(array, i) == (i & 0xff)); } qeocore_data_sequence_free(seqdata, (qeo_sequence_t *)&array); qeocore_data_free(seqdata); sem_post(&_sync); /* release main thread */ break; } case QEOCORE_NO_MORE_DATA: case QEOCORE_REMOVE: /* ignore */ break; default: abort(); break; } }
void dr_on_statistic_data_available(DDS_DataReaderListener *self, DDS_DataReader dataReader) { acceptance_high_end_StatisticPtrSeq samples; DDS_SampleInfoSeq sampleInfos; DDS_ReturnCode_t retCode; int i; DDS_SEQ_INIT(samples); DDS_SEQ_INIT(sampleInfos); retCode = DDS_DataReader_take(dataReader, (DDS_DataSeq *)&samples, &sampleInfos, -1, DDS_ANY_SAMPLE_STATE, DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE); if (retCode == DDS_RETCODE_NO_DATA) { return; } else if (retCode != DDS_RETCODE_OK) { fprintf(stderr, "Error taking sample (%s).\r\n", DDS_error(retCode)); return; } for (i = 0; i < DDS_SEQ_LENGTH (samples); i++) if (DDS_SEQ_ITEM (sampleInfos, i)->valid_data) nofConfigSamples++; retCode = DDS_DataReader_return_loan(dataReader, (DDS_DataSeq *)&samples, &sampleInfos); if (retCode != DDS_RETCODE_OK) { fprintf(stderr, "Error returning loan (%s).\r\n", DDS_error(retCode)); return; } }
void introspect_annotation (DDS_AnnotationDescriptor *adp, int after) { unsigned i; DDS_ReturnCode_t ret; DDS_TypeDescriptor desc; DDS_Parameters pars; MapEntry_DDS_ObjectName_DDS_ObjectName *p; if (after) dbg_printf (" //"); DDS_TypeDescriptor__init (&desc); ret = DDS_DynamicType_get_descriptor (adp->type, &desc); fail_unless (ret == DDS_RETCODE_OK); dbg_printf ("@%s", desc.name); DDS_SEQ_INIT (pars); ret = DDS_AnnotationDescriptor_get_all_value (adp, &pars); fail_unless (ret == DDS_RETCODE_OK); if (DDS_SEQ_LENGTH (pars) == 1 && !strcmp (DDS_SEQ_ITEM (pars, 0).key, "value")) { /* Shorthand notation! */ if (strcmp (DDS_SEQ_ITEM (pars, 0).value, "true")) dbg_printf ("(%s)", DDS_SEQ_ITEM (pars, 0).value); } else { dbg_printf ("("); for (i = 0; i < DDS_SEQ_LENGTH (pars); i++) { if (i) dbg_printf (", "); p = DDS_SEQ_ITEM_PTR (pars, i); dbg_printf ("%s=\"%s\"", p->key, p->value); } dbg_printf (")"); } if (!after) dbg_printf (" "); DDS_Parameters__clear (&pars); DDS_TypeDescriptor__clear (&desc); }
void DDS_Security_write_volatile_data (Domain_t *dp, DDS_DataHolder *dh) { DDS_ParticipantVolatileSecureMessage msg; DDS_ReturnCode_t error; memset (&msg, 0, sizeof (msg)); msg.message_class_id = GMCLASSID_SECURITY_VOL_DATA; DDS_SEQ_INIT (msg.message_data); error = dds_seq_require (&msg.message_data, 1); if (error) return; DDS_SEQ_ITEM (msg.message_data, 0) = *dh; ctt_send (dp, NULL, NULL, NULL, &msg); }
static size_t partition_size (Strings_t *partition) { size_t s; unsigned i; String_t *sp; if (!partition) return (0); s = DDS_SEQ_LENGTH (*partition) * sizeof (char *); for (i = 0; i < DDS_SEQ_LENGTH (*partition); i++) { sp = DDS_SEQ_ITEM (*partition, i); if (sp) s += str_len (sp) + 1; else s += 1; } return (s); }
static void run_writer(pid_t peer) { qeo_factory_t *factory; qeocore_type_t *type; qeocore_writer_t *writer; qeocore_data_t *data, *seqdata; byte_array_t array; int status, i; /* initialize */ assert(NULL != (factory = qeocore_factory_new(QEO_IDENTITY_DEFAULT))); init_factory(factory); assert(NULL != (type = type_register(factory))); assert(NULL != (writer = qeocore_writer_open(factory, type, NULL, QEOCORE_EFLAG_STATE_DATA | QEOCORE_EFLAG_ENABLE, NULL, NULL))); log_pid("writer initialized"); assert(NULL != (data = qeocore_writer_data_new(writer))); assert(QEO_OK == qeocore_data_set_member(data, _size_id, &_test_size)); /* init sequence */ DDS_SEQ_INIT(array); assert(NULL != (DDS_SEQ_DATA(array) = malloc(_test_size * sizeof(char)))); DDS_SEQ_LENGTH(array) = DDS_SEQ_MAXIMUM(array) = _test_size; for (i = 0; i < _test_size; i++) { DDS_SEQ_ITEM(array, i) = i & 0xff; } assert(QEO_OK == qeocore_data_get_member(data, _buf_id, &seqdata)); assert(QEO_OK == qeocore_data_sequence_set(seqdata, (const qeo_sequence_t *)&array, 0)); assert(QEO_OK == qeocore_data_set_member(data, _buf_id, &seqdata)); /* write */ assert(QEO_OK == qeocore_writer_write(writer, data)); log_pid("writer wrote data"); assert(peer == waitpid(peer, &status, 0)); assert(0 == status); log_pid("writer done"); /* clean up */ free(DDS_SEQ_DATA(array)); qeocore_data_free(seqdata); qeocore_data_free(data); qeocore_writer_close(writer); qeocore_type_free(type); qeocore_factory_close(factory); }
static qeo_retcode_t write_generated_data(qeocore_writer_t *writer, int arraysize){ org_qeo_dynamic_qdm_test_TypeWithStructs_t t = {}; size_t i, j; qeo_retcode_t rc = QEO_EFAIL; int stringsize = 10; t.mfloat32 = 32; t.mstring = "asdfdfasdfqwreqwrqwdfadfadsfadfd"; DDS_SEQ_INIT(t.msubstruct3); org_qeo_dynamic_qdm_test_Substruct3_t ss3[arraysize]; char strings[arraysize][arraysize+2][stringsize]; for (i = 0; i < arraysize; ++i) { ss3[i].msubfloat = i; ss3[i].msubstring = str_random(strings[i][0], stringsize); DDS_SEQ_INIT(ss3[i].msubstruct2); org_qeo_dynamic_qdm_test_Substruct2_t ss2[arraysize]; for (j = 0; j < arraysize; ++j) { ss2[j].msubshort = j*i; ss2[j].msubstring = str_random(strings[i][j+2], stringsize); } dds_seq_from_array(&ss3[i].msubstruct2, ss2, arraysize); } dds_seq_from_array(&t.msubstruct3, ss3, arraysize); DDS_SEQ_INIT(t.msubstruct1); org_qeo_dynamic_qdm_test_Substruct1_t ss1[arraysize]; for (i = 0; i < arraysize; ++i) { ss1[i].msubint32 = i; ss1[i].msubstring = str_random(strings[i][1], stringsize); } dds_seq_from_array(&t.msubstruct1, ss1, arraysize); rc = qeocore_writer_write(writer, &t); for(i = 0; i < DDS_SEQ_LENGTH(t.msubstruct3); ++i) { dds_seq_cleanup(&(DDS_SEQ_ITEM(t.msubstruct3, i).msubstruct2)); } dds_seq_cleanup(&t.msubstruct3); dds_seq_cleanup(&t.msubstruct1); return rc; }
void test_dyn_array1 (void) { DDS_DynamicTypeSupport ts; DDS_DynamicTypeBuilder sb, abc20; DDS_TypeDescriptor *desc; DDS_MemberDescriptor *md; DDS_DynamicType s, ac20; DDS_BoundSeq bounds; DDS_DynamicData dd, dda, dd2; DDS_ReturnCode_t rc; unsigned i; v_printf ("test_dyn_array1 - "); /* 1. Create the type. */ desc = DDS_TypeDescriptor__alloc (); fail_unless (desc != NULL); desc->kind = DDS_STRUCTURE_TYPE; desc->name = "dstruct1"; sb = DDS_DynamicTypeBuilderFactory_create_type (desc); fail_unless (sb != NULL); md = DDS_MemberDescriptor__alloc (); fail_unless (md != NULL); DDS_SEQ_INIT (bounds); dds_seq_require (&bounds, 1); DDS_SEQ_LENGTH (bounds) = 1; DDS_SEQ_ITEM (bounds, 0) = 20; abc20 = DDS_DynamicTypeBuilderFactory_create_array_type ( DDS_DynamicTypeBuilderFactory_get_primitive_type (DDS_CHAR_8_TYPE), &bounds); fail_unless (abc20 != NULL); dds_seq_cleanup (&bounds); ac20 = DDS_DynamicTypeBuilder_build (abc20); fail_unless (ac20 != NULL); DDS_DynamicTypeBuilderFactory_delete_type (abc20); md->name = "char_a"; md->index = md->id = 0; md->type = ac20; rc = DDS_DynamicTypeBuilder_add_member (sb, md); fail_unless (rc == DDS_RETCODE_OK); s = DDS_DynamicTypeBuilder_build (sb); fail_unless (s != NULL); DDS_DynamicTypeBuilderFactory_delete_type (sb); ts = DDS_DynamicTypeSupport_create_type_support (s); fail_unless (ts != NULL); DDS_TypeDescriptor__free (desc); DDS_MemberDescriptor__free (md); /* 2. Create a Dynamic Data item for this type. */ dd = DDS_DynamicDataFactory_create_data (s); fail_unless (dd != NULL); dda = DDS_DynamicDataFactory_create_data (ac20); fail_unless (dda != NULL); for (i = 0; i < 20; i++) { SET_FIELD (dda, i, char8, i + '0'); } SET_FIELD (dd, 0, complex, dda); marshallDynamic (dd, &dd2, ts); DDS_DynamicDataFactory_delete_data (dd); DDS_DynamicDataFactory_delete_data (dda); DDS_DynamicTypeBuilderFactory_delete_type (ac20); DDS_DynamicTypeBuilderFactory_delete_type (s); DDS_DynamicTypeSupport_delete_type_support (ts); v_printf ("success!\r\n"); }
void test_dyn_oseq (void) { DDS_DynamicTypeSupport ts; DDS_DynamicTypeBuilder sb, oseqb; DDS_TypeDescriptor *desc; DDS_MemberDescriptor *md; DDS_DynamicType s, oseq; DDS_DynamicData dd, dda, dd2; DDS_ReturnCode_t rc; DDS_ByteSeq values; unsigned i; v_printf ("test_dyn_oseq - "); /* 1. Create the type. */ desc = DDS_TypeDescriptor__alloc (); fail_unless (desc != NULL); desc->kind = DDS_STRUCTURE_TYPE; desc->name = "dstruct3"; sb = DDS_DynamicTypeBuilderFactory_create_type (desc); fail_unless (sb != NULL); md = DDS_MemberDescriptor__alloc (); fail_unless (md != NULL); ADD_FIELD (sb, md, "anuint", 0, 0, DDS_UINT_32_TYPE); oseqb = DDS_DynamicTypeBuilderFactory_create_sequence_type ( DDS_DynamicTypeBuilderFactory_get_primitive_type (DDS_BYTE_TYPE), 0); fail_unless (oseqb != NULL); oseq = DDS_DynamicTypeBuilder_build (oseqb); fail_unless (oseq != NULL); DDS_DynamicTypeBuilderFactory_delete_type (oseqb); md->name = "oseq"; md->index = md->id = 1; md->type = oseq; rc = DDS_DynamicTypeBuilder_add_member (sb, md); fail_unless (rc == DDS_RETCODE_OK); ADD_FIELD (sb, md, "ch", 2, 2, DDS_CHAR_8_TYPE); s = DDS_DynamicTypeBuilder_build (sb); fail_unless (s != NULL); DDS_DynamicTypeBuilderFactory_delete_type (sb); ts = DDS_DynamicTypeSupport_create_type_support (s); fail_unless (ts != NULL); DDS_TypeDescriptor__free (desc); DDS_MemberDescriptor__free (md); /* 2. Create a Dynamic Data item for this type. */ dd = DDS_DynamicDataFactory_create_data (s); fail_unless (dd != NULL); dda = DDS_DynamicDataFactory_create_data (oseq); fail_unless (dda != NULL); SET_FIELD (dd, 0, uint32, 1000); DDS_SEQ_INIT (values); rc = dds_seq_require (&values, 21); fail_unless (rc == DDS_RETCODE_OK); for (i = 0; i < 21; i++) DDS_SEQ_ITEM (values, i) = i + '0'; rc = DDS_DynamicData_set_byte_values (dda, 0, &values); fail_unless (rc == DDS_RETCODE_OK); SET_FIELD (dd, 1, complex, dda); SET_FIELD (dd, 2, char8, 'X'); marshallDynamic (dd, &dd2, ts); DDS_DynamicDataFactory_delete_data (dd); DDS_DynamicDataFactory_delete_data (dda); DDS_DynamicTypeBuilderFactory_delete_type (oseq); DDS_DynamicTypeBuilderFactory_delete_type (s); DDS_DynamicTypeSupport_delete_type_support (ts); v_printf ("success!\r\n"); }
void test_dyn_array2 (void) { DDS_DynamicTypeSupport ts; DDS_DynamicTypeBuilder sb1, sb1a, abi64, abs1a; DDS_DynamicType s1, s1a, ai64, as1a; DDS_TypeDescriptor *desc; DDS_MemberDescriptor *md; DDS_DynamicData dd, dds, dda, ddas, dd2; DDS_ReturnCode_t rc; DDS_BoundSeq bounds; unsigned i, j; v_printf ("test_dyn_array2 - "); /* 1. Create the type. */ desc = DDS_TypeDescriptor__alloc (); fail_unless (desc != NULL); desc->kind = DDS_STRUCTURE_TYPE; desc->name = "dstruct2a"; sb1a = DDS_DynamicTypeBuilderFactory_create_type (desc); fail_unless (sb1a != NULL); md = DDS_MemberDescriptor__alloc (); fail_unless (md != NULL); DDS_SEQ_INIT (bounds); dds_seq_require (&bounds, 1); DDS_SEQ_LENGTH (bounds) = 1; DDS_SEQ_ITEM (bounds, 0) = 5; abi64 = DDS_DynamicTypeBuilderFactory_create_array_type ( DDS_DynamicTypeBuilderFactory_get_primitive_type (DDS_INT_64_TYPE), &bounds); fail_unless (abi64 != NULL); ai64 = DDS_DynamicTypeBuilder_build (abi64); fail_unless (ai64 != NULL); DDS_DynamicTypeBuilderFactory_delete_type (abi64); md->name = "i64"; md->index = md->id = 0; md->type = ai64; rc = DDS_DynamicTypeBuilder_add_member (sb1a, md); fail_unless (rc == DDS_RETCODE_OK); ADD_FIELD (sb1a, md, "ch", 1, 1, DDS_CHAR_8_TYPE); s1a = DDS_DynamicTypeBuilder_build (sb1a); fail_unless (s1a != NULL); DDS_DynamicTypeBuilderFactory_delete_type (sb1a); DDS_SEQ_ITEM (bounds, 0) = 7; abs1a = DDS_DynamicTypeBuilderFactory_create_array_type (s1a, &bounds); fail_unless (abs1a != NULL); dds_seq_cleanup (&bounds); as1a = DDS_DynamicTypeBuilder_build (abs1a); fail_unless (as1a != NULL); DDS_DynamicTypeBuilderFactory_delete_type (abs1a); desc->kind = DDS_STRUCTURE_TYPE; desc->name = "dstruct2"; sb1 = DDS_DynamicTypeBuilderFactory_create_type (desc); fail_unless (sb1 != NULL); ADD_FIELD (sb1, md, "c", 0, 0, DDS_CHAR_8_TYPE); md->name = "str2"; md->index = md->id = 1; md->type = as1a; rc = DDS_DynamicTypeBuilder_add_member (sb1, md); fail_unless (rc == DDS_RETCODE_OK); ADD_FIELD (sb1, md, "u16", 2, 2, DDS_UINT_16_TYPE); s1 = DDS_DynamicTypeBuilder_build (sb1); fail_unless (s1 != NULL); DDS_DynamicTypeBuilderFactory_delete_type (sb1); ts = DDS_DynamicTypeSupport_create_type_support (s1); fail_unless (ts != NULL); DDS_TypeDescriptor__free (desc); DDS_MemberDescriptor__free (md); /* 2. Create a Dynamic Data item for this type. */ dd = DDS_DynamicDataFactory_create_data (s1); fail_unless (dd != NULL); ddas = DDS_DynamicDataFactory_create_data (as1a); fail_unless (ddas != NULL); SET_FIELD (dd, 0, char8, 'A'); for (i = 0; i < 7; i++) { dds = DDS_DynamicDataFactory_create_data (s1a); fail_unless (dds != NULL); dda = DDS_DynamicDataFactory_create_data (ai64); fail_unless (dda != NULL); for (j = 0; j < 5; j++) { SET_FIELD (dda, j, int64, ((i + 6) * j) << i); } SET_FIELD (dds, 0, complex, dda); DDS_DynamicDataFactory_delete_data (dda); SET_FIELD (dds, 1, char8, i + 0x30); SET_FIELD (ddas, i, complex, dds); DDS_DynamicDataFactory_delete_data (dds); } SET_FIELD (dd, 1, complex, ddas); DDS_DynamicDataFactory_delete_data (ddas); SET_FIELD (dd, 2, uint16, 1366); marshallDynamic (dd, &dd2, ts); DDS_DynamicDataFactory_delete_data (dd); DDS_DynamicTypeBuilderFactory_delete_type (s1); DDS_DynamicTypeBuilderFactory_delete_type (as1a); DDS_DynamicTypeBuilderFactory_delete_type (s1a); DDS_DynamicTypeBuilderFactory_delete_type (ai64); DDS_DynamicTypeSupport_delete_type_support (ts); v_printf ("success!\r\n"); }
static qeocore_type_t *build_enum(const qeo_factory_t *factory, json_t *typedesc){ qeocore_type_t *qeoType = NULL; qeocore_enum_constants_t vals = DDS_SEQ_INITIALIZER(qeocore_enum_constant_t); const char *enumstr = NULL; DDS_ReturnCode_t ddsret; assert(typedesc != NULL); assert(factory != NULL); do { json_t *type_enum = json_object_get(typedesc, KEY_ENUM); if ((NULL == type_enum) || !json_is_string(type_enum)) { qeo_log_e("Invalid type_enum (%p)", type_enum); return qeoType; } json_t *values = json_object_get(typedesc, KEY_VALUES); if ((NULL == values) || !json_is_object(values)) { qeo_log_e("Invalid values (%p)", values); return qeoType; } enumstr = json_string_value(type_enum); //Replace all "::" with ".", because there's a mismatch in topic definitions found in the TSM structs, with "." and the QDM topic definitions with "::" find_and_replace((char *) enumstr, "::", "."); if ((ddsret = dds_seq_require(&vals, json_object_size(values))) != DDS_RETCODE_OK){ qeo_log_e("dds_seq_require failed (%d)", ddsret); return NULL; } void *iter = json_object_iter(values); while (iter) { json_int_t labelint; const char *name = json_object_iter_key(iter); json_t *label = json_object_iter_value(iter); if (!json_is_integer(label)){ qeo_log_e("not a integer"); } labelint = json_integer_value(label); if (labelint >= json_object_size(values)){ qeo_log_e("Currently we only support 0,1,2..[n-1] as labels"); break; } DDS_SEQ_ITEM(vals, labelint).name = (char *)name; iter = json_object_iter_next(values, iter); } qeoType = qeocore_type_enum_new(enumstr, &vals); if (qeoType == NULL){ qeo_log_e("Cannot register enum"); } dds_seq_cleanup(&vals); } while(0); return qeoType; }
void dr_listener_data_available (DDS_DataReaderListener *list, DDS_DataReader dr) { MsgData_t *data; types_t *datax; static DDS_DataSeq rx_sample = DDS_SEQ_INITIALIZER (void *); static DDS_SampleInfoSeq rx_info = DDS_SEQ_INITIALIZER (DDS_SampleInfo *); DDS_ReturnCode_t error; DDS_SampleInfo *info; DDS_DataReader_return_loan (dr, &rx_sample, &rx_info); error = DDS_DataReader_take_next_instance(dr, &rx_sample, &rx_info, 1, DDS_HANDLE_NIL, DDS_NOT_READ_SAMPLE_STATE, DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE); printf ("dds-interop: Take next instance.\r\n"); if (error) printf ("Error taking next instance\r\n"); /* === print sample === */ if (DDS_SEQ_LENGTH (rx_info)) { data = DDS_SEQ_ITEM (rx_sample, 0); datax = DDS_SEQ_ITEM (rx_sample, 0); info = DDS_SEQ_ITEM (rx_info, 0); if (info->instance_state == DDS_ALIVE_INSTANCE_STATE) { if (tsm_type == 0) printf ("DDS-R: [%2u] ALIVE - %2u :%6llu - %s\r\n", info->instance_handle, data->key, (unsigned long long) data->counter, data->message); else printf ("DDS-R: [%2u] ALIVE - %2u - %s\r\n", info->instance_handle, datax->i8, datax->string); if (test == 3) sem_post (&_sync); } else if (info->instance_state == DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE) { if (tsm_type == 0) printf ("DDS-R: The sample %s with key (%d) has been disposed.\r\n", data->message, data->key); else printf ("DDS-R: The sample has been disposed.\r\n", datax->string); if (test == 3) sem_post (&_sync); } else if (info->instance_state == DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) { printf ("DDS-R: There are no more writers.\r\n"); if (test == 3) sem_post (&_sync); } else printf ("DDS-R: Unknown state.\r\n"); } DDS_DataReader_return_loan (dr, &rx_sample, &rx_info); }
static void test_qos (int enabled) { DDS_DomainParticipantFactoryQos qos; DDS_DomainParticipant p; DDS_Publisher pub; DDS_Subscriber sub; DDS_DataWriter dw; DDS_DataReader dr; DDS_Topic t; DDS_TopicDescription td; DDS_SubscriberQos psq, refsq; DDS_ReturnCode_t r; static char *buf [] = { "Hello", "World" }; static unsigned char data [] = { 0x77, 0x88, 0xaa, 0xbb, 0xcc }; unsigned char d2 [sizeof (data) + 1]; unsigned n; size_t i; int err; v_printf (" - Set factory QoS to %sabled.\r\n", (enabled) ? "en" : "dis"); r = DDS_DomainParticipantFactory_get_qos (&qos); fail_unless (r == DDS_RETCODE_OK); qos.entity_factory.autoenable_created_entities = enabled; r = DDS_DomainParticipantFactory_set_qos (&qos); fail_unless (r == DDS_RETCODE_OK); p = DDS_DomainParticipantFactory_create_participant (1, DDS_PARTICIPANT_QOS_DEFAULT, NULL, 0); fail_unless (p != NULL); r = register_HelloWorldData_type (p); fail_unless (r == DDS_RETCODE_OK); DDS_SubscriberQos__init (&refsq); for (i = 0; (size_t) i < sizeof (buf) / sizeof (char *); i++) { err = dds_seq_append (&refsq.partition.name, &buf [i]); fail_unless (err == 0); } err = dds_seq_from_array (&refsq.group_data, data, sizeof (data)); fail_unless (err == 0); v_printf (" - Create subscriber with specific QoS parameters.\r\n"); sub = DDS_DomainParticipant_create_subscriber (p, &refsq, NULL, 0); fail_unless (sub != NULL); memset (&psq, 0, sizeof (psq)); r = DDS_Subscriber_get_qos (sub, &psq); fail_unless (r == DDS_RETCODE_OK && DDS_SEQ_LENGTH (refsq.partition.name) == DDS_SEQ_LENGTH (psq.partition.name) && DDS_SEQ_LENGTH (refsq.group_data.value) == sizeof (data)); DDS_SEQ_FOREACH (refsq.partition.name, i) fail_unless (!strcmp (DDS_SEQ_ITEM (psq.partition.name, i), DDS_SEQ_ITEM (refsq.partition.name, i))); n = dds_seq_to_array (&psq.group_data, d2, sizeof (d2)); fail_unless (n == sizeof (data) && !memcmp (data, d2, sizeof (data))); DDS_SubscriberQos__clear (&psq); r = DDS_DomainParticipant_delete_subscriber (p, sub); fail_unless (r == DDS_RETCODE_OK); v_printf (" - Create topic/publisher/writer/subscriber/reader entities.\r\n"); t = DDS_DomainParticipant_create_topic (p, "HelloWorld", TYPE_NAME, DDS_TOPIC_QOS_DEFAULT, NULL, 0); fail_unless (t != NULL); td = DDS_DomainParticipant_lookup_topicdescription (p, "HelloWorld"); fail_unless (td != NULL); pub = DDS_DomainParticipant_create_publisher (p, DDS_PUBLISHER_QOS_DEFAULT, NULL, 0); fail_unless (pub != NULL); dw = DDS_Publisher_create_datawriter (pub, t, DDS_DATAWRITER_QOS_DEFAULT, NULL, 0); fail_unless (dw != NULL); sub = DDS_DomainParticipant_create_subscriber (p, DDS_SUBSCRIBER_QOS_DEFAULT, NULL, 0); fail_unless (sub != NULL); dr = DDS_Subscriber_create_datareader (sub, td, DDS_DATAREADER_QOS_DEFAULT, NULL, 0); fail_unless (dr != NULL); v_printf (" - Update subscriber QoS.\r\n"); r = DDS_Subscriber_get_qos (sub, &psq); fail_unless (r == DDS_RETCODE_OK); DDS_SubscriberQos__clear (&refsq); fail_unless (r == DDS_RETCODE_OK && !memcmp (&psq, &refsq, sizeof (refsq))); for (i = 0; (size_t) i < sizeof (buf) / sizeof (char *); i++) { err = dds_seq_append (&refsq.partition.name, &buf [i]); fail_unless (err == 0); } err = dds_seq_from_array (&refsq.group_data, data, sizeof (data)); fail_unless (err == 0); r = DDS_Subscriber_set_qos (sub, &refsq); fail_unless (r == DDS_RETCODE_OK); delay (); r = DDS_Subscriber_get_qos (sub, &psq); fail_unless (r == DDS_RETCODE_OK && DDS_SEQ_LENGTH (refsq.partition.name) == DDS_SEQ_LENGTH (psq.partition.name) && DDS_SEQ_LENGTH (psq.group_data.value) == sizeof (data)); DDS_SEQ_FOREACH (psq.partition.name, i) fail_unless (!strcmp (DDS_SEQ_ITEM (psq.partition.name, i), DDS_SEQ_ITEM (refsq.partition.name, i))); n = dds_seq_to_array (&psq.group_data, d2, sizeof (d2)); fail_unless (n == sizeof (data) && !memcmp (data, d2, sizeof (data))); DDS_SubscriberQos__clear (&refsq); DDS_SubscriberQos__clear (&psq); delay (); if (!enabled) { v_printf (" - Enable child entities.\r\n"); r = DDS_DomainParticipant_enable (p); fail_unless (r == DDS_RETCODE_OK); r = DDS_Topic_enable (t); fail_unless (r == DDS_RETCODE_OK); r = DDS_Publisher_enable (pub); fail_unless (r == DDS_RETCODE_OK); r = DDS_Subscriber_enable (sub); fail_unless (r == DDS_RETCODE_OK); r = DDS_DataWriter_enable (dw); fail_unless (r == DDS_RETCODE_OK); r = DDS_DataReader_enable (dr); fail_unless (r == DDS_RETCODE_OK); sleep (1); } v_printf (" - Delete child entities.\r\n"); r = DDS_Publisher_delete_datawriter (pub, dw); fail_unless (r == DDS_RETCODE_OK); r = DDS_Subscriber_delete_datareader (sub, dr); fail_unless (r == DDS_RETCODE_OK); r = DDS_DomainParticipant_delete_publisher (p, pub); fail_unless (r == DDS_RETCODE_OK); r = DDS_DomainParticipant_delete_subscriber (p, sub); fail_unless (r == DDS_RETCODE_OK); r = DDS_DomainParticipant_delete_topic (p, t); fail_unless (r == DDS_RETCODE_OK); unregister_HelloWorldData_type (p); r = DDS_DomainParticipantFactory_delete_participant (p); fail_unless (r == DDS_RETCODE_OK); }