File: dlt_viewer_plugins_programming_guide.txt

package info (click to toggle)
dlt-viewer 2.23.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,432 kB
  • sloc: cpp: 27,832; ansic: 4,454; xml: 491; sh: 154; makefile: 75
file content (360 lines) | stat: -rw-r--r-- 13,856 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
DLT Viewer Plugins Programming Guide
====================================
Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
0.0.2, February 2016: Updates and improvements for current DLT Viewer state
// 0.0.1, 2012/10/23: Initial version

image::images/genivi_chrome_1_transparent.png[width=128]

Overview
--------
The DLT Viewer's functionality can be extended by plugins. There are currently four different types of plugins:

Decoder Plugins::
    Interprets DLT messages and translates them into human readable data. The decoded message content is also used to
    filter the messages.
Viewer Plugins::
    These plugins create UI widgets which can display additional graphical information about DLT messages. They can be used with individual selected messages or whole log streams and DLT files.
Control Plugins::
    These plugins are able to control the message table of the DLT Viewer and to communicate with target applications.
Command Plugins::
    These plugins can read command line arguments passed to the DLT Viewer.

Each plugin can be a mixture of the types listed above, depending on which interfaces the plugins implement.

Interfaces
----------
The plugins can implement several plugin interfaces:

QDLTPluginInterface::
    This is the standard DLT Viewer plugin interface.
    This interface *must* be inherited by each DLT Viewer plugin.
QDLTPluginDecoderInterface::
    This is an extended DLT Viewer plugin interface.
    This interface must be used by decoder plugins.
    DLT messages are passed to and can be decoded by the plugin. The plugin decides on its own which messages to decode.
QDltPluginViewerInterface::
    This is an extended DLT Viewer plugin interface.
    This interface must be used by viewer plugins.
    The viewer plugin gets full access to the loaded DLT file. Viewer plugins provide a UI widget to display additional information or other graphical content.
QDltPluginControlInterface::
    This is an extended DLT Viewer plugin interface.
    This interface must be used by control plugins.
    Control plugins get informed about the available connections to DLT daemons.
    They can send control requests to and receive responses from target applications.
    The plugin can also "jump" inside the message table in order to guide the user's focus to specific messages.
QDltPluginCommandInterface::
    This is an extended DLT Viewer plugin interface.
    This interface must be used by command plugins.
    The command plugin interface can be used to receive commands passed from the UI or command line.

The QDLTPluginInterface must be implemented by every plugin. The other plugin interfaces are optional.

A Basic Plugin
--------------

The following code samples show the minimal code needed for a DLT Viewer plugin. + 
(You can find these files in the DLT Viewer project.)

.dummyplugin.h
----
#ifndef DUMMYPLUGIN_H
#define DUMMYPLUGIN_H

#include <QObject>
#include "plugininterface.h"

#define DUMMY_PLUGIN_VERSION "1.0.0"

class DummyPlugin : public QObject, QDLTPluginInterface
{
    Q_OBJECT
    Q_INTERFACES(QDLTPluginInterface)

public:
    DummyPlugin();
    ~DummyPlugin();

    /* QDLTPluginInterface interface */
    QString name();
    QString pluginVersion();
    QString pluginInterfaceVersion();
    QString description();
    QString error();
    bool loadConfig(QString filename);
    bool saveConfig(QString filename);
    QStringList infoConfig();
};

#endif // DUMMYPLUGIN_H
----

.dummyplugin.c
----
#include <QtGui>

#include "dummydecoderplugin.h"

DummyPlugin::DummyPlugin()
{}

DummyPlugin::~DummyPlugin()
{}

QString DummyPlugin::name()
{
    return QString("Dummy Plugin");
}

QString DummyPlugin::pluginVersion()
{
    return DUMMY_PLUGIN_VERSION;
}

QString DummyPlugin::pluginInterfaceVersion()
{
    return PLUGIN_INTERFACE_VERSION;
}

QString DummyPlugin::description()
{
    return QString();
}

QString DummyPlugin::error()
{
    return QString();
}

bool DummyPlugin::loadConfig(QString /* filename */ )
{
    return true;
}

bool DummyPlugin::saveConfig(QString /* filename */)
{
    return true;
}

QStringList DummyPlugin::infoConfig()
{
    return QStringList();
}

#ifndef QT5
Q_EXPORT_PLUGIN2(dummyplugin, DummyPlugin);
#endif
----

.dummyplugin.pro
----
# include global settings for all DLT Viewer Plugins
include( ../plugin.pri )

# target name
TARGET = $$qtLibraryTarget(dummyplugin)

# plugin header files
HEADERS += \
    dummyplugin.h

# plugin source files
SOURCES += \
    dummyplugin.cpp

# plugin forms
FORMS +=
----

Additional interfaces and thus additional functionality can be added by deriving the plugin class from any of the other interfaces.
Remember that the QDLTPluginInterface must still be implemented, even if you add one or more of the optional plugin interfaces.

----
class DummyDecoderPlugin : public QObject, QDLTPluginInterface, QDLTPluginDecoderInterface
----

You also have to declare the interfaces you use with the +Q_INTERFACES+ macro in the plugin's header file.

----
   Q_INTERFACES(QDLTDecoderPluginInterface)
   
public:
    /* QDltPluginDecoderInterface */
    bool isMsg(QDltMsg &msg, int triggeredByUser);
    bool decodeMsg(QDltMsg &msg, int triggeredByUser);
----

All interface functions are _pure virtual functions_, so they must be defined in the plugin's +.cpp+ file.

If you also implemented a widget for viewer plugins, add a form to the plugin project and return an instance of the widget in the +initViewer()+ function.

[IMPORTANT]
If you return a UI widget in the +initViewer()+ function, this widget will be owned by the Qt framework, which will handle the widget's destruction. Do not try to delete this widget on your own!


QDLTPluginInterface description
-------------------------------
This is the standard DLT Viewer Plugin Interface.
This interface must be inherited by each DLT Viewer plugin.
Most of the functions in this interface are called when loading the plugin the first time.

Function +QString name()+
~~~~~~~~~~~~~~~~~~~~~~~
The plugin must provide a name. This name is shown to the user in the project configuration.

Function +QString pluginVersion()+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The plugin has to return a version number in the format +X.Y.Z+.

* _X_ should count up in case of really heavy changes (API changes or purpose changes)
* _Y_ should count up when the module is reworked internally, functions are added etc
* _Z_ should count up whenever a bug is fixed

Recommendation: +#define <plugin name>_PLUGIN_VERSION "X.Y.Z"+ in your plugin header file.

Function +QString pluginInterfaceVersion()+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The plugin has to return a version number of the used plugin interface. The plugin interface provides the +PLUGIN_INTERFACE_VERSION+ definition for this purpose.

Function +QString description()+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Currently not used by DLT Viewer.

Function +QString error()+
~~~~~~~~~~~~~~~~~~~~~~~~
The plugin can provide an error message for the last failed function call. In some cases the DLT Viewer can display this message to the user.
You can also just return an empty +QString+ if you don't care about this.

Function +bool loadConfig(QString filename)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The plugin can use configuration stored in files. This can be a single file or a directory containing several files.
This function is called whenever a new file gets loaded.

Function +bool saveConfig(QString filename)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Currently not used by DLT Viewer.

Function +QStringList infoConfig()+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is called after a call to +loadConfig()+. The plugin can provide a detailed list of the loaded configuration. This is very useful for checking whether the configuration was loaded successfully.


QDLTPluginDecoderInterface description
--------------------------------------
These functions are called in the following cases:

* A new DLT message is shown in the table
* A DLT message has been filtered to create the internal filter index
* A DLT message is being exported to ASCII

Function +bool isMsg(QDltMsg &msg, int triggeredByUser)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The plugin checks whether this DLT message should be handled by the plugin. This is called before +initMsgDecoded()+ and +updateMsgDecoded()+.

Function +bool decodeMsg(QDltMsg &msg, int triggeredByUser)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is only called if the previous call to +isMsg()+ returned +true+. The function can access the message reference to alter its content. The function should return +true+ if the message was successfully converted, and +false+ otherwise.


QDltPluginViewerInterface description
-------------------------------------
The following sequence of functions is called for every viewer plugin whenever a new DLT file is loaded:

* +initFileStart()+
* for each DLT message in the file:
  - +initMsg()+
  - +initMsgDecoded()+
* +initFileFinish()+

Before calling +updateMsgDecoded()+, the functions +isMsg()+ and +decodeMsg()+ are called for each decoder plugin, possibly altering the messages' contents.

The following sequence is called for every plugin when new DLT messages are received by DLT Viewer:

* +updateFileStart()+
* for each DLT message received:
  - +updateMsg()+
  - +updateMsgDecoded()+
* +updateFileFinish()+

Before calling +updateMsgDecoded()+, the functions +isMsg()+ and is +decodeMsg()+ are called for each decoder plugin, possibly altering the messages' contents.

Currently the DLT messages are iterated from the first to the last message in the DLT file. It is possible that in future versions the calls will arrive in a different order when multithreading is introduced.

Function +QWidget* initViewer()+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Called when loading the plugin. The created widget must be returned.

[IMPORTANT]
The widget will be owned and destroyed by the Qt framework, so don't delete it yourself.

Function +void initFileStart(QDltFile *file)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is called every time a new log file is opened by the Viewer, or a new log file is created, and *before* any messages are processed with +initMsg()+ and +initMsgDecoded()+.

Function +void initFileFinish()+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is called after a log file was opened by the Viewer, or a new log file was created, and *after* all messages were processed with +initMsg()+ and +initMsgDecoded()+.

Function +void initMsg(int index, QDltMsg &msg)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is called every time a new _undecoded_ message is being processed when loading or creating a new log file.

Function +void initMsgDecoded(int index, QDltMsg &msg)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is called every time a new _decoded_ message is being processed when loading or creating a new log file.

Function +void updateFileStart()+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is called every time a new message was received by the Viewer and *before* the message is processed with +updateMsg()+ and +updateMsgDecoded()+.

Function +void updateFileFinish()+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is called every time a new message was received by the Viewer and *after* the message was processed with +updateMsg()+ and +updateMsgDecoded()+.

Function +void updateMsg(int index, QDltMsg &msg)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is called every time a new _undecoded_ message was received by the Viewer.

Function +void updateMsgDecoded(int index, QDltMsg &msg)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is called every time a new _decoded_ message was received by the Viewer.

Function +void selectedIdxMsg(int index, QDltMsg &msg)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An _undecoded_ log message was selected in the message table. The Viewer plugin can now show additional information about this message.

Function +void selectedIdxMsgDecoded(int index, QDltMsg &msg)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A _decoded_ log message was selected in the message table. The Viewer plugin can now show additional information about this message.


QDltPluginControlInterface description
--------------------------------------

Function +bool initControl(QDltControl *control)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is called once during initialisation of the plugin. It provides a pointer to the control object. Store this pointer inside your plugin for later usage.

Function +bool initConnections(QStringList list)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is called when the user changes the connections to available ECUs.

Function +bool controlMsg(int index, QDltMsg &msg)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is called whenever a control message is received by the DLT Viewer.

Function +bool stateChanged(int index, QDltConnection::QDltConnectionState connectionState, QString hostname)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is called whenever the connection state changed for an ECU item.

Function +bool autoscrollStateChanged(bool enabled)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function is called whenever the _AutoScroll_ option was toggled in the DLT Viewer.


QDltPluginCommandInterface description
--------------------------------------

Function +bool command(QString command, QList<QString> params)+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This function gets called by the DLT Viewer framework when the *-e* command line parameter is used.