void msgListener_on_data_available(void* listener_data,
        DDS_DataReader* reader) {
    msgDataReader *msg_reader = NULL;
    struct msgSeq data_seq = DDS_SEQUENCE_INITIALIZER;
    struct DDS_SampleInfoSeq info_seq = DDS_SEQUENCE_INITIALIZER;
    DDS_ReturnCode_t retcode;
    int i;

    msg_reader = msgDataReader_narrow(reader);
    if (msg_reader == NULL) {
        printf("DataReader narrow error\n");
        return;
    }

    retcode = msgDataReader_take(msg_reader, &data_seq, &info_seq,
            DDS_LENGTH_UNLIMITED, DDS_ANY_SAMPLE_STATE, DDS_ANY_VIEW_STATE,
            DDS_ANY_INSTANCE_STATE);
    if (retcode == DDS_RETCODE_NO_DATA) {
        return;
    } else if (retcode != DDS_RETCODE_OK) {
        printf("take error %d\n", retcode);
        return;
    }

    for (i = 0; i < msgSeq_get_length(&data_seq); ++i) {
        if (DDS_SampleInfoSeq_get_reference(&info_seq, i)->valid_data) {
            msgTypeSupport_print_data(msgSeq_get_reference(&data_seq, i));
        }
    }

    retcode = msgDataReader_return_loan(msg_reader, &data_seq, &info_seq);
    if (retcode != DDS_RETCODE_OK) {
        printf("return loan error %d\n", retcode);
    }
}
/* We are going to use the BuiltinPublicationListener_on_data_available
 * to detect the topics that are being published on the domain
 *
 * Once we have detected a new topic, we will print out the Topic Name,
 * Participant ID, DataWriter id, and Data Type.
 */
void BuiltinPublicationListener_on_data_available(
    void* listener_data,
    DDS_DataReader* reader)
{
    DDS_PublicationBuiltinTopicDataDataReader *builtin_reader = NULL;
    struct DDS_PublicationBuiltinTopicDataSeq data_seq = DDS_SEQUENCE_INITIALIZER;
    struct DDS_PublicationBuiltinTopicData *data = NULL;
    struct DDS_SampleInfoSeq info_seq = DDS_SEQUENCE_INITIALIZER;
    DDS_ReturnCode_t retcode;
    DDS_ExceptionCode_t exception_code;
    int i, len;

    builtin_reader = DDS_PublicationBuiltinTopicDataDataReader_narrow(reader);

    retcode = DDS_PublicationBuiltinTopicDataDataReader_take(
        builtin_reader,
        &data_seq, &info_seq, DDS_LENGTH_UNLIMITED,
        DDS_ANY_SAMPLE_STATE, DDS_NEW_VIEW_STATE,
        DDS_ANY_INSTANCE_STATE);

    if (retcode == DDS_RETCODE_NO_DATA)
        return;

    if (retcode != DDS_RETCODE_OK) {
        printf("***Error: failed to access data from the built-in reader\n");
        return;
    }

    len = DDS_PublicationBuiltinTopicDataSeq_get_length(&data_seq);
    for (i = 0; i < len; ++i) {
        if (DDS_SampleInfoSeq_get_reference(&info_seq, i)->valid_data) {
            data = DDS_PublicationBuiltinTopicDataSeq_get_reference(&data_seq, i);
            printf("-----\nFound topic \"%s\"\nparticipant: %08x%08x%08x\ndatawriter: %08x%08x%08x\ntype:\n",
                   data->topic_name,
                   data->participant_key.value[0],
                   data->participant_key.value[1],
                   data->participant_key.value[2],
                   data->key.value[0],
                   data->key.value[1],
                   data->key.value[2]);

            if (data->type_code == NULL) {
                printf("No type code received, perhaps increase type_code_max_serialized_length?\n");
                continue;
            }

            /* Using the type_code propagated we print the data type
             * with print_IDL(). */
            DDS_TypeCode_print_IDL(data->type_code, 2, &exception_code);
            if (exception_code != DDS_NO_EXCEPTION_CODE) {
                printf("Error***: print_IDL returns exception code %d",
                        exception_code);
            }

        }
    }
    DDS_PublicationBuiltinTopicDataDataReader_return_loan(
        builtin_reader, &data_seq, &info_seq);
}
void tbfListener_on_data_available(
    void* listener_data,
    DDS_DataReader* reader)
{
    tbfDataReader *tbf_reader = NULL;
    struct tbfSeq data_seq = DDS_SEQUENCE_INITIALIZER;
    struct DDS_SampleInfoSeq info_seq = DDS_SEQUENCE_INITIALIZER;
    DDS_ReturnCode_t retcode;
    int i;
    double source_timestamp;
    tbf* data;
    struct DDS_SampleInfo *sample_info;

    tbf_reader = tbfDataReader_narrow(reader);
    if (tbf_reader == NULL) {
        printf("DataReader narrow error\n");
        return;
    }

    retcode = tbfDataReader_take(
        tbf_reader,
        &data_seq, &info_seq, DDS_LENGTH_UNLIMITED,
        DDS_ANY_SAMPLE_STATE, DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE);
    if (retcode == DDS_RETCODE_NO_DATA) {
        return;
    } else if (retcode != DDS_RETCODE_OK) {
        printf("take error %d\n", retcode);
        return;
    }

    for (i = 0; i < tbfSeq_get_length(&data_seq); ++i) {
        sample_info = DDS_SampleInfoSeq_get_reference(&info_seq, i);
        if (sample_info->valid_data) {
            data = tbfSeq_get_reference(&data_seq, i);

            /* Here we get source timestamp of the sample using the sample info.
             *
             * info_seq[i].source_timestamp returns DDS_Time_t
             * ({seconds,nanoseconds}). We convert nanoseconds to seconds to get
             * the decimal part of the timestamp.
             */
            source_timestamp = sample_info->source_timestamp.sec +
                    sample_info->source_timestamp.nanosec/NANOSECOND;

            printf("%f\t%d\t\t%d\n",
                    source_timestamp,
                    data->code, data->x);
        }
    }

    retcode = tbfDataReader_return_loan(
        tbf_reader,
        &data_seq, &info_seq);
    if (retcode != DDS_RETCODE_OK) {
        printf("return loan error %d\n", retcode);
    }
}
/* No listener is needed; we poll readers in this function*/
void poll_data(orderedDataReader *ordered_reader[], int numreaders) {
    struct DDS_SampleInfoSeq info_seq;
    struct orderedSeq data_seq = DDS_SEQUENCE_INITIALIZER;
    DDS_ReturnCode_t retcode = DDS_RETCODE_OK;
    int r, i, ident;
    for (r = 0; r < numreaders; ++r) {
        retcode = orderedDataReader_take(ordered_reader[r], &data_seq,
                                         &info_seq, DDS_LENGTH_UNLIMITED, DDS_ANY_SAMPLE_STATE,
                                         DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE);
        if (retcode == DDS_RETCODE_NO_DATA) {
            /* Not an error */
            continue;
        } else if (retcode != DDS_RETCODE_OK) {
            /* Is an error */
            printf("take error: %d\n", retcode);
            return;
        }

        for (i = 0; i < orderedSeq_get_length(&data_seq); ++i) {
            ordered* data;
            if (DDS_SampleInfoSeq_get_reference(&info_seq, i)->valid_data) {
                data = orderedSeq_get_reference(&data_seq, i);
                /* Make things a bit easier to read. */
                ident = r;
                while (ident--) {
                    printf("\t");
                }
                printf("Reader %d: Instance%d->value = %d\n", r, data->id,
                       data->value);
            }
        }

        retcode = orderedDataReader_return_loan(ordered_reader[r], &data_seq,
                                                &info_seq);
        if (retcode != DDS_RETCODE_OK) {
            printf("return loan error %d\n", retcode);
        }

        DDS_SampleInfoSeq_set_maximum(&info_seq, 0);
        orderedSeq_set_maximum(&data_seq, 0);
    }
}
示例#5
0
void FidCt_StatCallback(void* listener_data, DDS_DataReader* reader)
{
   FidCt_Stat *FidCtIssue;
   struct DDS_SampleInfo* info = NULL;
   struct DDS_SampleInfoSeq info_seq = DDS_SEQUENCE_INITIALIZER;
   DDS_ReturnCode_t retcode;
   DDS_Boolean result;
   long i,numIssues;

   struct FidCt_StatSeq data_seq = DDS_SEQUENCE_INITIALIZER;
   FidCt_StatDataReader *FidCt_Stat_reader = NULL;

   FidCt_Stat_reader = FidCt_StatDataReader_narrow(pFidCt_StatSub->pDReader);
   if ( FidCt_Stat_reader == NULL)
   {
        errLogRet(LOGIT,debugInfo,"FidCt_StatCallback: DataReader narrow error\n");
        return;
   }

   while(1)
   {

        // Given DDS_HANDLE_NIL as a parameter, take_next_instance returns
        // a sequence containing samples from only the next (in a well-determined
        // but unspecified order) un-taken instance.
        retcode =  FidCt_StatDataReader_take_next_instance(
            FidCt_Stat_reader,
            &data_seq, &info_seq, DDS_LENGTH_UNLIMITED,
            &DDS_HANDLE_NIL,
            DDS_ANY_SAMPLE_STATE, DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE);


        // retcode = Cntlr_CommDataReader_take(CntlrComm_reader,
        //                      &data_seq, &info_seq,
        //                      DDS_LENGTH_UNLIMITED, DDS_ANY_SAMPLE_STATE,
        //                      DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE);

        if (retcode == DDS_RETCODE_NO_DATA) {
                 break; // return;
        } else if (retcode != DDS_RETCODE_OK) {
                 errLogRet(LOGIT,debugInfo,"FidCt_StatCallback: next instance error %d\n",retcode);
                 break; // return;
        }

        numIssues = FidCt_StatSeq_get_length(&data_seq);

        for (i=0; i < numIssues; i++)
        {
           info = DDS_SampleInfoSeq_get_reference(&info_seq, i);
           if (info->valid_data)
           {
              FidCtIssue = (FidCt_Stat *) Cntlr_CommSeq_get_reference(&data_seq,i);
              DPRINT2(+3,"FidCt_StatCallback(): FID=%d, Ct=%d\n",
				        FidCtIssue->FidCt, FidCtIssue->Ct);
              if (pCurrentStatBlock != NULL)
              {
                 if ( (pCurrentStatBlock->Acqstate == ACQ_INACTIVE) && (FidCtIssue->FidCt == 0) && (FidCtIssue->Ct == 0) )
                 {  
                     /* DPRINT(-5,"Set IDLE\n"); */
                     pCurrentStatBlock->Acqstate = ACQ_IDLE;
                 }
                 else if ( (pCurrentStatBlock->Acqstate == ACQ_IDLE) && (FidCtIssue->FidCt == -1) && (FidCtIssue->Ct == -1) )
                 {
                    pCurrentStatBlock->Acqstate = ACQ_INACTIVE;
                     /* DPRINT(-5,"Set INACTIVE\n"); */
                 }

                 if ( (pCurrentStatBlock->Acqstate != ACQ_ACQUIRE) || FidCtIssue->FidCt || FidCtIssue->Ct )
                 {
                    pCurrentStatBlock->AcqFidCnt = FidCtIssue->FidCt;
                    pCurrentStatBlock->AcqCtCnt  = FidCtIssue->Ct;
                    sendConsoleStatus();
                 }
              }
           }
        }
        retcode = FidCt_StatDataReader_return_loan( FidCt_Stat_reader,
                  &data_seq, &info_seq);
        DDS_SampleInfoSeq_set_maximum(&info_seq, 0);
   } // while
   return;
}
示例#6
0
/* NDDS 4x callback */
void Monitor_CmdCallback(void* listener_data, DDS_DataReader* reader)
{
   Monitor_Cmd *recvIssue;
   NDDSBUFMNGR_ID pBufMngr;
   char *bufferAddr;
   char *bufptr;

   DDS_ReturnCode_t retcode;
   DDS_Boolean result;
   struct DDS_SampleInfoSeq info_seq = DDS_SEQUENCE_INITIALIZER;
   struct Monitor_CmdSeq data_seq = DDS_SEQUENCE_INITIALIZER;
   struct DDS_SampleInfo* info = NULL;
   long i,numIssues,len;
   Monitor_CmdDataReader *MonitorCmd_reader = NULL;

   pBufMngr = (NDDSBUFMNGR_ID) listener_data;

   MonitorCmd_reader = Monitor_CmdDataReader_narrow(pMonitorSub->pDReader);
   if ( MonitorCmd_reader == NULL)
   {
        errLogRet(LOGIT,debugInfo, "Monitor_CmdCallback: DataReader narrow error.\n");
        return;
   }


   retcode = Monitor_CmdDataReader_take(MonitorCmd_reader,
                              &data_seq, &info_seq,
                              DDS_LENGTH_UNLIMITED, DDS_ANY_SAMPLE_STATE,
                              DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE);
   if (retcode == DDS_RETCODE_NO_DATA) {
            return;
   } else if (retcode != DDS_RETCODE_OK) {
            errLogRet(LOGIT,debugInfo, "Monitor_CmdCallback: next instance error %d\n",retcode);
            return;
   }


   numIssues = Monitor_CmdSeq_get_length(&data_seq);

   for (i=0; i < numIssues; i++)
   {

      info = DDS_SampleInfoSeq_get_reference(&info_seq, i);
      if ( info->valid_data)
      {
          recvIssue = Monitor_CmdSeq_get_reference(&data_seq,i);

          DPRINT6(1,"Monitor_CmdCallback() - Cmds: %ld, arg1: %ld, arg2: %ld, arg3: %ld, crc: 0x%lx, msgstr: '%s'\n",
            recvIssue->cmd, recvIssue->arg1, recvIssue->arg2, recvIssue->arg3, recvIssue->crc32chksum, recvIssue->msgstr);

          bufferAddr = msgeBufGet(pBufMngr);
          if (bufferAddr == NULL)
	      return;

          memcpy(bufferAddr,recvIssue,sizeof(Monitor_Cmd));

          len = strlen(recvIssue->msgstr);
          bufptr = bufferAddr + sizeof(Monitor_Cmd);
          /* DPRINT3(3,"bufferAddr: 0x%lx, offset: 0x%lx, msgptr: 0x%lx\n", bufferAddr, sizeof(Monitor_Cmd), bufptr); */
          if (len > 0)
          {
             DPRINT1(1,"Msge: '%s'\n",recvIssue->msgstr);
             strncpy(bufptr,recvIssue->msgstr,len+1);
          }
          else
          {
             bufptr = (char) 0;
          }
          msgePost(pBufMngr,bufferAddr);

          pthread_kill(main_threadId,SIGUSR2); /* signal console msg arrival to main thread */
      }
   }
   retcode = Monitor_CmdDataReader_return_loan( MonitorCmd_reader,
                  &data_seq, &info_seq);

   return;
}
示例#7
0
/* 4x callback */
void Monitor_CmdCallback(void* listener_data, DDS_DataReader* reader)
{
   Monitor_Cmd *recvIssue;
   MONITOR_MSG monIssue;
   DDS_ReturnCode_t retcode;
   DDS_Boolean result;
   struct DDS_SampleInfoSeq info_seq = DDS_SEQUENCE_INITIALIZER;
   struct Monitor_CmdSeq data_seq = DDS_SEQUENCE_INITIALIZER;
   struct DDS_SampleInfo* info = NULL;
   long i,numIssues;
   Monitor_CmdDataReader *MonitorCmd_reader = NULL;
   void decode(MONITOR_MSG *issue);


   MonitorCmd_reader = Monitor_CmdDataReader_narrow(pMonitorSub->pDReader);
   if ( MonitorCmd_reader == NULL)
   {
        errLogRet(LOGIT,debugInfo, "Monitor_CmdCallback: DataReader narrow error.\n");
        return;
   }


   retcode = Monitor_CmdDataReader_take(MonitorCmd_reader,
                              &data_seq, &info_seq,
                              DDS_LENGTH_UNLIMITED, DDS_ANY_SAMPLE_STATE,
                              DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE);
   if (retcode == DDS_RETCODE_NO_DATA) {
            return;
   } else if (retcode != DDS_RETCODE_OK) {
            errLogRet(LOGIT,debugInfo, "Monitor_CmdCallback: next instance error %d\n",retcode);
            return;
   }


   numIssues = Monitor_CmdSeq_get_length(&data_seq);

   for (i=0; i < numIssues; i++)
   {

      info = DDS_SampleInfoSeq_get_reference(&info_seq, i);
      if ( info->valid_data)
      {
          recvIssue = Monitor_CmdSeq_get_reference(&data_seq,i);
          monIssue.cmd  = recvIssue->cmd;
          monIssue.arg1 = recvIssue->arg1;
          monIssue.arg2 = recvIssue->arg2;
          monIssue.arg3 = recvIssue->arg3;
          monIssue.arg4 = recvIssue->arg4;
          monIssue.arg5 = recvIssue->arg5;
          monIssue.crc32chksum = recvIssue->crc32chksum;
          monIssue.msgstr.len = strlen(recvIssue->msgstr)+1;
          strncpy(monIssue.msgstr.val,recvIssue->msgstr,MAX_MONITOR_MSG_STR);
          DPRINT6(+1,"Monitor_Cmd CallBack:  cmd: %d, arg1: %d, arg2: %d, arg3: %d, crc: 0x%lx, msgstr: '%s'\n",
            recvIssue->cmd,recvIssue->arg1, recvIssue->arg2, recvIssue->arg3, recvIssue->crc32chksum, recvIssue->msgstr);
     	  msgQSend(pMsgesToMonitor,(char*) &monIssue, sizeof(MONITOR_MSG), NO_WAIT, MSG_PRI_NORMAL);
      }
   }
   retcode = Monitor_CmdDataReader_return_loan( MonitorCmd_reader,
                  &data_seq, &info_seq);

   return;
}
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);
}
示例#9
0
/* 4x callback */
void Lock_CmdCallback(void* listener_data, DDS_DataReader* reader)
{
   Lock_Cmd *recvIssue;
   DDS_ReturnCode_t retcode;
   DDS_Boolean result;
   struct DDS_SampleInfoSeq info_seq = DDS_SEQUENCE_INITIALIZER;
   struct Lock_CmdSeq data_seq = DDS_SEQUENCE_INITIALIZER;
   struct DDS_SampleInfo* info = NULL;
   long i,numIssues;
   Lock_CmdDataReader *LockCmd_reader = NULL;
   DDS_TopicDescription *topicDesc;


   LockCmd_reader = Lock_CmdDataReader_narrow(pLockCmdSubs[0]->pDReader);
   if ( LockCmd_reader == NULL)
   {
        errLogRet(LOGIT,debugInfo, "Lock_CmdCallback: DataReader narrow error.\n");
        return;
   }
   topicDesc = DDS_DataReader_get_topicdescription(reader); 
   DPRINT2(-1,"Lock_CmdCallback; Type: '%s', Name: '%s'\n",
       DDS_TopicDescription_get_type_name(topicDesc), DDS_TopicDescription_get_name(topicDesc));
   while(1)
   {
      // Given DDS_HANDLE_NIL as a parameter, take_next_instance returns
      // a sequence containing samples from only the next (in a well-determined
      // but unspecified order) un-taken instance.
      retcode =  Lock_CmdDataReader_take_next_instance(
            LockCmd_reader,
            &data_seq, &info_seq, DDS_LENGTH_UNLIMITED,
            &DDS_HANDLE_NIL,
            DDS_ANY_SAMPLE_STATE, DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE);

        // retcode = Lock_CmdDataReader_take(LockCmd_reader,
        //                       &data_seq, &info_seq,
        //                       DDS_LENGTH_UNLIMITED, DDS_ANY_SAMPLE_STATE,
        //                       DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE);

      if (retcode == DDS_RETCODE_NO_DATA) {
            break ; // return;
      } else if (retcode != DDS_RETCODE_OK) {
            errLogRet(LOGIT,debugInfo, "Lock_CmdCallback: next instance error %d\n",retcode);
            break ; // return;
      }


      numIssues = Lock_CmdSeq_get_length(&data_seq);

      for (i=0; i < numIssues; i++)
      {

         info = DDS_SampleInfoSeq_get_reference(&info_seq, i);
         if ( info->valid_data)
         {
             recvIssue = Lock_CmdSeq_get_reference(&data_seq,i);
             DPRINT5(-1,"Lock_Cmd CallBack:  cmd: %d, arg1: %d, arg2: %d, arg3: %lf, arg4: %lf crc: 0x%lx\n",
             recvIssue->cmd,recvIssue->arg1, recvIssue->arg2, recvIssue->arg3, recvIssue->arg4);
             msgQSend(pMsgesToLockParser, (char*) recvIssue, sizeof(Lock_Cmd), NO_WAIT, MSG_PRI_NORMAL);
         }
      }
      retcode = Lock_CmdDataReader_return_loan( LockCmd_reader,
                  &data_seq, &info_seq);
      DDS_SampleInfoSeq_set_maximum(&info_seq, 0);
   }  // while

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