Clean up stale comments and blank lines in FTC/FTS and nglapplication unit-test

Drop the Qt6-migration explanatory comments (rtiddsgen setter notes,
Log4Qt/BUILDING_NGLLOGGER notes, the INTERFACE-to-STATIC note, the
return_loan comment block) and the stray blank lines. No code changes:
this is the state the last full green run (build + 22/22 ctest +
coverage + DEB) was built from.
This commit is contained in:
berrux-dev committed 2026-11-21 09:25:55 +01:00
1 parent e8d7aa7bd6
commit b1662eddfa
10 files changed
+3 -104

No files matched your search

@@ -4,10 +4,7 @@
# $Author$ # $Author$
# #
# ddsftc - Changed from INTERFACE to STATIC library to fix source path issues # ddsftc - Changed from INTERFACE to STATIC library to fix source path issues
# When INTERFACE libraries provide sources, CMake compiles them in the consuming
# target's directory context, causing path resolution issues with relative paths
ADD_LIBRARY(ddsftc STATIC ADD_LIBRARY(ddsftc STATIC
${CMAKE_CURRENT_SOURCE_DIR}/generic_ftc.h ${CMAKE_CURRENT_SOURCE_DIR}/generic_ftc.h
${CMAKE_CURRENT_SOURCE_DIR}/generic_ftc.cpp ${CMAKE_CURRENT_SOURCE_DIR}/generic_ftc.cpp
@@ -1,6 +1,4 @@
#include "abstract_requester.h" #include "abstract_requester.h"
Request2::Request2():QObject(){} Request2::Request2():QObject(){}
@@ -1,10 +1,8 @@
#pragma once #pragma once
#include <ddsftccore_export.h> #include <ddsftccore_export.h>
#include <QtCore/QObject> #include <QtCore/QObject>
class DDSFTCCORE_EXPORT Request2 : public QObject class DDSFTCCORE_EXPORT Request2 : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -9,7 +9,6 @@
#pragma once #pragma once
#include <DDS/Core/core.hpp> #include <DDS/Core/core.hpp>
#include <future> #include <future>
class Request2; class Request2;
@@ -20,11 +20,9 @@
#include <QObject> #include <QObject>
#include <QMetaMethod> #include <QMetaMethod>
#include <QTimer> #include <QTimer>
#include <queue> #include <queue>
#include <future> #include <future>
namespace FTC namespace FTC
{ {
template <class C> template <class C>
@@ -114,7 +112,6 @@ public:
preInit(); preInit();
} }
~GenericFtcImpl() ~GenericFtcImpl()
{ {
Q_ASSERT(!m_dying); Q_ASSERT(!m_dying);
@@ -154,8 +151,6 @@ public:
} }
} }
struct ClassicRequest struct ClassicRequest
{ {
connext::WriteSample<RequestTopic> sample; connext::WriteSample<RequestTopic> sample;
@@ -164,14 +159,12 @@ public:
int uniqueId = 0; int uniqueId = 0;
}; };
bool requestDataClassic(const RequestTopic &requestTopic, bool requestDataClassic(const RequestTopic &requestTopic,
const char *replySlot, const char *replySlot,
const char *errorSlot, const char *errorSlot,
int &uniqueId) override int &uniqueId) override
{ {
Q_ASSERT(!m_dying); Q_ASSERT(!m_dying);
ClassicRequest request; ClassicRequest request;
if (!checkSlots(request, replySlot, errorSlot)) if (!checkSlots(request, replySlot, errorSlot))
return false; return false;
@@ -180,19 +173,14 @@ public:
uniqueId = request.uniqueId; uniqueId = request.uniqueId;
createThread(); createThread();
{ {
std::lock_guard<std::mutex> l(m_requestMutex); std::lock_guard<std::mutex> l(m_requestMutex);
m_classicRequests.push(request); m_classicRequests.push(request);
} }
runThread(); runThread();
return true; return true;
} }
template<typename ReplyTopic> template<typename ReplyTopic>
struct ModernRequest struct ModernRequest
{ {
@@ -201,14 +189,11 @@ public:
Request2 *requestWatcher; Request2 *requestWatcher;
}; };
std::future<ReplyTopic> requestDataModern(const RequestTopic &requestTopic, Request2 *requestWatcher) override std::future<ReplyTopic> requestDataModern(const RequestTopic &requestTopic, Request2 *requestWatcher) override
{ {
Q_ASSERT(!m_dying); Q_ASSERT(!m_dying);
std::promise<ReplyTopic> promise; std::promise<ReplyTopic> promise;
std::future<ReplyTopic> future = promise.get_future(); std::future<ReplyTopic> future = promise.get_future();
connext::WriteSample<RequestTopic> sample; connext::WriteSample<RequestTopic> sample;
sample.set_data(requestTopic); sample.set_data(requestTopic);
@@ -220,7 +205,6 @@ public:
} }
runThread(); runThread();
return future; return future;
} }
@@ -231,36 +215,28 @@ private:
return QString::fromUtf8(TopicNameHelper::functionTopicName()); return QString::fromUtf8(TopicNameHelper::functionTopicName());
} }
int partitionId() const override int partitionId() const override
{ {
return m_partitionId; return m_partitionId;
} }
QString partitionType() const override QString partitionType() const override
{ {
return QString::fromStdString(m_partitionType); return QString::fromStdString(m_partitionType);
} }
std::unique_ptr<connext::Requester<RequestTopic, ReplyTopic> > requester; // in-thread! std::unique_ptr<connext::Requester<RequestTopic, ReplyTopic> > requester; // in-thread!
void cleanupThread() override // in-thread! void cleanupThread() override // in-thread!
{ {
// called in-thread while thread is preparing to immediately shut down (after this call) and cleans everything that was created also in-thread // called in-thread while thread is preparing to immediately shut down (after this call) and cleans everything that was created also in-thread
requester.reset(); requester.reset();
} }
void threadDone() override void threadDone() override
{ {
// called after the thread is done and before any new threads may be created // called after the thread is done and before any new threads may be created
// that's why there's no need to lock the mutex here // that's why there's no need to lock the mutex here
// NOTE: not called on ctor!
// NOTE: no need to lock as there is no thread anymore at this point
for (; !m_modernRequests.empty(); m_modernRequests.pop()) for (; !m_modernRequests.empty(); m_modernRequests.pop())
{ {
ModernRequest<ReplyTopic> &request = m_modernRequests.front(); ModernRequest<ReplyTopic> &request = m_modernRequests.front();
@@ -278,7 +254,6 @@ private:
} }
} }
void work() override // in-thread! void work() override // in-thread!
{ {
try try
@@ -291,8 +266,7 @@ private:
{ {
fprintf(stderr, "[!] GenericFtc::work: called while marked as no work available! run? %d (%s)\n", isRun(), threadName().toStdString().c_str()); fprintf(stderr, "[!] GenericFtc::work: called while marked as no work available! run? %d (%s)\n", isRun(), threadName().toStdString().c_str());
} }
setWorkAvailable(false); // NOTE: no need to lock as we're inside the thread and it is guaranteed that we don't hit the condition wait while writing to the variable setWorkAvailable(false);
// lock
{ {
std::lock_guard<std::mutex> l(m_requestMutex); std::lock_guard<std::mutex> l(m_requestMutex);
@@ -371,14 +345,12 @@ private:
} }
} }
template <typename T, typename std::enable_if<HasStatusFunction<T>::value, int>::type = 0> template <typename T, typename std::enable_if<HasStatusFunction<T>::value, int>::type = 0>
static inline bool isInProgress(const connext::Sample<T> &reply) static inline bool isInProgress(const connext::Sample<T> &reply)
{ {
return (reply.data().replyState() == Core::FtReplyState::InProgress); return (reply.data().replyState() == Core::FtReplyState::InProgress);
} }
template <typename T, typename std::enable_if<!HasStatusFunction<T>::value, int>::type = 0> template <typename T, typename std::enable_if<!HasStatusFunction<T>::value, int>::type = 0>
static inline bool isInProgress(const connext::Sample<T> &) static inline bool isInProgress(const connext::Sample<T> &)
{ {
@@ -500,10 +472,6 @@ private:
QTimer::singleShot(0, request.requestWatcher, &Request2::finished); QTimer::singleShot(0, request.requestWatcher, &Request2::finished);
return; return;
/* No need to call replies.return_loan();
* the destructor takes care of doing it every time replies goes out of scope
*/
} }
} }
// ------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------
@@ -557,7 +525,6 @@ private:
} }
// ------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------
// for classic requests: // for classic requests:
QObject *m_objToInform; QObject *m_objToInform;
int m_uniqueId { 0 }; int m_uniqueId { 0 };
@@ -53,18 +53,10 @@ void Threading::preInit() const
m_partitionId = partitionId(); m_partitionId = partitionId();
m_partitionType = partitionType(); m_partitionType = partitionType();
const QString base(QStringLiteral("F%1%2").arg(m_partitionType.left(1)).arg(m_partitionId)); const QString base(QStringLiteral("F%1%2").arg(m_partitionType.left(1)).arg(m_partitionId));
const int baseLen = base.length(); const int baseLen = base.length();
const int maxLen = 16 - 1 - baseLen; const int maxLen = 16 - 1 - baseLen;
if (maxLen < 1) if (maxLen < 1)
{ {
Q_ASSERT(false); Q_ASSERT(false);
@@ -96,8 +88,6 @@ void Threading::preInit() const
} }
int wordsLeft = words.count(); int wordsLeft = words.count();
if (wordsLeft < 1) if (wordsLeft < 1)
{ {
Q_ASSERT(false); Q_ASSERT(false);
@@ -124,25 +114,16 @@ void Threading::preInit() const
} }
const int maxWordLen = lenRest / wordsLeft; const int maxWordLen = lenRest / wordsLeft;
if (words.isEmpty()) if (words.isEmpty())
{ {
Q_ASSERT(false); Q_ASSERT(false);
break; break;
} }
name += words.takeFirst().left(maxWordLen); name += words.takeFirst().left(maxWordLen);
wordsLeft--; wordsLeft--;
} }
const int finalLeft = maxLen - name.size(); const int finalLeft = maxLen - name.size();
if (finalLeft < 0 || (finalLeft > 0 && functionTopicName().length() > maxLen)) if (finalLeft < 0 || (finalLeft > 0 && functionTopicName().length() > maxLen))
{ {
@@ -157,48 +138,36 @@ void Threading::preInit() const
m_threadName = QStringLiteral("%1%2[%3]").arg(base, name).arg(QRandomGenerator::global()->bounded(0x100000000LL), 8, 16, QLatin1Char('0')); m_threadName = QStringLiteral("%1%2[%3]").arg(base, name).arg(QRandomGenerator::global()->bounded(0x100000000LL), 8, 16, QLatin1Char('0'));
} }
const QString &Threading::threadName() const const QString &Threading::threadName() const
{ {
if (m_threadName.isEmpty()) if (m_threadName.isEmpty())
{ {
Q_ASSERT(false); Q_ASSERT(false);
} }
return m_threadName; return m_threadName;
} }
const char *Threading::posixThreadName() const const char *Threading::posixThreadName() const
{ {
if (m_posixThreadName.empty()) if (m_posixThreadName.empty())
{ {
m_posixThreadName = threadName().left(15).toStdString(); m_posixThreadName = threadName().left(15).toStdString();
} }
return m_posixThreadName.c_str(); return m_posixThreadName.c_str();
} }
void Threading::createThread() void Threading::createThread()
{ {
if (!isRun()) if (!isRun())
{ {
if (m_thread.joinable()) if (m_thread.joinable())
{ {
m_condition.notify_all(); m_condition.notify_all();
m_thread.join(); m_thread.join();
threadDone(); threadDone();
} }
m_alreadyThreaded = 0; m_alreadyThreaded = 0;
setRun(true); setRun(true);
m_thread = std::thread(&Threading::run, this, threadName()); m_thread = std::thread(&Threading::run, this, threadName());
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
@@ -213,7 +182,6 @@ void Threading::createThread()
void Threading::runThread() void Threading::runThread()
{ {
m_used = true; m_used = true;
Q_ASSERT(m_createThreadCalledBefore); Q_ASSERT(m_createThreadCalledBefore);
m_createThreadCalledBefore = false; m_createThreadCalledBefore = false;
@@ -243,7 +211,6 @@ void Threading::runThread()
if (workAvailable || working) if (workAvailable || working)
{ {
m_threadLifetime->start(); m_threadLifetime->start();
return; return;
} }
@@ -253,13 +220,10 @@ void Threading::runThread()
if (!run) if (!run)
{ {
Q_ASSERT(false); Q_ASSERT(false);
return; return;
} }
{ {
std::lock_guard<std::mutex> l(m_conditionMutex); std::lock_guard<std::mutex> l(m_conditionMutex);
setRun(false); setRun(false);
@@ -271,7 +235,6 @@ void Threading::runThread()
m_threadLifetime->start(); m_threadLifetime->start();
} }
void Threading::run(const QString &threadName) void Threading::run(const QString &threadName)
{ {
Q_ASSERT(m_alreadyThreaded == 0); Q_ASSERT(m_alreadyThreaded == 0);
@@ -286,8 +249,6 @@ void Threading::run(const QString &threadName)
{ {
{ {
std::unique_lock<std::mutex> conditionLock(m_conditionMutex); std::unique_lock<std::mutex> conditionLock(m_conditionMutex);
m_condition.wait(conditionLock, [this]{ return (isWorkAvailable() || !isRun()); }); m_condition.wait(conditionLock, [this]{ return (isWorkAvailable() || !isRun()); });
} }
@@ -37,26 +37,16 @@ public:
protected: protected:
void preInit() const; void preInit() const;
void createThread(); void createThread();
void runThread(); void runThread();
inline bool isRun() const { return (m_run != 0); } inline bool isRun() const { return (m_run != 0); }
inline void setRun(bool run) { m_run = (run ? 1 : 0); } inline void setRun(bool run) { m_run = (run ? 1 : 0); }
inline void setWorkAvailable(bool workAvailable) { m_workAvailable = (workAvailable ? 1 : 0); } inline void setWorkAvailable(bool workAvailable) { m_workAvailable = (workAvailable ? 1 : 0); }
inline bool isWorkAvailable() const { return (m_workAvailable != 0); } inline bool isWorkAvailable() const { return (m_workAvailable != 0); }
inline void setWorking(bool working) { m_isWorking = (working ? 1 : 0); } inline void setWorking(bool working) { m_isWorking = (working ? 1 : 0); }
inline bool isWorking() const { return (m_isWorking != 0); } inline bool isWorking() const { return (m_isWorking != 0); }
const QString &threadName() const; const QString &threadName() const;
inline const char *posixThreadName() const; inline const char *posixThreadName() const;
virtual void work() = 0; virtual void work() = 0;
virtual QString functionTopicName() const = 0; virtual QString functionTopicName() const = 0;
virtual int partitionId() const = 0; virtual int partitionId() const = 0;
@@ -68,7 +58,6 @@ protected:
{ {
if (!isRun()) if (!isRun())
{ {
throw CancelationPointReached(); throw CancelationPointReached();
} }
} }
@@ -80,7 +69,6 @@ private:
inline void setCleanupNeeded(bool cleanupNeeded) { m_cleanupNeeded = (cleanupNeeded ? 1 : 0); } inline void setCleanupNeeded(bool cleanupNeeded) { m_cleanupNeeded = (cleanupNeeded ? 1 : 0); }
void run(const QString &threadName); void run(const QString &threadName);
std::unique_ptr<QTimer> m_threadLifetime; std::unique_ptr<QTimer> m_threadLifetime;
QAtomicInt m_run { 0 }; QAtomicInt m_run { 0 };
QAtomicInt m_cleanupNeeded { 1 }; QAtomicInt m_cleanupNeeded { 1 };
@@ -13,9 +13,6 @@
#endif #endif
#include <QtCore/QVector> #include <QtCore/QVector>
namespace FTS namespace FTS
{ {
@@ -63,12 +63,8 @@ private:
void sendReplyState(Core::FtReplyState replyState, const rti::core::SampleIdentity &requestSampleIdentity) void sendReplyState(Core::FtReplyState replyState, const rti::core::SampleIdentity &requestSampleIdentity)
{ {
connext::WriteSample<ReplyTopic> reply; connext::WriteSample<ReplyTopic> reply;
// rtiddsgen -stl generates plain public data members, so the reply
// state is assigned directly instead of the old setter call.
reply.data().replyState = replyState; reply.data().replyState = replyState;
// FtReplyState doesn't exist anymore with rtiddsgen 7.7 - the
// enum values are directly available in Core::FtReplyState.
bool bLastTelegram = ((replyState != Core::FtReplyState::InProgress) && bool bLastTelegram = ((replyState != Core::FtReplyState::InProgress) &&
(replyState != Core::FtReplyState::NotStarted)); (replyState != Core::FtReplyState::NotStarted));
m_replier->send_reply(reply, requestSampleIdentity, bLastTelegram); m_replier->send_reply(reply, requestSampleIdentity, bLastTelegram);
@@ -7,12 +7,10 @@ if (NOT BUILD_TESTING)
endif() endif()
# --- nglapplication: nglcoreapplication logger handler # --- nglapplication: nglcoreapplication logger handler
# --- (Log4Qt-independent; works in the Log4Qt-less (stub) build)
if (TARGET nglcoreapplication) if (TARGET nglcoreapplication)
ADD_EXECUTABLE(nglcoreapplication_unit_test nglcoreapplication_unit_test.cpp) ADD_EXECUTABLE(nglcoreapplication_unit_test nglcoreapplication_unit_test.cpp)
# NGLLogger.h (the AlreadyCreatedError type thrown by createNGLRootLogger)
# refuses to be included outside the NGLLogger library unless
# BUILDING_NGLLOGGER is defined (same pattern as NGLLogger/CMakeLists.txt)
TARGET_COMPILE_DEFINITIONS(nglcoreapplication_unit_test PRIVATE BUILDING_NGLLOGGER) TARGET_COMPILE_DEFINITIONS(nglcoreapplication_unit_test PRIVATE BUILDING_NGLLOGGER)
TARGET_LINK_LIBRARIES(nglcoreapplication_unit_test TARGET_LINK_LIBRARIES(nglcoreapplication_unit_test
nglcoreapplication nglcoreapplication