From e7488031e069a358413867725d58a06742e05c10 Mon Sep 17 00:00:00 2001 From: Viktor Kopp Date: Tue, 24 Dec 2024 10:50:53 +0100 Subject: [PATCH 1/6] Simplify initConnections Signed-off-by: Viktor Kopp --- plugin/dltdbusplugin/dltdbusplugin.cpp | 3 +-- plugin/dlttestrobotplugin/dlttestrobotplugin.cpp | 15 ++++----------- plugin/dlttestrobotplugin/dlttestrobotplugin.h | 4 ++-- plugin/filetransferplugin/filetransferplugin.cpp | 3 +-- plugin/nonverboseplugin/nonverboseplugin.cpp | 4 +--- 5 files changed, 9 insertions(+), 20 deletions(-) diff --git a/plugin/dltdbusplugin/dltdbusplugin.cpp b/plugin/dltdbusplugin/dltdbusplugin.cpp index f9072550..2042fa1f 100644 --- a/plugin/dltdbusplugin/dltdbusplugin.cpp +++ b/plugin/dltdbusplugin/dltdbusplugin.cpp @@ -787,9 +787,8 @@ bool DltDBusPlugin::initControl(QDltControl *control) } -bool DltDBusPlugin::initConnections(QStringList list) +bool DltDBusPlugin::initConnections(QStringList) { - Q_UNUSED(list); return true; } diff --git a/plugin/dlttestrobotplugin/dlttestrobotplugin.cpp b/plugin/dlttestrobotplugin/dlttestrobotplugin.cpp index 99fcdb23..7c17c9e0 100644 --- a/plugin/dlttestrobotplugin/dlttestrobotplugin.cpp +++ b/plugin/dlttestrobotplugin/dlttestrobotplugin.cpp @@ -30,18 +30,12 @@ DltTestRobotPlugin::DltTestRobotPlugin() counterVerboseMessages = 0; dltFile = 0; dltControl = 0; - ecuList = 0; tcpSocket = 0; port = 4490; } -DltTestRobotPlugin::~DltTestRobotPlugin() -{ - -} - QString DltTestRobotPlugin::name() { return QString("DLT Test Robot Plugin"); @@ -98,7 +92,7 @@ bool DltTestRobotPlugin::initControl(QDltControl *control) bool DltTestRobotPlugin::initConnections(QStringList list) { - ecuList = new QStringList(list); + ecuList = std::move(list); return false; } @@ -196,12 +190,12 @@ void DltTestRobotPlugin::readyRead() QStringList list = text.split(' '); - if(list[0]=="injection" && ecuList) + if(list[0]=="injection") { QString ecuId = list[1]; - for(int num=0;numlength();num++) + for(int num=0;numat(num).contains(ecuId) && dltControl) + if(ecuList.at(num).contains(ecuId) && dltControl) { list.removeAt(0); list.removeAt(0); @@ -296,7 +290,6 @@ void DltTestRobotPlugin::newConnection() void DltTestRobotPlugin::connected() { - } void DltTestRobotPlugin::disconnected() diff --git a/plugin/dlttestrobotplugin/dlttestrobotplugin.h b/plugin/dlttestrobotplugin/dlttestrobotplugin.h index 9f0015d4..fba4ffa1 100644 --- a/plugin/dlttestrobotplugin/dlttestrobotplugin.h +++ b/plugin/dlttestrobotplugin/dlttestrobotplugin.h @@ -41,7 +41,7 @@ class DltTestRobotPlugin : public QObject, QDLTPluginInterface, QDltPluginViewer public: DltTestRobotPlugin(); - ~DltTestRobotPlugin(); + ~DltTestRobotPlugin() = default; /* QDLTPluginInterface interface */ QString name(); @@ -101,7 +101,7 @@ private slots: private: QDltFile *dltFile; QString errorText; - QStringList *ecuList; + QStringList ecuList; QTcpServer tcpServer; QTcpSocket *tcpSocket; diff --git a/plugin/filetransferplugin/filetransferplugin.cpp b/plugin/filetransferplugin/filetransferplugin.cpp index dbfa32ae..ba96ad8e 100644 --- a/plugin/filetransferplugin/filetransferplugin.cpp +++ b/plugin/filetransferplugin/filetransferplugin.cpp @@ -448,9 +448,8 @@ bool FiletransferPlugin::initControl(QDltControl *control) } -bool FiletransferPlugin::initConnections(QStringList list) +bool FiletransferPlugin::initConnections(QStringList) { - Q_UNUSED(list); return true; } diff --git a/plugin/nonverboseplugin/nonverboseplugin.cpp b/plugin/nonverboseplugin/nonverboseplugin.cpp index c30eaa21..96a50789 100644 --- a/plugin/nonverboseplugin/nonverboseplugin.cpp +++ b/plugin/nonverboseplugin/nonverboseplugin.cpp @@ -666,10 +666,8 @@ bool NonverbosePlugin::initControl(QDltControl *control) return true; } -bool NonverbosePlugin::initConnections(QStringList list) +bool NonverbosePlugin::initConnections(QStringList) { - Q_UNUSED(list); - return false; } From 753bdb1d39c1cfc2b4ae9a6071b158a2788ec9d2 Mon Sep 17 00:00:00 2001 From: Viktor Kopp Date: Tue, 24 Dec 2024 11:09:35 +0100 Subject: [PATCH 2/6] rm code duplication in plugin manager Signed-off-by: Viktor Kopp --- qdlt/qdltpluginmanager.cpp | 143 +++++++++++-------------------------- qdlt/qdltpluginmanager.h | 24 ++++--- 2 files changed, 58 insertions(+), 109 deletions(-) diff --git a/qdlt/qdltpluginmanager.cpp b/qdlt/qdltpluginmanager.cpp index c8c0cce2..61ba3e83 100644 --- a/qdlt/qdltpluginmanager.cpp +++ b/qdlt/qdltpluginmanager.cpp @@ -6,7 +6,6 @@ #include #include #include -//#include #include #include @@ -14,16 +13,6 @@ #define PLUGIN_INSTALLATION_PATH "" #endif -QDltPluginManager::QDltPluginManager() -{ - pMutex_pluginList = new QMutex(); -} - -QDltPluginManager::~QDltPluginManager() -{ - delete pMutex_pluginList; -} - int QDltPluginManager::size() const { return plugins.size(); @@ -93,9 +82,9 @@ QStringList QDltPluginManager::loadPluginsPath(QDir &dir) QDltPlugin* item = new QDltPlugin(); item->loadPlugin(plugin); item->initMessageDecoder(this); - pMutex_pluginList->lock(); + pluginListMutex.lock(); plugins.append(item); - pMutex_pluginList->unlock(); + pluginListMutex.unlock(); //project.plugin->addTopLevelItem(item); @@ -131,50 +120,37 @@ QStringList QDltPluginManager::loadPluginsPath(QDir &dir) return errorStrings; } -void QDltPluginManager::loadConfig(QString pluginName,QString filename) -{ - pMutex_pluginList->lock(); - for(int num=0;numname()==pluginName) +void QDltPluginManager::loadConfig(QString pluginName, QString filename) { + forEachPlugin([&](auto* plugin) { + if (plugin->name() == pluginName) plugin->setFilename(filename); - } - pMutex_pluginList->unlock(); + }); } - void QDltPluginManager::decodeMsg(QDltMsg &msg, int triggeredByUser) { - pMutex_pluginList->lock(); - for(int num=0;numdecodeMsg(msg,triggeredByUser)) break; } - pMutex_pluginList->unlock(); + pluginListMutex.unlock(); } QDltPlugin* QDltPluginManager::findPlugin(QString &name) { - QDltPlugin *plugin = nullptr; - - pMutex_pluginList->lock(); - for(int num=0;numname()==name) - { - pMutex_pluginList->unlock(); - return plugin; + QDltPlugin* result = nullptr; + pluginListMutex.lock(); + for (auto* plugin : plugins) { + if (plugin->name() == name) { + result = plugin; + break; } } + pluginListMutex.unlock(); - pMutex_pluginList->unlock(); - return plugin; + return result; } void QDltPluginManager::initPluginPriority(const QStringList& desiredPrio) @@ -198,7 +174,7 @@ bool QDltPluginManager::decreasePluginPriority(const QString &name) if(plugins.size() > 1) { - pMutex_pluginList->lock(); + pluginListMutex.lock(); for(int num=0; num < plugins.size()-1; ++num) { if(plugins[num]->name() == name) @@ -209,7 +185,7 @@ bool QDltPluginManager::decreasePluginPriority(const QString &name) break; } } - pMutex_pluginList->unlock(); + pluginListMutex.unlock(); } return result; @@ -221,7 +197,7 @@ bool QDltPluginManager::raisePluginPriority(const QString &name) if(plugins.size() > 1) { - pMutex_pluginList->lock(); + pluginListMutex.lock(); for(int num=1; num < plugins.size(); ++num) { if( plugins[num]->name() == name) @@ -232,7 +208,7 @@ bool QDltPluginManager::raisePluginPriority(const QString &name) break; } } - pMutex_pluginList->unlock(); + pluginListMutex.unlock(); } return result; @@ -248,7 +224,7 @@ bool QDltPluginManager::setPluginPriority(const QString& name, int prio) prio = plugins.size() - 1; } - pMutex_pluginList->lock(); + pluginListMutex.lock(); for (int num = 0; num < plugins.size(); ++num) { if (plugins[num]->name() == name) { if (prio != num) { @@ -259,7 +235,7 @@ bool QDltPluginManager::setPluginPriority(const QString& name, int prio) break; } } - pMutex_pluginList->unlock(); + pluginListMutex.unlock(); } return result; @@ -268,15 +244,11 @@ bool QDltPluginManager::setPluginPriority(const QString& name, int prio) QStringList QDltPluginManager::getPluginPriorities() const { QStringList finalPrio; - - if(plugins.size() > 0) { - pMutex_pluginList->lock(); - for(int num=0; num < plugins.size(); ++num) - { - finalPrio << plugins[num]->name(); - } - pMutex_pluginList->unlock(); + pluginListMutex.lock(); + for (auto* plugin: plugins) { + finalPrio << plugin->name(); } + pluginListMutex.unlock(); return finalPrio; } @@ -284,16 +256,10 @@ QStringList QDltPluginManager::getPluginPriorities() const QList QDltPluginManager::getDecoderPlugins() { QList list; - - pMutex_pluginList->lock(); - for(int num=0;numisDecoder() && plugin->getMode()>=QDltPlugin::ModeEnable) + forEachPlugin([&](auto* plugin) { + if (plugin->isDecoder() && plugin->getMode() >= QDltPlugin::ModeEnable) list.append(plugin); - } - pMutex_pluginList->unlock(); + }); return list; } @@ -301,73 +267,50 @@ QList QDltPluginManager::getDecoderPlugins() QList QDltPluginManager::getViewerPlugins() { QList list; - - pMutex_pluginList->lock(); - for(int num=0;numisViewer() && plugin->getMode()>=QDltPlugin::ModeEnable) + forEachPlugin([&](auto* plugin) { + if (plugin->isViewer() && plugin->getMode() >= QDltPlugin::ModeEnable) list.append(plugin); - } - pMutex_pluginList->unlock(); + }); return list; } bool QDltPluginManager::stateChanged(int index, QDltConnection::QDltConnectionState connectionState,QString hostname) { - pMutex_pluginList->lock(); - for(int num=0;numisControl() ) - plugin->stateChanged(index,connectionState,hostname); - } - pMutex_pluginList->unlock(); + forEachPlugin([&](auto* plugin) { + if (plugin->isControl()) + plugin->stateChanged(index, connectionState, hostname); + }); return true; } bool QDltPluginManager::autoscrollStateChanged(bool enabled) { - pMutex_pluginList->lock(); - for(int num=0;numisControl() ) plugin->autoscrollStateChanged(enabled); - } - pMutex_pluginList->unlock(); + }); return true; } - bool QDltPluginManager::initControl(QDltControl *control) { - pMutex_pluginList->lock(); - for(int num=0;numisControl() ) plugin->initControl(control); - } - pMutex_pluginList->unlock(); + }); return true; } bool QDltPluginManager::initConnections(QStringList list) { - pMutex_pluginList->lock(); - for(int num=0;numisControl() ) plugin->initConnections(list); - } - pMutex_pluginList->unlock(); + }); return true; } diff --git a/qdlt/qdltpluginmanager.h b/qdlt/qdltpluginmanager.h index 468db4a6..d645e6a0 100644 --- a/qdlt/qdltpluginmanager.h +++ b/qdlt/qdltpluginmanager.h @@ -1,12 +1,14 @@ #ifndef QDLTPLUGINMANAGER_H #define QDLTPLUGINMANAGER_H -#include "plugininterface.h" - -#include +#include "qdltconnection.h" +#include "qdltcontrol.h" +#include "qdltmessagedecoder.h" #include "export_rules.h" +#include + //! Manage all DLT Plugins /*! This class loads all DLT Viewer Plugins and provides access to them. @@ -18,11 +20,6 @@ class QMutex; class QDLT_EXPORT QDltPluginManager : public QDltMessageDecoder { public: - - //! Constructor - QDltPluginManager(); - ~QDltPluginManager(); - //! The number of plugins /*! \return the number of loaded plugins. @@ -84,7 +81,16 @@ class QDLT_EXPORT QDltPluginManager : public QDltMessageDecoder QStringList getPluginPriorities() const; private: - mutable QMutex* pMutex_pluginList; + template + void forEachPlugin(F&& f) { + pluginListMutex.lock(); + for (QDltPlugin* plugin : plugins) { + f(plugin); + } + pluginListMutex.unlock(); + } + + mutable QMutex pluginListMutex; //! The list of pointers to all loaded plugins QList plugins; From 6f9462fb1ccb8f824f4408c4dd549d8330f54c1f Mon Sep 17 00:00:00 2001 From: Viktor Kopp Date: Tue, 24 Dec 2024 11:49:38 +0100 Subject: [PATCH 3/6] clang-format ref and ptr to the left Signed-off-by: Viktor Kopp --- .clang-format | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.clang-format b/.clang-format index 7631cd1a..30a5e61a 100644 --- a/.clang-format +++ b/.clang-format @@ -2,4 +2,6 @@ BasedOnStyle: LLVM ColumnLimit: 100 IndentWidth: 4 +ReferenceAlignment: Pointer +PointerAlignment: Left ... From f14dedb6baab0dfd6a911da36de88ab2ff361db2 Mon Sep 17 00:00:00 2001 From: Viktor Kopp Date: Tue, 24 Dec 2024 12:23:29 +0100 Subject: [PATCH 4/6] additional minor code improvements Signed-off-by: Viktor Kopp --- qdlt/qdltpluginmanager.cpp | 9 +++------ qdlt/qdltpluginmanager.h | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/qdlt/qdltpluginmanager.cpp b/qdlt/qdltpluginmanager.cpp index 61ba3e83..cdb4397c 100644 --- a/qdlt/qdltpluginmanager.cpp +++ b/qdlt/qdltpluginmanager.cpp @@ -62,11 +62,9 @@ QStringList QDltPluginManager::loadPlugins(const QString &settingsPluginPath) QStringList QDltPluginManager::loadPluginsPath(QDir &dir) { /* set filter for plugin files */ - QStringList filters, errorStrings; - QString errorString; - filters << "*.dll" << "*.so" << "*.dylib"; - dir.setNameFilters(filters); + QStringList errorStrings; + dir.setNameFilters(QStringList{} << "*.dll" << "*.so" << "*.dylib"); /* iterate through all plugins */ foreach (QString fileName, dir.entryList(QDir::Files)) { @@ -138,8 +136,7 @@ void QDltPluginManager::decodeMsg(QDltMsg &msg, int triggeredByUser) pluginListMutex.unlock(); } -QDltPlugin* QDltPluginManager::findPlugin(QString &name) -{ +QDltPlugin* QDltPluginManager::findPlugin(const QString& name) const { QDltPlugin* result = nullptr; pluginListMutex.lock(); for (auto* plugin : plugins) { diff --git a/qdlt/qdltpluginmanager.h b/qdlt/qdltpluginmanager.h index d645e6a0..9d167d0d 100644 --- a/qdlt/qdltpluginmanager.h +++ b/qdlt/qdltpluginmanager.h @@ -63,9 +63,9 @@ class QDLT_EXPORT QDltPluginManager : public QDltMessageDecoder //! Find a plugin with the specific name /*! \param name The name of the plugin to be searched for. - \return pinter to plugin or zero if no plugin with the name is found + \return pointer to plugin or nullptr if no plugin with the name is found */ - QDltPlugin* findPlugin(QString &name); + QDltPlugin* findPlugin(const QString &name) const; //control plugin interface bool stateChanged(int index, QDltConnection::QDltConnectionState connectionState, QString hostname); From a2bf202ca7e8ed602ab62123a00304318127f370 Mon Sep 17 00:00:00 2001 From: Viktor Kopp Date: Tue, 24 Dec 2024 12:36:25 +0100 Subject: [PATCH 5/6] Use QMutexLocker instead of explicit lock/unlock Signed-off-by: Viktor Kopp --- qdlt/qdltpluginmanager.cpp | 18 ++++++------------ qdlt/qdltpluginmanager.h | 7 +++---- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/qdlt/qdltpluginmanager.cpp b/qdlt/qdltpluginmanager.cpp index cdb4397c..19d96326 100644 --- a/qdlt/qdltpluginmanager.cpp +++ b/qdlt/qdltpluginmanager.cpp @@ -127,25 +127,23 @@ void QDltPluginManager::loadConfig(QString pluginName, QString filename) { void QDltPluginManager::decodeMsg(QDltMsg &msg, int triggeredByUser) { - pluginListMutex.lock(); + QMutexLocker mutexLocker(&pluginListMutex); for(auto* plugin : plugins) { if(plugin->decodeMsg(msg,triggeredByUser)) break; } - pluginListMutex.unlock(); } QDltPlugin* QDltPluginManager::findPlugin(const QString& name) const { QDltPlugin* result = nullptr; - pluginListMutex.lock(); + QMutexLocker mutexLocker(&pluginListMutex); for (auto* plugin : plugins) { if (plugin->name() == name) { result = plugin; break; } } - pluginListMutex.unlock(); return result; } @@ -171,7 +169,7 @@ bool QDltPluginManager::decreasePluginPriority(const QString &name) if(plugins.size() > 1) { - pluginListMutex.lock(); + QMutexLocker mutexLocker(&pluginListMutex); for(int num=0; num < plugins.size()-1; ++num) { if(plugins[num]->name() == name) @@ -182,7 +180,6 @@ bool QDltPluginManager::decreasePluginPriority(const QString &name) break; } } - pluginListMutex.unlock(); } return result; @@ -194,7 +191,7 @@ bool QDltPluginManager::raisePluginPriority(const QString &name) if(plugins.size() > 1) { - pluginListMutex.lock(); + QMutexLocker mutexLocker(&pluginListMutex); for(int num=1; num < plugins.size(); ++num) { if( plugins[num]->name() == name) @@ -205,7 +202,6 @@ bool QDltPluginManager::raisePluginPriority(const QString &name) break; } } - pluginListMutex.unlock(); } return result; @@ -221,7 +217,7 @@ bool QDltPluginManager::setPluginPriority(const QString& name, int prio) prio = plugins.size() - 1; } - pluginListMutex.lock(); + QMutexLocker mutexLocker(&pluginListMutex); for (int num = 0; num < plugins.size(); ++num) { if (plugins[num]->name() == name) { if (prio != num) { @@ -232,7 +228,6 @@ bool QDltPluginManager::setPluginPriority(const QString& name, int prio) break; } } - pluginListMutex.unlock(); } return result; @@ -241,11 +236,10 @@ bool QDltPluginManager::setPluginPriority(const QString& name, int prio) QStringList QDltPluginManager::getPluginPriorities() const { QStringList finalPrio; - pluginListMutex.lock(); + QMutexLocker mutexLocker(&pluginListMutex); for (auto* plugin: plugins) { finalPrio << plugin->name(); } - pluginListMutex.unlock(); return finalPrio; } diff --git a/qdlt/qdltpluginmanager.h b/qdlt/qdltpluginmanager.h index 9d167d0d..d1459387 100644 --- a/qdlt/qdltpluginmanager.h +++ b/qdlt/qdltpluginmanager.h @@ -81,13 +81,12 @@ class QDLT_EXPORT QDltPluginManager : public QDltMessageDecoder QStringList getPluginPriorities() const; private: - template + template void forEachPlugin(F&& f) { - pluginListMutex.lock(); + QMutexLocker mutexLocker(&pluginListMutex); for (QDltPlugin* plugin : plugins) { - f(plugin); + f(plugin); } - pluginListMutex.unlock(); } mutable QMutex pluginListMutex; From 619f71492c7bdc9cca6be2de564d3e8e108e6638 Mon Sep 17 00:00:00 2001 From: Viktor Kopp Date: Tue, 24 Dec 2024 12:40:41 +0100 Subject: [PATCH 6/6] use std algos Signed-off-by: Viktor Kopp --- qdlt/qdltplugin.cpp | 2 +- qdlt/qdltplugin.h | 2 +- qdlt/qdltpluginmanager.cpp | 56 ++++++++++++++++++++------------------ qdlt/qdltpluginmanager.h | 14 ++-------- 4 files changed, 35 insertions(+), 39 deletions(-) diff --git a/qdlt/qdltplugin.cpp b/qdlt/qdltplugin.cpp index 4a85d186..bda2574a 100644 --- a/qdlt/qdltplugin.cpp +++ b/qdlt/qdltplugin.cpp @@ -96,7 +96,7 @@ bool QDltPlugin::isCommand() } // generic plugin interfaces -QString QDltPlugin::name() +QString QDltPlugin::name() const { if(plugininterface) return plugininterface->name(); diff --git a/qdlt/qdltplugin.h b/qdlt/qdltplugin.h index 6980422f..5bb4688a 100644 --- a/qdlt/qdltplugin.h +++ b/qdlt/qdltplugin.h @@ -71,7 +71,7 @@ class QDLT_EXPORT QDltPlugin bool isCommand(); // generic plugin interfaces - QString name(); + QString name() const; QString pluginVersion(); QString pluginInterfaceVersion(); QString error(); diff --git a/qdlt/qdltpluginmanager.cpp b/qdlt/qdltpluginmanager.cpp index 19d96326..1c3966b8 100644 --- a/qdlt/qdltpluginmanager.cpp +++ b/qdlt/qdltpluginmanager.cpp @@ -119,7 +119,8 @@ QStringList QDltPluginManager::loadPluginsPath(QDir &dir) } void QDltPluginManager::loadConfig(QString pluginName, QString filename) { - forEachPlugin([&](auto* plugin) { + QMutexLocker mutexLocker(&pluginListMutex); + std::for_each(plugins.begin(), plugins.end(), [&](auto* plugin) { if (plugin->name() == pluginName) plugin->setFilename(filename); }); @@ -136,26 +137,20 @@ void QDltPluginManager::decodeMsg(QDltMsg &msg, int triggeredByUser) } QDltPlugin* QDltPluginManager::findPlugin(const QString& name) const { - QDltPlugin* result = nullptr; + QMutexLocker mutexLocker(&pluginListMutex); - for (auto* plugin : plugins) { - if (plugin->name() == name) { - result = plugin; - break; - } - } + auto it = std::find_if(plugins.begin(), plugins.end(), [&](auto* plugin) { + return plugin->name() == name; + }); - return result; + return it != plugins.end() ? *it : nullptr; } void QDltPluginManager::initPluginPriority(const QStringList& desiredPrio) { - QStringList finalPrio; - if(plugins.size() > 1) { int prio = 0; - for (int i = 0; i < desiredPrio.count(); ++i) { - QString pluginName(desiredPrio[i]); + for (const auto& pluginName: desiredPrio) { if (setPluginPriority(pluginName, prio)) { ++prio; } @@ -194,8 +189,7 @@ bool QDltPluginManager::raisePluginPriority(const QString &name) QMutexLocker mutexLocker(&pluginListMutex); for(int num=1; num < plugins.size(); ++num) { - if( plugins[num]->name() == name) - { + if (plugins[num]->name() == name) { qDebug() << "raise prio of" << name << "from" << num << "to" << num-1; plugins.move(num, num-1); result = true; @@ -236,18 +230,22 @@ bool QDltPluginManager::setPluginPriority(const QString& name, int prio) QStringList QDltPluginManager::getPluginPriorities() const { QStringList finalPrio; + finalPrio.reserve(plugins.size()); + QMutexLocker mutexLocker(&pluginListMutex); - for (auto* plugin: plugins) { - finalPrio << plugin->name(); - } + std::transform(plugins.begin(), plugins.end(), std::back_inserter(finalPrio), [](const auto* plugin) { + return plugin->name(); + }); return finalPrio; } -QList QDltPluginManager::getDecoderPlugins() +QList QDltPluginManager::getDecoderPlugins() const { QList list; - forEachPlugin([&](auto* plugin) { + + QMutexLocker mutexLocker(&pluginListMutex); + std::for_each(plugins.begin(), plugins.end(), [&](auto* plugin) { if (plugin->isDecoder() && plugin->getMode() >= QDltPlugin::ModeEnable) list.append(plugin); }); @@ -255,10 +253,12 @@ QList QDltPluginManager::getDecoderPlugins() return list; } -QList QDltPluginManager::getViewerPlugins() +QList QDltPluginManager::getViewerPlugins() const { QList list; - forEachPlugin([&](auto* plugin) { + + QMutexLocker mutexLocker(&pluginListMutex); + std::for_each(plugins.begin(), plugins.end(), [&](auto* plugin) { if (plugin->isViewer() && plugin->getMode() >= QDltPlugin::ModeEnable) list.append(plugin); }); @@ -268,7 +268,8 @@ QList QDltPluginManager::getViewerPlugins() bool QDltPluginManager::stateChanged(int index, QDltConnection::QDltConnectionState connectionState,QString hostname) { - forEachPlugin([&](auto* plugin) { + QMutexLocker mutexLocker(&pluginListMutex); + std::for_each(plugins.begin(), plugins.end(), [&](auto* plugin) { if (plugin->isControl()) plugin->stateChanged(index, connectionState, hostname); }); @@ -278,7 +279,8 @@ bool QDltPluginManager::stateChanged(int index, QDltConnection::QDltConnectionSt bool QDltPluginManager::autoscrollStateChanged(bool enabled) { - forEachPlugin([&](auto* plugin){ + QMutexLocker mutexLocker(&pluginListMutex); + std::for_each(plugins.begin(), plugins.end(), [&](auto* plugin){ if(plugin->isControl() ) plugin->autoscrollStateChanged(enabled); }); @@ -288,7 +290,8 @@ bool QDltPluginManager::autoscrollStateChanged(bool enabled) bool QDltPluginManager::initControl(QDltControl *control) { - forEachPlugin([&](auto* plugin){ + QMutexLocker mutexLocker(&pluginListMutex); + std::for_each(plugins.begin(), plugins.end(), [&](auto* plugin){ if(plugin->isControl() ) plugin->initControl(control); }); @@ -298,7 +301,8 @@ bool QDltPluginManager::initControl(QDltControl *control) bool QDltPluginManager::initConnections(QStringList list) { - forEachPlugin([&](auto* plugin){ + QMutexLocker mutexLocker(&pluginListMutex); + std::for_each(plugins.begin(), plugins.end(), [&](auto* plugin){ if(plugin->isControl() ) plugin->initConnections(list); }); diff --git a/qdlt/qdltpluginmanager.h b/qdlt/qdltpluginmanager.h index d1459387..ce5c8949 100644 --- a/qdlt/qdltpluginmanager.h +++ b/qdlt/qdltpluginmanager.h @@ -52,13 +52,13 @@ class QDLT_EXPORT QDltPluginManager : public QDltMessageDecoder void decodeMsg(QDltMsg &msg,int triggeredByUser) override; //! Get the list of pointers to all loaded plugins - QList getPlugins() { return plugins; } + QList getPlugins() const { return plugins; } //! Get the list of pointers to all enabled decoder plugins - QList getDecoderPlugins(); + QList getDecoderPlugins() const; //! Get the list of pointers to all enabled viewer plugins - QList getViewerPlugins(); + QList getViewerPlugins() const; //! Find a plugin with the specific name /*! @@ -81,14 +81,6 @@ class QDLT_EXPORT QDltPluginManager : public QDltMessageDecoder QStringList getPluginPriorities() const; private: - template - void forEachPlugin(F&& f) { - QMutexLocker mutexLocker(&pluginListMutex); - for (QDltPlugin* plugin : plugins) { - f(plugin); - } - } - mutable QMutex pluginListMutex; //! The list of pointers to all loaded plugins