| 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 "tinycanbackend.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_TINYCAN, "qt.canbus.plugins.tinycan") |
| 16 | |
| 17 | class TinyCanBusPlugin : 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 | Q_UNUSED(errorMessage); |
| 27 | return TinyCanBackend::interfaces(); |
| 28 | } |
| 29 | |
| 30 | QCanBusDevice *createDevice(const QString &interfaceName, QString *errorMessage) const override |
| 31 | { |
| 32 | QString errorReason; |
| 33 | if (!TinyCanBackend::canCreate(errorReason: &errorReason)) { |
| 34 | qCWarning(QT_CANBUS_PLUGINS_TINYCAN, "%ls", qUtf16Printable(errorReason)); |
| 35 | if (errorMessage) |
| 36 | *errorMessage = errorReason; |
| 37 | return nullptr; |
| 38 | } |
| 39 | |
| 40 | auto device = new TinyCanBackend(interfaceName); |
| 41 | return device; |
| 42 | } |
| 43 | }; |
| 44 | |
| 45 | QT_END_NAMESPACE |
| 46 | |
| 47 | #include "main.moc" |
| 48 |
