Ejemplo n.º 1
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);
}
Ejemplo n.º 2
0
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 int subscriber_main(int domainId, int sample_count)
{
    DDS_DomainParticipant *participant = NULL;
    DDS_Subscriber *subscriber = NULL;
    DDS_Topic *topic = NULL;
    struct DDS_DataReaderListener reader_listener =
        DDS_DataReaderListener_INITIALIZER;
    DDS_DataReader *reader = NULL;
    DDS_ReturnCode_t retcode;
    const char *type_name = NULL;
    int count = 0;
    DDS_StatusCondition *status_condition;
    DDS_WaitSet *waitset = NULL;
    waitset_statuscondDataReader *waitsets_reader = NULL;
    struct DDS_Duration_t timeout = {4,0};

    /* To customize participant QoS, use 
       the configuration file USER_QOS_PROFILES.xml */
    participant = DDS_DomainParticipantFactory_create_participant(
        DDS_TheParticipantFactory, domainId, &DDS_PARTICIPANT_QOS_DEFAULT,
        NULL /* listener */, DDS_STATUS_MASK_NONE);
    if (participant == NULL) {
        printf("create_participant error\n");
        subscriber_shutdown(participant);
        return -1;
    }

    /* To customize subscriber QoS, use 
       the configuration file USER_QOS_PROFILES.xml */
    subscriber = DDS_DomainParticipant_create_subscriber(
        participant, &DDS_SUBSCRIBER_QOS_DEFAULT, NULL /* listener */,
        DDS_STATUS_MASK_NONE);
    if (subscriber == NULL) {
        printf("create_subscriber error\n");
        subscriber_shutdown(participant);
        return -1;
    }

    /* Register the type before creating the topic */
    type_name = waitset_statuscondTypeSupport_get_type_name();
    retcode = waitset_statuscondTypeSupport_register_type(participant, type_name);
    if (retcode != DDS_RETCODE_OK) {
        printf("register_type error %d\n", retcode);
        subscriber_shutdown(participant);
        return -1;
    }

    /* To customize topic QoS, use 
       the configuration file USER_QOS_PROFILES.xml */
    topic = DDS_DomainParticipant_create_topic(
        participant, "Example waitset_statuscond",
        type_name, &DDS_TOPIC_QOS_DEFAULT, NULL /* listener */,
        DDS_STATUS_MASK_NONE);
    if (topic == NULL) {
        printf("create_topic error\n");
        subscriber_shutdown(participant);
        return -1;
    }


    /* To customize data reader QoS, use 
       the configuration file USER_QOS_PROFILES.xml */
    reader = DDS_Subscriber_create_datareader(
        subscriber, DDS_Topic_as_topicdescription(topic),
        &DDS_DATAREADER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE);
    if (reader == NULL) {
        printf("create_datareader error\n");
        subscriber_shutdown(participant);
        return -1;
    }

    status_condition = DDS_Entity_get_statuscondition((DDS_Entity*)reader);
    if (status_condition == NULL) {
        printf("get_statuscondition error\n");
        subscriber_shutdown(participant);
        return -1;
    }

    // Since a single status condition can match many statuses, 
    // enable only those we're interested in.
    retcode = DDS_StatusCondition_set_enabled_statuses(
        status_condition,
        DDS_DATA_AVAILABLE_STATUS);
    if (retcode != DDS_RETCODE_OK) {
        printf("set_enabled_statuses error\n");
        subscriber_shutdown(participant);
        return -1;
    }

    // Create WaitSet, and attach conditions
    waitset = DDS_WaitSet_new();
    if (waitset == NULL) {
        printf("create waitset error\n");
        subscriber_shutdown(participant);
        return -1;        
    }


    retcode = DDS_WaitSet_attach_condition(waitset, (DDS_Condition*)status_condition);
    if (retcode != DDS_RETCODE_OK) {
        printf("attach_condition error\n");
        subscriber_shutdown(participant);
        return -1;
    }    

    // Get narrowed datareader
    waitsets_reader = waitset_statuscondDataReader_narrow(reader);
    if (waitsets_reader == NULL) {
        printf("DataReader narrow error\n");
        return -1;
    }

    /* Main loop */
    for (count=0; (sample_count == 0) || (count < sample_count); ++count) {
        struct DDS_ConditionSeq active_conditions = DDS_SEQUENCE_INITIALIZER;
        int i, j;

        retcode = DDS_WaitSet_wait(waitset, &active_conditions, &timeout);
        if (retcode == DDS_RETCODE_TIMEOUT) {
            printf("wait timed out\n");
            count+=2;
            continue;
        } else if (retcode != DDS_RETCODE_OK) {
            printf("wait returned error: %d\n", retcode);
            break;
        }

        printf("got %d active conditions\n",
               DDS_ConditionSeq_get_length(&active_conditions));
        
        for (i = 0; i < DDS_ConditionSeq_get_length(&active_conditions); ++i) {
            if (DDS_ConditionSeq_get(&active_conditions, i) == (DDS_Condition*)status_condition) {
                // A status condition triggered--see which ones
                DDS_StatusMask triggeredmask;
                triggeredmask = DDS_Entity_get_status_changes((DDS_Entity*)waitsets_reader);

                if (triggeredmask & DDS_DATA_AVAILABLE_STATUS) {
                    struct waitset_statuscondSeq data_seq = 
                        DDS_SEQUENCE_INITIALIZER;
                    struct DDS_SampleInfoSeq info_seq = 
                        DDS_SEQUENCE_INITIALIZER;
                
                    retcode = waitset_statuscondDataReader_take(
                        waitsets_reader, &data_seq, &info_seq,
                        DDS_LENGTH_UNLIMITED, DDS_ANY_SAMPLE_STATE,
                        DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE);
                    if (retcode != DDS_RETCODE_OK) {
                        printf("take error %d\n", retcode);
                        break;
                    }
                
                    for (j = 0; j < waitset_statuscondSeq_get_length(&data_seq); ++j) {
                        if (!DDS_SampleInfoSeq_get_reference(&info_seq, j)->valid_data) {
                            printf("   Got metadata\n");                     
                            continue;
                        }
                        waitset_statuscondTypeSupport_print_data(
                            waitset_statuscondSeq_get_reference(&data_seq, j));
                    }

                    retcode = waitset_statuscondDataReader_return_loan(
                        waitsets_reader, &data_seq, &info_seq);
                    if (retcode != DDS_RETCODE_OK) {
                        printf("return loan error %d\n", retcode);
                    }

                }

            }
        }
    }    

    /* Delete all entities */
    retcode = DDS_WaitSet_delete(waitset);
    if (retcode != DDS_RETCODE_OK) {
        printf("delete waitset error %d\n", retcode);
    }

    /* Cleanup and delete all entities */ 
    return subscriber_shutdown(participant);
}