void ordered_groupListener_on_data_on_readers(
        void *listener_data, DDS_Subscriber* subscriber)
{
    struct DDS_DataReaderSeq MyDataReaders;	
    DDS_ReturnCode_t retcode;
    int i;

    /* IMPORTANT for GROUP access scope: Invoking 
     * DDS_Subscriber_begin_access() */
    DDS_Subscriber_begin_access(subscriber);

    /* Obtain DataReaders. We obtain a sequence of DataReaders that 
     * specifies the order in which each sample should be read */
    retcode = DDS_Subscriber_get_datareaders(subscriber,
            &MyDataReaders,
            DDS_ANY_SAMPLE_STATE,
            DDS_ANY_VIEW_STATE,
            DDS_ANY_INSTANCE_STATE);
    if (retcode != DDS_RETCODE_OK) {
        printf("ERROR error %d\n", retcode);
        /* IMPORTANT. Remember to invoke DDS_Subscriber_end_access() before a 
         * return call. Also reset DataReaders sequence */
        DDS_DataReaderSeq_ensure_length(&MyDataReaders,0,0);			
        DDS_Subscriber_end_access(subscriber); 
        return;
    }

    /* Read the samples received, following the DataReaders sequence */
    for (i = 0; i < DDS_DataReaderSeq_get_length(&MyDataReaders); i++) {	
        ordered_groupDataReader *ordered_group_reader = NULL;
        struct ordered_group data;		
        struct DDS_SampleInfo info;
        ordered_group_initialize(&data);	

        ordered_group_reader = 
                ordered_groupDataReader_narrow(
                        DDS_DataReaderSeq_get(&MyDataReaders,i));
        if (ordered_group_reader == NULL) {
            printf("DataReader narrow error\n");
            /* IMPORTANT. Remember to invoke DDS_Subscriber_end_access() before 
             * a return call. Also reset DataReaders sequence */
            DDS_DataReaderSeq_ensure_length(&MyDataReaders,0,0);			
            DDS_Subscriber_end_access(subscriber); 
            return;
        }

        /* IMPORTANT. Use take_next_sample(). We need to take only
	   one sample each time, as we want to follow the sequence of 
	   DataReaders. This way the samples will be returned in the
	   order in which they were modified */
        retcode = ordered_groupDataReader_take_next_sample(ordered_group_reader,
                &data, 
                &info);

        /* In case there is no data in current DataReader, 
	   check next in the sequence */
        if (retcode == DDS_RETCODE_NO_DATA) {
            continue;
        } else if (retcode != DDS_RETCODE_OK) {
            printf("take error %d\n", retcode);
            continue;
        } 

        /* Print data sample */
        if (info.valid_data) {
            ordered_groupTypeSupport_print_data(&data);
        }

    }
    /* Reset DataReaders sequence */
    DDS_DataReaderSeq_ensure_length(&MyDataReaders,0,0);			

    /* IMPORTANT for GROUP access scope: Invoking DDS_Subscriber_end_access() */
    DDS_Subscriber_end_access(subscriber); 
}
Beispiel #2
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);
}