<commit_before>
/* Chat_subscriber.cxx

A subscription example

This file is derived from code automatically generated by the rtiddsgen 
command:

rtiddsgen -language C++ -example <arch> Chat.idl

Example subscription of type My::ChatObject automatically generated by 
'rtiddsgen'. To test them follow these steps:

(1) Compile this file and the example publication.

(2) Start the subscription with the command
objs/<arch>/Chat_subscriber <domain_id> <sample_count>

(3) Start the publication with the command
objs/<arch>/Chat_publisher <domain_id> <sample_count>

(4) [Optional] Specify the list of discovery initial peers and 
multicast receive addresses via an environment variable or a file 
(in the current working directory) called NDDS_DISCOVERY_PEERS. 

You can run any number of publishers and subscribers programs, and can 
add and remove them dynamically from the domain.

Example:

To run the example application on domain <domain_id>:

On Unix: 

objs/<arch>/Chat_publisher <domain_id> 
objs/<arch>/Chat_subscriber <domain_id> 

On Windows:

objs\<arch>\Chat_publisher <domain_id>  
objs\<arch>\Chat_subscriber <domain_id>   

*/

#include <stdio.h>
#include <stdlib.h>
#include "Chat.h"
#include "ChatSupport.h"
#include "ndds/ndds_cpp.h"

#include "ndds/ndds_namespace_cpp.h"

using namespace DDS;

namespace My {

    class ChatObjectListener : public DataReaderListener {

      public:

        virtual void on_requested_deadline_missed(
            DataReader* /*reader*/,
            const RequestedDeadlineMissedStatus& /*status*/) {}

        virtual void on_requested_incompatible_qos(
            DataReader* /*reader*/,
            const RequestedIncompatibleQosStatus& /*status*/) {}

        virtual void on_sample_rejected(
            DataReader* /*reader*/,
            const SampleRejectedStatus& /*status*/) {}

        virtual void on_liveliness_changed(
            DataReader* /*reader*/,
            const LivelinessChangedStatus& /*status*/) {}

        virtual void on_sample_lost(
            DataReader* /*reader*/,
            const SampleLostStatus& /*status*/) {}

        virtual void on_subscription_matched(
            DataReader* /*reader*/,
            const SubscriptionMatchedStatus& /*status*/) {}

        virtual void on_data_available(DataReader* reader);
    };

    void ChatObjectListener::on_data_available(DataReader* reader)
    {
        My::ChatObjectDataReader *ChatObject_reader = NULL;
        My::ChatObjectSeq data_seq;
        SampleInfoSeq info_seq;
        ReturnCode_t retcode;
        int i;

        ChatObject_reader = My::ChatObjectDataReader::narrow(reader);
        if (ChatObject_reader == NULL) {
            printf("DataReader narrow error\n");
            return;
        }

        retcode = ChatObject_reader->read(  /*>>><<<*/
            data_seq, info_seq, LENGTH_UNLIMITED,
            ANY_SAMPLE_STATE, ANY_VIEW_STATE, ANY_INSTANCE_STATE);

        if (retcode == RETCODE_NO_DATA) {
            return;
        } else if (retcode != RETCODE_OK) {
            printf("take error %d\n", retcode);
            return;
        }

        for (i = 0; i < data_seq.length(); ++i) {
            if (info_seq[i].valid_data) {
                printf("Received data\n");
                My::ChatObjectTypeSupport::print_data(&data_seq[i]);<commit_msg>Updated comment for read()<commit_after>
/* Chat_subscriber.cxx

A subscription example

This file is derived from code automatically generated by the rtiddsgen 
command:

rtiddsgen -language C++ -example <arch> Chat.idl

Example subscription of type My::ChatObject automatically generated by 
'rtiddsgen'. To test them follow these steps:

(1) Compile this file and the example publication.

(2) Start the subscription with the command
objs/<arch>/Chat_subscriber <domain_id> <sample_count>

(3) Start the publication with the command
objs/<arch>/Chat_publisher <domain_id> <sample_count>

(4) [Optional] Specify the list of discovery initial peers and 
multicast receive addresses via an environment variable or a file 
(in the current working directory) called NDDS_DISCOVERY_PEERS. 

You can run any number of publishers and subscribers programs, and can 
add and remove them dynamically from the domain.

Example:

To run the example application on domain <domain_id>:

On Unix: 

objs/<arch>/Chat_publisher <domain_id> 
objs/<arch>/Chat_subscriber <domain_id> 

On Windows:

objs\<arch>\Chat_publisher <domain_id>  
objs\<arch>\Chat_subscriber <domain_id>   

*/

#include <stdio.h>
#include <stdlib.h>
#include "Chat.h"
#include "ChatSupport.h"
#include "ndds/ndds_cpp.h"

#include "ndds/ndds_namespace_cpp.h"

using namespace DDS;

namespace My {

    class ChatObjectListener : public DataReaderListener {

      public:

        virtual void on_requested_deadline_missed(
            DataReader* /*reader*/,
            const RequestedDeadlineMissedStatus& /*status*/) {}

        virtual void on_requested_incompatible_qos(
            DataReader* /*reader*/,
            const RequestedIncompatibleQosStatus& /*status*/) {}

        virtual void on_sample_rejected(
            DataReader* /*reader*/,
            const SampleRejectedStatus& /*status*/) {}

        virtual void on_liveliness_changed(
            DataReader* /*reader*/,
            const LivelinessChangedStatus& /*status*/) {}

        virtual void on_sample_lost(
            DataReader* /*reader*/,
            const SampleLostStatus& /*status*/) {}

        virtual void on_subscription_matched(
            DataReader* /*reader*/,
            const SubscriptionMatchedStatus& /*status*/) {}

        virtual void on_data_available(DataReader* reader);
    };

    void ChatObjectListener::on_data_available(DataReader* reader)
    {
        My::ChatObjectDataReader *ChatObject_reader = NULL;
        My::ChatObjectSeq data_seq;
        SampleInfoSeq info_seq;
        ReturnCode_t retcode;
        int i;

        ChatObject_reader = My::ChatObjectDataReader::narrow(reader);
        if (ChatObject_reader == NULL) {
            printf("DataReader narrow error\n");
            return;
        }

        retcode = ChatObject_reader->read(  /*>>><<<*/
            data_seq, info_seq, LENGTH_UNLIMITED,
            ANY_SAMPLE_STATE, ANY_VIEW_STATE, ANY_INSTANCE_STATE);

        if (retcode == RETCODE_NO_DATA) {
            return;
        } else if (retcode != RETCODE_OK) {
            printf("take/read error %d\n", retcode); /*>>><<<*/
            return;
        }

        for (i = 0; i < data_seq.length(); ++i) {
            if (info_seq[i].valid_data) {
                printf("Received data\n");
                My::ChatObjectTypeSupport::print_data(&data_seq[i]);
{'fraction_non_alphanumeric': 0.09938723658645943, 'fraction_numerical': 0.0014945449110745778, 'mean_word_length': 2.886178861788618, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '116307', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1937, 'n_words': 528}