File indexing completed on 2023-09-24 04:02:11
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Ivan Podkurkov <podkiva2@gmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "gattcharacteristicinterface.h" 0008 #include "inputinterface.h" 0009 #include "objectmanager.h" 0010 0011 #include <QDBusArgument> 0012 #include <QDBusConnection> 0013 #include <QDBusMessage> 0014 0015 // GattServiceObject 0016 GattCharacteristicObject::GattCharacteristicObject(const QDBusObjectPath &path, QObject *parent) 0017 : QObject(parent) 0018 { 0019 QDBusConnection::sessionBus().registerObject(path.path(), this); 0020 } 0021 0022 // GattServiceInterface 0023 GattCharacteristicInterface::GattCharacteristicInterface(const QDBusObjectPath &path, const QVariantMap &properties, QObject *parent) 0024 : QDBusAbstractAdaptor(parent) 0025 { 0026 setPath(path); 0027 setObjectParent(parent); 0028 setProperties(properties); 0029 setName(QStringLiteral("org.bluez.GattCharacteristic1")); 0030 } 0031 0032 QString GattCharacteristicInterface::UUID() const 0033 { 0034 return Object::property(QStringLiteral("UUID")).toString(); 0035 } 0036 0037 QDBusObjectPath GattCharacteristicInterface::service() const 0038 { 0039 return Object::property(QStringLiteral("Service")).value<QDBusObjectPath>(); 0040 } 0041 0042 QByteArray GattCharacteristicInterface::value() const 0043 { 0044 return Object::property(QStringLiteral("Value")).value<QByteArray>(); 0045 } 0046 0047 bool GattCharacteristicInterface::notifying() const 0048 { 0049 return Object::property(QStringLiteral("Notifying")).toBool(); 0050 } 0051 0052 QStringList GattCharacteristicInterface::flags() const 0053 { 0054 return Object::property(QStringLiteral("Flags")).value<QStringList>(); 0055 } 0056 0057 quint16 GattCharacteristicInterface::handle() const 0058 { 0059 return Object::property(QStringLiteral("Handle")).value<quint16>(); 0060 } 0061 0062 void GattCharacteristicInterface::setHandle(const quint16 handle) 0063 { 0064 Object::changeProperty(QStringLiteral("Handle"), QVariant::fromValue(handle)); 0065 } 0066 0067 quint16 GattCharacteristicInterface::MTU() const 0068 { 0069 return Object::property(QStringLiteral("MTU")).value<quint16>(); 0070 } 0071 0072 QByteArray GattCharacteristicInterface::ReadValue(const QVariantMap& options) 0073 { 0074 Q_UNUSED(options) 0075 QByteArray value = QByteArray("TEST"); 0076 Object::changeProperty(QStringLiteral("Value"), value); 0077 return value; 0078 } 0079 0080 void GattCharacteristicInterface::WriteValue(const QByteArray& value, const QVariantMap& options) 0081 { 0082 Q_UNUSED(options) 0083 Object::changeProperty(QStringLiteral("Value"), value); 0084 } 0085 0086 void GattCharacteristicInterface::StartNotify() 0087 { 0088 Object::changeProperty(QStringLiteral("Notifying"), true); 0089 } 0090 0091 void GattCharacteristicInterface::StopNotify() 0092 { 0093 Object::changeProperty(QStringLiteral("Notifying"), false); 0094 } 0095 0096 #include "moc_gattcharacteristicinterface.cpp"