From 531e8d37eb92f04c3ed54c697bf63e8ef3f45300 Mon Sep 17 00:00:00 2001 From: EduPonz Date: Mon, 11 Mar 2024 07:11:46 +0100 Subject: [PATCH] Refs #20567: Make TimeConversion private Signed-off-by: EduPonz --- include/fastdds/rtps/rtps_all.h | 47 ----- include/fastrtps/rtps/rtps_all.h | 25 --- include/fastrtps/utils/TimeConversion.h | 160 --------------- src/cpp/fastdds/publisher/DataWriterImpl.cpp | 12 +- src/cpp/fastdds/subscriber/DataReaderImpl.cpp | 10 +- .../builtin/data/ParticipantProxyData.cpp | 11 +- .../DS/PDPSecurityInitiatorListener.cpp | 1 - .../builtin/discovery/participant/PDP.cpp | 5 +- .../discovery/participant/PDPClient.cpp | 2 +- .../discovery/participant/PDPListener.cpp | 1 - .../discovery/participant/PDPServer.cpp | 2 +- .../discovery/participant/PDPSimple.cpp | 1 - src/cpp/rtps/builtin/liveliness/WLP.cpp | 11 +- .../persistence/SQLite3PersistenceService.cpp | 1 - src/cpp/rtps/reader/StatefulReader.cpp | 1 - src/cpp/rtps/reader/WriterProxy.cpp | 8 +- src/cpp/rtps/resources/TimedEventImpl.cpp | 4 +- src/cpp/rtps/writer/ReaderProxy.cpp | 4 +- src/cpp/rtps/writer/StatefulWriter.cpp | 8 +- src/cpp/utils/TimeConversion.hpp | 184 ++++++++++++++++++ src/cpp/xmlparser/XMLEndpointParser.cpp | 6 +- .../common/BlackboxTestsDeadlineQos.cpp | 1 - .../common/BlackboxTestsLifespanQoS.cpp | 1 - .../common/BlackboxTestsReliability.cpp | 1 - .../common/DDSBlackboxTestsAckPositive.cpp | 1 - .../throughput/ThroughputPublisher.cpp | 1 - .../throughput/ThroughputSubscriber.cpp | 1 - test/performance/video/VideoTestTypes.hpp | 1 - test/realtime/CMakeLists.txt | 1 + test/realtime/UserThreadNonBlockedTest.cpp | 6 +- .../rtps/persistence/PersistenceTests.cpp | 16 +- 31 files changed, 239 insertions(+), 295 deletions(-) delete mode 100644 include/fastdds/rtps/rtps_all.h delete mode 100644 include/fastrtps/rtps/rtps_all.h delete mode 100644 include/fastrtps/utils/TimeConversion.h create mode 100644 src/cpp/utils/TimeConversion.hpp diff --git a/include/fastdds/rtps/rtps_all.h b/include/fastdds/rtps/rtps_all.h deleted file mode 100644 index 7010a35eb9c..00000000000 --- a/include/fastdds/rtps/rtps_all.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @file rtps_all.h - * - */ - -#ifndef _FASTDDS_RTPS_ALL_H_ -#define _FASTDDS_RTPS_ALL_H_ - -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include - -#include - -#endif /* _FASTDDS_RTPS_ALL_H_ */ diff --git a/include/fastrtps/rtps/rtps_all.h b/include/fastrtps/rtps/rtps_all.h deleted file mode 100644 index 78f0b99f7cf..00000000000 --- a/include/fastrtps/rtps/rtps_all.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @file rtps_all.h - * - */ - -#ifndef RTPS_ALL_H_ -#define RTPS_ALL_H_ - -#include - -#endif /* RTPS_ALL_H_ */ diff --git a/include/fastrtps/utils/TimeConversion.h b/include/fastrtps/utils/TimeConversion.h deleted file mode 100644 index e5950a41f49..00000000000 --- a/include/fastrtps/utils/TimeConversion.h +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @file TimeConversion.h - * - */ - -#ifndef TIMECONVERSION_H_ -#define TIMECONVERSION_H_ - -#include -#include - -namespace eprosima { -namespace fastrtps{ -namespace rtps { - - -namespace TimeConv{ - -/** -* Convert Time_t to seconds as a double -*/ -inline double Time_t2SecondsDouble(const rtps::Time_t& t) -{ - return (double)t.seconds() + (double)(t.fraction()/pow(2.0,32)); -} - -/** -* Convert Time_t to seconds as an int64 -*/ -inline int64_t Time_t2MicroSecondsInt64(const rtps::Time_t& t) -{ - return (int64_t)(t.fraction()/pow(2.0,32)*pow(10.0,6)) + t.seconds()*(int64_t)pow(10.0,6); -} - -/** -* Convert Duration_t to seconds as an int64 -*/ -inline int64_t Duration_t2MicroSecondsInt64(const Duration_t& t) -{ - return (int64_t)(t.nanosec/1000.0)+t.seconds*(int64_t)pow(10.0,6); -} - -/** -* Convert Time_t to microseconds as a double -*/ -inline double Time_t2MicroSecondsDouble(const rtps::Time_t& t) -{ - return ((double)t.fraction()/pow(2.0,32)*pow(10.0,6)) + (double)t.seconds()*pow(10.0,6); -} - -/** -* Convert Time_t to milliseconds as an int64 -*/ -inline int64_t Time_t2MilliSecondsInt64(const rtps::Time_t& t) -{ - return (int64_t)(t.fraction()/pow(2.0,32)*pow(10.0,3)) + t.seconds()*(int64_t)pow(10.0,3); -} - -/** -* Convert Time_t to milliseconds as a double -*/ -inline double Time_t2MilliSecondsDouble(const rtps::Time_t& t) -{ - return ((double)t.fraction()/pow(2.0,32)*pow(10.0,3)) + (double)t.seconds()*pow(10.0,3); -} - -/** -* Convert Duration_t to milliseconds as a double -*/ -inline double Duration_t2MilliSecondsDouble(const Duration_t& t) -{ - return ((double)t.nanosec/1000000.0)+(double)t.seconds*pow(10.0,3); -} - -/** -* Convert milliseconds to Time_t -*/ -inline rtps::Time_t MilliSeconds2Time_t(double millisec) -{ - rtps::Time_t t; - t.seconds((int32_t)(millisec/pow(10.0,3))); - t.fraction((uint32_t)((millisec-(double)t.seconds()*pow(10.0,3))/pow(10.0,3)*pow(2.0,32))); - return t; -} - -/** -* Convert microseconds to Time_t -*/ -inline rtps::Time_t MicroSeconds2Time_t(double microsec) -{ - rtps::Time_t t; - t.seconds((int32_t)(microsec/pow(10.0,6))); - t.fraction((uint32_t)((microsec-(double)t.seconds()*pow(10.0,6))/pow(10.0,6)*pow(2.0,32))); - return t; -} - -/** -* Convert seconds to Time_t -*/ -inline rtps::Time_t Seconds2Time_t(double seconds) -{ - rtps::Time_t t; - t.seconds((int32_t)seconds); - t.fraction((uint32_t)((seconds-(double)t.seconds())*pow(2.0,32))); - return t; -} - -/** -* Get the absolute difference between two Time_t in milliseconds as double -*/ -inline double Time_tAbsDiff2DoubleMillisec(const rtps::Time_t& t1, const rtps::Time_t& t2) -{ - double result = 0; - result +=(double)abs((t2.seconds()-t1.seconds())*1000); - result +=(double)std::abs((t2.fraction()-t1.fraction())/pow(2.0,32)*1000); - return result; -} - -//! Create a random Time_t that is millisec + [-randoff,randoff] -inline rtps::Time_t MilliSecondsWithRandOffset2Time_t(double millisec, double randoff) -{ - randoff = std::abs(randoff); - millisec = millisec + (-randoff) + static_cast (rand()) /( static_cast (RAND_MAX/(2*randoff))); - return MilliSeconds2Time_t(millisec); -} -//! Create a random Time_t that is microsec + [-randoff,randoff] -inline rtps::Time_t MicroSecondsWithRandOffset2Time_t(double microsec, double randoff) -{ - randoff = std::abs(randoff); - microsec = microsec + (-randoff) + static_cast (rand()) /( static_cast (RAND_MAX/(2*randoff))); - return MicroSeconds2Time_t(microsec); -} -//! Create a random Time_t that is sec + [-randoff,randoff] -inline rtps::Time_t SecondsWithRandOffset2Time_t(double sec, double randoff) -{ - randoff = std::abs(randoff); - sec = sec + (-randoff) + static_cast (rand()) /( static_cast (RAND_MAX/(2*randoff))); - return Seconds2Time_t(sec); -} - -} -} -} /* namespace rtps */ -} /* namespace eprosima */ - -#endif /* TIMECONVERSION_H_ */ diff --git a/src/cpp/fastdds/publisher/DataWriterImpl.cpp b/src/cpp/fastdds/publisher/DataWriterImpl.cpp index 055d216be9a..6a77fe2556e 100644 --- a/src/cpp/fastdds/publisher/DataWriterImpl.cpp +++ b/src/cpp/fastdds/publisher/DataWriterImpl.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include @@ -50,6 +49,7 @@ #include #include #include +#include #ifdef FASTDDS_STATISTICS #include @@ -462,7 +462,7 @@ ReturnCode_t DataWriterImpl::loan_sample( { // Block lowlevel writer auto max_blocking_time = steady_clock::now() + - microseconds(::TimeConv::Time_t2MicroSecondsInt64(qos_.reliability().max_blocking_time)); + microseconds(rtps::TimeConv::Time_t2MicroSecondsInt64(qos_.reliability().max_blocking_time)); // Type should be plain and have space for the representation header if (!type_->is_plain() || SerializedPayload_t::representation_header_size > type_->m_typeSize) @@ -764,7 +764,7 @@ InstanceHandle_t DataWriterImpl::do_register_instance( // Block lowlevel writer auto max_blocking_time = std::chrono::steady_clock::now() + - std::chrono::microseconds(::TimeConv::Time_t2MicroSecondsInt64(qos_.reliability().max_blocking_time)); + std::chrono::microseconds(rtps::TimeConv::Time_t2MicroSecondsInt64(qos_.reliability().max_blocking_time)); #if HAVE_STRICT_REALTIME std::unique_lock lock(writer_->getMutex(), std::defer_lock); @@ -882,7 +882,7 @@ ReturnCode_t DataWriterImpl::get_key_value( // Block lowlevel writer #if HAVE_STRICT_REALTIME auto max_blocking_time = std::chrono::steady_clock::now() + - std::chrono::microseconds(::TimeConv::Time_t2MicroSecondsInt64(qos_.reliability().max_blocking_time)); + std::chrono::microseconds(rtps::TimeConv::Time_t2MicroSecondsInt64(qos_.reliability().max_blocking_time)); std::unique_lock lock(writer_->getMutex(), std::defer_lock); if (!lock.try_lock_until(max_blocking_time)) { @@ -943,7 +943,7 @@ ReturnCode_t DataWriterImpl::perform_create_new_change( { // Block lowlevel writer auto max_blocking_time = steady_clock::now() + - microseconds(::TimeConv::Time_t2MicroSecondsInt64(qos_.reliability().max_blocking_time)); + microseconds(rtps::TimeConv::Time_t2MicroSecondsInt64(qos_.reliability().max_blocking_time)); #if HAVE_STRICT_REALTIME std::unique_lock lock(writer_->getMutex(), std::defer_lock); @@ -1378,7 +1378,7 @@ ReturnCode_t DataWriterImpl::wait_for_acknowledgments( // Block low-level writer auto max_blocking_time = steady_clock::now() + - microseconds(::TimeConv::Time_t2MicroSecondsInt64(max_wait)); + microseconds(rtps::TimeConv::Time_t2MicroSecondsInt64(max_wait)); # if HAVE_STRICT_REALTIME std::unique_lock lock(writer_->getMutex(), std::defer_lock); diff --git a/src/cpp/fastdds/subscriber/DataReaderImpl.cpp b/src/cpp/fastdds/subscriber/DataReaderImpl.cpp index 62d07ac8b52..9119a667c78 100644 --- a/src/cpp/fastdds/subscriber/DataReaderImpl.cpp +++ b/src/cpp/fastdds/subscriber/DataReaderImpl.cpp @@ -24,6 +24,8 @@ #endif // if defined(__has_include) && __has_include() #include +#include +#include #include #include #include @@ -33,24 +35,22 @@ #include #include #include +#include #include #include #include #include #include -#include - -#include -#include -#include #include #include #include #include #include #include + #include #include +#include #ifdef FASTDDS_STATISTICS #include diff --git a/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp b/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp index f273c2c7c10..91c25442e96 100644 --- a/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp +++ b/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp @@ -29,12 +29,12 @@ #include #include #include -#include #include #include #include #include +#include #include "ProxyDataFilters.hpp" #include "ProxyHashTables.hpp" @@ -604,7 +604,7 @@ bool ParticipantProxyData::readFromCDRMessage( m_leaseDuration = p.time.to_duration_t(); lease_duration_ = - std::chrono::microseconds(TimeConv::Duration_t2MicroSecondsInt64( + std::chrono::microseconds(fastdds::rtps::TimeConv::Duration_t2MicroSecondsInt64( m_leaseDuration)); break; } @@ -767,7 +767,9 @@ void ParticipantProxyData::copy( default_locators = pdata.default_locators; m_participantName = pdata.m_participantName; m_leaseDuration = pdata.m_leaseDuration; - lease_duration_ = std::chrono::microseconds(TimeConv::Duration_t2MicroSecondsInt64(pdata.m_leaseDuration)); + lease_duration_ = + std::chrono::microseconds(fastdds::rtps::TimeConv::Duration_t2MicroSecondsInt64( + pdata.m_leaseDuration)); m_key = pdata.m_key; isAlive = pdata.isAlive; m_userData = pdata.m_userData; @@ -801,7 +803,8 @@ bool ParticipantProxyData::updateData( security_attributes_ = pdata.security_attributes_; plugin_security_attributes_ = pdata.plugin_security_attributes_; #endif // if HAVE_SECURITY - auto new_lease_duration = std::chrono::microseconds(TimeConv::Duration_t2MicroSecondsInt64(m_leaseDuration)); + auto new_lease_duration = + std::chrono::microseconds(fastdds::rtps::TimeConv::Duration_t2MicroSecondsInt64(m_leaseDuration)); if (lease_duration_event != nullptr) { if (new_lease_duration < lease_duration_) diff --git a/src/cpp/rtps/builtin/discovery/participant/DS/PDPSecurityInitiatorListener.cpp b/src/cpp/rtps/builtin/discovery/participant/DS/PDPSecurityInitiatorListener.cpp index 70adc0bc735..1139ad44f55 100644 --- a/src/cpp/rtps/builtin/discovery/participant/DS/PDPSecurityInitiatorListener.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/DS/PDPSecurityInitiatorListener.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include diff --git a/src/cpp/rtps/builtin/discovery/participant/PDP.cpp b/src/cpp/rtps/builtin/discovery/participant/PDP.cpp index a8eacf9a45d..20040a58a01 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDP.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDP.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include #include @@ -54,6 +53,7 @@ #include #include #include +#include namespace eprosima { namespace fastrtps { @@ -1347,7 +1347,8 @@ void PDP::check_remote_participant_liveliness( // If overcame, remove participant. auto now = std::chrono::steady_clock::now(); auto real_lease_tm = remote_participant->last_received_message_tm() + - std::chrono::microseconds(TimeConv::Duration_t2MicroSecondsInt64(remote_participant->m_leaseDuration)); + std::chrono::microseconds(fastdds::rtps::TimeConv::Duration_t2MicroSecondsInt64(remote_participant-> + m_leaseDuration)); if (now > real_lease_tm) { guard.unlock(); diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp index ea5adadc54d..7b6f707461b 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include #include @@ -48,6 +47,7 @@ #include #include #include +#include using namespace eprosima::fastrtps; diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPListener.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPListener.cpp index 8c8a41d0143..7ba8a71f80a 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPListener.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPListener.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp index 9a5b8d707a8..67a51120127 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -47,6 +46,7 @@ #include #include #include +#include namespace eprosima { namespace fastdds { diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPSimple.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPSimple.cpp index 5a43d803842..81cd0aa8b05 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPSimple.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPSimple.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include diff --git a/src/cpp/rtps/builtin/liveliness/WLP.cpp b/src/cpp/rtps/builtin/liveliness/WLP.cpp index e541ffd7512..23cc4a5e018 100644 --- a/src/cpp/rtps/builtin/liveliness/WLP.cpp +++ b/src/cpp/rtps/builtin/liveliness/WLP.cpp @@ -33,7 +33,6 @@ #include #include -#include #include #include @@ -41,6 +40,7 @@ #include #include #include +#include namespace eprosima { namespace fastrtps { @@ -622,7 +622,8 @@ bool WLP::add_local_writer( std::lock_guard guard(*mp_builtinProtocols->mp_PDP->getMutex()); EPROSIMA_LOG_INFO(RTPS_LIVELINESS, W->getGuid().entityId << " to Liveliness Protocol"); - double wAnnouncementPeriodMilliSec(TimeConv::Duration_t2MilliSecondsDouble(wqos.m_liveliness.announcement_period)); + double wAnnouncementPeriodMilliSec(fastdds::rtps::TimeConv::Duration_t2MilliSecondsDouble(wqos.m_liveliness. + announcement_period)); if (wqos.m_liveliness.kind == AUTOMATIC_LIVELINESS_QOS ) { @@ -736,7 +737,8 @@ bool WLP::remove_local_writer( // There are still some writers. Calculate the new minimum announcement period for (const auto& w : automatic_writers_) { - auto announcement_period = TimeConv::Duration_t2MilliSecondsDouble(w->get_liveliness_announcement_period()); + auto announcement_period = fastdds::rtps::TimeConv::Duration_t2MilliSecondsDouble( + w->get_liveliness_announcement_period()); if (min_automatic_ms_ > announcement_period) { min_automatic_ms_ = announcement_period; @@ -779,7 +781,8 @@ bool WLP::remove_local_writer( // There are still some writers. Calculate the new minimum announcement period for (const auto& w : manual_by_participant_writers_) { - auto announcement_period = TimeConv::Duration_t2MilliSecondsDouble(w->get_liveliness_announcement_period()); + auto announcement_period = fastdds::rtps::TimeConv::Duration_t2MilliSecondsDouble( + w->get_liveliness_announcement_period()); if (min_manual_by_participant_ms_ > announcement_period) { min_manual_by_participant_ms_ = announcement_period; diff --git a/src/cpp/rtps/persistence/SQLite3PersistenceService.cpp b/src/cpp/rtps/persistence/SQLite3PersistenceService.cpp index cb59fdf0d5d..4e016485bee 100644 --- a/src/cpp/rtps/persistence/SQLite3PersistenceService.cpp +++ b/src/cpp/rtps/persistence/SQLite3PersistenceService.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include diff --git a/src/cpp/rtps/reader/StatefulReader.cpp b/src/cpp/rtps/reader/StatefulReader.cpp index 546a69eaebf..aeadc183cb4 100644 --- a/src/cpp/rtps/reader/StatefulReader.cpp +++ b/src/cpp/rtps/reader/StatefulReader.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include diff --git a/src/cpp/rtps/reader/WriterProxy.cpp b/src/cpp/rtps/reader/WriterProxy.cpp index fcb3b3a11de..98a46fdb56e 100644 --- a/src/cpp/rtps/reader/WriterProxy.cpp +++ b/src/cpp/rtps/reader/WriterProxy.cpp @@ -20,19 +20,15 @@ #include #include - #include #include #include #include -#include - -#include -#include - #include "rtps/RTPSDomainImpl.hpp" #include "utils/collections/node_size_helpers.hpp" +#include +#include #if !defined(NDEBUG) && !defined(ANDROID) && defined(FASTDDS_SOURCE) && defined(__unix__) #define SHOULD_DEBUG_LINUX diff --git a/src/cpp/rtps/resources/TimedEventImpl.cpp b/src/cpp/rtps/resources/TimedEventImpl.cpp index 3bcddc6e09f..0249b500083 100644 --- a/src/cpp/rtps/resources/TimedEventImpl.cpp +++ b/src/cpp/rtps/resources/TimedEventImpl.cpp @@ -21,7 +21,7 @@ #include "TimedEventImpl.h" #include -#include +#include namespace eprosima { namespace fastrtps { @@ -113,7 +113,7 @@ void TimedEventImpl::trigger( bool TimedEventImpl::update_interval( const eprosima::fastrtps::Duration_t& interval) { - interval_microsec_ = std::chrono::microseconds(TimeConv::Duration_t2MicroSecondsInt64(interval)); + interval_microsec_ = std::chrono::microseconds(fastdds::rtps::TimeConv::Duration_t2MicroSecondsInt64(interval)); return true; } diff --git a/src/cpp/rtps/writer/ReaderProxy.cpp b/src/cpp/rtps/writer/ReaderProxy.cpp index 2655f87e42f..65d9f0a3247 100644 --- a/src/cpp/rtps/writer/ReaderProxy.cpp +++ b/src/cpp/rtps/writer/ReaderProxy.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include @@ -66,7 +66,7 @@ ReaderProxy::ReaderProxy( writer_->perform_nack_supression(guid()); return false; }, - TimeConv::Time_t2MilliSecondsDouble(times.nackSupressionDuration)); + fastdds::rtps::TimeConv::Time_t2MilliSecondsDouble(times.nackSupressionDuration)); initial_heartbeat_event_ = new TimedEvent(writer_->getRTPSParticipant()->getEventResource(), [&]() -> bool diff --git a/src/cpp/rtps/writer/StatefulWriter.cpp b/src/cpp/rtps/writer/StatefulWriter.cpp index 03a923a4b88..37275c93a71 100644 --- a/src/cpp/rtps/writer/StatefulWriter.cpp +++ b/src/cpp/rtps/writer/StatefulWriter.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include @@ -281,7 +281,7 @@ void StatefulWriter::init( { return send_periodic_heartbeat(); }, - TimeConv::Time_t2MilliSecondsDouble(m_times.heartbeatPeriod)); + fastdds::rtps::TimeConv::Time_t2MilliSecondsDouble(m_times.heartbeatPeriod)); nack_response_event_ = new TimedEvent( pimpl->getEventResource(), @@ -290,7 +290,7 @@ void StatefulWriter::init( perform_nack_response(); return false; }, - TimeConv::Time_t2MilliSecondsDouble(m_times.nackResponseDelay)); + fastdds::rtps::TimeConv::Time_t2MilliSecondsDouble(m_times.nackResponseDelay)); if (disable_positive_acks_) { @@ -1458,7 +1458,7 @@ bool StatefulWriter::wait_for_all_acked( if (!all_acked_) { - std::chrono::microseconds max_w(TimeConv::Duration_t2MicroSecondsInt64(max_wait)); + std::chrono::microseconds max_w(fastdds::rtps::TimeConv::Duration_t2MicroSecondsInt64(max_wait)); all_acked_cond_.wait_for(all_acked_lock, max_w, [&]() { return all_acked_; diff --git a/src/cpp/utils/TimeConversion.hpp b/src/cpp/utils/TimeConversion.hpp new file mode 100644 index 00000000000..845649305c0 --- /dev/null +++ b/src/cpp/utils/TimeConversion.hpp @@ -0,0 +1,184 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @file TimeConversion.h + * + */ + +#ifndef _FASTDDS_TIMECONVERSION_H_ +#define _FASTDDS_TIMECONVERSION_H_ + +#include +#include + +namespace eprosima { +namespace fastdds { +namespace rtps { + + +namespace TimeConv { + +using namespace eprosima::fastrtps::rtps; + +/** + * Convert Time_t to seconds as a double + */ +inline double Time_t2SecondsDouble( + const Time_t& t) +{ + return (double)t.seconds() + (double)(t.fraction() / pow(2.0, 32)); +} + +/** + * Convert Time_t to seconds as an int64 + */ +inline int64_t Time_t2MicroSecondsInt64( + const Time_t& t) +{ + return (int64_t)(t.fraction() / pow(2.0, 32) * pow(10.0, 6)) + t.seconds() * (int64_t)pow(10.0, 6); +} + +/** + * Convert Duration_t to seconds as an int64 + */ +inline int64_t Duration_t2MicroSecondsInt64( + const fastrtps::Duration_t& t) +{ + return (int64_t)(t.nanosec / 1000.0) + t.seconds * (int64_t)pow(10.0, 6); +} + +/** + * Convert Time_t to microseconds as a double + */ +inline double Time_t2MicroSecondsDouble( + const Time_t& t) +{ + return ((double)t.fraction() / pow(2.0, 32) * pow(10.0, 6)) + (double)t.seconds() * pow(10.0, 6); +} + +/** + * Convert Time_t to milliseconds as an int64 + */ +inline int64_t Time_t2MilliSecondsInt64( + const Time_t& t) +{ + return (int64_t)(t.fraction() / pow(2.0, 32) * pow(10.0, 3)) + t.seconds() * (int64_t)pow(10.0, 3); +} + +/** + * Convert Time_t to milliseconds as a double + */ +inline double Time_t2MilliSecondsDouble( + const Time_t& t) +{ + return ((double)t.fraction() / pow(2.0, 32) * pow(10.0, 3)) + (double)t.seconds() * pow(10.0, 3); +} + +/** + * Convert Duration_t to milliseconds as a double + */ +inline double Duration_t2MilliSecondsDouble( + const fastrtps::Duration_t& t) +{ + return ((double)t.nanosec / 1000000.0) + (double)t.seconds * pow(10.0, 3); +} + +/** + * Convert milliseconds to Time_t + */ +inline Time_t MilliSeconds2Time_t( + double millisec) +{ + Time_t t; + t.seconds((int32_t)(millisec / pow(10.0, 3))); + t.fraction((uint32_t)((millisec - (double)t.seconds() * pow(10.0, 3)) / pow(10.0, 3) * pow(2.0, 32))); + return t; +} + +/** + * Convert microseconds to Time_t + */ +inline Time_t MicroSeconds2Time_t( + double microsec) +{ + Time_t t; + t.seconds((int32_t)(microsec / pow(10.0, 6))); + t.fraction((uint32_t)((microsec - (double)t.seconds() * pow(10.0, 6)) / pow(10.0, 6) * pow(2.0, 32))); + return t; +} + +/** + * Convert seconds to Time_t + */ +inline Time_t Seconds2Time_t( + double seconds) +{ + Time_t t; + t.seconds((int32_t)seconds); + t.fraction((uint32_t)((seconds - (double)t.seconds()) * pow(2.0, 32))); + return t; +} + +/** + * Get the absolute difference between two Time_t in milliseconds as double + */ +inline double Time_tAbsDiff2DoubleMillisec( + const Time_t& t1, + const Time_t& t2) +{ + double result = 0; + result += (double)abs((t2.seconds() - t1.seconds()) * 1000); + result += (double)std::abs((t2.fraction() - t1.fraction()) / pow(2.0, 32) * 1000); + return result; +} + +//! Create a random Time_t that is millisec + [-randoff,randoff] +inline Time_t MilliSecondsWithRandOffset2Time_t( + double millisec, + double randoff) +{ + randoff = std::abs(randoff); + millisec = millisec + (-randoff) + static_cast (rand()) / + ( static_cast (RAND_MAX / (2 * randoff))); + return MilliSeconds2Time_t(millisec); +} + +//! Create a random Time_t that is microsec + [-randoff,randoff] +inline Time_t MicroSecondsWithRandOffset2Time_t( + double microsec, + double randoff) +{ + randoff = std::abs(randoff); + microsec = microsec + (-randoff) + static_cast (rand()) / + ( static_cast (RAND_MAX / (2 * randoff))); + return MicroSeconds2Time_t(microsec); +} + +//! Create a random Time_t that is sec + [-randoff,randoff] +inline Time_t SecondsWithRandOffset2Time_t( + double sec, + double randoff) +{ + randoff = std::abs(randoff); + sec = sec + (-randoff) + static_cast (rand()) / ( static_cast (RAND_MAX / (2 * randoff))); + return Seconds2Time_t(sec); +} + +} // namespace TimeConv +} /* namespace rtps */ +} /* namespace fastdds */ +} /* namespace eprosima */ + +#endif /* _FASTDDS_TIMECONVERSION_H_ */ diff --git a/src/cpp/xmlparser/XMLEndpointParser.cpp b/src/cpp/xmlparser/XMLEndpointParser.cpp index 61cd550723f..6521ca18979 100644 --- a/src/cpp/xmlparser/XMLEndpointParser.cpp +++ b/src/cpp/xmlparser/XMLEndpointParser.cpp @@ -28,8 +28,8 @@ #include #include #include -#include +#include #include namespace eprosima { @@ -449,7 +449,7 @@ XMLP_ret XMLEndpointParser::loadXMLReaderEndpoint( { uint32_t milliseclease = std::strtoul(auxstring.c_str(), nullptr, 10); rdata->m_qos.m_liveliness.lease_duration = - TimeConv::MilliSeconds2Time_t((double)milliseclease).to_duration_t(); + fastdds::rtps::TimeConv::MilliSeconds2Time_t((double)milliseclease).to_duration_t(); if (milliseclease == 0) { EPROSIMA_LOG_WARNING(RTPS_EDP, "BAD XML:livelinessQos leaseDuration is 0"); @@ -741,7 +741,7 @@ XMLP_ret XMLEndpointParser::loadXMLWriterEndpoint( { uint32_t milliseclease = std::strtoul(auxstring.c_str(), nullptr, 10); wdata->m_qos.m_liveliness.lease_duration = - TimeConv::MilliSeconds2Time_t((double)milliseclease).to_duration_t(); + fastdds::rtps::TimeConv::MilliSeconds2Time_t((double)milliseclease).to_duration_t(); if (milliseclease == 0) { EPROSIMA_LOG_WARNING(RTPS_EDP, "BAD XML:livelinessQos leaseDuration is 0"); diff --git a/test/blackbox/common/BlackboxTestsDeadlineQos.cpp b/test/blackbox/common/BlackboxTestsDeadlineQos.cpp index 9a1a6f08a60..c891c387feb 100644 --- a/test/blackbox/common/BlackboxTestsDeadlineQos.cpp +++ b/test/blackbox/common/BlackboxTestsDeadlineQos.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include "BlackboxTests.hpp" diff --git a/test/blackbox/common/BlackboxTestsLifespanQoS.cpp b/test/blackbox/common/BlackboxTestsLifespanQoS.cpp index 23f127eb8f6..d4656d832d2 100644 --- a/test/blackbox/common/BlackboxTestsLifespanQoS.cpp +++ b/test/blackbox/common/BlackboxTestsLifespanQoS.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include "BlackboxTests.hpp" diff --git a/test/blackbox/common/BlackboxTestsReliability.cpp b/test/blackbox/common/BlackboxTestsReliability.cpp index 501914ea4ea..871a4f18e4e 100644 --- a/test/blackbox/common/BlackboxTestsReliability.cpp +++ b/test/blackbox/common/BlackboxTestsReliability.cpp @@ -14,7 +14,6 @@ #include -#include #include // TODO(jlbueno): remove private header diff --git a/test/blackbox/common/DDSBlackboxTestsAckPositive.cpp b/test/blackbox/common/DDSBlackboxTestsAckPositive.cpp index ff7f69ef7b7..ad9e6fa2ae5 100644 --- a/test/blackbox/common/DDSBlackboxTestsAckPositive.cpp +++ b/test/blackbox/common/DDSBlackboxTestsAckPositive.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include // TODO(jlbueno): remove private headers diff --git a/test/performance/throughput/ThroughputPublisher.cpp b/test/performance/throughput/ThroughputPublisher.cpp index b517cd53b7a..fd8b96c2ea8 100644 --- a/test/performance/throughput/ThroughputPublisher.cpp +++ b/test/performance/throughput/ThroughputPublisher.cpp @@ -34,7 +34,6 @@ #include #include #include -#include using namespace eprosima::fastdds::dds; using namespace eprosima::fastrtps::rtps; diff --git a/test/performance/throughput/ThroughputSubscriber.cpp b/test/performance/throughput/ThroughputSubscriber.cpp index 67112e56f83..ba45b4c535a 100644 --- a/test/performance/throughput/ThroughputSubscriber.cpp +++ b/test/performance/throughput/ThroughputSubscriber.cpp @@ -32,7 +32,6 @@ #include #include #include -#include using namespace eprosima::fastdds::dds; using namespace eprosima::fastrtps::rtps; diff --git a/test/performance/video/VideoTestTypes.hpp b/test/performance/video/VideoTestTypes.hpp index 3ff566578f0..e6a2446c583 100644 --- a/test/performance/video/VideoTestTypes.hpp +++ b/test/performance/video/VideoTestTypes.hpp @@ -42,7 +42,6 @@ #include #include -#include diff --git a/test/realtime/CMakeLists.txt b/test/realtime/CMakeLists.txt index 453830146f5..ceadad83f65 100644 --- a/test/realtime/CMakeLists.txt +++ b/test/realtime/CMakeLists.txt @@ -7,6 +7,7 @@ target_compile_definitions(user_thread_nonblocked_test PRIVATE $<$>,$>:__DEBUG> $<$:__INTERNALDEBUG> # Internal debug activated. ) +target_include_directories(user_thread_nonblocked_test PRIVATE ${CMAKE_SOURCE_DIR}/src/cpp/utils) target_link_libraries(user_thread_nonblocked_test mutex_testing_tool fastdds fastcdr GTest::gtest) STRING(REPLACE " " "\\ " MUTEX_PRELOAD_LIBRARY_FILE "$") diff --git a/test/realtime/UserThreadNonBlockedTest.cpp b/test/realtime/UserThreadNonBlockedTest.cpp index f03716ade8a..778e706fa46 100644 --- a/test/realtime/UserThreadNonBlockedTest.cpp +++ b/test/realtime/UserThreadNonBlockedTest.cpp @@ -2,7 +2,10 @@ #include #include +#include + #include + #include #include #include @@ -15,10 +18,9 @@ #include #include #include -#include -#include #include "mutex_testing_tool/TMutex.hpp" +#include #if defined(_WIN32) #define GET_PID _getpid diff --git a/test/unittest/rtps/persistence/PersistenceTests.cpp b/test/unittest/rtps/persistence/PersistenceTests.cpp index 9e1ff61e15f..d76b4ba1b7b 100644 --- a/test/unittest/rtps/persistence/PersistenceTests.cpp +++ b/test/unittest/rtps/persistence/PersistenceTests.cpp @@ -12,23 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include +#include + +#include + #include +#include +#include #include #include #include #include - -#include -#include -#include - #include -#include -#include -#include - using namespace eprosima::fastrtps::rtps; class NoOpPayloadPool : public IPayloadPool