static int subscriber_main(int domainId, int sample_count, int sel_cft)
{
    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;
    struct DDS_Duration_t poll_period = {1,0};
    DDS_ContentFilteredTopic *cft = NULL;
    /* If you want to modify datareader_qos programatically you
     * will need to use the following structure. */
    struct DDS_DataReaderQos datareader_qos = DDS_DataReaderQos_INITIALIZER;
    /* For this filter we only allow 1 parameter*/
    struct DDS_StringSeq parameters;
    const char* param_list[] = {"SOME_STRING"};

    /* 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 = cftTypeSupport_get_type_name();
    retcode = cftTypeSupport_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 cft",
        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;
    }

    DDS_StringSeq_initialize(&parameters);
    DDS_StringSeq_set_maximum(&parameters, 1);
    /* Here we set the default filter using the param_list */
    DDS_StringSeq_from_array(&parameters, param_list, 1);
    
    if (sel_cft) {
        /* create_contentfilteredtopic_with_filter */
        cft = DDS_DomainParticipant_create_contentfilteredtopic_with_filter(
            participant,"ContentFilteredTopic", topic, "name MATCH %0",
            &parameters, DDS_STRINGMATCHFILTER_NAME);
        if (cft == NULL) {
            printf("create_contentfilteredtopic error\n");
            subscriber_shutdown(participant);
            return -1;
        }
    }

    /* Set up a data reader listener */
    reader_listener.on_requested_deadline_missed  =
        cftListener_on_requested_deadline_missed;
    reader_listener.on_requested_incompatible_qos =
        cftListener_on_requested_incompatible_qos;
    reader_listener.on_sample_rejected =
        cftListener_on_sample_rejected;
    reader_listener.on_liveliness_changed =
        cftListener_on_liveliness_changed;
    reader_listener.on_sample_lost =
        cftListener_on_sample_lost;
    reader_listener.on_subscription_matched =
        cftListener_on_subscription_matched;
    reader_listener.on_data_available =
        cftListener_on_data_available;

    /* To customize data reader QoS, use 
       the configuration file USER_QOS_PROFILES.xml */
    if (sel_cft) {
        printf("Using ContentFiltered Topic\n");
        reader = DDS_Subscriber_create_datareader(
            subscriber, DDS_ContentFilteredTopic_as_topicdescription(cft),
            &DDS_DATAREADER_QOS_DEFAULT, &reader_listener, DDS_STATUS_MASK_ALL);
    } else {
        printf("Using Normal Topic\n");
        reader = DDS_Subscriber_create_datareader(
            subscriber, DDS_Topic_as_topicdescription(topic),
            &DDS_DATAREADER_QOS_DEFAULT, &reader_listener, DDS_STATUS_MASK_ALL);
    }
    if (reader == NULL) {
        printf("create_datareader error\n");
        subscriber_shutdown(participant);
        return -1;
    }
        
    /* If you want to set the reliability and history QoS settings
     * programmatically rather than using the XML, you will need to add
     * the following lines to your code and comment out the create_datareader
     * calls above.
     */

    /*
    retcode = DDS_Subscriber_get_default_datareader_qos(subscriber,
        &datareader_qos);
    if (retcode != DDS_RETCODE_OK) {
        printf("get_default_datareader_qos error\n");
        return -1;
    }

    datareader_qos.reliability.kind = DDS_RELIABLE_RELIABILITY_QOS;
    datareader_qos.durability.kind = DDS_TRANSIENT_LOCAL_DURABILITY_QOS;
    datareader_qos.history.kind = DDS_KEEP_LAST_HISTORY_QOS;
    datareader_qos.history.depth = 20;

    if (sel_cft) {
        printf("Using ContentFiltered Topic\n");
        reader = DDS_Subscriber_create_datareader(
            subscriber, DDS_ContentFilteredTopic_as_topicdescription(cft),
            &datareader_qos, &reader_listener, DDS_STATUS_MASK_ALL);
    } else {
        printf("Using Normal Topic\n");
        reader = DDS_Subscriber_create_datareader(
            subscriber, DDS_Topic_as_topicdescription(topic),
            &datareader_qos, &reader_listener, DDS_STATUS_MASK_ALL);
    }
    if (reader == NULL) {
        printf("create_datareader error\n");
        subscriber_shutdown(participant);
        return -1;
    }
*/
    /* Change the filter */
    if (sel_cft) {
        printf(">>> Now setting a new filter: name MATCH \"EVEN\"\n");
        retcode = DDS_ContentFilteredTopic_append_to_expression_parameter(
            cft, 0,"EVEN");
        if (retcode != DDS_RETCODE_OK) {
            printf("append_to_expression_parameter error\n");
            subscriber_shutdown(participant);
            return -1;
        }
    }

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

        if (sel_cft == 0) {
            continue;
        }
        if (count == 10) {
            printf("\n===========================\n");
            printf("Changing filter parameters\n");
            printf("Append 'ODD' filter\n");
            printf("===========================\n");
            retcode = DDS_ContentFilteredTopic_append_to_expression_parameter(
                cft, 0,"ODD");
            if (retcode != DDS_RETCODE_OK) {
                printf("append_to_expression_parameter error\n");
                subscriber_shutdown(participant);
                return -1;
            }
        } else if (count == 20) {
            printf("\n===========================\n");
            printf("Changing filter parameters\n");
            printf("Removing 'EVEN' filter \n");
            printf("===========================\n");

            retcode = DDS_ContentFilteredTopic_remove_from_expression_parameter(
                cft, 0,"EVEN");
            if (retcode != DDS_RETCODE_OK) {
                printf("append_to_expression_parameter error\n");
                subscriber_shutdown(participant);
                return -1;
            }
        }
    }

    /* Cleanup and delete all entities */ 
    return subscriber_shutdown(participant);
}
static int subscriber_main(int domain_id, int sample_count,
        char *participant_auth) {
    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;
    struct DDS_Duration_t poll_period = { 1, 0 };
    struct DDS_DomainParticipantQos participant_qos =
            DDS_DomainParticipantQos_INITIALIZER;
    int len, max;

    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;
    }

    /* The maximum length for USER_DATA QoS field is set by default
       to 256 bytes. To increase it programmatically uncomment the
       following line of code. */
    /*
    participant_qos.resource_limits.participant_user_data_max_length = 1024;
    */

    /* We include the subscriber credentials into de USER_DATA QoS. */
    len = strlen(participant_auth) + 1;
    max = participant_qos.resource_limits.participant_user_data_max_length;

    if (len > max) {
        printf("error, participant user_data exceeds resource limits\n");
    } else {
        /*
         *  DDS_Octet is defined to be 8 bits.  If chars are not 8 bits
         *  on your system, this will not work.
         */
        DDS_OctetSeq_from_array(&participant_qos.user_data.value,
                (DDS_Octet*) (participant_auth), len);
    }

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

    /* Done!  All the listeners are installed, so we can enable the
     * participant now.
     */
    if (DDS_Entity_enable((DDS_Entity*) participant) != DDS_RETCODE_OK) {
        printf("***Error: Failed to Enable Participant\n");
        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 = msgTypeSupport_get_type_name();
    retcode = msgTypeSupport_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 msg",
            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;
    }

    /* Set up a data reader listener */
    reader_listener.on_requested_deadline_missed =
            msgListener_on_requested_deadline_missed;
    reader_listener.on_requested_incompatible_qos =
            msgListener_on_requested_incompatible_qos;
    reader_listener.on_sample_rejected = msgListener_on_sample_rejected;
    reader_listener.on_liveliness_changed = msgListener_on_liveliness_changed;
    reader_listener.on_sample_lost = msgListener_on_sample_lost;
    reader_listener.on_subscription_matched =
            msgListener_on_subscription_matched;
    reader_listener.on_data_available = msgListener_on_data_available;

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

    /* Main loop */
    for (count = 0; (sample_count == 0) || (count < sample_count); ++count) {
        /*
         printf("msg subscriber sleeping for %d sec...\n",
         poll_period.sec);
         */
        NDDS_Utility_sleep(&poll_period);
    }

    /* Cleanup and delete all entities */
    return subscriber_shutdown(participant);
}
static int subscriber_main(int domainId, int sample_count) {
    DDS_DomainParticipant *participant = NULL;
    DDS_Subscriber *subscriber[MAX_SUBSCRIBERS] = { 0 };
    DDS_Topic *topic = NULL;
    DDS_DataReader *reader[MAX_SUBSCRIBERS] = { 0 };
    DDS_ReturnCode_t retcode;
    const char *type_name = NULL;
    int count = 0;
    struct DDS_Duration_t poll_period = { 4, 0 };
    orderedDataReader *ordered_reader[MAX_SUBSCRIBERS] = { 0 };
    int i;
    struct DDS_SubscriberQos subscriber_qos = DDS_SubscriberQos_INITIALIZER;
    struct DDS_DataReaderQos datareader_qos = DDS_DataReaderQos_INITIALIZER;
    char* profile_name[] = { "ordered_Profile_subscriber_instance",
                             "ordered_Profile_subscriber_topic"
                           };

    /* 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, &subscriber_qos, &datareader_qos);
        return -1;
    }

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

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

    /* Start changes for ordered_presentation */
    /* Create two subscriber to illustrate different presentation QoS
     * This is a publisher/subscriber level QoS, so we have to do it
     * here instead of just making two datareaders
     */
    /* Subscriber[0], reader[0] and ordered_reader[0] is getting
     * the profile "ordered_Profile_subscriber_instance"
     */

    for (i = 0; i < MAX_SUBSCRIBERS; ++i) {
        /* Subscriber[1], reader[1] and ordered_reader[1] is getting
         * the profile "ordered_Profile_subscriber_topic"
         */
        printf("Subscriber %d using %s\n", i, profile_name[i]);

        subscriber[i] = DDS_DomainParticipant_create_subscriber_with_profile(
                            participant, "ordered_Library", profile_name[i],
                            NULL /* Listener */, DDS_STATUS_MASK_NONE);
        if (subscriber[i] == NULL) {
            printf("create_subscriber%d error\n", i);
            subscriber_shutdown(participant, &subscriber_qos, &datareader_qos);
            return -1;
        }

        reader[i] = DDS_Subscriber_create_datareader_with_profile(subscriber[i],
                    DDS_Topic_as_topicdescription(topic), "ordered_Library",
                    profile_name[i], NULL, DDS_STATUS_MASK_NONE);
        if (reader[i] == NULL) {
            printf("create_datareader%d error\n", i);
            subscriber_shutdown(participant, &subscriber_qos, &datareader_qos);
            return -1;
        }

        ordered_reader[i] = orderedDataReader_narrow(reader[i]);
        if (ordered_reader[i] == NULL) {
            printf("DataReader%d narrow error\n", i);
            return -1;
        }
    }

    /* If you want to change the Publisher's QoS programmatically rather than
     * using the XML file, you will need to add the following lines to your
     * code and comment out the above 'for' loop.
     */
    /*
        for (i = 0; i < MAX_SUBSCRIBERS; ++i) {

    */      /* Get default subscriber QoS to customize */
    /*      retcode = DDS_DomainParticipant_get_default_subscriber_qos(participant,
                    &subscriber_qos);
            if (retcode != DDS_RETCODE_OK) {
                printf("get_default_subscriber_qos error\n");
                return -1;
            }

    */      /* Set ordered_access = TRUE for both subscribers */
    /*      subscriber_qos.presentation.ordered_access = DDS_BOOLEAN_TRUE;

    */      /* We are assuming there are only 2 subscribers. Otherwise you
         * will need to modify the following conditions.
         */
    /*      if (i == 0) {
                printf("Subscriber 0 using Instance access scope\n");
                subscriber_qos.presentation.access_scope =
                        DDS_INSTANCE_PRESENTATION_QOS;
            } else {
                printf("Subscriber 1 using Topic access scope\n");
                subscriber_qos.presentation.access_scope =
                        DDS_TOPIC_PRESENTATION_QOS;
            }

    */      /* To create subscriber with default QoS, use DDS_SUBSCRIBER_QOS_DEFAULT
           instead of subscriber_qos */
    /*      subscriber[i] = DDS_DomainParticipant_create_subscriber(participant,
                    &subscriber_qos, NULL, DDS_STATUS_MASK_NONE);
            if (subscriber == NULL) {
                printf("create_subscriber error\n");
                subscriber_shutdown(participant, &subscriber_qos, &datareader_qos);
                return -1;
            }

    */      /* No listener needed, but we do need to increase history depth */

    /* Get default datareader QoS to customize */
    /*        retcode = DDS_Subscriber_get_default_datareader_qos(subscriber[i],
                    &datareader_qos);
            if (retcode != DDS_RETCODE_OK) {
                printf("get_default_datareader_qos error\n");
                return -1;
            }

            datareader_qos.history.depth = 10;

    */      /* To create datareader with default QoS, use DDS_DATAREADER_QOS_DEFAULT
         instead of datareader_qos */
    /*        reader[i] = DDS_Subscriber_create_datareader(subscriber[i],
                    DDS_Topic_as_topicdescription(topic), &datareader_qos, NULL,
                    DDS_STATUS_MASK_NONE);
            if (reader == NULL) {
                printf("create_datareader error\n");
                subscriber_shutdown(participant, &subscriber_qos, &datareader_qos);
                return -1;
            }

            ordered_reader[i] = orderedDataReader_narrow(reader[i]);
            if (ordered_reader[i] == NULL) {
                printf("DataReader narrow error\n");
                return -1;
            }
        }
    */
    /* Main loop */
    for (count = 0; (sample_count == 0) || (count < sample_count); ++count) {
        printf("ordered subscriber sleeping for %d sec...\n", poll_period.sec);
        NDDS_Utility_sleep(&poll_period);
        poll_data(ordered_reader, MAX_SUBSCRIBERS);
    }

    /* Cleanup and delete all entities */
    return subscriber_shutdown(participant, &subscriber_qos, &datareader_qos);
}
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;
    struct DDS_Duration_t poll_period = { 1, 0 };
    const char* param_list[] = { "2", "divides" };
    DDS_ContentFilteredTopic *cft = NULL;
    struct DDS_StringSeq parameters;
    struct DDS_ContentFilter custom_filter = DDS_ContentFilter_INITIALIZER;

    /* 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 = ccfTypeSupport_get_type_name();
    retcode = ccfTypeSupport_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 ccf",
            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;
    }

    /*------ Start changes for Custom_Content_Filter ------*/
    /* Create and register custom filter */
    custom_filter.compile = custom_filter_compile_function;
    custom_filter.evaluate = custom_filter_evaluate_function;
    custom_filter.finalize = custom_filter_finalize_function;
    custom_filter.filter_data = NULL;

    retcode = DDS_DomainParticipant_register_contentfilter(participant,
            "CustomFilter", &custom_filter);
    if (retcode != DDS_RETCODE_OK) {
        printf("Failed to register custom content filter");
        subscriber_shutdown(participant);
        return -1;
    }

    DDS_StringSeq_initialize(&parameters);
    DDS_StringSeq_set_maximum(&parameters, 2);
    DDS_StringSeq_from_array(&parameters, param_list, 2);

    cft = DDS_DomainParticipant_create_contentfilteredtopic_with_filter(
            participant, "ContentFilteredTopic", topic, "%0 %1 x", &parameters,
            "CustomFilter");
    if (cft == NULL) {
        printf("create_contentfilteredtopic error\n");
        subscriber_shutdown(participant);
        return -1;
    }

    printf("Filter: 2 divides x\n");

    /* Note that we pass 'ccf' rather than 'topic' to the datareader below */
    /*------ End changes for Custom_Content_Filter ------*/

    /* Set up a data reader listener */
    reader_listener.on_requested_deadline_missed =
            ccfListener_on_requested_deadline_missed;
    reader_listener.on_requested_incompatible_qos =
            ccfListener_on_requested_incompatible_qos;
    reader_listener.on_sample_rejected = ccfListener_on_sample_rejected;
    reader_listener.on_liveliness_changed = ccfListener_on_liveliness_changed;
    reader_listener.on_sample_lost = ccfListener_on_sample_lost;
    reader_listener.on_subscription_matched =
            ccfListener_on_subscription_matched;
    reader_listener.on_data_available = ccfListener_on_data_available;

    /*
     * NOTE THAT WE USE THE PREVIOUSLY CREATED CUSTOM FILTERED TOPIC TO READ
     * NEW SAMPLES
     */
    reader = DDS_Subscriber_create_datareader(subscriber,
            DDS_Topic_as_topicdescription(cft), &DDS_DATAREADER_QOS_DEFAULT,
            &reader_listener, DDS_STATUS_MASK_ALL);
    if (reader == NULL) {
        printf("create_datareader error\n");
        subscriber_shutdown(participant);
        return -1;
    }

    /* Start changes for Custom_Content_Filter */
    /* Main loop */
    for (count = 0; (sample_count == 0) || (count < sample_count); ++count) {

        if (count == 10) {
            printf("changing filter parameters\n");
            printf("Filter: 15 greater-than x\n");
            DDS_String_free(DDS_StringSeq_get(&parameters, 0));
            DDS_String_free(DDS_StringSeq_get(&parameters, 1));
            *DDS_StringSeq_get_reference(&parameters, 0) = DDS_String_dup("15");
            *DDS_StringSeq_get_reference(&parameters, 1) = DDS_String_dup(
                    "greater-than");

            retcode = DDS_ContentFilteredTopic_set_expression_parameters(cft,
                    &parameters);
            if (retcode != DDS_RETCODE_OK) {
                printf("set_expression_parameters error\n");
                subscriber_shutdown(participant);
                return -1;
            }
        } else if (count == 20) {
            struct DDS_StringSeq oldParameters;
            printf("changing filter parameters\n");
            printf("Filter: 3 divides x\n");
            DDS_ContentFilteredTopic_get_expression_parameters(cft,
                    &oldParameters);
            DDS_String_free(DDS_StringSeq_get(&oldParameters, 0));
            *DDS_StringSeq_get_reference(&oldParameters, 0) = DDS_String_dup(
                    "3");
            *DDS_StringSeq_get_reference(&oldParameters, 1) = DDS_String_dup(
                    "divides");

            retcode = DDS_ContentFilteredTopic_set_expression_parameters(cft,
                    &oldParameters);
            if (retcode != DDS_RETCODE_OK) {
                printf("set_expression_parameters error\n");
                subscriber_shutdown(participant);
                return -1;
            }
        }
        NDDS_Utility_sleep(&poll_period);
    }

    /* Cleanup and delete all entities */
    return subscriber_shutdown(participant);
}
static int subscriber_main(int domainId, int sample_count)
{
    DDS_DomainParticipant *participant = NULL;
    DDS_Subscriber *subscriber = NULL;

    DDS_Topic *topic1 = NULL;
    DDS_Topic *topic2 = NULL;
    DDS_Topic *topic3 = NULL;

    struct DDS_SubscriberListener subscriber_listener =
            DDS_SubscriberListener_INITIALIZER;

    DDS_DataReader *reader1 = NULL;
    DDS_DataReader *reader2 = NULL;
    DDS_DataReader *reader3 = NULL;

    DDS_ReturnCode_t retcode;
    const char *type_name = NULL;
    int count = 0;
    struct DDS_Duration_t poll_period = {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;
    }

    /* Set up Subscriber listener and establish on_data_on_readers callback */
    /* Set up a data reader listener */
    subscriber_listener.on_data_on_readers  =
            ordered_groupListener_on_data_on_readers;

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

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

    /* TOPICS */ 

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

    topic2 = DDS_DomainParticipant_create_topic(
            participant, "Topic2",
            type_name, &DDS_TOPIC_QOS_DEFAULT, NULL /* listener */,
            DDS_STATUS_MASK_NONE);
    if (topic2 == NULL) {
        printf("create_topic error\n");
        subscriber_shutdown(participant);
        return -1;
    }

    topic3 = DDS_DomainParticipant_create_topic(
            participant, "Topic3",
            type_name, &DDS_TOPIC_QOS_DEFAULT, NULL /* listener */,
            DDS_STATUS_MASK_NONE);
    if (topic3 == NULL) {
        printf("create_topic error\n");
        subscriber_shutdown(participant);
        return -1;
    }

    /* DATAREADERS */

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

    reader2 = DDS_Subscriber_create_datareader(
            subscriber, DDS_Topic_as_topicdescription(topic2),
            &DDS_DATAREADER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE);
    if (reader2 == NULL) {
        printf("create_datareader error\n");
        subscriber_shutdown(participant);
        return -1;
    }

    reader3 = DDS_Subscriber_create_datareader(
            subscriber, DDS_Topic_as_topicdescription(topic3),
            &DDS_DATAREADER_QOS_DEFAULT, NULL, DDS_STATUS_MASK_NONE);
    if (reader3 == NULL) {
        printf("create_datareader error\n");
        subscriber_shutdown(participant);
        return -1;
    }

    /* Main loop */
    for (count=0; (sample_count == 0) || (count < sample_count); ++count) {
        printf("ordered_group subscriber sleeping for %d sec...\n",
                poll_period.sec);
        NDDS_Utility_sleep(&poll_period);
    }

    /* Cleanup and delete all entities */ 
    return subscriber_shutdown(participant);
}
static int subscriber_main(int domainId, int sample_count)
{
    DDS_DomainParticipant *participant = NULL;
    DDS_Subscriber *subscriber = NULL;
    DDS_Topic *topic = NULL;
    DDS_DataReader *reader = NULL;
    DDS_ReturnCode_t retcode;
    const char *type_name = NULL;
    int count = 0;
    struct DDS_Duration_t wait_timeout = {1,0};
    /* Additional variables for this example */
    int i;
    DDS_WaitSet *waitset = NULL;
    DDS_QueryCondition* query_condition = NULL;
    waitset_query_condDataReader *waitset_query_cond_reader = NULL;
    const char* query_expression = DDS_String_dup("name MATCH %0");
    struct DDS_StringSeq query_parameters;
    struct DDS_ConditionSeq active_conditions_seq =
                DDS_SEQUENCE_INITIALIZER;
    struct waitset_query_condSeq data_seq = DDS_SEQUENCE_INITIALIZER;
    struct DDS_SampleInfoSeq info_seq = DDS_SEQUENCE_INITIALIZER;
    /* Auxiliary variables */
    char * odd_string = DDS_String_dup("'ODD'");
    char * even_string = DDS_String_dup("'EVEN'");
    /* The initial value of the param_list is EVEN string */
    const char* param_list[] = {even_string};

    /* 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_query_condTypeSupport_get_type_name();
    retcode = waitset_query_condTypeSupport_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_query_cond",
        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;
    }

    /* Narrow the reader into your specific data type */
    waitset_query_cond_reader = waitset_query_condDataReader_narrow(reader);
    if (waitset_query_cond_reader == NULL) {
        printf("DataReader narrow error\n");
        return -1;
    }

    /* Create query condition */

    DDS_StringSeq_initialize(&query_parameters);
    DDS_StringSeq_set_maximum(&query_parameters, 1);
    
    /*Here we set the default filter using the param_list */
    DDS_StringSeq_from_array(&query_parameters, param_list, 1);

    query_condition = DDS_DataReader_create_querycondition(
        reader,
        DDS_NOT_READ_SAMPLE_STATE,
        DDS_ANY_VIEW_STATE,
        DDS_ANY_INSTANCE_STATE,
        query_expression,
        &query_parameters);
    if (query_condition == NULL) {
        printf("create_query_condition error\n");
        subscriber_shutdown(participant);
        return -1;
    }
    
    waitset = DDS_WaitSet_new();
    if (waitset == NULL) {
        printf("create waitset error\n");
        subscriber_shutdown(participant);
        return -1;
    }

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

    printf ("\n>>>Timeout: %.0d sec & %d nanosec\n",wait_timeout.sec,
            wait_timeout.nanosec);
    printf (">>> Query conditions: name MATCH %%0\n");
    printf ("\t%%0 = %s\n", param_list[0]);
    printf ("---------------------------------\n\n");

    /* Main loop */
    for (count=0; (sample_count == 0) || (count < sample_count); ++count) {
        
        /* We set a new parameter in the Query Condition after 7 secs */
        if (count == 7) {
            param_list[0] = odd_string;
            printf ("CHANGING THE QUERY CONDITION\n");
            printf ("\n>>> Query conditions: name MATCH %%0\n");
            printf ("\t%%0 = %s\n", param_list[0]);
            printf (">>> We keep one sample in the history\n");
            printf ("-------------------------------------\n\n");
            DDS_StringSeq_from_array(&query_parameters, param_list, 1);
            DDS_QueryCondition_set_query_parameters(query_condition,
                    &query_parameters);
            
        }
        /* wait() blocks execution of the thread until one or more attached
         * Conditions become true, or until a user-specified timeout expires.
         */
        retcode = DDS_WaitSet_wait(
                waitset,                       /* waitset */
                &active_conditions_seq,        /* active conditions sequence */
                &wait_timeout);                /* timeout */
        
        /* We get to timeout if no conditions were triggered */
        if (retcode == DDS_RETCODE_TIMEOUT) {
            printf("Wait timed out!! No conditions were triggered.\n");
            continue;
        } else if (retcode != DDS_RETCODE_OK) {
            printf("wait returned error: %d", retcode);
            break;
        }

        retcode = DDS_RETCODE_OK;
            while (retcode != DDS_RETCODE_NO_DATA) {
                retcode = 
                    waitset_query_condDataReader_take_w_condition(
                        waitset_query_cond_reader, &data_seq, &info_seq,
                        DDS_LENGTH_UNLIMITED, 
                        DDS_QueryCondition_as_readcondition(query_condition));
                    
                for (i = 0; i < waitset_query_condSeq_get_length(&data_seq);
                        ++i) {
                    if (!DDS_SampleInfoSeq_get_reference(
                            &info_seq, i)->valid_data) {
                        printf("Got metadata\n");
                        continue;
                    }
                    waitset_query_condTypeSupport_print_data(
                        waitset_query_condSeq_get_reference(&data_seq, i));
                }
                waitset_query_condDataReader_return_loan(
                    waitset_query_cond_reader, &data_seq, &info_seq);
            }
        }

    /* Cleanup and delete all entities */ 
    return subscriber_shutdown(participant);
}
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);
}
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;
    struct DDS_Duration_t poll_period = {4,0};

    /* 
     * This example uses a built-in QoS profile to enable monitoring on the
     * DomainParticipant.  The code below loads the XML QoS from the
     * USER_QOS_PROFILES.xml file, which is inheriting from the 
     * "BuiltinQoSLib::Generic.Monitoring.Common" profile to enable monitoring.
     *
     * !!!! NOTE: This example will only work when dynamically linking !!!
     * In Visual Studio, change the target to "Debug DLL" or "Release DLL" 
     * to build.
     */
    /* 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 you want to change the DomainParticipant's QoS programatically rather
     * than using the XML file, you will need to add the following lines to
     * your code and comment out the create_participant call above.
     * 
     * This example uses a built-in QoS profile to enable 
     * monitoring on the DomainParticipant.*/
    /*participant = DDS_DomainParticipantFactory_create_participant_with_profile(
        DDS_TheParticipantFactory, domainId, 
        DDS_BUILTIN_QOS_LIB, DDS_PROFILE_GENERIC_MONITORING_COMMON,
        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 = profilesTypeSupport_get_type_name();
    retcode = profilesTypeSupport_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 profiles",
        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;
    }

    /* Set up a data reader listener */
    reader_listener.on_requested_deadline_missed  =
        profilesListener_on_requested_deadline_missed;
    reader_listener.on_requested_incompatible_qos =
        profilesListener_on_requested_incompatible_qos;
    reader_listener.on_sample_rejected =
        profilesListener_on_sample_rejected;
    reader_listener.on_liveliness_changed =
        profilesListener_on_liveliness_changed;
    reader_listener.on_sample_lost =
        profilesListener_on_sample_lost;
    reader_listener.on_subscription_matched =
        profilesListener_on_subscription_matched;
    reader_listener.on_data_available =
        profilesListener_on_data_available;

    /* 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, &reader_listener, DDS_STATUS_MASK_ALL);

    /* If you want to change the DataReader's QoS programatically rather
     * than using the XML file, you will need to add the following lines to
     * your code and comment out the create_datareader call above.
     * 
     * This example uses a built-in QoS profile to tune the QoS for 
     * reliable streaming data. */
     /*reader = DDS_Subscriber_create_datareader_with_profile(
        subscriber, DDS_Topic_as_topicdescription(topic),
        DDS_BUILTIN_QOS_LIB_EXP, DDS_PROFILE_PATTERN_RELIABLE_STREAMING,
        &reader_listener, DDS_STATUS_MASK_ALL);
    */


    if (reader == NULL) {
        printf("create_datareader error\n");
        subscriber_shutdown(participant);
        return -1;
    }

    /* Main loop */
    for (count=0; (sample_count == 0) || (count < sample_count); ++count) {
        printf("profiles subscriber sleeping for %d sec...\n",
               poll_period.sec);
        NDDS_Utility_sleep(&poll_period);
    }

    /* Cleanup and delete all entities */ 
    return subscriber_shutdown(participant);
}
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);
}
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;
    struct DDS_Duration_t poll_period = {4,0};
    /* To change the time-based filter programmatically you will need to declare
     * the DataReaderQoS */
    struct DDS_DataReaderQos datareader_qos = DDS_DataReaderQos_INITIALIZER;


    /* 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 = tbfTypeSupport_get_type_name();
    retcode = tbfTypeSupport_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 tbf",
        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;
    }

    /* Set up a data reader listener */
    reader_listener.on_requested_deadline_missed  =
        tbfListener_on_requested_deadline_missed;
    reader_listener.on_requested_incompatible_qos =
        tbfListener_on_requested_incompatible_qos;
    reader_listener.on_sample_rejected =
        tbfListener_on_sample_rejected;
    reader_listener.on_liveliness_changed =
        tbfListener_on_liveliness_changed;
    reader_listener.on_sample_lost =
        tbfListener_on_sample_lost;
    reader_listener.on_subscription_matched =
        tbfListener_on_subscription_matched;
    reader_listener.on_data_available =
        tbfListener_on_data_available;


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

    /* If you want to change the time-based filter programmatically (e.g., to
     * 2 seconds) rather than using the XML file, you will need to add the
     * following lines to your code and comment out the create_datareader
     * call above. */

       /*datareader_qos.time_based_filter.minimum_separation.sec = 2;
       datareader_qos.time_based_filter.minimum_separation.nanosec = 0;
       reader = DDS_Subscriber_create_datareader(
            subscriber, DDS_Topic_as_topicdescription(topic),
            &datareader_qos, &reader_listener, DDS_STATUS_MASK_ALL);
        if (reader == NULL) {
            printf("create_datareader error\n");
            subscriber_shutdown(participant);
            return -1;
        }*/

    /* Results table header: (1) source timestamp of the sample received;
     * (2) instance id (instance.code value); and (3) value of x (instance.x).
     */
    printf("================================================\n");
    printf("Source Timestamp\tInstance\tX\n");
    printf("================================================\n");

    /* Main loop */
    for (count=0; (sample_count == 0) || (count < sample_count); ++count) {
        /*printf("tbf subscriber sleeping for %d sec...\n",
               poll_period.sec);*/
        NDDS_Utility_sleep(&poll_period);
    }

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