Skip to content

Commit 1b050c0

Browse files
committed
populate ecus tree efficiently
fix symbols visibility Fix macos-13 build It still uses qmake, so new sources should be added there too Signed-off-by: Viktor Kopp <[email protected]>
1 parent b45cbae commit 1b050c0

8 files changed

+105
-41
lines changed

qdlt/qdlt.pro

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ SOURCES += \
6868
fieldnames.cpp \
6969
qdltimporter.cpp \
7070
dltmessagematcher.cpp \
71+
qdltctrlmsg.cpp \
7172

7273
HEADERS += qdlt.h \
7374
export_rules.h \
@@ -101,6 +102,7 @@ HEADERS += qdlt.h \
101102
fieldnames.h \
102103
qdltimporter.h \
103104
dltmessagematcher.h \
105+
qdltctrlmsg.h \
104106

105107
unix:VERSION = 1.0.0
106108

qdlt/qdltctrlmsg.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef QDLTCTRLMSG_H
22
#define QDLTCTRLMSG_H
33

4+
#include "export_rules.h"
5+
46
#include <vector>
57
#include <variant>
68

@@ -57,7 +59,7 @@ struct UnregisterContext {
5759
using Type = std::variant<GetLogInfo, GetSoftwareVersion, GetDefaultLogLevel, SetLogLevel, Timezone,
5860
UnregisterContext>;
5961

60-
Type parse(const QByteArray&, bool isBigEndian);
62+
QDLT_EXPORT Type parse(const QByteArray&, bool isBigEndian);
6163

6264
} // namespace qdlt::msg::payload
6365

src/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ add_executable(dlt-viewer
5151
searchform.cpp
5252
${UI_RESOURCES_RCC}
5353
resources/dlt_viewer.rc
54-
)
54+
ecutree.h
55+
ecutree.cpp
56+
)
5557

5658
target_link_libraries(dlt-viewer
5759
qdlt

src/ecutree.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "ecutree.h"
2+
3+
void EcuTree::add(const QString& ecuId, const qdlt::msg::payload::GetLogInfo& info)
4+
{
5+
for (const auto& app : info.apps) {
6+
App appData;
7+
appData.description = app.description;
8+
for (const auto& ctx : app.ctxs) {
9+
Ctx ctxData;
10+
ctxData.description = ctx.description;
11+
ctxData.logLevel = ctx.logLevel;
12+
ctxData.traceStatus = ctx.traceStatus;
13+
appData.contexts[ctx.id] = std::move(ctxData);
14+
}
15+
ecus[ecuId][app.id] = std::move(appData);
16+
}
17+
}

src/ecutree.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef ECUTREEBUILDER_H
2+
#define ECUTREEBUILDER_H
3+
4+
#include <qdltctrlmsg.h>
5+
6+
#include <map>
7+
8+
struct EcuTree
9+
{
10+
void add(const QString& ecuId, const qdlt::msg::payload::GetLogInfo&);
11+
12+
using EcuId = QString;
13+
using AppId = QString;
14+
using CtxId = QString;
15+
struct Ctx {
16+
QString description;
17+
int8_t logLevel;
18+
int8_t traceStatus;
19+
};
20+
struct App {
21+
QString description;
22+
std::map<CtxId, Ctx> contexts;
23+
};
24+
std::map<EcuId, std::map<AppId, App>> ecus;
25+
};
26+
27+
#endif // ECUTREEBUILDER_H

src/mainwindow.cpp

+47-31
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ extern "C" {
8888
#include "sortfilterproxymodel.h"
8989
#include "qdltoptmanager.h"
9090
#include "qdltctrlmsg.h"
91+
#include "ecutree.h"
9192

9293

9394
MainWindow::MainWindow(QWidget *parent) :
@@ -1893,45 +1894,52 @@ void MainWindow::on_action_menuFile_Clear_triggered()
18931894
return;
18941895
}
18951896

1896-
void MainWindow::contextLoadingFile(const QDltMsg &msg)
1897+
void MainWindow::populateEcusTree(EcuTree&& ecuTree)
18971898
{
1898-
/* find ecu item */
1899-
EcuItem *ecuitemFound = 0;
1900-
for(int num = 0; num < project.ecu->topLevelItemCount (); num++)
1901-
{
1902-
EcuItem *ecuitem = (EcuItem*)project.ecu->topLevelItem(num);
1903-
if(ecuitem->id == msg.getEcuid())
1904-
{
1905-
ecuitemFound = ecuitem;
1906-
break;
1907-
}
1908-
}
1899+
QList<QTreeWidgetItem*> ecus;
1900+
// populate ECUs tree view
1901+
for (auto& [ecuid, apps] : ecuTree.ecus) {
1902+
EcuItem* ecuItem = new EcuItem(nullptr);
19091903

1910-
if(!ecuitemFound)
1911-
{
1912-
/* no Ecuitem found, create a new one */
1913-
ecuitemFound = new EcuItem(0);
1904+
ecuItem->id = ecuid;
19141905

1915-
/* update ECU item */
1916-
ecuitemFound->id = msg.getEcuid();
1917-
ecuitemFound->update();
1906+
QList<QTreeWidgetItem*> appsItems;
1907+
for(const auto& [appid, appdata] : apps) {
1908+
ApplicationItem* appItem = new ApplicationItem(ecuItem);
1909+
appItem->id = appid;
1910+
appItem->description = appdata.description;
1911+
appItem->update();
19181912

1919-
/* add ECU to configuration */
1920-
project.ecu->addTopLevelItem(ecuitemFound);
1913+
QList<QTreeWidgetItem*> contextsItems;
1914+
for(const auto& [ctxid, ctxdata] : appdata.contexts) {
1915+
ContextItem* conItem = new ContextItem(appItem);
1916+
conItem->id = ctxid;
1917+
conItem->loglevel = ctxdata.logLevel;
1918+
conItem->tracestatus = ctxdata.traceStatus;
1919+
conItem->description = ctxdata.description;
1920+
conItem->status = ContextItem::valid;
1921+
conItem->update();
19211922

1922-
/* Update the ECU list in control plugins */
1923-
updatePluginsECUList();
1923+
contextsItems.append(conItem);
1924+
}
19241925

1925-
pluginManager.stateChanged(project.ecu->indexOfTopLevelItem(ecuitemFound), QDltConnection::QDltConnectionOffline,ecuitemFound->getHostname());
1926+
appItem->addChildren(contextsItems);
1927+
appsItems.append(appItem);
1928+
}
19261929

1927-
}
1930+
ecuItem->addChildren(appsItems);
1931+
ecuItem->update();
19281932

1929-
controlMessage_ReceiveControlMessage(ecuitemFound, msg);
1930-
}
1933+
pluginManager.stateChanged(ecus.size(), QDltConnection::QDltConnectionOffline,
1934+
ecuItem->getHostname());
19311935

1932-
void MainWindow::reloadLogFileStop()
1933-
{
1936+
ecus.append(ecuItem);
1937+
}
1938+
1939+
project.ecu->addTopLevelItems(ecus);
19341940

1941+
/* Update the ECU list in control plugins */
1942+
updatePluginsECUList();
19351943
}
19361944

19371945
void MainWindow::reloadLogFileProgressMax(int num)
@@ -2062,13 +2070,21 @@ void MainWindow::reloadLogFileFinishFilter()
20622070
settings->updateContextLoadingFile) {
20632071
const QList<int> &msgIndexList = dltIndexer->getGetLogInfoList();
20642072

2065-
// FIXME: this is slow operation running in the main loop
20662073
QDltMsg msg;
2074+
EcuTree ecuTree;
20672075
for (const auto msgIndex : msgIndexList) {
20682076
if (qfile.getMsg(msgIndex, msg)) {
2069-
contextLoadingFile(msg);
2077+
auto ctrlMsg = qdlt::msg::payload::parse(msg.getPayload(), msg.getEndianness() == QDltMsg::DltEndiannessBigEndian);
2078+
std::visit([&ecuTree, ecuId = msg.getEcuid()](auto&& payload) {
2079+
using T = std::decay_t<decltype(payload)>;
2080+
if constexpr (std::is_same_v<T, qdlt::msg::payload::GetLogInfo>) {
2081+
ecuTree.add(ecuId, payload);
2082+
}
2083+
}, ctrlMsg);
20702084
}
20712085
}
2086+
project.ecu->clear();
2087+
populateEcusTree(std::move(ecuTree));
20722088
}
20732089

20742090
// reconnect ecus again

src/mainwindow.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ namespace Ui {
9696
class MainWindow;
9797
}
9898

99+
struct EcuTree;
100+
99101
class MainWindow : public QMainWindow
100102
{
101103
Q_OBJECT
@@ -236,13 +238,8 @@ class MainWindow : public QMainWindow
236238

237239
void getSelectedItems(EcuItem **ecuitem,ApplicationItem** appitem,ContextItem** conitem);
238240

239-
/**
240-
* @brief Reload the complete log file
241-
* @param update if this parameter is false, the file is loaded the first time, if true the reload is performed because of a changed configuration
242-
*
243-
*/
244-
void reloadLogFileStop();
245241
void reloadLogFile(bool update=false, bool multithreaded = true);
242+
void populateEcusTree(EcuTree&& ecuTree);
246243

247244
void reloadLogFileDefaultFilter();
248245

@@ -275,7 +272,6 @@ class MainWindow : public QMainWindow
275272
void updatePluginsECUList();
276273
void updatePlugins();
277274
void updatePlugin(PluginItem *item);
278-
void contextLoadingFile(const QDltMsg &msg);
279275
void versionString(const QDltMsg &msg);
280276
void pluginsAutoload(QString version);
281277

src/src.pro

+3-1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ SOURCES += main.cpp \
149149
dltmsgqueue.cpp \
150150
dltfileindexerthread.cpp \
151151
dltfileindexerdefaultfilterthread.cpp \
152+
ecutree.cpp \
152153

153154
# Show these headers in the project
154155
HEADERS += mainwindow.h \
@@ -180,7 +181,8 @@ HEADERS += mainwindow.h \
180181
dltmsgqueue.h \
181182
dltfileindexerthread.h \
182183
dltfileindexerdefaultfilterthread.h \
183-
mcudpsocket.h
184+
mcudpsocket.h \
185+
ecutree.h \
184186

185187
# Compile these UI files
186188
FORMS += mainwindow.ui \

0 commit comments

Comments
 (0)