2022-06-08 11:30:04 +00:00
|
|
|
// Copyright (C) 2017 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2017-02-28 14:30:46 +00:00
|
|
|
|
2017-04-03 10:17:20 +00:00
|
|
|
#include "heartrate-global.h"
|
2017-02-28 14:30:46 +00:00
|
|
|
#include "connectionhandler.h"
|
2017-03-15 12:19:46 +00:00
|
|
|
#include <QtBluetooth/qtbluetooth-config.h>
|
2018-01-04 13:37:52 +00:00
|
|
|
#include <QtCore/qsystemdetection.h>
|
2017-02-28 14:30:46 +00:00
|
|
|
|
|
|
|
ConnectionHandler::ConnectionHandler(QObject *parent) : QObject(parent)
|
|
|
|
{
|
|
|
|
connect(&m_localDevice, &QBluetoothLocalDevice::hostModeStateChanged,
|
|
|
|
this, &ConnectionHandler::hostModeChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConnectionHandler::alive() const
|
|
|
|
{
|
2018-01-04 13:37:52 +00:00
|
|
|
#if defined(SIMULATOR) || defined(QT_PLATFORM_UIKIT)
|
2017-02-28 14:30:46 +00:00
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return m_localDevice.isValid() && m_localDevice.hostMode() != QBluetoothLocalDevice::HostPoweredOff;
|
|
|
|
#endif
|
|
|
|
}
|
2017-03-15 12:19:46 +00:00
|
|
|
|
|
|
|
bool ConnectionHandler::requiresAddressType() const
|
|
|
|
{
|
|
|
|
#if QT_CONFIG(bluez)
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-02-28 14:30:46 +00:00
|
|
|
QString ConnectionHandler::name() const
|
|
|
|
{
|
|
|
|
return m_localDevice.name();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ConnectionHandler::address() const
|
|
|
|
{
|
|
|
|
return m_localDevice.address().toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionHandler::hostModeChanged(QBluetoothLocalDevice::HostMode /*mode*/)
|
|
|
|
{
|
|
|
|
emit deviceChanged();
|
|
|
|
}
|