mirror of https://github.com/nymea/nymea.git
Add bluetooth debug chategory and continue work on bluetooth le manager
parent
f7cf13aba5
commit
691473bcb1
|
|
@ -1,3 +1,9 @@
|
|||
guh (0.8.1+201711270858~ecd6840~xenial) UNRELEASED; urgency=medium
|
||||
|
||||
*
|
||||
|
||||
-- <timon@guh-guh-builder-xenial-amd64-amd64.lxd> Mon, 27 Nov 2017 07:58:39 +0000
|
||||
|
||||
guh (0.8.1) xenial; urgency=medium
|
||||
|
||||
* Avahi interfaces and collision handling
|
||||
|
|
|
|||
|
|
@ -23,18 +23,6 @@
|
|||
#include "bluetoothlowenergydevice.h"
|
||||
#include "loggingcategories.h"
|
||||
|
||||
BluetoothLowEnergyDevice::BluetoothLowEnergyDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType, QObject *parent) :
|
||||
QObject(parent), m_deviceInfo(deviceInfo)
|
||||
{
|
||||
m_controller = new QLowEnergyController(address(), this);
|
||||
m_controller->setRemoteAddressType(addressType);
|
||||
|
||||
connect(m_controller, &QLowEnergyController::connected, this, &BluetoothLowEnergyDevice::connected);
|
||||
connect(m_controller, &QLowEnergyController::disconnected, this, &BluetoothLowEnergyDevice::disconnected);
|
||||
connect(m_controller, SIGNAL(error(QLowEnergyController::Error)), this, SLOT(deviceError(QLowEnergyController::Error)));
|
||||
connect(m_controller, SIGNAL(discoveryFinished()), this, SIGNAL(servicesDiscoveryFinished()));
|
||||
}
|
||||
|
||||
QString BluetoothLowEnergyDevice::name() const
|
||||
{
|
||||
return m_deviceInfo.name();
|
||||
|
|
@ -50,15 +38,77 @@ QLowEnergyController *BluetoothLowEnergyDevice::controller() const
|
|||
return m_controller;
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyDevice::connectDevice()
|
||||
BluetoothLowEnergyDevice::BluetoothLowEnergyDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType, QObject *parent) :
|
||||
QObject(parent), m_deviceInfo(deviceInfo)
|
||||
{
|
||||
m_controller->connectToDevice();
|
||||
m_controller = new QLowEnergyController(address(), this);
|
||||
m_controller->setRemoteAddressType(addressType);
|
||||
|
||||
connect(m_controller, &QLowEnergyController::connected, this, &BluetoothLowEnergyDevice::onConnected);
|
||||
connect(m_controller, &QLowEnergyController::disconnected, this, &BluetoothLowEnergyDevice::onDisconnected);
|
||||
connect(m_controller, &QLowEnergyController::discoveryFinished, this, &BluetoothLowEnergyDevice::onServiceDiscoveryFinished);
|
||||
connect(m_controller, &QLowEnergyController::stateChanged, this, &BluetoothLowEnergyDevice::onStateChanged);
|
||||
connect(m_controller, SIGNAL(error(QLowEnergyController::Error)), this, SLOT(onDeviceError(QLowEnergyController::Error)));
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyDevice::reconnectDevice()
|
||||
void BluetoothLowEnergyDevice::setConnected(const bool &connected)
|
||||
{
|
||||
if (!isConnected())
|
||||
m_controller->connectToDevice();
|
||||
if (m_connected != connected) {
|
||||
m_connected = connected;
|
||||
emit connectedChanged(m_connected);
|
||||
}
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyDevice::setEnabled(const bool &enabled)
|
||||
{
|
||||
m_enabled = enabled;
|
||||
|
||||
if (!m_enabled) {
|
||||
m_controller->disconnectFromDevice();
|
||||
} else {
|
||||
if (m_autoConnecting) {
|
||||
m_controller->connectToDevice();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyDevice::onConnected()
|
||||
{
|
||||
qCDebug(dcBluetooth()) << "Device connected" << name() << address().toString();
|
||||
setConnected(true);
|
||||
|
||||
qCDebug(dcBluetooth()) << "Discover services on" << name() << address().toString();
|
||||
m_controller->discoverServices();
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyDevice::onDisconnected()
|
||||
{
|
||||
qCWarning(dcBluetooth()) << "Device disconnected" << name() << address().toString();
|
||||
setConnected(false);
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyDevice::onServiceDiscoveryFinished()
|
||||
{
|
||||
qCDebug(dcBluetooth()) << "Service discovery finished for" << name() << address().toString();
|
||||
foreach (const QBluetoothUuid &serviceUuid, m_controller->services()) {
|
||||
QLowEnergyService *service = m_controller->createServiceObject(serviceUuid, this);
|
||||
qCDebug(dcBluetooth()) << "--> Service" << serviceUuid.toString();
|
||||
m_services.append(service);
|
||||
}
|
||||
emit servicesDiscoveryFinished();
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyDevice::onStateChanged(const QLowEnergyController::ControllerState &state)
|
||||
{
|
||||
emit stateChanged(state);
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyDevice::connectDevice()
|
||||
{
|
||||
if (!m_enabled)
|
||||
return;
|
||||
|
||||
m_controller->connectToDevice();
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyDevice::disconnectDevice()
|
||||
|
|
@ -66,29 +116,43 @@ void BluetoothLowEnergyDevice::disconnectDevice()
|
|||
m_controller->disconnectFromDevice();
|
||||
}
|
||||
|
||||
bool BluetoothLowEnergyDevice::isConnected() const
|
||||
bool BluetoothLowEnergyDevice::autoConnecting() const
|
||||
{
|
||||
return m_autoConnecting;
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyDevice::setAutoConnecting(const bool &autoConnecting)
|
||||
{
|
||||
if (m_autoConnecting != autoConnecting) {
|
||||
m_autoConnecting = autoConnecting;
|
||||
emit autoConnectingChanged(m_autoConnecting);
|
||||
}
|
||||
}
|
||||
|
||||
bool BluetoothLowEnergyDevice::connected() const
|
||||
{
|
||||
return m_connected;
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyDevice::connected()
|
||||
bool BluetoothLowEnergyDevice::discovered() const
|
||||
{
|
||||
m_connected = true;
|
||||
qCDebug(dcHardware) << "Connected to Bluetooth LE device:" << name() << address().toString();
|
||||
emit connectionStatusChanged();
|
||||
qCDebug(dcHardware) << "Discover Bluetooth LE services...";
|
||||
m_controller->discoverServices();
|
||||
return m_discovered;
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyDevice::disconnected()
|
||||
QList<QLowEnergyService *> BluetoothLowEnergyDevice::services() const
|
||||
{
|
||||
m_connected = false;
|
||||
qCWarning(dcHardware) << "Disconnected from Bluetooth LE device:" << name() << address().toString();
|
||||
emit connectionStatusChanged();
|
||||
return m_services;
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyDevice::deviceError(const QLowEnergyController::Error &error)
|
||||
QList<QBluetoothUuid> BluetoothLowEnergyDevice::serviceUuids() const
|
||||
{
|
||||
if (isConnected())
|
||||
qCWarning(dcHardware) << "Bluetooth LE device:" << name() << address().toString() << ": " << error << m_controller->errorString();
|
||||
return m_controller->services();
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyDevice::onDeviceError(const QLowEnergyController::Error &error)
|
||||
{
|
||||
if (connected())
|
||||
qCWarning(dcBluetooth()) << "Device error:" << name() << address().toString() << ": " << error << m_controller->errorString();
|
||||
|
||||
emit errorOccured(error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,37 +34,57 @@
|
|||
class LIBGUH_EXPORT BluetoothLowEnergyDevice : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit BluetoothLowEnergyDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::PublicAddress, QObject *parent = 0);
|
||||
|
||||
friend class BluetoothLowEnergyManager;
|
||||
|
||||
public:
|
||||
QString name() const;
|
||||
QBluetoothAddress address() const;
|
||||
|
||||
void connectDevice();
|
||||
void reconnectDevice();
|
||||
void disconnectDevice();
|
||||
|
||||
bool isConnected() const;
|
||||
bool isDiscovered() const;
|
||||
bool autoConnecting() const;
|
||||
void setAutoConnecting(const bool &autoConnecting);
|
||||
|
||||
bool connected() const;
|
||||
bool discovered() const;
|
||||
|
||||
QList<QLowEnergyService *> services() const;
|
||||
QList<QBluetoothUuid> serviceUuids() const;
|
||||
|
||||
protected:
|
||||
QLowEnergyController *controller() const;
|
||||
|
||||
private:
|
||||
explicit BluetoothLowEnergyDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::PublicAddress, QObject *parent = 0);
|
||||
QBluetoothDeviceInfo m_deviceInfo;
|
||||
QLowEnergyController *m_controller;
|
||||
QLowEnergyController *m_controller = nullptr;
|
||||
QList<QLowEnergyService *> m_services;
|
||||
|
||||
bool m_connected;
|
||||
bool m_discovered;
|
||||
bool m_connected = false;
|
||||
bool m_autoConnecting = false;
|
||||
bool m_discovered = false;
|
||||
bool m_enabled = true;
|
||||
|
||||
void setConnected(const bool &connected);
|
||||
|
||||
// Methods called from BluetoothLowEnergyManager
|
||||
void setEnabled(const bool &enabled);
|
||||
|
||||
signals:
|
||||
void connectionStatusChanged();
|
||||
void connectedChanged(const bool &connected);
|
||||
void autoConnectingChanged(const bool &autoConnecting);
|
||||
void stateChanged(const QLowEnergyController::ControllerState &state);
|
||||
void errorOccured(const QLowEnergyController::Error &error);
|
||||
void servicesDiscoveryFinished();
|
||||
|
||||
private slots:
|
||||
void connected();
|
||||
void disconnected();
|
||||
void deviceError(const QLowEnergyController::Error &error);
|
||||
void onConnected();
|
||||
void onDisconnected();
|
||||
void onServiceDiscoveryFinished();
|
||||
void onStateChanged(const QLowEnergyController::ControllerState &state);
|
||||
void onDeviceError(const QLowEnergyController::Error &error);
|
||||
};
|
||||
|
||||
#endif // BLUETOOTHLOWENERGYDEVICE_H
|
||||
|
|
|
|||
|
|
@ -28,89 +28,118 @@ BluetoothDiscoveryReply *BluetoothLowEnergyManager::discoverDevices(const int &i
|
|||
// Create the reply for this discovery request
|
||||
QPointer<BluetoothDiscoveryReply> reply = new BluetoothDiscoveryReply(this);
|
||||
if (!available()) {
|
||||
qCWarning(dcHardware()) << name() << "is not avilable.";
|
||||
qCWarning(dcBluetooth()) << "is not avilable.";
|
||||
reply->setError(BluetoothDiscoveryReply::BluetoothDiscoveryReplyErrorNotAvailable);
|
||||
reply->setFinished();
|
||||
return reply.data();
|
||||
}
|
||||
|
||||
if (!enabled()) {
|
||||
qCWarning(dcHardware()) << name() << "is not enabled.";
|
||||
qCWarning(dcBluetooth()) << "is not enabled.";
|
||||
reply->setError(BluetoothDiscoveryReply::BluetoothDiscoveryReplyErrorNotEnabled);
|
||||
reply->setFinished();
|
||||
return reply.data();
|
||||
}
|
||||
|
||||
if (!m_currentReply.isNull()) {
|
||||
qCWarning(dcHardware()) << name() << "resource busy. There is already a discovery running.";
|
||||
qCWarning(dcBluetooth()) << "resource busy. There is already a discovery running.";
|
||||
reply->setError(BluetoothDiscoveryReply::BluetoothDiscoveryReplyErrorBusy);
|
||||
reply->setFinished();
|
||||
return reply.data();
|
||||
}
|
||||
|
||||
qCDebug(dcHardware) << name() << "start discovering";
|
||||
m_currentReply = reply;
|
||||
m_discoveredDevices.clear();
|
||||
|
||||
// Start discovery on all adapters
|
||||
qCDebug(dcHardware()) << name() << "Start bluetooth discovery";
|
||||
qCDebug(dcBluetooth()) << "Start bluetooth discovery";
|
||||
foreach (QBluetoothDeviceDiscoveryAgent *discoveryAgent, m_bluetoothDiscoveryAgents) {
|
||||
discoveryAgent->start();
|
||||
}
|
||||
|
||||
// TODO: limit interval to prevent resource blocking from a plugin
|
||||
m_timer->start(interval);
|
||||
// Prevent blocking the hardware resource from plugins
|
||||
int finalInterval = interval;
|
||||
if (finalInterval > 30) {
|
||||
qCWarning(dcBluetooth()) << "Discovery interval out of range. Reset to 30 seconds.";
|
||||
finalInterval = 30;
|
||||
}
|
||||
|
||||
if (finalInterval <= 0) {
|
||||
qCWarning(dcBluetooth()) << "Discovery interval out of range. Reset to 5 seconds.";
|
||||
finalInterval = 5;
|
||||
}
|
||||
|
||||
m_timer->start(finalInterval);
|
||||
return reply.data();
|
||||
}
|
||||
|
||||
BluetoothLowEnergyDevice *BluetoothLowEnergyManager::registerDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType)
|
||||
{
|
||||
QPointer<BluetoothLowEnergyDevice> device = new BluetoothLowEnergyDevice(deviceInfo, addressType, this);
|
||||
m_devices.append(device);
|
||||
return device.data();
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyManager::unregisterDevice(BluetoothLowEnergyDevice *bluetoothDevice)
|
||||
{
|
||||
QPointer<BluetoothLowEnergyDevice> devicePointer(bluetoothDevice);
|
||||
if (devicePointer.isNull()) {
|
||||
qCWarning(dcBluetooth()) << "Cannot unregister bluetooth device. Looks like the device is already unregistered.";
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (QPointer<BluetoothLowEnergyDevice> dPointer, m_devices) {
|
||||
if (devicePointer.data() == dPointer.data()) {
|
||||
m_devices.removeAll(dPointer);
|
||||
dPointer->deleteLater();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BluetoothLowEnergyManager::BluetoothLowEnergyManager(QObject *parent) :
|
||||
HardwareResource(HardwareResource::TypeBluetoothLE, "Bluetooth LE manager", parent)
|
||||
{
|
||||
// Check which bluetooth adapter are available
|
||||
QList<QBluetoothHostInfo> bluetoothAdapters = QBluetoothLocalDevice::allDevices();
|
||||
if (bluetoothAdapters.isEmpty()) {
|
||||
qCWarning(dcHardware()) << name() << "No bluetooth adapter found. Resource not available.";
|
||||
qCWarning(dcBluetooth()) << "No bluetooth adapter found. Resource not available.";
|
||||
setAvailable(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a scanner for each adapter
|
||||
foreach (const QBluetoothHostInfo &hostInfo, bluetoothAdapters) {
|
||||
qCDebug(dcHardware()) << name() << "Using adapter:" << hostInfo.name() << hostInfo.address().toString();
|
||||
qCDebug(dcBluetooth()) << "Using adapter:" << hostInfo.name() << hostInfo.address().toString();
|
||||
QBluetoothLocalDevice localDevice(hostInfo.address());
|
||||
localDevice.powerOn();
|
||||
localDevice.setHostMode(QBluetoothLocalDevice::HostDiscoverable);
|
||||
|
||||
QBluetoothDeviceDiscoveryAgent *discoveryAgent = new QBluetoothDeviceDiscoveryAgent(hostInfo.address(), this);
|
||||
connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &BluetoothLowEnergyManager::onDeviceDiscovered);
|
||||
connect(discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), this, SLOT(onDiscoveryError(QBluetoothDeviceDiscoveryAgent::Error)));
|
||||
|
||||
m_bluetoothDiscoveryAgents.append(discoveryAgent);
|
||||
}
|
||||
|
||||
// Discovery timer
|
||||
// Discovery timer, interval depends on discovery call
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setSingleShot(true);
|
||||
|
||||
connect(m_timer, &QTimer::timeout, this, &BluetoothLowEnergyManager::discoveryTimeout);
|
||||
connect(m_timer, &QTimer::timeout, this, &BluetoothLowEnergyManager::onDiscoveryTimeout);
|
||||
|
||||
qCDebug(dcHardware()) << "-->" << name() << "created successfully.";
|
||||
setAvailable(true);
|
||||
}
|
||||
|
||||
void BluetoothLowEnergyManager::discoveryTimeout()
|
||||
void BluetoothLowEnergyManager::onDiscoveryTimeout()
|
||||
{
|
||||
// Stop discovery on all adapters
|
||||
qCDebug(dcHardware()) << name() << "Stop bluetooth discovery";
|
||||
qCDebug(dcBluetooth()) << "Stop bluetooth discovery";
|
||||
foreach (QBluetoothDeviceDiscoveryAgent *discoveryAgent, m_bluetoothDiscoveryAgents) {
|
||||
discoveryAgent->stop();
|
||||
}
|
||||
|
||||
qCDebug(dcHardware()) << name() << "Discovery finished. Found" << m_discoveredDevices.count() << "bluetooth devices.";
|
||||
qCDebug(dcBluetooth()) << "Discovery finished. Found" << m_discoveredDevices.count() << "bluetooth devices.";
|
||||
|
||||
if (m_currentReply.isNull()) {
|
||||
qCWarning(dcHardware()) << name() << "Reply does not exist any more. Please don't delete the reply before it has finished.";
|
||||
qCWarning(dcBluetooth()) << "Reply does not exist any more. Please don't delete the reply before it has finished.";
|
||||
m_currentReply.clear();
|
||||
return;
|
||||
}
|
||||
|
|
@ -133,7 +162,7 @@ void BluetoothLowEnergyManager::onDeviceDiscovered(const QBluetoothDeviceInfo &d
|
|||
}
|
||||
|
||||
if (!alreadyAdded) {
|
||||
qCDebug(dcHardware()) << name() << "device discovered" << deviceInfo.name() <<deviceInfo.address().toString();
|
||||
qCDebug(dcBluetooth()) << "device discovered" << deviceInfo.name() <<deviceInfo.address().toString();
|
||||
m_discoveredDevices.append(deviceInfo);
|
||||
}
|
||||
}
|
||||
|
|
@ -141,19 +170,29 @@ void BluetoothLowEnergyManager::onDeviceDiscovered(const QBluetoothDeviceInfo &d
|
|||
void BluetoothLowEnergyManager::onDiscoveryError(const QBluetoothDeviceDiscoveryAgent::Error &error)
|
||||
{
|
||||
QBluetoothDeviceDiscoveryAgent *discoveryAgent = static_cast<QBluetoothDeviceDiscoveryAgent *>(sender());
|
||||
qCWarning(dcHardware()) << name() << "Discovery error:" << error << discoveryAgent->errorString();
|
||||
qCWarning(dcBluetooth()) << "Discovery error:" << error << discoveryAgent->errorString();
|
||||
}
|
||||
|
||||
bool BluetoothLowEnergyManager::enable()
|
||||
{
|
||||
// TODO: enable all devices and trigger reconnect
|
||||
qCDebug(dcBluetooth()) << "Hardware resource enabled.";
|
||||
setEnabled(true);
|
||||
|
||||
foreach (QPointer<BluetoothLowEnergyDevice> bluetoothDevice, m_devices) {
|
||||
bluetoothDevice->setEnabled(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BluetoothLowEnergyManager::disable()
|
||||
{
|
||||
// TODO: disable reconnect and disconnect all devices
|
||||
qCDebug(dcBluetooth()) << "Hardware resource disabled.";
|
||||
setEnabled(false);
|
||||
|
||||
foreach (QPointer<BluetoothLowEnergyDevice> bluetoothDevice, m_devices) {
|
||||
bluetoothDevice->setEnabled(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "hardwareresource.h"
|
||||
#include "bluetoothdiscoveryreply.h"
|
||||
#include "bluetoothlowenergydevice.h"
|
||||
|
||||
class BluetoothLowEnergyManager : public HardwareResource
|
||||
{
|
||||
|
|
@ -40,24 +41,26 @@ class BluetoothLowEnergyManager : public HardwareResource
|
|||
friend class HardwareManager;
|
||||
|
||||
public:
|
||||
BluetoothDiscoveryReply *discoverDevices(const int &interval = 5000);
|
||||
BluetoothDiscoveryReply *discoverDevices(const int &interval = 5000);
|
||||
|
||||
// Bluetooth device registration methods
|
||||
BluetoothLowEnergyDevice *registerDevice(const QBluetoothDeviceInfo &deviceInfo, const QLowEnergyController::RemoteAddressType &addressType = QLowEnergyController::RandomAddress);
|
||||
void unregisterDevice(BluetoothLowEnergyDevice *bluetoothDevice);
|
||||
|
||||
private:
|
||||
explicit BluetoothLowEnergyManager(QObject *parent = nullptr);
|
||||
QTimer *m_timer = nullptr;
|
||||
QList<QPointer<BluetoothLowEnergyDevice>> m_devices;
|
||||
|
||||
QList<QBluetoothDeviceDiscoveryAgent *> m_bluetoothDiscoveryAgents;
|
||||
QList<QBluetoothDeviceInfo> m_discoveredDevices;
|
||||
|
||||
QPointer<BluetoothDiscoveryReply> m_currentReply;
|
||||
|
||||
signals:
|
||||
|
||||
private slots:
|
||||
void onDeviceDiscovered(const QBluetoothDeviceInfo &deviceInfo);
|
||||
void onDiscoveryError(const QBluetoothDeviceDiscoveryAgent::Error &error);
|
||||
|
||||
void discoveryTimeout();
|
||||
void onDiscoveryTimeout();
|
||||
|
||||
public slots:
|
||||
bool enable();
|
||||
|
|
|
|||
|
|
@ -23,13 +23,14 @@
|
|||
#include "hardwareresource.h"
|
||||
#include "guhsettings.h"
|
||||
#include "hardwaremanager.h"
|
||||
#include "loggingcategories.h"
|
||||
|
||||
HardwareResource::HardwareResource(const Type &hardwareReourceType, const QString &name, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_hardwareReourceType(hardwareReourceType),
|
||||
m_name(name)
|
||||
{
|
||||
// TODO: load if hardware resource is enabled or not
|
||||
|
||||
}
|
||||
|
||||
QString HardwareResource::name() const
|
||||
|
|
@ -54,13 +55,16 @@ HardwareResource::Type HardwareResource::hardwareReourceType() const
|
|||
|
||||
void HardwareResource::setEnabled(const bool &enabled)
|
||||
{
|
||||
// TODO: save this information to settings
|
||||
m_enabled = enabled;
|
||||
emit enabledChanged(m_enabled);
|
||||
if (m_enabled != enabled) {
|
||||
m_enabled = enabled;
|
||||
emit enabledChanged(m_enabled);
|
||||
}
|
||||
}
|
||||
|
||||
void HardwareResource::setAvailable(const bool &available)
|
||||
{
|
||||
m_available = available;
|
||||
emit availableChanged(m_available);
|
||||
if (m_available != available) {
|
||||
m_available = available;
|
||||
emit availableChanged(m_available);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public:
|
|||
private:
|
||||
HardwareResource::Type m_hardwareReourceType;
|
||||
QString m_name;
|
||||
// Note: default enabled, but not available. Each hardwareresource has explicitly chek if available
|
||||
// Note: default enabled, but not available. Each hardwareresource has explicitly check if available
|
||||
bool m_available = false;
|
||||
bool m_enabled = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ Q_LOGGING_CATEGORY(dcJsonRpcTraffic, "JsonRpcTraffic")
|
|||
Q_LOGGING_CATEGORY(dcRest, "Rest")
|
||||
Q_LOGGING_CATEGORY(dcOAuth2, "OAuth2")
|
||||
Q_LOGGING_CATEGORY(dcAvahi, "Avahi")
|
||||
Q_LOGGING_CATEGORY(dcBluetooth, "Bluetooth")
|
||||
Q_LOGGING_CATEGORY(dcCloud, "Cloud")
|
||||
Q_LOGGING_CATEGORY(dcNetworkManager, "NetworkManager")
|
||||
Q_LOGGING_CATEGORY(dcUserManager, "UserManager")
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ Q_DECLARE_LOGGING_CATEGORY(dcJsonRpcTraffic)
|
|||
Q_DECLARE_LOGGING_CATEGORY(dcRest)
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcOAuth2)
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcAvahi)
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcBluetooth)
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcCloud)
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcNetworkManager)
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcUserManager)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
QtAvahiClient::QtAvahiClient(QObject *parent) :
|
||||
QObject(parent),
|
||||
m_poll(avahi_qt_poll_get()),
|
||||
m_client(0),
|
||||
m_client(nullptr),
|
||||
error(0),
|
||||
m_state(QtAvahiClientStateNone)
|
||||
{
|
||||
|
|
@ -53,7 +53,7 @@ void QtAvahiClient::start()
|
|||
if (m_client)
|
||||
return;
|
||||
|
||||
avahi_client_new(m_poll, (AvahiClientFlags) 0, QtAvahiClient::callback, this, &error);
|
||||
m_client = avahi_client_new(m_poll, (AvahiClientFlags) 0, QtAvahiClient::callback, this, &error);
|
||||
}
|
||||
|
||||
void QtAvahiClient::stop()
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ QtAvahiServiceBrowser::QtAvahiServiceBrowser(QObject *parent) :
|
|||
HardwareResource(HardwareResource::TypeAvahiBrowser, "Avahi service browser", parent),
|
||||
d_ptr(new QtAvahiServiceBrowserPrivate(new QtAvahiClient))
|
||||
{
|
||||
if (d_ptr->client->state())
|
||||
|
||||
connect(d_ptr->client, &QtAvahiClient::clientStateChanged, this, &QtAvahiServiceBrowser::onClientStateChanged);
|
||||
|
||||
// TODO: check available here
|
||||
|
|
|
|||
|
|
@ -76,8 +76,10 @@ UpnpDiscovery::~UpnpDiscovery()
|
|||
{
|
||||
qCDebug(dcApplication) << "Shutting down \"UPnP Server\"";
|
||||
sendByeByeMessage();
|
||||
m_socket->waitForBytesWritten();
|
||||
m_socket->close();
|
||||
if (m_socket) {
|
||||
m_socket->waitForBytesWritten(1000);
|
||||
m_socket->close();
|
||||
}
|
||||
}
|
||||
|
||||
UpnpDiscoveryReply *UpnpDiscovery::discoverDevices(const QString &searchTarget, const QString &userAgent, const int &timeout)
|
||||
|
|
|
|||
|
|
@ -116,6 +116,9 @@ void PluginTimer::stop()
|
|||
PluginTimer *PluginTimerManager::registerTimer(int seconds)
|
||||
{
|
||||
QPointer<PluginTimer> pluginTimer = new PluginTimer(seconds, this);
|
||||
|
||||
// TODO: start timer depending on the schedule from other timers, loadbalancing
|
||||
|
||||
m_timers.append(pluginTimer);
|
||||
return pluginTimer.data();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ int main(int argc, char *argv[])
|
|||
s_loggingFilters.insert("RuleEngine", true);
|
||||
s_loggingFilters.insert("RuleEngineDebug", false);
|
||||
s_loggingFilters.insert("Hardware", false);
|
||||
s_loggingFilters.insert("Bluetooth", false);
|
||||
s_loggingFilters.insert("Connection", true);
|
||||
s_loggingFilters.insert("LogEngine", false);
|
||||
s_loggingFilters.insert("TcpServer", false);
|
||||
|
|
@ -130,7 +131,7 @@ int main(int argc, char *argv[])
|
|||
s_loggingFilters.insert("Coap", false);
|
||||
s_loggingFilters.insert("Avahi", false);
|
||||
s_loggingFilters.insert("Cloud", true);
|
||||
s_loggingFilters.insert("NetworkManager", true);
|
||||
s_loggingFilters.insert("NetworkManager", false);
|
||||
s_loggingFilters.insert("UserManager", true);
|
||||
s_loggingFilters.insert("AWS", false);
|
||||
s_loggingFilters.insert("AWSTraffic", false);
|
||||
|
|
|
|||
Loading…
Reference in New Issue