1 | // Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> |
---|---|
2 | // Copyright (C) 2017 The Qt Company Ltd. |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
4 | |
5 | #include "peakcanbackend.h" |
6 | |
7 | #include <QtSerialBus/qcanbus.h> |
8 | #include <QtSerialBus/qcanbusdevice.h> |
9 | #include <QtSerialBus/qcanbusfactory.h> |
10 | |
11 | #include <QtCore/qloggingcategory.h> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | Q_LOGGING_CATEGORY(QT_CANBUS_PLUGINS_PEAKCAN, "qt.canbus.plugins.peakcan") |
16 | |
17 | class PeakCanBusPlugin : public QObject, public QCanBusFactory |
18 | { |
19 | Q_OBJECT |
20 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QCanBusFactory"FILE "plugin.json") |
21 | Q_INTERFACES(QCanBusFactory) |
22 | |
23 | public: |
24 | QList<QCanBusDeviceInfo> availableDevices(QString *errorMessage) const override |
25 | { |
26 | if (Q_UNLIKELY(!PeakCanBackend::canCreate(errorMessage))) |
27 | return QList<QCanBusDeviceInfo>(); |
28 | |
29 | return PeakCanBackend::interfaces(); |
30 | } |
31 | |
32 | QCanBusDevice *createDevice(const QString &interfaceName, QString *errorMessage) const override |
33 | { |
34 | QString errorReason; |
35 | if (!PeakCanBackend::canCreate(errorReason: &errorReason)) { |
36 | qCWarning(QT_CANBUS_PLUGINS_PEAKCAN, "%ls", qUtf16Printable(errorReason)); |
37 | if (errorMessage) |
38 | *errorMessage = errorReason; |
39 | return nullptr; |
40 | } |
41 | |
42 | auto device = new PeakCanBackend(interfaceName); |
43 | return device; |
44 | } |
45 | }; |
46 | |
47 | QT_END_NAMESPACE |
48 | |
49 | #include "main.moc" |
50 |