File indexing completed on 2025-01-19 06:44:35
0001 /* 0002 * BluezQt - Asynchronous Bluez wrapper library 0003 * 0004 * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "gattcharacteristic.h" 0010 #include "gattcharacteristic_p.h" 0011 #include "gattservice.h" 0012 #include "utils.h" 0013 0014 namespace BluezQt 0015 { 0016 GattCharacteristic::GattCharacteristic(const QString &uuid, GattService *service) 0017 : GattCharacteristic(uuid, {QLatin1String("read"), QLatin1String("write")}, service) 0018 { 0019 } 0020 0021 GattCharacteristic::GattCharacteristic(const QString &uuid, const QStringList &flags, GattService *service) 0022 : QObject(service) 0023 , d(new GattCharacterisiticPrivate(uuid, flags, service)) 0024 { 0025 } 0026 0027 GattCharacteristic::~GattCharacteristic() = default; 0028 0029 QByteArray GattCharacteristic::readValue() 0030 { 0031 if (d->m_readCallback) { 0032 d->m_value = d->m_readCallback(); 0033 } 0034 0035 return d->m_value; 0036 } 0037 0038 void GattCharacteristic::writeValue(const QByteArray &value) 0039 { 0040 d->m_value = value; 0041 0042 if (isNotifying()) { 0043 d->emitPropertyChanged({{QLatin1String("Value"), value}}); 0044 } 0045 0046 Q_EMIT valueWritten(d->m_value); 0047 } 0048 0049 QString GattCharacteristic::uuid() const 0050 { 0051 return d->m_uuid; 0052 } 0053 0054 const GattService *GattCharacteristic::service() const 0055 { 0056 return d->m_service; 0057 } 0058 0059 QStringList GattCharacteristic::flags() const 0060 { 0061 return d->m_flags; 0062 } 0063 0064 void GattCharacteristic::startNotify() 0065 { 0066 if (d->m_canNotify) { 0067 d->m_notifying = true; 0068 } 0069 } 0070 0071 void GattCharacteristic::stopNotify() 0072 { 0073 d->m_notifying = false; 0074 } 0075 0076 bool GattCharacteristic::isNotifying() const 0077 { 0078 return d->m_notifying; 0079 } 0080 0081 QDBusObjectPath GattCharacteristic::objectPath() const 0082 { 0083 return d->m_objectPath; 0084 } 0085 0086 void GattCharacteristic::setReadCallback(ReadCallback callback) 0087 { 0088 d->m_readCallback = callback; 0089 } 0090 0091 } // namespace BluezQt 0092 0093 #include "moc_gattcharacteristic.cpp"