DeviceDiscovery is not using the Engine singleton any more

This commit is contained in:
Michael Zanetti 2018-08-31 18:42:57 +02:00
parent 5f6a3f5f31
commit b1338caf33
3 changed files with 32 additions and 1 deletions

View File

@ -43,16 +43,38 @@ void DeviceDiscovery::discoverDevices(const QUuid &deviceClassId, const QVariant
endResetModel();
emit countChanged();
if (!m_jsonRpcClient) {
qWarning() << "Cannot discover devices. No JsonRpcClient set";
return;
}
if (!m_jsonRpcClient->connected()) {
qWarning() << "Cannot discover devices. JsonRpcClient not connected.";
return;
}
QVariantMap params;
params.insert("deviceClassId", deviceClassId.toString());
if (!discoveryParams.isEmpty()) {
params.insert("discoveryParams", discoveryParams);
}
Engine::instance()->jsonRpcClient()->sendCommand("Devices.GetDiscoveredDevices", params, this, "discoverDevicesResponse");
m_jsonRpcClient->sendCommand("Devices.GetDiscoveredDevices", params, this, "discoverDevicesResponse");
m_busy = true;
emit busyChanged();
}
JsonRpcClient *DeviceDiscovery::jsonRpcClient() const
{
return m_jsonRpcClient;
}
void DeviceDiscovery::setJsonRpcClient(JsonRpcClient *jsonRpcClient)
{
if (m_jsonRpcClient != jsonRpcClient) {
m_jsonRpcClient = jsonRpcClient;
emit jsonRpcClientChanged();
}
}
bool DeviceDiscovery::busy() const
{
return m_busy;

View File

@ -4,9 +4,12 @@
#include <QAbstractListModel>
#include <QUuid>
#include "jsonrpc/jsonrpcclient.h"
class DeviceDiscovery : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(JsonRpcClient* jsonRpcClient READ jsonRpcClient WRITE setJsonRpcClient)
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
public:
@ -25,6 +28,9 @@ public:
Q_INVOKABLE void discoverDevices(const QUuid &deviceClassId, const QVariantList &discoveryParams = {});
JsonRpcClient* jsonRpcClient() const;
void setJsonRpcClient(JsonRpcClient *jsonRpcClient);
bool busy() const;
private slots:
@ -33,6 +39,7 @@ private slots:
signals:
void busyChanged();
void countChanged();
void jsonRpcClientChanged();
private:
class DeviceDescriptor {
@ -43,6 +50,7 @@ private:
QString m_description;
};
JsonRpcClient *m_jsonRpcClient = nullptr;
bool m_busy = false;
bool contains(const QUuid &deviceDescriptorId) const;

View File

@ -61,6 +61,7 @@ Page {
DeviceDiscovery {
id: discovery
jsonRpcClient: Engine.jsonRpcClient
}
StackView {