Beispiel #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);
}
static int subscriber_main(int domainId, int sample_count)
{
    DDS_DomainParticipant *participant = NULL;
    int count = 0;
    struct DDS_Duration_t poll_period = {4,0};
    DDS_ReturnCode_t retcode;

    DDS_Subscriber *builtin_subscriber = NULL;
    DDS_PublicationBuiltinTopicDataDataReader *builtin_publication_datareader = NULL;

    /* Listener for the Built-in Publication Data Reader */
    struct DDS_DataReaderListener builtin_publication_listener =
        DDS_DataReaderListener_INITIALIZER;

    /* If you want to change the type_code_max_serialized_length
     * programmatically (e.g., to 3070) rather than using the XML file, you
     * will need to add the following lines to your code and comment out the
     * create_participant call bellow. */

    /*
    struct DDS_DomainParticipantQos participant_qos =
            DDS_DomainParticipantQos_INITIALIZER;
    retcode = DDS_DomainParticipantFactory_get_default_participant_qos(
            DDS_TheParticipantFactory, &participant_qos);
    if (retcode != DDS_RETCODE_OK) {
        printf("get_default_participant_qos error\n");
        return -1;
    }

    participant_qos.resource_limits.type_code_max_serialized_length = 3070;

    participant = DDS_DomainParticipantFactory_create_participant(
            DDS_TheParticipantFactory, domainId, &participant_qos,
            NULL, DDS_STATUS_MASK_NONE);
    if (participant == NULL) {
        printf("create_participant error\n");
        subscriber_shutdown(participant);
        return -1;
    }
    */

    /* 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, DDS_STATUS_MASK_NONE);
    if (participant == NULL) {
        printf("create_participant error\n");
        subscriber_shutdown(participant);
        return -1;
    }

    /* First get the built-in subscriber */
    builtin_subscriber = DDS_DomainParticipant_get_builtin_subscriber(participant);
    if (builtin_subscriber == NULL) {
        printf("***Error: failed to create builtin subscriber\n");
        return 0;
    }

    /* Then get the data reader for the built-in subscriber */
    builtin_publication_datareader =
            (DDS_PublicationBuiltinTopicDataDataReader*)
            DDS_Subscriber_lookup_datareader(builtin_subscriber,
                    DDS_PUBLICATION_TOPIC_NAME);
    if (builtin_publication_datareader == NULL) {
        printf("***Error: failed to create builtin publication data reader\n");
        return 0;
    }

    /* Finally install the listener */
    builtin_publication_listener.on_data_available =
        BuiltinPublicationListener_on_data_available;
    DDS_DataReader_set_listener((DDS_DataReader*)builtin_publication_datareader,
                                &builtin_publication_listener,
                                DDS_DATA_AVAILABLE_STATUS);


    /* Main loop */
    for (count=0; (sample_count == 0) || (count < sample_count); ++count) {
        NDDS_Utility_sleep(&poll_period);
    }

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