Exemple #1
0
    ::DDS::ReturnCode_t
    DataReader_T <TYPED_DDS_READER, TYPED_READER_TYPE, VALUE_TYPE, SEQ_TYPE, RTI_SEQ_TYPE>::complete_read (
        RTI_SEQ_TYPE & dds_data_values,
        SEQ_TYPE & data_values,
        DDS_SampleInfoSeq & dds_sample_infos,
        ::DDS::SampleInfoSeq & sample_infos,
        const ::DDS::ReturnCode_t & retcode,
        const char * method_name)
    {
      if (retcode == ::DDS::RETCODE_OK)
        {
          data_values.length (dds_data_values.length ());
          sample_infos.length (dds_sample_infos.length ());

          for (::DDS_Long i = 0 ; i < dds_sample_infos.length(); ++i)
            {
              sample_infos[i] <<= dds_sample_infos[i];
              data_values[i] = dds_data_values[i];
            }
        }
      else if (retcode != ::DDS::RETCODE_NO_DATA)
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                        ACE_TEXT ("DataReader_T::%C - ")
                        ACE_TEXT ("Error while reading samples from DDS - <%C>\n"),
                        method_name,
                        ::CIAO::DDS4CCM::translate_retcode (retcode)));
        }
      ::DDS::ReturnCode_t const retcode_return_loan =
        this->rti_entity ()->return_loan (dds_data_values, dds_sample_infos);
      if (retcode_return_loan != ::DDS::RETCODE_OK)
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                        ACE_TEXT ("DataReader_T::%C - ")
                        ACE_TEXT ("Error returning loan to DDS - <%C>\n"),
                        method_name,
                        ::CIAO::DDS4CCM::translate_retcode (retcode_return_loan)));
          // In case a read action from DDS causes errors, the users wants to see
          // this error (and not the return loan error).
          if (retcode  == ::DDS::RETCODE_OK)
            return retcode_return_loan;
        }
      return retcode;
    }
Exemple #2
0
    void
    DataReaderListener_T<CCM_TYPE, TYPED_READER, SEQ_TYPE>::on_data_available_i (
      ::DDS::DataReader_ptr rdr)
    {
      DDS4CCM_TRACE ("DataReaderListener_T::on_data_available_i");

      if (::CORBA::is_nil (rdr))
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                             ACE_TEXT ("DataReaderListener_T::on_data_available_i - ")
                             ACE_TEXT ("No datareader received.\n")));
          return;
        }

      ::CCM_DDS::ListenerMode const mode = this->control_->mode ();
      if (mode == ::CCM_DDS::NOT_ENABLED)
        {
          return;
        }

      typename TYPED_READER::_var_type reader;
      reader = TYPED_READER::_narrow (rdr);

      if (::CORBA::is_nil (reader.in ()))
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                             ACE_TEXT ("DataReaderListener_T::on_data_available_i - ")
                             ACE_TEXT ("Failed to narrow DataReader to a type ")
                             ACE_TEXT ("specific DataReader.\n")));
          return;
        }

      try
        {
          SEQ_TYPE data;
          ::DDS::SampleInfoSeq sample_info;
          ::CORBA::Long max_samples = 0;

          mode == ::CCM_DDS::ONE_BY_ONE
            ? max_samples = ::DDS::LENGTH_UNLIMITED
            : this->control_->max_delivered_data() == 0
              ? max_samples = ::DDS::LENGTH_UNLIMITED
              : max_samples = this->control_->max_delivered_data ();

          ::DDS::QueryCondition_var qc =
            this->condition_manager_.get_querycondition_listener ();

          ::DDS::ReturnCode_t result = ::DDS::RETCODE_OK;

          if (! ::CORBA::is_nil (qc.in ()))
            {
              ::DDS::ReadCondition_var rd = ::DDS::ReadCondition::_narrow (qc.in ());
              result = reader->take_w_condition (data,
                                                 sample_info,
                                                 max_samples,
                                                 rd.in ());
            }
          else
            {
              result = reader->take (data,
                                     sample_info,
                                     max_samples,
                                     ::DDS::NOT_READ_SAMPLE_STATE,
                                     ::DDS::NEW_VIEW_STATE | ::DDS::NOT_NEW_VIEW_STATE,
                                     ::DDS::ANY_INSTANCE_STATE);
            }

          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_DDS_STATUS, (LM_INFO, DDS4CCM_INFO
                              ACE_TEXT ("DataReaderListener_T::on_data_available_i - ")
                              ACE_TEXT ("Take data returned %C.\n"),
                              translate_retcode (result)));

          if (result == ::DDS::RETCODE_OK)
            {
              if (mode == ::CCM_DDS::ONE_BY_ONE)
                {
                  for (::CORBA::ULong i = 0; i < data.length (); ++i)
                    {
                      if (sample_info[i].valid_data)
                        {
                          ::CCM_DDS::ReadInfo info;
                          info <<= sample_info[i];
                          this->listener_->on_one_data (data[i], info);
                        }
                    }
                }
              else
                {
                  CORBA::ULong nr_of_samples = 0;
                  for (::CORBA::ULong i = 0 ; i < sample_info.length(); i++)
                    {
                      if (sample_info[i].valid_data)
                        {
                          ++nr_of_samples;
                        }
                    }

                  if (nr_of_samples > 0)
                    {
                      SEQ_TYPE inst_seq (nr_of_samples);
                      ::CCM_DDS::ReadInfoSeq infoseq (nr_of_samples);

                      infoseq.length (nr_of_samples);
                      inst_seq.length (nr_of_samples);

                      // Copy the valid samples
                      CORBA::ULong ix = 0;
                      for (::CORBA::ULong i = 0 ; i < sample_info.length(); i++)
                        {
                          if(sample_info[i].valid_data)
                            {
                              infoseq[ix] <<= sample_info[i];
                              inst_seq[ix] = data[i];
                              ++ix;
                            }
                        }
                      this->listener_->on_many_data (inst_seq, infoseq);
                    }
                }
            }

          // Return the loan
          DDS::ReturnCode_t const retval = reader->return_loan (data, sample_info);
          if (retval != ::DDS::RETCODE_OK)
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                            ACE_TEXT ("DataReaderListener_T::on_data_available_i - ")
                            ACE_TEXT ("Error returning loan to DDS - <%C>\n"),
                            translate_retcode (retval)));
              // No exception here since this the DDS vendor doesn't expect this.
              // It will likely causes a crash in their implementation
            }
        }
      catch (const ::CORBA::BAD_INV_ORDER& ex)
        {
          DDS4CCM_PRINT_DEBUG_CORBA_EXCEPTION (
                                  DDS4CCM_LOG_LEVEL_ACTION,
                                  ex,
                                  "DataReaderListener_T::on_data_available_i");
        }
      catch (const ::CORBA::Exception& ex)
        {
          DDS4CCM_PRINT_CORBA_EXCEPTION (
                                  DDS4CCM_LOG_LEVEL_ERROR,
                                  ex,
                                  "DataReaderListener_T::on_data_available_i");
        }
      catch (...)
        {
          DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                        ACE_TEXT ("DataReaderListener_T::on_data_available_i - ")
                        ACE_TEXT ("Unexpected exception caught\n")));
        }
    }