2015-03-01 20:17:46 +00:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2016 Saikrishna Arcot <saiarcot895@gmail.com>
|
2015-03-01 20:17:46 +00:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2015-03-01 20:17:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BLUETOOTHLINKPROVIDER_H
|
|
|
|
#define BLUETOOTHLINKPROVIDER_H
|
|
|
|
|
2019-02-03 00:44:22 +00:00
|
|
|
#include <QBluetoothAddress>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QBluetoothDeviceDiscoveryAgent>
|
2019-02-03 00:44:22 +00:00
|
|
|
#include <QBluetoothLocalDevice>
|
|
|
|
#include <QBluetoothServer>
|
|
|
|
#include <QBluetoothServiceDiscoveryAgent>
|
|
|
|
#include <QBluetoothSocket>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QBluetoothUuid>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QPointer>
|
|
|
|
#include <QTimer>
|
2015-03-01 20:17:46 +00:00
|
|
|
|
|
|
|
#include "../linkprovider.h"
|
|
|
|
|
|
|
|
class BluetoothDeviceLink;
|
2019-03-08 18:18:01 +00:00
|
|
|
class ConnectionMultiplexer;
|
|
|
|
class MultiplexChannel;
|
2015-03-01 20:17:46 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
class KDECONNECTCORE_EXPORT BluetoothLinkProvider : public LinkProvider
|
2015-03-01 20:17:46 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
BluetoothLinkProvider();
|
2016-11-11 14:55:16 +00:00
|
|
|
virtual ~BluetoothLinkProvider();
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
QString name() override
|
|
|
|
{
|
|
|
|
return QStringLiteral("BluetoothLinkProvider");
|
|
|
|
}
|
2015-03-01 20:17:46 +00:00
|
|
|
|
2023-10-01 11:39:59 +01:00
|
|
|
int priority() override
|
|
|
|
{
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
2015-03-01 20:17:46 +00:00
|
|
|
public Q_SLOTS:
|
2016-11-11 14:55:16 +00:00
|
|
|
virtual void onNetworkChange() override;
|
|
|
|
virtual void onStart() override;
|
|
|
|
virtual void onStop() override;
|
2023-06-27 12:10:59 +01:00
|
|
|
virtual void onLinkDestroyed(const QString &deviceId, DeviceLink *oldPtr) override;
|
2015-03-01 20:17:46 +00:00
|
|
|
void connectError();
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
2019-03-08 18:18:01 +00:00
|
|
|
void socketDisconnected(const QBluetoothAddress &peerAddress, MultiplexChannel *socket);
|
2017-05-24 22:28:49 +01:00
|
|
|
|
2015-03-01 20:17:46 +00:00
|
|
|
void serverNewConnection();
|
2019-03-08 18:18:01 +00:00
|
|
|
void serverDataReceived(const QBluetoothAddress &peerAddress, QSharedPointer<MultiplexChannel> socket);
|
|
|
|
void clientConnected(QPointer<QBluetoothSocket> socket);
|
|
|
|
void clientIdentityReceived(const QBluetoothAddress &peerAddress, QSharedPointer<MultiplexChannel> socket);
|
|
|
|
|
|
|
|
void serviceDiscovered(const QBluetoothServiceInfo &info);
|
2015-03-01 20:17:46 +00:00
|
|
|
|
|
|
|
private:
|
2022-09-10 22:23:52 +01:00
|
|
|
void addLink(BluetoothDeviceLink *deviceLink, const QString &deviceId);
|
2015-03-01 20:17:46 +00:00
|
|
|
QList<QBluetoothAddress> getPairedDevices();
|
2024-10-04 05:25:51 +01:00
|
|
|
void tryToInitialise();
|
2015-03-01 20:17:46 +00:00
|
|
|
|
|
|
|
QBluetoothUuid mServiceUuid;
|
2016-11-11 14:55:16 +00:00
|
|
|
QPointer<QBluetoothServer> mBluetoothServer;
|
2015-03-01 20:17:46 +00:00
|
|
|
QBluetoothServiceInfo mKdeconnectService;
|
2022-09-10 22:23:52 +01:00
|
|
|
QBluetoothServiceDiscoveryAgent *mServiceDiscoveryAgent;
|
|
|
|
QTimer *connectTimer;
|
2015-03-01 20:17:46 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
QMap<QString, DeviceLink *> mLinks;
|
2015-03-01 20:17:46 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
QMap<QBluetoothAddress, ConnectionMultiplexer *> mSockets;
|
2015-03-01 20:17:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|