Merge PR #629: Adjust logging category for bluetooth discovery
This commit is contained in:
commit
f25be32dbc
@ -34,6 +34,9 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QBluetoothLocalDevice>
|
#include <QBluetoothLocalDevice>
|
||||||
#include <QBluetoothUuid>
|
#include <QBluetoothUuid>
|
||||||
|
#include <QLoggingCategory>
|
||||||
|
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(dcBtWiFiSetup);
|
||||||
|
|
||||||
BluetoothDiscovery::BluetoothDiscovery(QObject *parent) :
|
BluetoothDiscovery::BluetoothDiscovery(QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
@ -44,13 +47,13 @@ BluetoothDiscovery::BluetoothDiscovery(QObject *parent) :
|
|||||||
// Check if bluetooth is available
|
// Check if bluetooth is available
|
||||||
QBluetoothLocalDevice localDevice;
|
QBluetoothLocalDevice localDevice;
|
||||||
if (!localDevice.isValid()) {
|
if (!localDevice.isValid()) {
|
||||||
qWarning() << "BluetoothDiscovery: there is no bluetooth device available.";
|
qCWarning(dcBtWiFiSetup) << "BluetoothDiscovery: there is no bluetooth device available.";
|
||||||
m_bluetoothAvailable = false;
|
m_bluetoothAvailable = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (localDevice.allDevices().isEmpty()) {
|
if (localDevice.allDevices().isEmpty()) {
|
||||||
qWarning() << "BluetoothDiscovery: there is no bluetooth device available currently.";
|
qCWarning(dcBtWiFiSetup) << "BluetoothDiscovery: there is no bluetooth device available currently.";
|
||||||
m_bluetoothAvailable = false;
|
m_bluetoothAvailable = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -74,7 +77,7 @@ BluetoothDiscovery::BluetoothDiscovery(QObject *parent) :
|
|||||||
// Always start with assuming BT is enabled
|
// Always start with assuming BT is enabled
|
||||||
m_bluetoothEnabled = true;
|
m_bluetoothEnabled = true;
|
||||||
|
|
||||||
qDebug() << "Initializing Bluetooth";
|
qCDebug(dcBtWiFiSetup) << "Initializing Bluetooth";
|
||||||
onBluetoothHostModeChanged(QBluetoothLocalDevice::HostConnectable);
|
onBluetoothHostModeChanged(QBluetoothLocalDevice::HostConnectable);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -91,7 +94,7 @@ bool BluetoothDiscovery::bluetoothEnabled() const
|
|||||||
#ifdef Q_OS_IOS
|
#ifdef Q_OS_IOS
|
||||||
return m_bluetoothAvailable && m_bluetoothEnabled;
|
return m_bluetoothAvailable && m_bluetoothEnabled;
|
||||||
#endif
|
#endif
|
||||||
qDebug() << "bluetoothEnabled(): m_bluetoothAvailable:" << m_bluetoothAvailable;
|
qCDebug(dcBtWiFiSetup) << "bluetoothEnabled(): m_bluetoothAvailable:" << m_bluetoothAvailable;
|
||||||
return m_bluetoothAvailable && m_localDevice->hostMode() != QBluetoothLocalDevice::HostPoweredOff;
|
return m_bluetoothAvailable && m_localDevice->hostMode() != QBluetoothLocalDevice::HostPoweredOff;
|
||||||
}
|
}
|
||||||
void BluetoothDiscovery::setBluetoothEnabled(bool bluetoothEnabled) {
|
void BluetoothDiscovery::setBluetoothEnabled(bool bluetoothEnabled) {
|
||||||
@ -141,7 +144,7 @@ BluetoothDeviceInfos *BluetoothDiscovery::deviceInfos()
|
|||||||
|
|
||||||
void BluetoothDiscovery::onBluetoothHostModeChanged(const QBluetoothLocalDevice::HostMode &hostMode)
|
void BluetoothDiscovery::onBluetoothHostModeChanged(const QBluetoothLocalDevice::HostMode &hostMode)
|
||||||
{
|
{
|
||||||
qDebug() << "BluetoothDiscovery: host mode changed" << hostMode;
|
qCDebug(dcBtWiFiSetup) << "BluetoothDiscovery: host mode changed" << hostMode;
|
||||||
switch (hostMode) {
|
switch (hostMode) {
|
||||||
case QBluetoothLocalDevice::HostPoweredOff:
|
case QBluetoothLocalDevice::HostPoweredOff:
|
||||||
if (m_discoveryAgent) {
|
if (m_discoveryAgent) {
|
||||||
@ -184,27 +187,27 @@ void BluetoothDiscovery::deviceDiscovered(const QBluetoothDeviceInfo &deviceInfo
|
|||||||
|
|
||||||
|
|
||||||
BluetoothDeviceInfo *deviceInformation = new BluetoothDeviceInfo(deviceInfo);
|
BluetoothDeviceInfo *deviceInformation = new BluetoothDeviceInfo(deviceInfo);
|
||||||
qDebug() << "BluetoothDiscovery: [+]" << deviceInformation->name() << "(" << deviceInformation->address() << ")" << (deviceInformation->isLowEnergy() ? "LE" : "") << deviceInfo.serviceUuids();
|
qCDebug(dcBtWiFiSetup) << "BluetoothDiscovery: [+]" << deviceInformation->name() << "(" << deviceInformation->address() << ")" << (deviceInformation->isLowEnergy() ? "LE" : "") << deviceInfo.serviceUuids();
|
||||||
m_deviceInfos->addBluetoothDeviceInfo(deviceInformation);
|
m_deviceInfos->addBluetoothDeviceInfo(deviceInformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BluetoothDiscovery::discoveryFinished()
|
void BluetoothDiscovery::discoveryFinished()
|
||||||
{
|
{
|
||||||
qDebug() << "BluetoothDiscovery: Discovery finished" << m_discoveryEnabled << this;
|
qCDebug(dcBtWiFiSetup) << "BluetoothDiscovery: Discovery finished" << m_discoveryEnabled << this;
|
||||||
if (m_discoveryEnabled) {
|
if (m_discoveryEnabled) {
|
||||||
qDebug() << "BluetoothDiscovery: Restarting discovery";
|
qCDebug(dcBtWiFiSetup) << "BluetoothDiscovery: Restarting discovery";
|
||||||
m_discoveryAgent->start();
|
m_discoveryAgent->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BluetoothDiscovery::discoveryCancelled()
|
void BluetoothDiscovery::discoveryCancelled()
|
||||||
{
|
{
|
||||||
qDebug() << "BluetoothDiscovery: Discovery cancelled";
|
qCDebug(dcBtWiFiSetup) << "BluetoothDiscovery: Discovery cancelled";
|
||||||
}
|
}
|
||||||
|
|
||||||
void BluetoothDiscovery::onError(const QBluetoothDeviceDiscoveryAgent::Error &error)
|
void BluetoothDiscovery::onError(const QBluetoothDeviceDiscoveryAgent::Error &error)
|
||||||
{
|
{
|
||||||
qWarning() << "BluetoothDiscovery: Discovery error:" << error << m_discoveryAgent->errorString();
|
qCWarning(dcBtWiFiSetup) << "BluetoothDiscovery: Discovery error:" << error << m_discoveryAgent->errorString();
|
||||||
#ifdef Q_OS_IOS
|
#ifdef Q_OS_IOS
|
||||||
if (error == QBluetoothDeviceDiscoveryAgent::PoweredOffError) {
|
if (error == QBluetoothDeviceDiscoveryAgent::PoweredOffError) {
|
||||||
m_bluetoothEnabled = false;
|
m_bluetoothEnabled = false;
|
||||||
@ -231,7 +234,7 @@ void BluetoothDiscovery::start()
|
|||||||
|
|
||||||
m_deviceInfos->clearModel();
|
m_deviceInfos->clearModel();
|
||||||
|
|
||||||
qDebug() << "BluetoothDiscovery: Starting discovery.";
|
qCDebug(dcBtWiFiSetup) << "BluetoothDiscovery: Starting discovery.";
|
||||||
m_discoveryAgent->start();
|
m_discoveryAgent->start();
|
||||||
emit discoveringChanged();
|
emit discoveringChanged();
|
||||||
}
|
}
|
||||||
@ -242,7 +245,7 @@ void BluetoothDiscovery::stop()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "BluetoothDiscovery: Stop discovering.";
|
qCDebug(dcBtWiFiSetup) << "BluetoothDiscovery: Stop discovering.";
|
||||||
m_discoveryAgent->stop();
|
m_discoveryAgent->stop();
|
||||||
emit discoveringChanged();
|
emit discoveringChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user