void init_types(void) { ts = ChatMsg_type_new (); if (!ts) { printf ("Can't create chat message type!\r\n"); exit (1); } error = DDS_DynamicTypeSupport_register_type (ts, part, "ChatMsg"); if (error) { printf ("Can't register chat message type.\r\n"); exit (1); } if (verbose) printf ("DDS Topic type ('%s') registered.\r\n", "ChatMsg"); topic = DDS_DomainParticipant_create_topic (part, "Chat", "ChatMsg", NULL, NULL, 0); if (!topic) { printf ("Can't register chat message type.\r\n"); exit (1); } if (verbose) printf ("DDS ChatMsg Topic created.\r\n"); td = DDS_DomainParticipant_lookup_topicdescription (part, "Chat"); if (!td) { printf ("Can't get topicdescription.\r\n"); exit (1); } }
static void test_aux (void) { DDS_DomainParticipant p; DDS_Topic t; DDS_TopicDescription td; DDS_Subscriber sub, nsub; DDS_DataReader dr; DDS_StatusCondition sc, sc2; DDS_StatusMask sm; DDS_InstanceHandle_t h, h2; DDS_Duration_t w; DDS_LivelinessChangedStatus lcs; DDS_RequestedDeadlineMissedStatus dms; DDS_RequestedIncompatibleQosStatus iqs; DDS_SampleLostStatus sls; DDS_SampleRejectedStatus srs; DDS_SubscriptionMatchedStatus sms; DDS_InstanceHandleSeq handles; DDS_ReturnCode_t r; p = DDS_DomainParticipantFactory_create_participant (0, DDS_PARTICIPANT_QOS_DEFAULT, NULL, 0); fail_unless (p != NULL); r = register_HelloWorldData_type (p); fail_unless (r == DDS_RETCODE_OK); 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); sub = DDS_DomainParticipant_create_subscriber (p, DDS_SUBSCRIBER_QOS_DEFAULT, NULL, 0); fail_unless (sub != NULL); v_printf (" - Test reader auxiliary functions.\r\n"); dr = DDS_Subscriber_create_datareader (sub, td, DDS_DATAREADER_QOS_DEFAULT, NULL, 0); fail_unless (dr != NULL); sc = DDS_DataReader_get_statuscondition (dr); fail_unless (sc != NULL); sc2 = DDS_Entity_get_statuscondition (dr); fail_unless (sc2 == sc); sm = DDS_DataReader_get_status_changes (dr); fail_unless (sm == 0); sm = DDS_Entity_get_status_changes (dr); fail_unless (sm == 0); h = DDS_Entity_get_instance_handle (dr); fail_unless (h != 0); h2 = DDS_DataReader_get_instance_handle (dr); fail_unless (h == h2); r = DDS_DataReader_get_liveliness_changed_status (dr, &lcs); fail_unless (r == DDS_RETCODE_OK); r = DDS_DataReader_get_requested_deadline_missed_status (dr, &dms); fail_unless (r == DDS_RETCODE_OK); r = DDS_DataReader_get_requested_incompatible_qos_status (dr, &iqs); fail_unless (r == DDS_RETCODE_OK); r = DDS_DataReader_get_sample_lost_status (dr, &sls); fail_unless (r == DDS_RETCODE_OK); r = DDS_DataReader_get_sample_rejected_status (dr, &srs); fail_unless (r == DDS_RETCODE_OK); r = DDS_DataReader_get_subscription_matched_status (dr, &sms); fail_unless (r == DDS_RETCODE_OK); td = DDS_DataReader_get_topicdescription (dr); fail_unless ((DDS_Topic) td == t); nsub = DDS_DataReader_get_subscriber (dr); fail_unless (nsub == sub); w.sec = 2; w.nanosec = 0; r = DDS_DataReader_wait_for_historical_data (dr, &w); fail_unless (r == DDS_RETCODE_OK); DDS_InstanceHandleSeq__init (&handles); r = DDS_DataReader_get_matched_publications (dr, &handles); fail_unless (r == DDS_RETCODE_OK); DDS_InstanceHandleSeq__clear (&handles); r = DDS_Subscriber_delete_datareader (sub, dr); 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); }
static void test_listener (void) { DDS_DomainParticipant p; DDS_Topic t; DDS_TopicDescription td; DDS_Subscriber sub; DDS_DataReader dr; DDS_DataReaderListener *lp; DDS_ReturnCode_t r; p = DDS_DomainParticipantFactory_create_participant (0, DDS_PARTICIPANT_QOS_DEFAULT, NULL, 0); fail_unless (p != NULL); r = register_HelloWorldData_type (p); fail_unless (r == DDS_RETCODE_OK); 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); sub = DDS_DomainParticipant_create_subscriber (p, DDS_SUBSCRIBER_QOS_DEFAULT, NULL, 0); fail_unless (sub != NULL); v_printf (" - Test reader listener.\r\n"); dr = DDS_Subscriber_create_datareader (sub, td, DDS_DATAREADER_QOS_DEFAULT, NULL, 0); fail_unless (dr != NULL); lp = DDS_DataReader_get_listener (dr); fail_unless (lp != NULL && lp->on_sample_rejected == NULL && lp->on_liveliness_changed == NULL && lp->on_requested_deadline_missed == NULL && lp->on_requested_incompatible_qos == NULL && lp->on_data_available == NULL && lp->on_subscription_matched == NULL && lp->on_sample_lost == NULL); v_printf (" - Test specific reader listener updates.\r\n"); r = DDS_DataReader_set_listener (dr, &r_listener, DDS_SAMPLE_REJECTED_STATUS | DDS_LIVELINESS_CHANGED_STATUS | DDS_REQUESTED_DEADLINE_MISSED_STATUS | DDS_REQUESTED_INCOMPATIBLE_QOS_STATUS | DDS_DATA_AVAILABLE_STATUS | DDS_SUBSCRIPTION_MATCHED_STATUS | DDS_SAMPLE_LOST_STATUS); fail_unless (r == DDS_RETCODE_OK); lp = DDS_DataReader_get_listener (dr); fail_unless (lp != NULL && lp->on_sample_rejected == sample_rejected && lp->on_liveliness_changed == liveliness_changed && lp->on_requested_deadline_missed == requested_deadline_missed && lp->on_requested_incompatible_qos == requested_inc_qos && lp->on_data_available == data_available && lp->on_subscription_matched == subscription_matched && lp->on_sample_lost == sample_lost && lp->cookie == (void *) 0x44556677); v_printf (" - Test default reader listener update.\r\n"); r = DDS_DataReader_set_listener (dr, NULL, DDS_REQUESTED_DEADLINE_MISSED_STATUS); fail_unless (r == DDS_RETCODE_OK); lp = DDS_DataReader_get_listener (dr); fail_unless (lp != NULL && lp->on_sample_rejected == NULL && lp->on_liveliness_changed == NULL && lp->on_requested_deadline_missed == NULL && lp->on_requested_incompatible_qos == NULL && lp->on_data_available == NULL && lp->on_subscription_matched == NULL && lp->on_sample_lost == NULL); r = DDS_Subscriber_delete_datareader (sub, dr); 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); }
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_DataReaderQos rq, refrq; DDS_ReturnCode_t r; static unsigned char data [] = { 0x77, 0x88, 0xaa, 0xbb, 0xcc, 0xdd }; unsigned char d2 [sizeof (data) + 1]; unsigned n; 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 (0, DDS_PARTICIPANT_QOS_DEFAULT, NULL, 0); fail_unless (p != NULL); r = register_HelloWorldData_type (p); fail_unless (r == DDS_RETCODE_OK); 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); sub = DDS_DomainParticipant_create_subscriber (p, NULL, NULL, 0); fail_unless (sub != NULL); DDS_DataReaderQos__init (&refrq); err = dds_seq_from_array (&refrq.user_data, data, sizeof (data)); fail_unless (err == 0); v_printf (" - Create datareader with specific QoS parameters.\r\n"); dr = DDS_Subscriber_create_datareader (sub, td, &refrq, NULL, 0); fail_unless (dr != NULL); memset (&rq, 0, sizeof (rq)); r = DDS_DataReader_get_qos (dr, &rq); n = dds_seq_to_array (&rq.user_data, d2, sizeof (d2)); fail_unless (r == DDS_RETCODE_OK && DDS_SEQ_LENGTH (refrq.user_data.value) == sizeof (data)); n = dds_seq_to_array (&rq.user_data, d2, sizeof (d2)); fail_unless (n == sizeof (data) && !memcmp (data, d2, sizeof (data))); DDS_DataReaderQos__clear (&rq); r = DDS_Subscriber_delete_datareader (sub, dr); fail_unless (r == DDS_RETCODE_OK); v_printf (" - Create datareader with default QoS parameters.\r\n"); dr = DDS_Subscriber_create_datareader (sub, td, DDS_DATAREADER_QOS_DEFAULT, NULL, 0); fail_unless (dr != NULL); pub = DDS_DomainParticipant_create_publisher (p, DDS_PUBLISHER_QOS_DEFAULT, NULL, 0); fail_unless (sub != NULL); dw = DDS_Publisher_create_datawriter (pub, t, DDS_DATAWRITER_QOS_DEFAULT, NULL, 0); fail_unless (dw != NULL); v_printf (" - Update datareader QoS parameters.\r\n"); r = DDS_DataReader_get_qos (dr, &rq); fail_unless (r == DDS_RETCODE_OK); DDS_DataReaderQos__clear (&refrq); fail_unless (r == DDS_RETCODE_OK && !memcmp (&rq, &refrq, sizeof (refrq))); err = dds_seq_from_array (&refrq.user_data, data, sizeof (data)); fail_unless (err == 0); r = DDS_DataReader_set_qos (dr, &refrq); fail_unless (r == DDS_RETCODE_OK); delay (); r = DDS_DataReader_get_qos (dr, &rq); fail_unless (r == DDS_RETCODE_OK && DDS_SEQ_LENGTH (rq.user_data.value) == sizeof (data)); n = dds_seq_to_array (&rq.user_data, d2, sizeof (d2)); fail_unless (n == sizeof (data) && !memcmp (data, d2, sizeof (data))); DDS_DataReaderQos__clear (&refrq); DDS_DataReaderQos__clear (&rq); delay (); if (!enabled) { v_printf (" - Enable all 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); } 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); }
int main_subscriber (int argc, const char **argv) { DDS_DataWriterQos wr_qos; DDS_DataReaderQos rd_qos; DDS_ReturnCode_t error; sprintf (user_name, ".pid.%u", getpid ()); DDS_entity_name ("Technicolor Chatroom"); #ifdef DDS_SECURITY if (cert_path || key_path || engine_id) enable_security (); #endif part = DDS_DomainParticipantFactory_create_participant (domain_id, NULL, NULL, 0); if (!part) { printf ("Can't create participant!\r\n"); exit (1); } if (verbose) printf ("DDS Domain Participant created.\r\n"); ts = Vector3_type_new (); if (!ts) { printf ("Can't create vector3 message type!\r\n"); exit (1); } error = DDS_DynamicTypeSupport_register_type (ts, part, "simple_msgs::dds_::Vector3_"); if (error) { printf ("Can't register vector3 message type.\r\n"); exit (1); } if (verbose) printf ("DDS Topic type ('%s') registered.\r\n", "simple_msgs::dds_::Vector3_"); topic = DDS_DomainParticipant_create_topic (part, "imu", "simple_msgs::dds_::Vector3_", NULL, NULL, 0); if (!topic) { printf ("Can't register vector3 message type.\r\n"); exit (1); } if (verbose) printf ("DDS Vector3 Topic created.\r\n"); td = DDS_DomainParticipant_lookup_topicdescription (part, "imu"); if (!td) { printf ("Can't get topicdescription.\r\n"); exit (1); } pub = DDS_DomainParticipant_create_publisher (part, NULL, NULL, 0); if (!pub) { printf ("DDS_DomainParticipant_create_publisher () failed!\r\n"); exit (1); } DDS_Publisher_get_default_datawriter_qos (pub, &wr_qos); #ifdef TRANSIENT_LOCAL wr_qos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS; #endif #ifdef RELIABLE wr_qos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS; #endif #ifdef KEEP_ALL wr_qos.history.kind = DDS_KEEP_ALL_HISTORY_QOS; wr_qos.history.depth = DDS_LENGTH_UNLIMITED; wr_qos.resource_limits.max_samples_per_instance = HISTORY; wr_qos.resource_limits.max_instances = HISTORY * 10; wr_qos.resource_limits.max_samples = HISTORY * 4; #else wr_qos.history.kind = DDS_KEEP_LAST_HISTORY_QOS; wr_qos.history.depth = HISTORY; #endif /* Create a Data Writer. */ dw = DDS_Publisher_create_datawriter (pub, topic, &wr_qos, NULL, 0); if (!dw) { printf ("Unable to create vector3 message writer.\r\n"); exit (1); } if (verbose) printf ("DDS Vector3 message writer created.\r\n"); sub = DDS_DomainParticipant_create_subscriber (part, NULL, NULL, 0); if (!sub) { printf ("DDS_DomainParticipant_create_subscriber () returned an error!\r\n"); exit (1); } if (verbose) printf ("DDS Subscriber created.\r\n"); DDS_Subscriber_get_default_datareader_qos (sub, &rd_qos); #ifdef TRANSIENT_LOCAL rd_qos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS; #endif #ifdef RELIABLE rd_qos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS; #endif #ifdef KEEP_ALL rd_qos.history.kind = DDS_KEEP_ALL_HISTORY_QOS; rd_qos.history.depth = DDS_LENGTH_UNLIMITED; rd_qos.resource_limits.max_samples_per_instance = HISTORY; rd_qos.resource_limits.max_instances = HISTORY * 10; rd_qos.resource_limits.max_samples = HISTORY * 4; #else rd_qos.history.kind = DDS_KEEP_LAST_HISTORY_QOS; rd_qos.history.depth = HISTORY; #endif dr = DDS_Subscriber_create_datareader (sub, td, &rd_qos, #ifndef WAITSETS &msg_listener, DDS_DATA_AVAILABLE_STATUS); #else NULL, 0); #endif if (!dr) { printf ("DDS_DomainParticipant_create_datareader () returned an error!\r\n"); exit (1); } if (verbose) printf ("DDS Vector message reader created.\r\n"); #ifdef WAITSETS start_imu_reader (dr); #endif // publisher thread //thread_create (rt2, dds_send_imu, dr); // DDS Debug shell thread do_dds_shell (dw); #ifdef WAITSETS stop_imu_reader (dr); #endif DDS_Publisher_delete_datawriter (pub, dw); usleep (200000); error = DDS_DomainParticipant_delete_contained_entities (part); if (verbose) printf ("DDS Entities deleted (error = %u).\r\n", error); Vector3_type_free (ts); if (verbose) printf ("Vector3 Type deleted.\r\n"); error = DDS_DomainParticipantFactory_delete_participant (part); if (verbose) printf ("DDS Participant deleted (error = %u).\r\n", error); #ifdef DDS_SECURITY if (cert_path || key_path || engine_id) cleanup_security (); #endif return (0); }
int main (int argc, char *argv []) { int domain_id = 128; DDS_ReturnCode_t error; do_switches (argc, argv); #ifdef DDS_DEBUG DDS_Debug_start (); #endif DDS_set_generate_callback (calculate_member_id); sem_init(&_sync, 0, 0); part = DDS_DomainParticipantFactory_create_participant (domain_id, NULL, NULL, 0); if (!part) fatal ("DDS_DomainParticipantFactory_create_participant () failed!"); if (tsm_type == 0) { error = register_HelloWorldData_type (part); if (error) { DDS_DomainParticipantFactory_delete_participant (part); fatal ("DDS_DomainParticipant_register_type ('HelloWorldData') failed (%s)!", DDS_error (error)); } sm = DDS_INCONSISTENT_TOPIC_STATUS; topic = DDS_DomainParticipant_create_topic (part, "HelloWorld", "HelloWorldData", NULL, NULL, sm); if (!topic) { DDS_DomainParticipantFactory_delete_participant (part); fatal ("DDS_DomainParticipant_create_topic ('HelloWorld') failed!"); } topic_desc = DDS_DomainParticipant_lookup_topicdescription (part, "HelloWorld"); if (!topic_desc) { DDS_DomainParticipantFactory_delete_participant (part); fatal ("Unable to create topic description for 'HelloWorld'!"); } } else { _tsm_types[0].flags |= TSMFLAG_KEY; error = register_TestType_type (part); if (error) { DDS_DomainParticipantFactory_delete_participant (part); fatal ("DDS_DomainParticipant_register_type ('HelloWorldData') failed (%s)!", DDS_error (error)); } sm = DDS_INCONSISTENT_TOPIC_STATUS; topic = DDS_DomainParticipant_create_topic (part, _tsm_types->name, _tsm_types->name, NULL, NULL, sm); if (!topic) { DDS_DomainParticipantFactory_delete_participant (part); fatal ("DDS_DomainParticipant_create_topic ('%s') failed!", _tsm_types->name); } topic_desc = DDS_DomainParticipant_lookup_topicdescription (part, _tsm_types->name); if (!topic_desc) { DDS_DomainParticipantFactory_delete_participant (part); fatal ("Unable to create topic description for '%s'!", _tsm_types->name); } } if (test == 3) { /* interop test */ make_state_reader (); make_state_writer (key); } else { if (reader) make_state_reader (); if (writer) make_state_writer (key); } if (reader) remove_state_reader (); if (writer) remove_state_writer (); if (test == 3) { remove_state_reader (); remove_state_writer (); } error = DDS_DomainParticipant_delete_topic (part, topic); if (error) fatal ("DDS_DomainParticipant_delete_topic () failed (%s)!", DDS_error (error)); free_HelloWorldData_type (part); error = DDS_DomainParticipant_delete_contained_entities (part); if (error) fatal ("DDS_DomainParticipant_delete_contained_entities () failed (%s)!", DDS_error (error)); error = DDS_DomainParticipantFactory_delete_participant (part); if (error) fatal ("DDS_DomainParticipantFactory_delete_participant () failed (%s)!", DDS_error (error)); return (0); }
int dds_chat_main(int argc, char *argv[]) #endif { DDS_DataWriterQos wr_qos; DDS_DataReaderQos rd_qos; DDS_ReturnCode_t error; struct in_addr addr; /* Configure the network */ /* Set up our host address */ addr.s_addr = HTONL(CONFIG_EXAMPLES_UDP_IPADDR); netlib_sethostaddr("eth0", &addr); /* Set up the default router address */ addr.s_addr = HTONL(CONFIG_EXAMPLES_UDP_DRIPADDR); netlib_setdraddr("eth0", &addr); /* Setup the subnet mask */ addr.s_addr = HTONL(CONFIG_EXAMPLES_UDP_NETMASK); netlib_setnetmask("eth0", &addr); /* Start the application */ printf("Network configured, starting DDS chat:\n"); sprintf (user_name, ".pid.%u", getpid ()); do_switches (argc, argv); if (verbose > 1) DDS_Log_stdio (1); DDS_entity_name ("ROS 2.0 embedded"); #ifdef DDS_SECURITY if (cert_path || key_path || engine_id) enable_security (); #endif part = DDS_DomainParticipantFactory_create_participant (domain_id, NULL, NULL, 0); if (!part) { printf ("Can't create participant!\r\n"); exit (1); } if (verbose) printf ("DDS Domain Participant created.\r\n"); ts = ChatMsg_type_new (); if (!ts) { printf ("Can't create chat message type!\r\n"); exit (1); } error = DDS_DynamicTypeSupport_register_type (ts, part, "ChatMsg"); if (error) { printf ("Can't register chat message type.\r\n"); exit (1); } if (verbose) printf ("DDS Topic type ('%s') registered.\r\n", "ChatMsg"); topic = DDS_DomainParticipant_create_topic (part, "Chat", "ChatMsg", NULL, NULL, 0); if (!topic) { printf ("Can't register chat message type.\r\n"); exit (1); } if (verbose) printf ("DDS ChatMsg Topic created.\r\n"); td = DDS_DomainParticipant_lookup_topicdescription (part, "Chat"); if (!td) { printf ("Can't get topicdescription.\r\n"); exit (1); } pub = DDS_DomainParticipant_create_publisher (part, NULL, NULL, 0); if (!pub) { printf ("DDS_DomainParticipant_create_publisher () failed!\r\n"); exit (1); } DDS_Publisher_get_default_datawriter_qos (pub, &wr_qos); #ifdef TRANSIENT_LOCAL wr_qos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS; #endif #ifdef RELIABLE wr_qos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS; #endif #ifdef KEEP_ALL wr_qos.history.kind = DDS_KEEP_ALL_HISTORY_QOS; wr_qos.history.depth = DDS_LENGTH_UNLIMITED; wr_qos.resource_limits.max_samples_per_instance = HISTORY; wr_qos.resource_limits.max_instances = HISTORY * 10; wr_qos.resource_limits.max_samples = HISTORY * 4; #else wr_qos.history.kind = DDS_KEEP_LAST_HISTORY_QOS; wr_qos.history.depth = HISTORY; #endif /* Create a Data Writer. */ dw = DDS_Publisher_create_datawriter (pub, topic, &wr_qos, NULL, 0); if (!dw) { printf ("Unable to create chat message writer.\r\n"); exit (1); } if (verbose) printf ("DDS Chat message writer created.\r\n"); sub = DDS_DomainParticipant_create_subscriber (part, NULL, NULL, 0); if (!sub) { printf ("DDS_DomainParticipant_create_subscriber () returned an error!\r\n"); exit (1); } if (verbose) printf ("DDS Subscriber created.\r\n"); DDS_Subscriber_get_default_datareader_qos (sub, &rd_qos); #ifdef TRANSIENT_LOCAL rd_qos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS; #endif #ifdef RELIABLE rd_qos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS; #endif #ifdef KEEP_ALL rd_qos.history.kind = DDS_KEEP_ALL_HISTORY_QOS; rd_qos.history.depth = DDS_LENGTH_UNLIMITED; rd_qos.resource_limits.max_samples_per_instance = HISTORY; rd_qos.resource_limits.max_instances = HISTORY * 10; rd_qos.resource_limits.max_samples = HISTORY * 4; #else rd_qos.history.kind = DDS_KEEP_LAST_HISTORY_QOS; rd_qos.history.depth = HISTORY; #endif dr = DDS_Subscriber_create_datareader (sub, td, &rd_qos, #ifndef WAITSETS &msg_listener, DDS_DATA_AVAILABLE_STATUS); #else NULL, 0); #endif if (!dr) { printf ("DDS_DomainParticipant_create_datareader () returned an error!\r\n"); exit (1); } if (verbose) printf ("DDS Chat message reader created.\r\n"); #ifdef WAITSETS start_chat_reader (dr); #endif do_chat (dw); #ifdef WAITSETS stop_chat_reader (dr); #endif DDS_Publisher_delete_datawriter (pub, dw); usleep (200000); error = DDS_DomainParticipant_delete_contained_entities (part); if (verbose) printf ("DDS Entities deleted (error = %u).\r\n", error); ChatMsg_type_free (ts); if (verbose) printf ("Chat Type deleted.\r\n"); error = DDS_DomainParticipantFactory_delete_participant (part); if (verbose) printf ("DDS Participant deleted (error = %u).\r\n", error); #ifdef DDS_SECURITY if (cert_path || key_path || engine_id) cleanup_security (); #endif return (0); }
static void test_aux (void) { DDS_DomainParticipant np, p; DDS_Subscriber sub; DDS_Topic t; DDS_TopicDescription td; DDS_DataReader dr, dr0, dr1; DDS_StatusCondition sc, sc2; DDS_StatusMask sm; DDS_InstanceHandle_t h, h2; DDS_DataReaderQos drq; DDS_ReturnCode_t r; v_printf (" - Test auxiliary subscriber functions.\r\n"); p = DDS_DomainParticipantFactory_create_participant (1, DDS_PARTICIPANT_QOS_DEFAULT, NULL, 0); fail_unless (p != NULL); sub = DDS_DomainParticipant_create_subscriber (p, DDS_SUBSCRIBER_QOS_DEFAULT, NULL, 0); fail_unless (sub != NULL); sc = DDS_Subscriber_get_statuscondition (sub); fail_unless (sc != NULL); sc2 = DDS_Entity_get_statuscondition (sub); fail_unless (sc2 != NULL); sm = DDS_Subscriber_get_status_changes (sub); fail_unless (sm == 0); sm = DDS_Entity_get_status_changes (sub); fail_unless (sm == 0); /*dbg_printf ("(mask=%u)", sm);*/ h = DDS_Subscriber_get_instance_handle (sub); fail_unless (h != 0); h2 = DDS_Entity_get_instance_handle (sub); fail_unless (h == h2); np = DDS_Subscriber_get_participant (sub); fail_unless (np == p); r = register_HelloWorldData_type (p); fail_unless (r == DDS_RETCODE_OK); 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); dr0 = DDS_Subscriber_create_datareader (sub, td, DDS_DATAREADER_QOS_DEFAULT, NULL, 0); fail_unless (dr0 != NULL); dr = DDS_Subscriber_lookup_datareader (sub, "HelloWorld"); fail_unless (dr == dr0); dr1 = DDS_Subscriber_create_datareader (sub, td, DDS_DATAREADER_QOS_DEFAULT, NULL, 0); fail_unless (dr1 != NULL); delay (); r = DDS_Subscriber_delete_contained_entities (sub); fail_unless (r == DDS_RETCODE_OK); v_printf (" - Test default child QoS of subscriber entities\r\n"); r = DDS_Subscriber_get_default_datareader_qos (sub, &drq); fail_unless (r == DDS_RETCODE_OK); drq.ownership.kind = DDS_EXCLUSIVE_OWNERSHIP_QOS; r = DDS_Subscriber_set_default_datareader_qos (sub, &drq); fail_unless (r == DDS_RETCODE_OK); dr1 = DDS_Subscriber_create_datareader (sub, td, DDS_DATAREADER_QOS_DEFAULT, NULL, 0); fail_unless (dr1 != NULL); delay (); v_printf (" - Test coherency (not implemented).\r\n"); r = DDS_Subscriber_begin_access (sub); fail_unless (r == DDS_RETCODE_UNSUPPORTED); r = DDS_Subscriber_end_access (sub); fail_unless (r == DDS_RETCODE_UNSUPPORTED); r = DDS_Subscriber_copy_from_topic_qos (sub, &drq, NULL); fail_unless (r == DDS_RETCODE_OK); r = DDS_Subscriber_notify_datareaders (sub); fail_unless (r == DDS_RETCODE_OK); r = DDS_DomainParticipant_delete_subscriber (p, sub); fail_unless (r == DDS_RETCODE_PRECONDITION_NOT_MET); r = DDS_Subscriber_delete_datareader (sub, dr1); 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); }
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); }
void start_reader (DDS_DomainParticipant part, Topic *tp) { Endpoint *wp; DDS_DynamicTypeBuilder tb; DDS_TypeObject tobj; DDS_TopicDescription td; DDS_DataReaderQos rqos; static DDS_Subscriber sub = NULL; wp = tp->writers; if (!wp) return; printf ("* Monitor (%s/%s)\r\n", tp->topic_name, tp->type_name); if (!tp->ts) { tobj = DDS_TypeObject_create_from_key (part, &wp->data.participant_key, &wp->data.key); if (!tobj) { printf ("No type information available for %s!\r\n", tp->type_name); return; } tb = DDS_DynamicTypeBuilderFactory_create_type_w_type_object (tobj); if (!tb) fatal ("Can't get Type from Type object for %s!", tp->type_name); DDS_TypeObject_delete (tobj); tp->dtype = DDS_DynamicTypeBuilder_build (tb); if (!tp->dtype) fatal ("Can't get build Type from Type builder for %s!", tp->type_name); DDS_DynamicTypeBuilderFactory_delete_type (tb); tp->ts = DDS_DynamicTypeSupport_create_type_support (tp->dtype); if (!tp->ts) fatal ("Can't get TypeSupport from Type for %s!", tp->type_name); if (DDS_DynamicTypeSupport_register_type (tp->ts, part, tp->type_name)) fatal ("Can't register TypeSupport in domain for %s!", tp->topic_name); } if (!sub) { sub = DDS_DomainParticipant_create_subscriber (part, NULL, NULL, 0); if (!sub) fatal ("Can't create subscriber!"); } tp->topic = DDS_DomainParticipant_create_topic (part, tp->topic_name, tp->type_name, NULL, NULL, 0); if (!tp->topic) fatal ("Can't create topic!"); td = DDS_DomainParticipant_lookup_topicdescription (part, tp->topic_name); if (!td) fatal ("Can't create topic description!"); DDS_Subscriber_get_default_datareader_qos (sub, &rqos); if (wp->data.durability.kind >= DDS_TRANSIENT_LOCAL_DURABILITY_QOS) rqos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS; rqos.reliability = wp->data.reliability; listener.cookie = tp; tp->sub = sub; tp->reader = DDS_Subscriber_create_datareader (sub, td, &rqos, &listener, DDS_DATA_AVAILABLE_STATUS); tp->active = 1; }
int main(int argc, char* argv[]) { int startTime = mstime(); DDS_PoolConstraints reqs; DDS_DomainParticipant domainParticipant; DDS_Publisher publisher; DDS_Subscriber subscriber; DDS_ReturnCode_t retCode; char *configTopicName[nofConfigTopics]; DDS_Topic configTopic[nofConfigTopics]; DDS_Topic stateTopic[nofStateTopics]; DDS_Topic statisticTopic[nofStatisticTopics]; DDS_DataWriterQos dataWriterQos; DDS_DataWriter configDataWriter[nofConfigTopics]; DDS_DataWriter stateDataWriter[nofStateTopics]; DDS_DataWriter statisticDataWriter[nofStatisticTopics]; DDS_DataReaderQos dataReaderQos; DDS_DataReader configDataReader[nofConfigTopics]; acceptance_high_end_Config config; acceptance_high_end_State state; acceptance_high_end_Statistic statistic; DDS_InstanceHandle_t configInstance[nofConfigTopics][nofConfigInstances]; DDS_InstanceHandle_t stateInstance[nofStateTopics][nofStateInstances]; DDS_InstanceHandle_t statisticInstance[nofStatisticTopics][nofStatisticInstances]; int i = 0; int j = 0; int firstConfigTopic = (argc > 1) ? atoi(argv[1]) : 0; int firstStateTopic = (argc > 2) ? atoi(argv[2]) : 0; int firstStatisticTopic = (argc > 3) ? atoi(argv[3]) : 0; int stagedLoading = (argc > 4) ? atoi(argv[4]) : 0; printf("[0] Config topics start at %d...\r\n", firstConfigTopic); printf("[0] State topics start at %d...\r\n", firstStateTopic); printf("[0] Statistic topics start at %d...\r\n", firstStatisticTopic); printf("[0] Staged loading %s.\r\n", stagedLoading ? "on" : "off"); if (stagedLoading) { char file_name[24]; sprintf(file_name, "/tmp/acceptStageLoad%d", firstConfigTopic); struct stat buf; if (stat(file_name, &buf)) { printf ("[%d] Waiting for %s\r\n", mstime() - startTime, file_name); do { sleep(1); } while (stat(file_name, &buf)); printf ("[%d] Got %s!\r\n", mstime() - startTime, file_name); } } DDS_program_name (&argc, argv); DDS_entity_name ("Technicolor Limits Component"); DDS_get_default_pool_constraints(&reqs, ~0, 100); #ifdef MINIMAL_POOLS configure_minimal_pool_constraints (&reqs); #else configure_optimal_pool_constraints (&reqs); #endif DDS_set_pool_constraints(&reqs); #ifdef DDS_DEBUG DDS_Debug_start (); #endif /* Create domain participant... */ domainParticipant = DDS_DomainParticipantFactory_create_participant(0, NULL, NULL, 0); if (!domainParticipant) { fprintf(stderr, "Error creating domain participant.\r\n"); return -1; } printf("[%d] Created domain participant.\r\n", mstime() - startTime); sleep(1); /* Create publisher... */ publisher = DDS_DomainParticipant_create_publisher(domainParticipant, NULL, NULL, 0); if (!publisher) { fprintf(stderr, "Error creating publisher.\r\n"); return -1; } printf("[%d] Created publisher.\r\n", mstime() - startTime); sleep(1); /* Create subscriber... */ subscriber = DDS_DomainParticipant_create_subscriber(domainParticipant, NULL, NULL, 0); if (!subscriber) { fprintf(stderr, "Error creating subscriber.\r\n"); return -1; } printf("[%d] Created subscriber.\r\n", mstime() - startTime); sleep(1); /* Register types... */ retCode = acceptance_high_end_ConfigTypeSupport_register_type(domainParticipant, NULL); if (retCode != DDS_RETCODE_OK) { fprintf(stderr, "Error registering type (%s).\r\n", DDS_error(retCode)); return -1; } printf("[%d] Registered config type.\r\n", mstime() - startTime); retCode = acceptance_high_end_StateTypeSupport_register_type(domainParticipant, NULL); if (retCode != DDS_RETCODE_OK) { fprintf(stderr, "Error registering type (%s).\r\n", DDS_error(retCode)); return -1; } printf("[%d] Registered state type.\r\n", mstime() - startTime); retCode = acceptance_high_end_StatisticTypeSupport_register_type(domainParticipant, NULL); if (retCode != DDS_RETCODE_OK) { fprintf(stderr, "Error registering type (%s).\r\n", DDS_error(retCode)); return -1; } printf("[%d] Registered statistic type.\r\n", mstime() - startTime); sleep(1); /* Create topics... */ for (i = 0; i < nofConfigTopics; i++) { char topicName[32]; sprintf(topicName, "ConfigTopic%d", firstConfigTopic + i); configTopicName[i] = strdup (topicName); configTopic[i] = DDS_DomainParticipant_create_topic(domainParticipant, topicName, acceptance_high_end_ConfigTypeSupport_get_type_name(), NULL, NULL, 0); if (!configTopic[i]) { fprintf(stderr, "Error creating topic.\r\n"); return -1; } } printf("[%d] Created %d config topics.\r\n", mstime() - startTime, nofConfigTopics); for (i = 0; i < nofStateTopics; i++) { char topicName[32]; sprintf(topicName, "StateTopic%d", firstStateTopic + i); stateTopic[i] = DDS_DomainParticipant_create_topic(domainParticipant, topicName, acceptance_high_end_StateTypeSupport_get_type_name(), NULL, NULL, 0); if (!stateTopic[i]) { fprintf(stderr, "Error creating topic.\r\n"); return -1; } } printf("[%d] Created %d state topics.\r\n", mstime() - startTime, nofStateTopics); for (i = 0; i < nofStatisticTopics; i++) { char topicName[32]; sprintf(topicName, "StatisticTopic%d", firstStatisticTopic + i); statisticTopic[i] = DDS_DomainParticipant_create_topic(domainParticipant, topicName, acceptance_high_end_StatisticTypeSupport_get_type_name(), NULL, NULL, 0); if (!statisticTopic[i]) { fprintf(stderr, "Error creating topic.\r\n"); return -1; } } printf("[%d] Created %d statistic topics.\r\n", mstime() - startTime, nofStatisticTopics); sleep(1); /* Create data writers... */ DDS_Publisher_get_default_datawriter_qos(publisher, &dataWriterQos); dataWriterQos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS; dataWriterQos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS; for (i = 0; i < nofConfigTopics; i++) { configDataWriter[i] = DDS_Publisher_create_datawriter(publisher, configTopic[i], &dataWriterQos, NULL, 0); if (!configDataWriter[i]) { fprintf(stderr, "Error creating data writer.\r\n"); return -1; } } printf("[%d] Created %d config data writers.\r\n", mstime() - startTime, nofConfigTopics); DDS_Publisher_get_default_datawriter_qos(publisher, &dataWriterQos); dataWriterQos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS; dataWriterQos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS; for (i = 0; i < nofStateTopics; i++) { stateDataWriter[i] = DDS_Publisher_create_datawriter(publisher, stateTopic[i], &dataWriterQos, NULL, 0); if (!stateDataWriter[i]) { fprintf(stderr, "Error creating data writer.\r\n"); return -1; } } printf("[%d] Created %d state data writers.\r\n", mstime() - startTime, nofStateTopics); DDS_Publisher_get_default_datawriter_qos(publisher, &dataWriterQos); for (i = 0; i < nofStatisticTopics; i++) { statisticDataWriter[i] = DDS_Publisher_create_datawriter(publisher, statisticTopic[i], &dataWriterQos, NULL, 0); if (!statisticDataWriter[i]) { fprintf(stderr, "Error creating data writer.\r\n"); return -1; } } printf("[%d] Created %d statistic data writers.\r\n", mstime() - startTime, nofStatisticTopics); sleep(1); /* Create data readers... */ DDS_Subscriber_get_default_datareader_qos(subscriber, &dataReaderQos); dataReaderQos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS; dataReaderQos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS; for (i = 0; i < nofConfigTopics; i++) { configDataReader[i] = DDS_Subscriber_create_datareader(subscriber, DDS_DomainParticipant_lookup_topicdescription(domainParticipant, configTopicName[i]), &dataReaderQos, NULL, 0); if (!configDataReader[i]) { fprintf(stderr, "Error creating data reader.\r\n"); return -1; } } printf("[%d] Created %d config data readers.\r\n", mstime() - startTime, nofConfigTopics); sleep(1); /* Register instances... */ for (i = 0; i < nofConfigTopics; i++) { for (j = 0; j < nofConfigInstances; j++) { config.key = j; configInstance[i][j] = DDS_DataWriter_register_instance(configDataWriter[i], &config); if (!configInstance[i][j]) { fprintf(stderr, "Error registering instance.\r\n"); break; } } } printf("[%d] Registered %d config instances.\r\n", mstime() - startTime, nofConfigTopics * nofConfigInstances); for (i = 0; i < nofStateTopics; i++) { for (j = 0; j < nofStateInstances; j++) { state.key = j; stateInstance[i][j] = DDS_DataWriter_register_instance(stateDataWriter[i], &state); if (!stateInstance[i][j]) { fprintf(stderr, "Error registering instance.\r\n"); break; } } } printf("[%d] Registered %d state instances.\r\n", mstime() - startTime, nofStatisticTopics * nofStatisticInstances); for (i = 0; i < nofStatisticTopics; i++) { for (j = 0; j < nofStatisticInstances; j++) { statistic.key = j; statisticInstance[i][j] = DDS_DataWriter_register_instance(statisticDataWriter[i], &statistic); if (!statisticInstance[i][j]) { fprintf(stderr, "Error registering instance.\r\n"); break; } } } printf("[%d] Registered %d statistic instances.\r\n", mstime() - startTime, nofStatisticTopics * nofStatisticInstances); sleep(1); /* Publish samples... */ for (i = 0; i < nofConfigTopics; i++) { for (j = 0; j < nofConfigInstances; j++) { config.key = j; retCode = DDS_DataWriter_write(configDataWriter[i], &config, configInstance[i][j]); if (retCode != DDS_RETCODE_OK) { fprintf(stderr, "Error publishing sample (%s).\r\n", DDS_error(retCode)); break; } } } printf("[%d] Published %d config samples.\r\n", mstime() - startTime, nofConfigTopics * nofConfigInstances); for (i = 0; i < nofStateTopics; i++) { for (j = 0; j < nofStateInstances; j++) { state.key = j; retCode = DDS_DataWriter_write(stateDataWriter[i], &state, stateInstance[i][j]); if (retCode != DDS_RETCODE_OK) { fprintf(stderr, "Error publishing sample (%s).\r\n", DDS_error(retCode)); break; } } } printf("[%d] Published %d state samples.\r\n", mstime() - startTime, nofStateTopics * nofStateInstances); for (i = 0; i < nofStatisticTopics; i++) { for (j = 0; j < nofStatisticInstances; j++) { statistic.key = j; retCode = DDS_DataWriter_write(statisticDataWriter[i], &statistic, statisticInstance[i][j]); if (retCode != DDS_RETCODE_OK) { fprintf(stderr, "Error publishing sample (%s).\r\n", DDS_error(retCode)); break; } } } printf("[%d] Published %d statistic samples.\r\n", mstime() - startTime, nofStatisticTopics * nofStatisticInstances); sleep(1); if (stagedLoading) { char file_name[24]; sprintf(file_name, "/tmp/acceptStageLoad%d", firstConfigTopic + nofConfigTopics); FILE *f = fopen(file_name, "w"); fclose(f); } // dbg_printf ("Zzzzzzz ... \r\n"); sleep(TEST_TIME); // dbg_printf ("... o?\r\n"); /* Delete contained entities... */ // printf (" -- deleting contained entities.\r\n"); retCode = DDS_DomainParticipant_delete_contained_entities(domainParticipant); if (retCode != DDS_RETCODE_OK) { fprintf(stderr, "Error deleting contained entities.\r\n"); return -1; } for (i = 0; i < nofConfigTopics; i++) free (configTopicName[i]); // printf (" -- contained entities deleted!\r\n"); // sleep(TEST_TIME); /* Delete domain participants... */ retCode = DDS_DomainParticipantFactory_delete_participant(domainParticipant); if (retCode != DDS_RETCODE_OK) { fprintf(stderr, "Error deleting domain participant.\r\n"); return -1; } printf ("[%d] comp completed successfully.\r\n", mstime() - startTime); return 0; }
int main(int argc, char* argv[]) { int startTime = mstime(); DDS_PoolConstraints reqs; DDS_DomainParticipant domainParticipant; DDS_Publisher publisher; DDS_Subscriber subscriber; DDS_ReturnCode_t retCode; char *configTopicName[nofConfigTopics]; char *stateTopicName[nofStateTopics]; char *statisticTopicName[nofStatisticTopics]; DDS_Topic configTopic[nofConfigTopics]; DDS_Topic stateTopic[nofStateTopics]; DDS_Topic statisticTopic[nofStatisticTopics]; DDS_DataWriterQos dataWriterQos; DDS_DataWriter configDataWriter[nofConfigTopics]; DDS_DataReaderQos dataReaderQos; DDS_DataReader configDataReader[nofConfigTopics]; DDS_DataReader stateDataReader[nofStateTopics]; DDS_DataReader statisticDataReader[nofStatisticTopics]; #if 0 acceptance_high_end_Config config; acceptance_high_end_State state; acceptance_high_end_Statistic statistic; DDS_InstanceHandle_t configInstance[nofConfigTopics][nofConfigInstances]; DDS_InstanceHandle_t stateInstance[nofStateTopics][nofStateInstances]; DDS_InstanceHandle_t statisticInstance[nofStatisticTopics][nofStatisticInstances]; #endif int i = 0; /*int j = 0;*/ int firstConfigTopic = (argc > 1) ? atoi(argv[1]) : 0; int firstStateTopic = (argc > 2) ? atoi(argv[2]) : 0; int firstStatisticTopic = (argc > 3) ? atoi(argv[3]) : 0; int stagedLoading = (argc > 4) ? atoi(argv[4]) : 0; printf("[0] Config topics start at %d...\r\n", firstConfigTopic); printf("[0] State topics start at %d...\r\n", firstStateTopic); printf("[0] Statistic topics start at %d...\r\n", firstStatisticTopic); printf("[0] Staged loading %s.\r\n", stagedLoading ? "on" : "off"); DDS_program_name (&argc, argv); DDS_entity_name ("Technicolor Limits Manager"); DDS_get_default_pool_constraints(&reqs, ~0, 100); #ifdef MINIMAL_POOLS configure_minimal_pool_constraints (&reqs); #else configure_optimal_pool_constraints (&reqs); #endif DDS_set_pool_constraints (&reqs); #ifdef DDS_DEBUG DDS_Debug_start (); #endif #ifdef TRACE_DATA rtps_dtrace_set (DRTRC_TRACE_ALL); #endif /* Create domain participant... */ domainParticipant = DDS_DomainParticipantFactory_create_participant(0, NULL, NULL, 0); if (!domainParticipant) { fprintf(stderr, "Error creating domain participant.\r\n"); return -1; } printf("[%d] Created domain participant.\r\n", mstime() - startTime); // sleep(1); /* Create publisher... */ publisher = DDS_DomainParticipant_create_publisher(domainParticipant, NULL, NULL, 0); if (!publisher) { fprintf(stderr, "Error creating publisher.\r\n"); return -1; } printf("[%d] Created publisher.\r\n", mstime() - startTime); // sleep(1); /* Create subscriber... */ subscriber = DDS_DomainParticipant_create_subscriber(domainParticipant, NULL, NULL, 0); if (!subscriber) { fprintf(stderr, "Error creating subscriber.\r\n"); return -1; } printf("[%d] Created subscriber.\r\n", mstime() - startTime); // sleep(1); /* Register types... */ retCode = acceptance_high_end_ConfigTypeSupport_register_type(domainParticipant, NULL); if (retCode != DDS_RETCODE_OK) { fprintf(stderr, "Error registering type (%s).\r\n", DDS_error(retCode)); return -1; } printf("[%d] Registered config type.\r\n", mstime() - startTime); retCode = acceptance_high_end_StateTypeSupport_register_type(domainParticipant, NULL); if (retCode != DDS_RETCODE_OK) { fprintf(stderr, "Error registering type (%s).\r\n", DDS_error(retCode)); return -1; } printf("[%d] Registered state type.\r\n", mstime() - startTime); retCode = acceptance_high_end_StatisticTypeSupport_register_type(domainParticipant, NULL); if (retCode != DDS_RETCODE_OK) { fprintf(stderr, "Error registering type (%s).\r\n", DDS_error(retCode)); return -1; } printf("[%d] Registered statistic type.\r\n", mstime() - startTime); // sleep(1); /* Create topics... */ for (i = 0; i < nofConfigTopics; i++) { char topicName[32]; sprintf(topicName, "ConfigTopic%d", firstConfigTopic + i); configTopicName[i] = topicName; configTopic[i] = DDS_DomainParticipant_create_topic(domainParticipant, topicName, acceptance_high_end_ConfigTypeSupport_get_type_name(), NULL, NULL, 0); if (!configTopic[i]) { fprintf(stderr, "Error creating topic.\r\n"); return -1; } } printf("[%d] Created %d config topics.\r\n", mstime() - startTime, nofConfigTopics); for (i = 0; i < nofStateTopics; i++) { char topicName[32]; sprintf(topicName, "StateTopic%d", firstStateTopic + i); stateTopicName[i] = topicName; stateTopic[i] = DDS_DomainParticipant_create_topic(domainParticipant, topicName, acceptance_high_end_StateTypeSupport_get_type_name(), NULL, NULL, 0); if (!stateTopic[i]) { fprintf(stderr, "Error creating topic.\r\n"); return -1; } } printf("[%d] Created %d state topics.\r\n", mstime() - startTime, nofStateTopics); for (i = 0; i < nofStatisticTopics; i++) { char topicName[32]; sprintf(topicName, "StatisticTopic%d", firstStatisticTopic + i); statisticTopicName[i] = topicName; statisticTopic[i] = DDS_DomainParticipant_create_topic(domainParticipant, topicName, acceptance_high_end_StatisticTypeSupport_get_type_name(), NULL, NULL, 0); if (!statisticTopic[i]) { fprintf(stderr, "Error creating topic.\r\n"); return -1; } } printf("[%d] Created %d statistic topics.\r\n", mstime() - startTime, nofStatisticTopics); // sleep(1); /* Create data writers... */ DDS_Publisher_get_default_datawriter_qos(publisher, &dataWriterQos); dataWriterQos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS; dataWriterQos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS; for (i = 0; i < nofConfigTopics; i++) { configDataWriter[i] = DDS_Publisher_create_datawriter(publisher, configTopic[i], &dataWriterQos, NULL, 0); if (!configDataWriter[i]) { fprintf(stderr, "Error creating data writer.\r\n"); return -1; } } printf("[%d] Created %d config data writers.\r\n", mstime() - startTime, nofConfigTopics); // sleep(1); /* Create data readers... */ DDS_Subscriber_get_default_datareader_qos(subscriber, &dataReaderQos); dataReaderQos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS; dataReaderQos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS; for (i = 0; i < nofConfigTopics; i++) { configDataReader[i] = DDS_Subscriber_create_datareader(subscriber, DDS_DomainParticipant_lookup_topicdescription(domainParticipant, configTopicName[i]), &dataReaderQos, &configDataReaderListener, DDS_DATA_AVAILABLE_STATUS); if (!configDataReader[i]) { fprintf(stderr, "Error creating data reader.\r\n"); return -1; } } printf("[%d] Created %d config data readers.\r\n", mstime() - startTime, nofConfigTopics); DDS_Subscriber_get_default_datareader_qos(subscriber, &dataReaderQos); dataReaderQos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS; dataReaderQos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS; for (i = 0; i < nofStateTopics; i++) { stateDataReader[i] = DDS_Subscriber_create_datareader(subscriber, DDS_DomainParticipant_lookup_topicdescription(domainParticipant, stateTopicName[i]), &dataReaderQos, &stateDataReaderListener, DDS_DATA_AVAILABLE_STATUS); if (!stateDataReader[i]) { fprintf(stderr, "Error creating data reader.\r\n"); return -1; } } printf("[%d] Created %d state data readers.\r\n", mstime() - startTime, nofStateTopics); DDS_Subscriber_get_default_datareader_qos(subscriber, &dataReaderQos); for (i = 0; i < nofStatisticTopics; i++) { statisticDataReader[i] = DDS_Subscriber_create_datareader(subscriber, DDS_DomainParticipant_lookup_topicdescription(domainParticipant, statisticTopicName[i]), &dataReaderQos, &statisticDataReaderListener, DDS_DATA_AVAILABLE_STATUS); if (!statisticDataReader[i]) { fprintf(stderr, "Error creating data reader.\r\n"); return -1; } } printf("[%d] Created %d statistic data readers.\r\n", mstime() - startTime, nofStatisticTopics); // sleep(1); /* Lookup instances... */ /*for (i = 0; i < nofConfigTopics; i++) { for (j = 0; j < nofConfigInstances; j++) { config.key = j; configInstance[i][j] = acceptance_high_end_ConfigDataReader_lookup_instance(configDataReader[i], &config); if (!configInstance[i][j]) { fprintf(stderr, "Error looking up instance.\r\n"); break; } } } printf("[%d] Looked up %d config instances.\r\n", mstime() - startTime, nofConfigTopics * nofConfigInstances); for (i = 0; i < nofStateTopics; i++) { for (j = 0; j < nofStateInstances; j++) { state.key = j; stateInstance[i][j] = acceptance_high_end_StateDataReader_lookup_instance(stateDataReader[i], &state); if (!stateInstance[i][j]) { fprintf(stderr, "Error looking up instance.\r\n"); break; } } } printf("[%d] Looked up %d state instances.\r\n", mstime() - startTime, nofStatisticTopics * nofStatisticInstances); for (i = 0; i < nofStatisticTopics; i++) { for (j = 0; j < nofStatisticInstances; j++) { statistic.key = j; statisticInstance[i][j] = acceptance_high_end_StatisticDataReader_lookup_instance(statisticDataReader[i], &statistic); if (!statisticInstance[i][j]) { fprintf(stderr, "Error looking up instance.\r\n"); break; } } } printf("[%d] Looked up %d statistic instances.\r\n", mstime() - startTime, nofStatisticTopics * nofStatisticInstances);*/ // sleep(1); if (stagedLoading) { char file_name[24]; sprintf(file_name, "/tmp/acceptStageLoad0"); FILE *f = fopen(file_name, "w"); fclose(f); } int waitTime = mstime(); int _nofConfigSamples = 0; int _nofStateSamples = 0; int _nofStatisticSamples = 0; while ((mstime() - waitTime) < (TEST_TIME * 1000)) { if ((nofConfigSamples > _nofConfigSamples) || (nofStateSamples > _nofStateSamples) || (nofStatisticSamples > _nofStatisticSamples)) { printf("[%d] Received %d config samples.\r\n", mstime() - startTime, nofConfigSamples); printf("[%d] Received %d state samples.\r\n", mstime() - startTime, nofStateSamples); printf("[%d] Received %d statistic samples.\r\n", mstime() - startTime, nofStatisticSamples); _nofConfigSamples = nofConfigSamples; _nofStateSamples = nofStateSamples; _nofStatisticSamples = nofStatisticSamples; } sleep(1); } /* Delete contained entities... */ // printf (" -- Deleting contained entities.\r\n"); retCode = DDS_DomainParticipant_delete_contained_entities(domainParticipant); if (retCode != DDS_RETCODE_OK) { fprintf(stderr, "Error deleting contained entities.\r\n"); return -1; } // printf ("contained entities deleted!\r\n"); /* Delete domain participants... */ retCode = DDS_DomainParticipantFactory_delete_participant(domainParticipant); if (retCode != DDS_RETCODE_OK) { fprintf(stderr, "Error deleting domain participant.\r\n"); return -1; } printf ("[%d] mgmt completed successfully.\r\n", mstime() - startTime); return 0; }