void eprosima::rpc::util::dds::get_guid(uint8_t (&id)[16], DDS::DataWriter *datawriter) { #if defined(RTI_WIN32) || defined(RTI_LINUX) DDS::DataWriterQos wQos; datawriter->get_qos(wQos); memcpy(id, wQos.protocol.virtual_guid.value, sizeof(id)); #elif defined(OPENDDS) OpenDDS::DCPS::DataWriterImpl *wimpl = dynamic_cast<OpenDDS::DCPS::DataWriterImpl*>(datawriter); OpenDDS::DCPS::RepoId guid = wimpl->get_publication_id(); id[0] = ((guid.guidPrefix[0] << 24) & 0xFF000000) + ((guid.guidPrefix[1] << 16) & 0xFF0000) + ((guid.guidPrefix[2] << 8) & 0xFF00) + (guid.guidPrefix[3] & 0xFF); id[1] = ((guid.guidPrefix[4] << 24) & 0xFF000000) + ((guid.guidPrefix[5] << 16) & 0xFF0000) + ((guid.guidPrefix[6] << 8) & 0xFF00) + (guid.guidPrefix[7] & 0xFF); id[2] = ((guid.guidPrefix[8] << 24) & 0xFF000000) + ((guid.guidPrefix[9] << 16) & 0xFF0000) + ((guid.guidPrefix[10] << 8) & 0xFF00) + (guid.guidPrefix[11] & 0xFF); id[3] = ((guid.entityId.entityKey[0] << 24) & 0xFF000000) + ((guid.entityId.entityKey[1] << 16) & 0xFF0000) + ((guid.entityId.entityKey[2] << 8) & 0xFF00) + (guid.entityId.entityKind & 0xFF); #else #error There not set OS. #endif }
int Publication::svc () { if( !this->enabled_) { if( this->verbose_) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publication::svc() - publication %C: ") ACE_TEXT("not enabled, declining to process.\n"), this->name_.c_str() )); } return 0; } else if( this->verbose_) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publication::svc() - publication %C: ") ACE_TEXT("processing starts on thread.\n"), this->name_.c_str() )); } // Honor a request to delay the start of publication. if( this->profile_->delay > 0) { ACE_Time_Value initialDelay( this->profile_->delay, 0); ACE_OS::sleep( initialDelay); if( this->verbose_) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publication::svc() - publication %C: ") ACE_TEXT("publication starting after initial delay.\n"), this->name_.c_str() )); } } OpenDDS::DCPS::DataWriterImpl* servant = dynamic_cast< OpenDDS::DCPS::DataWriterImpl*>( this->writer_.in()); OpenDDS::DCPS::GuidConverter converter(servant->get_publication_id()); int pid = converter.checksum(); ACE_Time_Value startTime = ACE_High_Res_Timer::gettimeofday_hr(); int count = 0; Test::Data sample; sample.priority = this->profile_->writerQos.transport_priority.value; sample.pid = pid; // Main loop for publishing. while( this->done_ == false) { sample.buffer.length( *this->profile_->size); sample.key = *this->profile_->instances; sample.seq = ++count; ACE_Time_Value start = ACE_High_Res_Timer::gettimeofday_hr(); DDS::Duration_t stamp = ::OpenDDS::DCPS::time_value_to_duration( start); sample.sec = stamp.sec; sample.nanosec = stamp.nanosec; DDS::ReturnCode_t result; { ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, guard, this->lock_, 0); result = this->writer_->write( sample, DDS::HANDLE_NIL); } switch( result) { case DDS::RETCODE_OK: ++this->messages_; break; case DDS::RETCODE_TIMEOUT: ++this->timeouts_; break; default: ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) Publication::svc() - publication %C: ") ACE_TEXT("write failed with code: %d.\n"), this->name_.c_str(), result )); break; } // Determine the interval to next message here so it can be mentioned // in the diagnostic messsage. long microseconds = static_cast<long>( 1.0e6 * *this->profile_->rate); ACE_Time_Value interval( 0, microseconds); if( this->verbose_ && BE_REALLY_VERBOSE) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publication::svc() - publication %C: ") ACE_TEXT("wrote sample %d at priority %d, ") ACE_TEXT("waiting %d microseconds to send next one.\n"), this->name_.c_str(), count, this->profile_->writerQos.transport_priority.value, interval.usec() )); } // Wait the remainder of the interval before sending the next message. ACE_Time_Value now = ACE_High_Res_Timer::gettimeofday_hr(); interval -= (now - start); if( interval > ACE_Time_Value::zero) { ACE_OS::sleep( interval); } } // Wait for data to be delivered if we have been asked to. if( this->profile_->ackDelay) { DDS::Duration_t timeout = {CORBA::Long(this->profile_->ackDelay), 0}; DDS::ReturnCode_t result; result = this->writer_->wait_for_acknowledgments( timeout); switch( result) { case DDS::RETCODE_OK: break; case DDS::RETCODE_TIMEOUT: ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) Publication::svc() - publication %C: ") ACE_TEXT("failed waiting %d seconds for acknowledgments.\n"), this->name_.c_str(), this->profile_->ackDelay )); break; default: ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) Publication::svc() - publication %C: ") ACE_TEXT("write failed with code: %d.\n"), this->name_.c_str(), result )); break; } } ACE_Time_Value elapsedTime = ACE_High_Res_Timer::gettimeofday_hr() - startTime; this->duration_ = elapsedTime.sec() + (elapsedTime.usec() * 1.0e-6); if( this->verbose_) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Publication::svc() - publication %C: ") ACE_TEXT("honoring termination request, stopping thread.\n"), this->name_.c_str() )); } return 0; }