void Test::DataReaderListener::on_data_available (DDS::DataReader_ptr reader) throw (CORBA::SystemException) { Test::DataDataReader_var dr = Test::DataDataReader::_narrow (reader); if (CORBA::is_nil (dr.in ())) { cerr << "read: _narrow failed." << endl; exit (1); } Test::Data the_data; DDS::SampleInfo si; (void) dr->take_next_sample (the_data, si); }
void Test::DataReaderListener::on_data_available (DDS::DataReader_ptr reader) throw (CORBA::SystemException) { Test::DataDataReader_var dr = Test::DataDataReader::_narrow (reader); if (CORBA::is_nil (dr.in ())) { ACE_ERROR((LM_ERROR, ACE_TEXT ("(%P|%t) Test::DataReaderListener::on_data_available() - ") ACE_TEXT ("data on unexpected reader type.\n") )); return; } Test::Data data; DDS::SampleInfo info; int count = 0; while( DDS::RETCODE_OK == dr->take_next_sample( data, info)) { if( info.valid_data) { ++this->count_; if (count_ % 50 == 0) ACE_OS::sleep(2); if (count_ % 1000 == 0) ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) DataReaderListener::on_data_available() - ") ACE_TEXT("received %d samples\n"), count_)); if( this->verbose_) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) DataReaderListener::on_data_available() - ") ACE_TEXT("received valid sample(%d): %03d: %d, %C priority\n"), count, data.key, data.value, (data.priority == true ? "high" : "low") )); } if (data.priority) { if (priority_sample_ != NOT_RECEIVED) { priority_sample_ = RECEIVED_INVALID; ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: DataReaderListener::on_data_available() - ") ACE_TEXT("Received multiple high priority samples.\n"))); } else if (recieved_samples_.count(data.before_value)) { priority_sample_ = RECEIVED_INVALID; // (there is at least one entry so rbegin is valid) const long highest = *recieved_samples_.rbegin(); ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: DataReaderListener::on_data_available() - ") ACE_TEXT("Did not receive high priority sample before low priority ") ACE_TEXT("sample %d (highest received sample=%d.\n"), data.before_value, highest)); } else priority_sample_ = RECEIVED_VALID; } else if (!recieved_samples_.insert(data.value).second) { recieved_samples_invalid_ = true; ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: DataReaderListener::on_data_available() - ") ACE_TEXT("Received duplicate sample %d.\n"), data.value)); } else if (data.value > 1 && !recieved_samples_.count(data.value - 1)) { recieved_samples_invalid_ = true; ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: DataReaderListener::on_data_available() - ") ACE_TEXT("Received the sample %d before the previous sample.\n"), data.value)); } else if (recieved_samples_.count(data.value + 1)) { recieved_samples_invalid_ = true; ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: DataReaderListener::on_data_available() - ") ACE_TEXT("Received the sample %d after the next sample.\n"), data.value)); } } else if (info.instance_state == DDS::NOT_ALIVE_DISPOSED_INSTANCE_STATE) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) DataReaderListener::on_data_available() - ") ACE_TEXT("received dispose\n"))); } else if (info.instance_state == DDS::NOT_ALIVE_NO_WRITERS_INSTANCE_STATE) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) DataReaderListener::on_data_available() - ") ACE_TEXT("received unregister\n"))); } else ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: DataReaderListener::on_data_available() - ") ACE_TEXT("received an INVALID sample.\n"))); } }