basic functionality

pull/1/head
Simon Stürz 2017-06-08 10:28:54 +02:00
parent ddd1208903
commit 86ae8ad65f
52 changed files with 3082 additions and 66 deletions

View File

@ -1,17 +1,48 @@
QT += qml quick websockets
include(../guh-control.pri)
QT += qml quick websockets quickcontrols2
TARGET = guh-control
CONFIG += c++11
RESOURCES += ../ui/qml.qrc ../data.qrc
SOURCES += main.cpp
INCLUDEPATH += $$top_srcdir/libguh-common
LIBS += -L$$top_builddir/libguh-common/ -lguh-common
RESOURCES += ui/qml.qrc
QML_FILES += $$files(*.qml,true) \
$$files(*.js,true)
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH = ui/
OTHER_FILES += $${QML_FILES}
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
engine.h \
guhinterface.h \
devicemanager.h \
websocketinterface.h \
jsonrpc/jsontypes.h \
jsonrpc/jsonrpcclient.h \
jsonrpc/devicehandler.h \
jsonrpc/jsonhandler.h \
jsonrpc/actionhandler.h \
jsonrpc/eventhandler.h \
jsonrpc/logginghandler.h \
jsonrpc/networkmanagerhandler.h \
jsonrpc/configurationhandler.h
SOURCES += main.cpp \
engine.cpp \
guhinterface.cpp \
devicemanager.cpp \
websocketinterface.cpp \
jsonrpc/jsontypes.cpp \
jsonrpc/jsonrpcclient.cpp \
jsonrpc/devicehandler.cpp \
jsonrpc/jsonhandler.cpp \
jsonrpc/actionhandler.cpp \
jsonrpc/eventhandler.cpp \
jsonrpc/logginghandler.cpp \
jsonrpc/networkmanagerhandler.cpp \
jsonrpc/configurationhandler.cpp
target.path = /usr/bin
INSTALLS += target

View File

@ -0,0 +1,93 @@
#include "bluetoothinterface.h"
#include <QJsonDocument>
#include <QJsonParseError>
BluetoothInterface::BluetoothInterface(QObject *parent) :
GuhInterface(parent),
m_socket(0),
m_discovery(new BluetoothDiscovery(this))
{
connect(m_discovery, &BluetoothDiscovery::serviceFound, this, &BluetoothInterface::onServiceFound);
}
void BluetoothInterface::sendData(const QByteArray &data)
{
if (m_socket)
m_socket->write(data + '\n');
}
void BluetoothInterface::sendRequest(const QVariantMap &request)
{
sendData(QJsonDocument::fromVariant(request).toJson(QJsonDocument::Compact));
}
BluetoothDiscovery *BluetoothInterface::discovery()
{
return m_discovery;
}
void BluetoothInterface::enable()
{
if (m_socket)
return;
m_socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
connect(m_socket, &QBluetoothSocket::readyRead, this, &BluetoothInterface::onDataReady);
connect(m_socket, &QBluetoothSocket::connected, this, &BluetoothInterface::onConnected);
connect(m_socket, &QBluetoothSocket::disconnected, this, &BluetoothInterface::onDisconnected);
}
void BluetoothInterface::disable()
{
delete m_socket;
m_socket = 0;
}
void BluetoothInterface::onServiceFound(const QBluetoothServiceInfo &service)
{
m_service = service;
enable();
if (m_socket->isOpen())
return;
qDebug() << "Connecting to service" << m_service.serviceName();
m_socket->connectToService(m_service);
}
void BluetoothInterface::onConnected()
{
qDebug() << "Bluetooth Interface: connected" << m_socket->peerName() << m_socket->peerAddress();
setConnected(true);
}
void BluetoothInterface::onDisconnected()
{
qDebug() << "Bluetooth Interface: disconnected";
setConnected(false);
}
void BluetoothInterface::onDataReady()
{
if (!m_socket)
return;
QByteArray message;
while (m_socket->canReadLine()) {
QByteArray dataLine = m_socket->readLine();
message.append(dataLine);
if (dataLine.endsWith('\n')) {
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(message, &error);
if (error.error != QJsonParseError::NoError) {
qWarning() << "Could not parse json data from guh" << message << error.errorString();
return;
}
emit dataReady(jsonDoc.toVariant().toMap());
message.clear();
}
}
}

View File

@ -0,0 +1,44 @@
#ifndef BLUETOOTHINTERFACE_H
#define BLUETOOTHINTERFACE_H
#include <QObject>
#include <QBluetoothSocket>
#include "guhinterface.h"
#include "discovery/bluetoothdiscovery.h"
class BluetoothInterface : public GuhInterface
{
Q_OBJECT
Q_PROPERTY(BluetoothDiscovery *discovery READ discovery CONSTANT)
public:
explicit BluetoothInterface(QObject *parent = 0);
void sendData(const QByteArray &data) override;
void sendRequest(const QVariantMap &request) override;
BluetoothDiscovery *discovery();
private:
QBluetoothSocket *m_socket;
QBluetoothServiceInfo m_service;
BluetoothDiscovery *m_discovery;
signals:
public slots:
Q_INVOKABLE void enable() override;
Q_INVOKABLE void disable() override;
private slots:
void onServiceFound(const QBluetoothServiceInfo &service);
void onConnected();
void onDisconnected();
void onDataReady();
};
#endif // BLUETOOTHINTERFACE_H

View File

@ -0,0 +1,129 @@
#include "connectionmanager.h"
#include <QState>
#include <QSettings>
ConnectionManager::ConnectionManager(QObject *parent) :
QObject(parent),
m_discovery(new UpnpDiscovery(this)),
m_interface(0),
m_websocketInterface(new WebsocketInterface(this)),
m_bluetoothInterface(new BluetoothInterface(this))
{
}
GuhInterface *ConnectionManager::interface()
{
return m_interface;
}
UpnpDiscovery *ConnectionManager::upnpDiscovery()
{
return m_discovery;
}
WebsocketInterface *ConnectionManager::websocketInterface()
{
return m_websocketInterface;
}
BluetoothInterface *ConnectionManager::bluetoothInterface()
{
return m_bluetoothInterface;
}
QString ConnectionManager::currentInterfaceName() const
{
return m_currentInterfaceName;
}
QString ConnectionManager::currentStatusMessage() const
{
return m_currentStatusMessage;
}
void ConnectionManager::setInterface(GuhInterface *interface)
{
if (m_interface) {
disconnect(m_interface, &GuhInterface::connectedChanged, this, &ConnectionManager::onConnectedChanged);
disconnect(m_interface, &GuhInterface::dataReady, this, &ConnectionManager::dataReady);
}
m_interface = interface;
connect(m_interface, &GuhInterface::connectedChanged, this, &ConnectionManager::onConnectedChanged);
connect(m_interface, &GuhInterface::dataReady, this, &ConnectionManager::dataReady);
emit interfaceChanged();
}
void ConnectionManager::setCurrentInterfaceName(const QString &name)
{
m_currentInterfaceName = name;
emit currentInterfaceNameChanged();
}
void ConnectionManager::setCurrentStatusMessage(const QString &message)
{
m_currentStatusMessage = message;
emit currentStatusMessageChanged();
}
void ConnectionManager::onConnectedChanged()
{
if (m_interface->connected())
emit connected();
else
emit disconnect();
emit connectedChanged();
}
void ConnectionManager::onConnectingState()
{
QSettings settings;
qDebug() << "Loading last connection" << settings.fileName();
settings.beginGroup("Connections");
QString url = settings.value("webSocketUrl").toString();
settings.endGroup();
if (url.isEmpty()) {
qDebug() << "No stored websocket url";
m_websocketInterface->connectionFailed();
}
m_websocketInterface->setUrl(url);
m_websocketInterface->enable();
}
void ConnectionManager::onUpnpDiscoveringState()
{
upnpDiscovery()->discover();
}
void ConnectionManager::start(const ConnectionType &connectionType)
{
switch (connectionType) {
case ConnectionTypeAuto:
setInterface(m_websocketInterface);
break;
case ConnectionTypeWebSocket:
setInterface(m_websocketInterface);
m_discovery->discover();
break;
case ConnectionTypeCloud:
break;
case ConnectionTypeBluetooth:
setInterface(m_bluetoothInterface);
break;
default:
setInterface(m_bluetoothInterface);
break;
}
}
void ConnectionManager::stop()
{
m_interface->disable();
}

View File

@ -0,0 +1,82 @@
#ifndef CONNECTIONMANAGER_H
#define CONNECTIONMANAGER_H
#include <QObject>
#include <QStateMachine>
#include "guhinterface.h"
#include "websocketinterface.h"
#include "bluetoothinterface.h"
#include "cloudconnection/cloudconnection.h"
#include "discovery/upnpdiscovery.h"
class ConnectionManager : public QObject
{
Q_OBJECT
Q_ENUMS(ConnectionType)
Q_PROPERTY(UpnpDiscovery *upnpDiscovery READ upnpDiscovery CONSTANT)
Q_PROPERTY(GuhInterface *interface READ interface NOTIFY interfaceChanged)
Q_PROPERTY(WebsocketInterface *websocketInterface READ websocketInterface CONSTANT)
Q_PROPERTY(BluetoothInterface *bluetoothInterface READ bluetoothInterface CONSTANT)
Q_PROPERTY(QString currentInterfaceName READ currentInterfaceName WRITE setCurrentInterfaceName NOTIFY currentInterfaceNameChanged)
Q_PROPERTY(QString currentStatusMessage READ currentStatusMessage WRITE setCurrentStatusMessage NOTIFY currentStatusMessageChanged)
public:
enum ConnectionType {
ConnectionTypeAuto,
ConnectionTypeWebSocket,
ConnectionTypeCloud,
ConnectionTypeBluetooth
};
explicit ConnectionManager(QObject *parent = 0);
GuhInterface *interface();
UpnpDiscovery *upnpDiscovery();
WebsocketInterface *websocketInterface();
BluetoothInterface *bluetoothInterface();
QString currentInterfaceName() const;
QString currentStatusMessage() const;
private:
UpnpDiscovery *m_discovery;
GuhInterface *m_interface;
WebsocketInterface *m_websocketInterface;
BluetoothInterface *m_bluetoothInterface;
QString m_currentInterfaceName;
QString m_currentStatusMessage;
void setInterface(GuhInterface *interface);
void setCurrentInterfaceName(const QString &name);
void setCurrentStatusMessage(const QString &message);
private slots:
void onConnectedChanged();
// State slots
void onConnectingState();
void onUpnpDiscoveringState();
signals:
void connectedChanged();
void dataReady(const QVariantMap &data);
void connected();
void disconnected();
void interfaceChanged();
void websocketInterfaceChanged();
void currentInterfaceNameChanged();
void currentStatusMessageChanged();
public slots:
void start(const ConnectionType &connectionType = ConnectionTypeAuto);
void stop();
};
#endif // CONNECTIONMANAGER_H

81
backend/devicemanager.cpp Normal file
View File

@ -0,0 +1,81 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "devicemanager.h"
#include "engine.h"
DeviceManager::DeviceManager(QObject *parent) :
QObject(parent),
m_vendors(new Vendors(this)),
m_vendorsProxy(new VendorsProxy(this)),
m_plugins(new Plugins(this)),
m_pluginsProxy(new PluginsProxy(this)),
m_devices(new Devices(this)),
m_devicesProxy(new DevicesProxy(this)),
m_deviceClasses(new DeviceClasses(this)),
m_deviceClassesProxy(new DeviceClassesProxy(this))
{
m_vendorsProxy->setVendors(m_vendors);
m_pluginsProxy->setPlugins(m_plugins);
m_devicesProxy->setDevices(m_devices);
m_deviceClassesProxy->setDeviceClasses(m_deviceClasses);
}
Vendors *DeviceManager::vendors() const
{
return m_vendors;
}
VendorsProxy *DeviceManager::vendorsProxy() const
{
return m_vendorsProxy;
}
Plugins *DeviceManager::plugins() const
{
return m_plugins;
}
PluginsProxy *DeviceManager::pluginsProxy() const
{
return m_pluginsProxy;
}
Devices *DeviceManager::devices() const
{
return m_devices;
}
DevicesProxy *DeviceManager::devicesProxy() const
{
return m_devicesProxy;
}
DeviceClasses *DeviceManager::deviceClasses() const
{
return m_deviceClasses;
}
DeviceClassesProxy *DeviceManager::deviceClassesProxy() const
{
return m_deviceClassesProxy;
}

71
backend/devicemanager.h Normal file
View File

@ -0,0 +1,71 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef DEVICEMANAGER_H
#define DEVICEMANAGER_H
#include <QObject>
#include "types/vendors.h"
#include "types/vendorsproxy.h"
#include "types/devices.h"
#include "types/devicesproxy.h"
#include "types/deviceclasses.h"
#include "types/deviceclassesproxy.h"
#include "types/plugins.h"
#include "types/pluginsproxy.h"
class DeviceManager : public QObject
{
Q_OBJECT
Q_PROPERTY(Vendors *vendors READ vendors CONSTANT)
Q_PROPERTY(VendorsProxy *vendorsProxy READ vendorsProxy CONSTANT)
Q_PROPERTY(Plugins *plugins READ plugins CONSTANT)
Q_PROPERTY(PluginsProxy *pluginsProxy READ pluginsProxy CONSTANT)
Q_PROPERTY(Devices *devices READ devices CONSTANT)
Q_PROPERTY(DevicesProxy *devicesProxy READ devicesProxy CONSTANT)
Q_PROPERTY(DeviceClasses *deviceClasses READ deviceClasses CONSTANT)
Q_PROPERTY(DeviceClassesProxy *deviceClassesProxy READ deviceClassesProxy CONSTANT)
public:
explicit DeviceManager(QObject *parent = 0);
Vendors *vendors() const;
VendorsProxy *vendorsProxy() const;
Plugins *plugins() const;
PluginsProxy *pluginsProxy() const;
Devices *devices() const;
DevicesProxy *devicesProxy() const;
DeviceClasses *deviceClasses() const;
DeviceClassesProxy *deviceClassesProxy() const;
private:
Vendors *m_vendors;
VendorsProxy *m_vendorsProxy;
Plugins *m_plugins;
PluginsProxy *m_pluginsProxy;
Devices *m_devices;
DevicesProxy *m_devicesProxy;
DeviceClasses *m_deviceClasses;
DeviceClassesProxy *m_deviceClassesProxy;
};
#endif // DEVICEMANAGER_H

100
backend/engine.cpp Normal file
View File

@ -0,0 +1,100 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "engine.h"
Engine* Engine::s_instance = 0;
Engine *Engine::instance()
{
if (!s_instance)
s_instance = new Engine();
return s_instance;
}
QObject *Engine::qmlInstance(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
{
Q_UNUSED(qmlEngine)
Q_UNUSED(jsEngine)
return Engine::instance();
}
bool Engine::connected() const
{
return m_connected;
}
DeviceManager *Engine::deviceManager()
{
return m_deviceManager;
}
JsonRpcClient *Engine::jsonRpcClient()
{
return m_jsonRpcClient;
}
WebsocketInterface *Engine::interface()
{
return m_interface;
}
void Engine::connectGuh()
{
m_interface->setUrl("ws://loop.local:4444");
m_interface->enable();
}
Engine::Engine(QObject *parent) :
QObject(parent),
m_connected(false),
m_deviceManager(new DeviceManager(this)),
m_jsonRpcClient(new JsonRpcClient(this)),
m_interface(new WebsocketInterface(this))
{
connect(m_interface, &WebsocketInterface::connectedChanged, this, &Engine::onConnectedChanged);
connect(m_interface, &WebsocketInterface::dataReady, m_jsonRpcClient, &JsonRpcClient::dataReceived);
}
void Engine::setConnected(const bool &connected)
{
if (m_connected != connected) {
m_connected = connected;
emit connectedChanged(m_connected);
}
}
void Engine::onConnectedChanged(const bool &connected)
{
setConnected(connected);
// delete all data
if (!connected) {
deviceManager()->devices()->clearModel();
deviceManager()->deviceClasses()->clearModel();
deviceManager()->vendors()->clearModel();
deviceManager()->plugins()->clearModel();
} else {
Engine::instance()->jsonRpcClient()->getVendors();
}
}

74
backend/engine.h Normal file
View File

@ -0,0 +1,74 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef ENGINE_H
#define ENGINE_H
#include <QObject>
#include <QQmlEngine>
#include <QJSEngine>
#include "devicemanager.h"
#include "websocketinterface.h"
#include "jsonrpc/jsonrpcclient.h"
class Engine : public QObject
{
Q_OBJECT
Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
Q_PROPERTY(DeviceManager *deviceManager READ deviceManager CONSTANT)
Q_PROPERTY(JsonRpcClient *jsonRpcClient READ jsonRpcClient CONSTANT)
Q_PROPERTY(WebsocketInterface *interface READ interface CONSTANT)
public:
static Engine *instance();
static QObject *qmlInstance(QQmlEngine *qmlEngine, QJSEngine *jsEngine);
bool connected() const;
DeviceManager *deviceManager();
JsonRpcClient *jsonRpcClient();
WebsocketInterface *interface();
Q_INVOKABLE void connectGuh();
private:
explicit Engine(QObject *parent = 0);
static Engine *s_instance;
bool m_connected;
DeviceManager *m_deviceManager;
JsonRpcClient *m_jsonRpcClient;
WebsocketInterface *m_interface;
void setConnected(const bool &connected);
signals:
void connectedChanged(const bool &connected);
private slots:
void onConnectedChanged(const bool &connected);
public slots:
};
#endif // ENGINE_H

41
backend/guhinterface.cpp Normal file
View File

@ -0,0 +1,41 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "guhinterface.h"
GuhInterface::GuhInterface(QObject *parent) :
QObject(parent),
m_connected(false)
{
}
bool GuhInterface::connected()
{
return m_connected;
}
void GuhInterface::setConnected(const bool &connected)
{
if (m_connected != connected) {
m_connected = connected;
emit connectedChanged(connected);
}
}

53
backend/guhinterface.h Normal file
View File

@ -0,0 +1,53 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef GUHINTERFACE_H
#define GUHINTERFACE_H
#include <QObject>
class GuhInterface : public QObject
{
Q_OBJECT
Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
public:
explicit GuhInterface(QObject *parent = 0);
bool connected();
virtual void sendData(const QByteArray &data) = 0;
virtual void sendRequest(const QVariantMap &request) = 0;
protected:
bool m_connected;
void setConnected(const bool &connected);
signals:
void dataReady(const QVariantMap &data);
void connectedChanged(const bool &connected);
public slots:
virtual void enable() { }
virtual void disable() { }
};
#endif // GUHINTERFACE_H

View File

@ -0,0 +1,40 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "actionhandler.h"
#include <QDebug>
ActionHandler::ActionHandler(QObject *parent) :
JsonHandler(parent)
{
}
QString ActionHandler::nameSpace() const
{
return "Actions";
}
void ActionHandler::processExecuteAction(const QVariantMap &params)
{
// response handled in the ui
Q_UNUSED(params);
}

View File

@ -0,0 +1,40 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef ACTIONHANDLER_H
#define ACTIONHANDLER_H
#include <QObject>
#include "jsonhandler.h"
class ActionHandler : public JsonHandler
{
Q_OBJECT
public:
explicit ActionHandler(QObject *parent = 0);
QString nameSpace() const;
Q_INVOKABLE void processExecuteAction(const QVariantMap &params);
};
#endif // ACTIONHANDLER_H

View File

@ -0,0 +1,12 @@
#include "configurationhandler.h"
ConfigurationHandler::ConfigurationHandler(QObject *parent) :
JsonHandler(parent)
{
}
QString ConfigurationHandler::nameSpace() const
{
return "Configuration";
}

View File

@ -0,0 +1,21 @@
#ifndef CONFIGURATIONHANDLER_H
#define CONFIGURATIONHANDLER_H
#include <QObject>
#include "jsonhandler.h"
class ConfigurationHandler : public JsonHandler
{
Q_OBJECT
public:
explicit ConfigurationHandler(QObject *parent = 0);
QString nameSpace() const;
signals:
public slots:
};
#endif // CONFIGURATIONHANDLER_H

View File

@ -0,0 +1,166 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "devicehandler.h"
#include "jsontypes.h"
#include "engine.h"
#include "types/states.h"
#include "types/deviceclass.h"
DeviceHandler::DeviceHandler(QObject *parent) :
JsonHandler(parent)
{
}
QString DeviceHandler::nameSpace() const
{
return QString("Devices");
}
void DeviceHandler::processGetSupportedVendors(const QVariantMap &params)
{
if (params.value("params").toMap().keys().contains("vendors")) {
QVariantList vendorList = params.value("params").toMap().value("vendors").toList();
foreach (QVariant vendorVariant, vendorList) {
Vendor *vendor = JsonTypes::unpackVendor(vendorVariant.toMap(), Engine::instance()->deviceManager()->vendors());
Engine::instance()->deviceManager()->vendors()->addVendor(vendor);
}
}
Engine::instance()->jsonRpcClient()->getDeviceClasses();
}
void DeviceHandler::processGetPlugins(const QVariantMap &params)
{
if (params.value("params").toMap().keys().contains("plugins")) {
QVariantList pluginList = params.value("params").toMap().value("plugins").toList();
foreach (QVariant pluginVariant, pluginList) {
Plugin *plugin = JsonTypes::unpackPlugin(pluginVariant.toMap(), Engine::instance()->deviceManager()->plugins());
Engine::instance()->deviceManager()->plugins()->addPlugin(plugin);
}
}
Engine::instance()->jsonRpcClient()->getDevices();
}
void DeviceHandler::processGetSupportedDevices(const QVariantMap &params)
{
if (params.value("params").toMap().keys().contains("deviceClasses")) {
QVariantList deviceClassList = params.value("params").toMap().value("deviceClasses").toList();
foreach (QVariant deviceClassVariant, deviceClassList) {
DeviceClass *deviceClass = JsonTypes::unpackDeviceClass(deviceClassVariant.toMap(), Engine::instance()->deviceManager()->deviceClasses());
Engine::instance()->deviceManager()->deviceClasses()->addDeviceClass(deviceClass);
}
}
Engine::instance()->jsonRpcClient()->getPlugins();
}
void DeviceHandler::processGetConfiguredDevices(const QVariantMap &params)
{
if (params.value("params").toMap().keys().contains("devices")) {
QVariantList deviceList = params.value("params").toMap().value("devices").toList();
foreach (QVariant deviceVariant, deviceList) {
Device *device = JsonTypes::unpackDevice(deviceVariant.toMap(), Engine::instance()->deviceManager()->devices());
Engine::instance()->deviceManager()->devices()->addDevice(device);
//qDebug() << QJsonDocument::fromVariant(deviceVariant).toJson();
// set initial state values
QVariantList stateVariantList = deviceVariant.toMap().value("states").toList();
foreach (const QVariant &stateMap, stateVariantList) {
QUuid stateTypeId = stateMap.toMap().value("stateTypeId").toUuid();
QVariant value = stateMap.toMap().value("value");
foreach (Device *d, Engine::instance()->deviceManager()->devices()->devices()) {
if (d->hasState(stateTypeId)) {
d->setStateValue(stateTypeId, value);
}
}
}
}
}
}
void DeviceHandler::processRemoveConfiguredDevice(const QVariantMap &params)
{
// response handled in the ui
Q_UNUSED(params);
}
void DeviceHandler::processAddConfiguredDevice(const QVariantMap &params)
{
// response handled in the ui
Q_UNUSED(params);
}
void DeviceHandler::processGetDiscoveredDevices(const QVariantMap &params)
{
// response handled in the ui
Q_UNUSED(params);
}
void DeviceHandler::processPairDevice(const QVariantMap &params)
{
// response handled in the ui
Q_UNUSED(params);
}
void DeviceHandler::processConfirmPairing(const QVariantMap &params)
{
// response handled in the ui
Q_UNUSED(params);
}
void DeviceHandler::processDeviceRemoved(const QVariantMap &params)
{
QUuid deviceId = params.value("params").toMap().value("deviceId").toUuid();
qDebug() << "JsonRpc: Notification: Device removed" << deviceId.toString();
Device *device = Engine::instance()->deviceManager()->devices()->getDevice(deviceId);
Engine::instance()->deviceManager()->devices()->removeDevice(device);
device->deleteLater();
}
void DeviceHandler::processDeviceAdded(const QVariantMap &params)
{
if (params.value("params").toMap().keys().contains("device")) {
QVariantMap deviceVariant = params.value("params").toMap().value("device").toMap();
Device *device = JsonTypes::unpackDevice(deviceVariant, Engine::instance()->deviceManager()->devices());
qDebug() << "JsonRpc: Notification: Device added" << device->id().toString();
Engine::instance()->deviceManager()->devices()->addDevice(device);
}
}
void DeviceHandler::processStateChanged(const QVariantMap &params)
{
QVariantMap notification = params.value("params").toMap();
QUuid deviceId = notification.value("deviceId").toUuid();
Device *device = Engine::instance()->deviceManager()->devices()->getDevice(deviceId);
if (!device) {
qWarning() << "JsonRpc: ERROR: could not find device for state changed notification";
return;
}
QUuid stateTypeId = notification.value("stateTypeId").toUuid();
QVariant value = notification.value("value");
device->setStateValue(stateTypeId, value);
}

View File

@ -0,0 +1,56 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef DEVICEHANDLER_H
#define DEVICEHANDLER_H
#include <QObject>
#include "jsonhandler.h"
class DeviceHandler : public JsonHandler
{
Q_OBJECT
public:
explicit DeviceHandler(QObject *parent = 0);
QString nameSpace() const;
// Get methods internal
Q_INVOKABLE void processGetSupportedVendors(const QVariantMap &params);
Q_INVOKABLE void processGetPlugins(const QVariantMap &params);
Q_INVOKABLE void processGetSupportedDevices(const QVariantMap &params);
Q_INVOKABLE void processGetConfiguredDevices(const QVariantMap &params);
// Methods ui
Q_INVOKABLE void processRemoveConfiguredDevice(const QVariantMap &params);
Q_INVOKABLE void processAddConfiguredDevice(const QVariantMap &params);
Q_INVOKABLE void processGetDiscoveredDevices(const QVariantMap &params);
Q_INVOKABLE void processPairDevice(const QVariantMap &params);
Q_INVOKABLE void processConfirmPairing(const QVariantMap &params);
// Notifications
Q_INVOKABLE void processDeviceRemoved(const QVariantMap &params);
Q_INVOKABLE void processDeviceAdded(const QVariantMap &params);
Q_INVOKABLE void processStateChanged(const QVariantMap &params);
};
#endif // DEVICEHANDLER_H

View File

@ -0,0 +1,38 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "eventhandler.h"
EventHandler::EventHandler(QObject *parent) :
JsonHandler(parent)
{
}
QString EventHandler::nameSpace() const
{
return "Events";
}
void EventHandler::processEventTriggered(const QVariantMap &params)
{
Q_UNUSED(params);
}

View File

@ -0,0 +1,40 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef EVENTHANDLER_H
#define EVENTHANDLER_H
#include <QObject>
#include "jsonhandler.h"
class EventHandler : public JsonHandler
{
Q_OBJECT
public:
explicit EventHandler(QObject *parent = 0);
QString nameSpace() const;
Q_INVOKABLE void processEventTriggered(const QVariantMap &params);
};
#endif // EVENTHANDLER_H

View File

@ -0,0 +1,26 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "jsonhandler.h"
JsonHandler::JsonHandler(QObject *parent) :
QObject(parent)
{
}

View File

@ -0,0 +1,35 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef JSONHANDLER_H
#define JSONHANDLER_H
#include <QObject>
#include <QDebug>
class JsonHandler : public QObject
{
Q_OBJECT
public:
JsonHandler(QObject *parent = 0);
virtual QString nameSpace() const = 0;
};
#endif // JSONHANDLER_H

View File

@ -0,0 +1,249 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "jsonrpcclient.h"
#include "engine.h"
#include "types/param.h"
#include "types/params.h"
#include <QJsonDocument>
#include <QVariantMap>
#include <QDebug>
JsonRpcClient::JsonRpcClient(QObject *parent) :
QObject(parent),
m_id(0)
{
m_deviceHandler = new DeviceHandler(this);
m_actionHandler = new ActionHandler(this);
m_eventHandler = new EventHandler(this);
m_loggingHandler = new LoggingHandler(this);
m_networkManagerHandler = new NetworkManagerHandler(this);
m_handlers.insert(m_deviceHandler->nameSpace(), m_deviceHandler);
m_handlers.insert(m_actionHandler->nameSpace(), m_actionHandler);
m_handlers.insert(m_eventHandler->nameSpace(), m_eventHandler);
m_handlers.insert(m_loggingHandler->nameSpace(), m_loggingHandler);
m_handlers.insert(m_networkManagerHandler->nameSpace(), m_networkManagerHandler);
}
void JsonRpcClient::getVendors()
{
qDebug() << "JsonRpc: get vendors";
JsonRpcReply *reply = createReply("Devices", "GetSupportedVendors");
m_replies.insert(reply->commandId(), reply);
Engine::instance()->interface()->sendRequest(reply->requestMap());
}
void JsonRpcClient::getPlugins()
{
qDebug() << "JsonRpc: get plugins";
JsonRpcReply *reply = createReply("Devices", "GetPlugins");
m_replies.insert(reply->commandId(), reply);
Engine::instance()->interface()->sendRequest(reply->requestMap());
}
void JsonRpcClient::getDevices()
{
qDebug() << "JsonRpc: get devices";
JsonRpcReply *reply = createReply("Devices", "GetConfiguredDevices");
m_replies.insert(reply->commandId(), reply);
Engine::instance()->interface()->sendRequest(reply->requestMap());
}
void JsonRpcClient::getDeviceClasses()
{
qDebug() << "JsonRpc: get device classes";
JsonRpcReply *reply = createReply("Devices", "GetSupportedDevices");
m_replies.insert(reply->commandId(), reply);
Engine::instance()->interface()->sendRequest(reply->requestMap());
}
int JsonRpcClient::addDevice(const QUuid &deviceClassId, const QVariantList &deviceParams)
{
qDebug() << "JsonRpc: add device " << deviceClassId.toString();
QVariantMap params;
params.insert("deviceClassId", deviceClassId.toString());
params.insert("deviceParams", deviceParams);
JsonRpcReply *reply = createReply("Devices", "AddConfiguredDevice", params);
m_replies.insert(reply->commandId(), reply);
Engine::instance()->interface()->sendRequest(reply->requestMap());
return reply->commandId();
}
int JsonRpcClient::addDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId)
{
qDebug() << "JsonRpc: add discovered device " << deviceClassId.toString();
QVariantMap params;
params.insert("deviceClassId", deviceClassId.toString());
params.insert("deviceDescriptorId", deviceDescriptorId.toString());
JsonRpcReply *reply = createReply("Devices", "AddConfiguredDevice", params);
m_replies.insert(reply->commandId(), reply);
Engine::instance()->interface()->sendRequest(reply->requestMap());
return reply->commandId();
}
int JsonRpcClient::pairDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId)
{
qDebug() << "JsonRpc: pair device " << deviceClassId.toString();
QVariantMap params;
params.insert("name", "name");
params.insert("deviceClassId", deviceClassId.toString());
params.insert("deviceDescriptorId", deviceDescriptorId.toString());
JsonRpcReply *reply = createReply("Devices", "PairDevice", params);
m_replies.insert(reply->commandId(), reply);
Engine::instance()->interface()->sendRequest(reply->requestMap());
return reply->commandId();
}
int JsonRpcClient::confirmPairing(const QUuid &pairingTransactionId, const QString &secret)
{
qDebug() << "JsonRpc: confirm pairing" << pairingTransactionId.toString();
QVariantMap params;
params.insert("pairingTransactionId", pairingTransactionId.toString());
params.insert("secret", secret);
JsonRpcReply *reply = createReply("Devices", "ConfirmPairing", params);
m_replies.insert(reply->commandId(), reply);
Engine::instance()->interface()->sendRequest(reply->requestMap());
return reply->commandId();
}
int JsonRpcClient::removeDevice(const QUuid &deviceId)
{
qDebug() << "JsonRpc: delete device" << deviceId.toString();
QVariantMap params;
params.insert("deviceId", deviceId.toString());
JsonRpcReply *reply = createReply("Devices", "RemoveConfiguredDevice", params);
m_replies.insert(reply->commandId(), reply);
Engine::instance()->interface()->sendRequest(reply->requestMap());
return reply->commandId();
}
int JsonRpcClient::discoverDevices(const QUuid &deviceClassId, const QVariantList &discoveryParams)
{
qDebug() << "JsonRpc: discover devices " << deviceClassId.toString();
QVariantMap params;
params.insert("deviceClassId", deviceClassId.toString());
if (!discoveryParams.isEmpty()) {
params.insert("discoveryParams", discoveryParams);
}
JsonRpcReply *reply = createReply("Devices", "GetDiscoveredDevices", params);
m_replies.insert(reply->commandId(), reply);
Engine::instance()->interface()->sendRequest(reply->requestMap());
return reply->commandId();
}
int JsonRpcClient::executeAction(const QUuid &deviceId, const QUuid &actionTypeId, const QVariantList &params)
{
qDebug() << "JsonRpc: execute action " << deviceId.toString() << actionTypeId.toString() << params;
QVariantMap p;
p.insert("deviceId", deviceId.toString());
p.insert("actionTypeId", actionTypeId.toString());
if (!params.isEmpty()) {
p.insert("params", params);
}
JsonRpcReply *reply = createReply("Actions", "ExecuteAction", p);
m_replies.insert(reply->commandId(), reply);
Engine::instance()->interface()->sendRequest(reply->requestMap());
return reply->commandId();
}
JsonRpcReply *JsonRpcClient::createReply(QString nameSpace, QString method, QVariantMap params)
{
m_id++;
return new JsonRpcReply(m_id, nameSpace, method, params, this);
}
void JsonRpcClient::dataReceived(const QVariantMap &data)
{
int commandId = data.value("id").toInt();
JsonRpcReply *reply = m_replies.take(commandId);
// check if this is a reply to a request
if (reply) {
qDebug() << "JsonRpc: got response for" << QString("%1.%2").arg(reply->nameSpace(), reply->method());
JsonHandler *handler = m_handlers.value(reply->nameSpace());
if (!QMetaObject::invokeMethod(handler, QString("process" + reply->method()).toLatin1().data(), Q_ARG(QVariantMap, data)))
qWarning() << "JsonRpc: method not implemented:" << reply->method();
emit responseReceived(reply->commandId(), data.value("params").toMap());
return;
}
// check if this is a notification
if (data.contains("notification")) {
QStringList notification = data.value("notification").toString().split(".");
QString nameSpace = notification.first();
QString method = notification.last();
JsonHandler *handler = m_handlers.value(nameSpace);
if (!handler) {
qWarning() << "JsonRpc: handler not implemented:" << nameSpace;
return;
}
if (!QMetaObject::invokeMethod(handler, QString("process" + method).toLatin1().data(), Q_ARG(QVariantMap, data)))
qWarning() << "method not implemented";
}
}
JsonRpcReply::JsonRpcReply(int commandId, QString nameSpace, QString method, QVariantMap params, QObject *parent):
QObject(parent),
m_commandId(commandId),
m_nameSpace(nameSpace),
m_method(method),
m_params(params)
{
}
int JsonRpcReply::commandId() const
{
return m_commandId;
}
QString JsonRpcReply::nameSpace() const
{
return m_nameSpace;
}
QString JsonRpcReply::method() const
{
return m_method;
}
QVariantMap JsonRpcReply::params() const
{
return m_params;
}
QVariantMap JsonRpcReply::requestMap()
{
QVariantMap request;
request.insert("id", m_commandId);
request.insert("method", m_nameSpace + "." + m_method);
if (!m_params.isEmpty())
request.insert("params", m_params);
return request;
}

View File

@ -0,0 +1,101 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef JSONRPCCLIENT_H
#define JSONRPCCLIENT_H
#include <QObject>
#include <QVariantMap>
#include "devicehandler.h"
#include "actionhandler.h"
#include "eventhandler.h"
#include "logginghandler.h"
#include "networkmanagerhandler.h"
class JsonRpcReply;
class JsonHandler;
class Param;
class Params;
class JsonRpcClient : public QObject
{
Q_OBJECT
public:
explicit JsonRpcClient(QObject *parent = 0);
// internal
void getVendors();
void getPlugins();
void getDevices();
void getDeviceClasses();
// ui methods
Q_INVOKABLE int addDevice(const QUuid &deviceClassId, const QVariantList &deviceParams);
Q_INVOKABLE int addDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId);
Q_INVOKABLE int pairDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId);
Q_INVOKABLE int confirmPairing(const QUuid &pairingTransactionId, const QString &secret = QString());
Q_INVOKABLE int removeDevice(const QUuid &deviceId);
Q_INVOKABLE int discoverDevices(const QUuid &deviceClassId, const QVariantList &discoveryParams = QVariantList());
Q_INVOKABLE int executeAction(const QUuid &deviceId, const QUuid &actionTypeId, const QVariantList &params = QVariantList());
private:
int m_id;
QHash<QString, JsonHandler *> m_handlers;
QHash<int, JsonRpcReply *> m_replies;
DeviceHandler *m_deviceHandler;
ActionHandler *m_actionHandler;
EventHandler *m_eventHandler;
LoggingHandler *m_loggingHandler;
NetworkManagerHandler *m_networkManagerHandler;
JsonRpcReply *createReply(QString nameSpace, QString method, QVariantMap params = QVariantMap());
signals:
void responseReceived(const int &commandId, const QVariantMap &response);
public slots:
void dataReceived(const QVariantMap &data);
};
class JsonRpcReply : public QObject
{
Q_OBJECT
public:
explicit JsonRpcReply(int commandId, QString nameSpace, QString method, QVariantMap params = QVariantMap(), QObject *parent = 0);
int commandId() const;
QString nameSpace() const;
QString method() const;
QVariantMap params() const;
QVariantMap requestMap();
private:
int m_commandId;
QString m_nameSpace;
QString m_method;
QVariantMap m_params;
};
#endif // JSONRPCCLIENT_H

View File

@ -0,0 +1,315 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "jsontypes.h"
#include "engine.h"
#include "types/vendors.h"
#include "types/deviceclasses.h"
#include "types/params.h"
#include "types/paramtypes.h"
#include <QMetaEnum>
JsonTypes::JsonTypes(QObject *parent) :
QObject(parent)
{
}
Vendor *JsonTypes::unpackVendor(const QVariantMap &vendorMap, QObject *parent)
{
return new Vendor(vendorMap.value("id").toUuid(), vendorMap.value("name").toString(), parent);
}
Plugin *JsonTypes::unpackPlugin(const QVariantMap &pluginMap, QObject *parent)
{
Plugin *plugin = new Plugin(parent);
plugin->setName(pluginMap.value("name").toString());
plugin->setPluginId(pluginMap.value("id").toUuid());
ParamTypes *paramTypes = new ParamTypes(plugin);
foreach (QVariant paramType, pluginMap.value("paramTypes").toList()) {
paramTypes->addParamType(JsonTypes::unpackParamType(paramType.toMap(), paramTypes));
}
plugin->setParamTypes(paramTypes);
return plugin;
}
DeviceClass *JsonTypes::unpackDeviceClass(const QVariantMap &deviceClassMap, QObject *parent)
{
DeviceClass *deviceClass = new DeviceClass(parent);
deviceClass->setName(deviceClassMap.value("name").toString());
deviceClass->setId(deviceClassMap.value("id").toUuid());
deviceClass->setVendorId(deviceClassMap.value("vendorId").toUuid());
QVariantList createMethodsList = deviceClassMap.value("createMethods").toList();
QStringList createMethods;
foreach (QVariant method, createMethodsList) {
createMethods.append(method.toString());
}
deviceClass->setCreateMethods(createMethods);
deviceClass->setSetupMethod(stringToSetupMethod(deviceClassMap.value("setupMethod").toString()));
// ParamTypes
ParamTypes *paramTypes = new ParamTypes(deviceClass);
foreach (QVariant paramType, deviceClassMap.value("paramTypes").toList()) {
paramTypes->addParamType(JsonTypes::unpackParamType(paramType.toMap(), paramTypes));
}
deviceClass->setParamTypes(paramTypes);
// discovery ParamTypes
ParamTypes *discoveryParamTypes = new ParamTypes(deviceClass);
foreach (QVariant paramType, deviceClassMap.value("discoveryParamTypes").toList()) {
discoveryParamTypes->addParamType(JsonTypes::unpackParamType(paramType.toMap(), discoveryParamTypes));
}
deviceClass->setDiscoveryParamTypes(discoveryParamTypes);
// StateTypes
StateTypes *stateTypes = new StateTypes(deviceClass);
foreach (QVariant stateType, deviceClassMap.value("stateTypes").toList()) {
stateTypes->addStateType(JsonTypes::unpackStateType(stateType.toMap(), stateTypes));
}
deviceClass->setStateTypes(stateTypes);
// EventTypes
EventTypes *eventTypes = new EventTypes(deviceClass);
foreach (QVariant eventType, deviceClassMap.value("eventTypes").toList()) {
eventTypes->addEventType(JsonTypes::unpackEventType(eventType.toMap(), eventTypes));
}
deviceClass->setEventTypes(eventTypes);
// ActionTypes
ActionTypes *actionTypes = new ActionTypes(deviceClass);
foreach (QVariant actionType, deviceClassMap.value("actionTypes").toList()) {
actionTypes->addActionType(JsonTypes::unpackActionType(actionType.toMap(), actionTypes));
}
deviceClass->setActionTypes(actionTypes);
return deviceClass;
}
Param *JsonTypes::unpackParam(const QVariantMap &paramMap, QObject *parent)
{
return new Param(paramMap.value("name").toString(), paramMap.value("value"), parent);
}
ParamType *JsonTypes::unpackParamType(const QVariantMap &paramTypeMap, QObject *parent)
{
ParamType *paramType = new ParamType(parent);
paramType->setName(paramTypeMap.value("name").toString());
paramType->setType(paramTypeMap.value("type").toString());
paramType->setIndex(paramTypeMap.value("index").toInt());
paramType->setDefaultValue(paramTypeMap.value("defaultValue"));
paramType->setMinValue(paramTypeMap.value("minValue"));
paramType->setMaxValue(paramTypeMap.value("maxValue"));
paramType->setAllowedValues(paramTypeMap.value("allowedValues").toList());
paramType->setInputType(stringToInputType(paramTypeMap.value("inputType").toString()));
paramType->setReadOnly(paramTypeMap.value("readOnly").toBool());
QPair<Types::Unit, QString> unit = stringToUnit(paramTypeMap.value("unit").toString());
paramType->setUnit(unit.first);
paramType->setUnitString(unit.second);
return paramType;
}
StateType *JsonTypes::unpackStateType(const QVariantMap &stateTypeMap, QObject *parent)
{
StateType *stateType = new StateType(parent);
stateType->setId(stateTypeMap.value("id").toUuid());
stateType->setName(stateTypeMap.value("name").toString());
stateType->setIndex(stateTypeMap.value("index").toInt());
stateType->setDefaultValue(stateTypeMap.value("defaultValue"));
stateType->setType(stateTypeMap.value("type").toString());
QPair<Types::Unit, QString> unit = stringToUnit(stateTypeMap.value("unit").toString());
stateType->setUnit(unit.first);
stateType->setUnitString(unit.second);
return stateType;
}
EventType *JsonTypes::unpackEventType(const QVariantMap &eventTypeMap, QObject *parent)
{
EventType *eventType = new EventType(parent);
eventType->setId(eventTypeMap.value("id").toUuid());
eventType->setName(eventTypeMap.value("name").toString());
eventType->setIndex(eventTypeMap.value("index").toInt());
ParamTypes *paramTypes = new ParamTypes(eventType);
foreach (QVariant paramType, eventTypeMap.value("paramTypes").toList()) {
paramTypes->addParamType(JsonTypes::unpackParamType(paramType.toMap(), paramTypes));
}
eventType->setParamTypes(paramTypes);
return eventType;
}
ActionType *JsonTypes::unpackActionType(const QVariantMap &actionTypeMap, QObject *parent)
{
ActionType *actionType = new ActionType(parent);
actionType->setId(actionTypeMap.value("id").toUuid());
actionType->setName(actionTypeMap.value("name").toString());
actionType->setIndex(actionTypeMap.value("index").toInt());
ParamTypes *paramTypes = new ParamTypes(actionType);
foreach (QVariant paramType, actionTypeMap.value("paramTypes").toList()) {
paramTypes->addParamType(JsonTypes::unpackParamType(paramType.toMap(), paramTypes));
}
actionType->setParamTypes(paramTypes);
return actionType;
}
Device *JsonTypes::unpackDevice(const QVariantMap &deviceMap, QObject *parent)
{
Device *device = new Device(parent);
device->setDeviceName(deviceMap.value("name").toString());
device->setId(deviceMap.value("id").toUuid());
device->setDeviceClassId(deviceMap.value("deviceClassId").toUuid());
device->setSetupComplete(deviceMap.value("setupComplete").toBool());
Params *params = new Params(device);
foreach (QVariant param, deviceMap.value("params").toList()) {
params->addParam(JsonTypes::unpackParam(param.toMap(), params));
}
device->setParams(params);
DeviceClass *deviceClass = Engine::instance()->deviceManager()->deviceClasses()->getDeviceClass(device->deviceClassId());
States *states = new States(device);
foreach (StateType *stateType, deviceClass->stateTypes()->stateTypes()) {
State *state = new State(device->id(), stateType->id(), stateType->defaultValue(), states);
states->addState(state);
}
device->setStates(states);
return device;
}
DeviceClass::SetupMethod JsonTypes::stringToSetupMethod(const QString &setupMethodString)
{
if (setupMethodString == "SetupMethodJustAdd") {
return DeviceClass::SetupMethodJustAdd;
} else if (setupMethodString == "SetupMethodDisplayPin") {
return DeviceClass::SetupMethodDisplayPin;
} else if (setupMethodString == "SetupMethodEnterPin") {
return DeviceClass::SetupMethodEnterPin;
} else if (setupMethodString == "SetupMethodPushButton") {
return DeviceClass::SetupMethodPushButton;
}
return DeviceClass::SetupMethodJustAdd;
}
QPair<Types::Unit, QString> JsonTypes::stringToUnit(const QString &unitString)
{
if (unitString == "UnitNone") {
return QPair<Types::Unit, QString>(Types::UnitNone, "-");
} else if (unitString == "UnitSeconds") {
return QPair<Types::Unit, QString>(Types::UnitSeconds, "s");
} else if (unitString == "UnitMinutes") {
return QPair<Types::Unit, QString>(Types::UnitMinutes, "m");
} else if (unitString == "UnitHours") {
return QPair<Types::Unit, QString>(Types::UnitHours, "h");
} else if (unitString == "UnitUnixTime") {
return QPair<Types::Unit, QString>(Types::UnitUnixTime, "");
} else if (unitString == "UnitMeterPerSecond") {
return QPair<Types::Unit, QString>(Types::UnitMeterPerSecond, "m/s");
} else if (unitString == "UnitKiloMeterPerHour") {
return QPair<Types::Unit, QString>(Types::UnitKiloMeterPerHour, "km/h");
} else if (unitString == "UnitDegree") {
return QPair<Types::Unit, QString>(Types::UnitDegree, "°");
} else if (unitString == "UnitRadiant") {
return QPair<Types::Unit, QString>(Types::UnitRadiant, "rad");
} else if (unitString == "UnitDegreeCelsius") {
return QPair<Types::Unit, QString>(Types::UnitDegreeCelsius, "°C");
} else if (unitString == "UnitDegreeKelvin") {
return QPair<Types::Unit, QString>(Types::UnitDegreeKelvin, "°K");
} else if (unitString == "UnitMired") {
return QPair<Types::Unit, QString>(Types::UnitMired, "mir");
} else if (unitString == "UnitMilliBar") {
return QPair<Types::Unit, QString>(Types::UnitMilliBar, "mbar");
} else if (unitString == "UnitBar") {
return QPair<Types::Unit, QString>(Types::UnitBar, "bar");
} else if (unitString == "UnitPascal") {
return QPair<Types::Unit, QString>(Types::UnitPascal, "Pa");
} else if (unitString == "UnitHectoPascal") {
return QPair<Types::Unit, QString>(Types::UnitHectoPascal, "hPa");
} else if (unitString == "UnitAtmosphere") {
return QPair<Types::Unit, QString>(Types::UnitAtmosphere, "atm");
} else if (unitString == "UnitLumen") {
return QPair<Types::Unit, QString>(Types::UnitLumen, "lm");
} else if (unitString == "UnitLux") {
return QPair<Types::Unit, QString>(Types::UnitLux, "lx");
} else if (unitString == "UnitCandela") {
return QPair<Types::Unit, QString>(Types::UnitCandela, "cd");
} else if (unitString == "UnitMilliMeter") {
return QPair<Types::Unit, QString>(Types::UnitMilliMeter, "mm");
} else if (unitString == "UnitCentiMeter") {
return QPair<Types::Unit, QString>(Types::UnitCentiMeter, "cm");
} else if (unitString == "UnitMeter") {
return QPair<Types::Unit, QString>(Types::UnitMeter, "m");
} else if (unitString == "UnitKiloMeter") {
return QPair<Types::Unit, QString>(Types::UnitKiloMeter, "km");
} else if (unitString == "UnitGram") {
return QPair<Types::Unit, QString>(Types::UnitGram, "g");
} else if (unitString == "UnitKiloGram") {
return QPair<Types::Unit, QString>(Types::UnitKiloGram, "kg");
} else if (unitString == "UnitDezibel") {
return QPair<Types::Unit, QString>(Types::UnitDezibel, "db");
} else if (unitString == "UnitKiloByte") {
return QPair<Types::Unit, QString>(Types::UnitKiloByte, "kB");
} else if (unitString == "UnitMegaByte") {
return QPair<Types::Unit, QString>(Types::UnitMegaByte, "MB");
} else if (unitString == "UnitGigaByte") {
return QPair<Types::Unit, QString>(Types::UnitGigaByte, "GB");
} else if (unitString == "UnitTeraByte") {
return QPair<Types::Unit, QString>(Types::UnitTeraByte, "TB");
} else if (unitString == "UnitMilliWatt") {
return QPair<Types::Unit, QString>(Types::UnitMilliWatt, "mW");
} else if (unitString == "UnitWatt") {
return QPair<Types::Unit, QString>(Types::UnitWatt, "W");
} else if (unitString == "UnitKiloWatt") {
return QPair<Types::Unit, QString>(Types::UnitKiloWatt, "kW");
} else if (unitString == "UnitKiloWattHour") {
return QPair<Types::Unit, QString>(Types::UnitKiloWattHour, "kWh");
} else if (unitString == "UnitPercentage") {
return QPair<Types::Unit, QString>(Types::UnitPercentage, "%");
} else if (unitString == "UnitEuro") {
return QPair<Types::Unit, QString>(Types::UnitEuro, "");
} else if (unitString == "UnitDollar") {
return QPair<Types::Unit, QString>(Types::UnitDollar, "$");
}
return QPair<Types::Unit, QString>(Types::UnitNone, "");
}
Types::InputType JsonTypes::stringToInputType(const QString &inputTypeString)
{
if (inputTypeString == "InputTypeNone") {
return Types::InputTypeNone;
} else if (inputTypeString == "InputTypeTextLine") {
return Types::InputTypeTextLine;
} else if (inputTypeString == "InputTypeTextArea") {
return Types::InputTypeTextArea;
} else if (inputTypeString == "InputTypePassword") {
return Types::InputTypePassword;
} else if (inputTypeString == "InputTypeSearch") {
return Types::InputTypeSearch;
} else if (inputTypeString == "InputTypeMail") {
return Types::InputTypeMail;
} else if (inputTypeString == "InputTypeIPv4Address") {
return Types::InputTypeIPv4Address;
} else if (inputTypeString == "InputTypeIPv6Address") {
return Types::InputTypeIPv6Address;
} else if (inputTypeString == "InputTypeUrl") {
return Types::InputTypeUrl;
} else if (inputTypeString == "InputTypeMacAddress") {
return Types::InputTypeMacAddress;
}
return Types::InputTypeNone;
}

View File

@ -0,0 +1,64 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef JSONTYPES_H
#define JSONTYPES_H
#include <QObject>
#include <QJsonDocument>
#include <QVariant>
#include <QUuid>
#include "types/types.h"
#include "types/device.h"
#include "types/plugin.h"
#include "types/deviceclass.h"
#include "types/paramtype.h"
#include "types/statetype.h"
#include "types/state.h"
#include "types/eventtype.h"
#include "types/actiontype.h"
class Vendor;
class JsonTypes : public QObject
{
Q_OBJECT
public:
explicit JsonTypes(QObject *parent = 0);
static Vendor *unpackVendor(const QVariantMap &vendorMap, QObject *parent);
static Plugin *unpackPlugin(const QVariantMap &pluginMap, QObject *parent);
static DeviceClass *unpackDeviceClass(const QVariantMap &deviceClassMap, QObject *parent);
static Param *unpackParam(const QVariantMap &paramMap, QObject *parent);
static ParamType *unpackParamType(const QVariantMap &paramTypeMap, QObject *parent);
static StateType *unpackStateType(const QVariantMap &stateTypeMap, QObject *parent);
static EventType *unpackEventType(const QVariantMap &eventTypeMap, QObject *parent);
static ActionType *unpackActionType(const QVariantMap &actionTypeMap, QObject *parent);
static Device *unpackDevice(const QVariantMap &deviceMap, QObject *parent);
private:
static DeviceClass::SetupMethod stringToSetupMethod(const QString &setupMethodString);
static QPair<Types::Unit, QString> stringToUnit(const QString &unitString);
static Types::InputType stringToInputType(const QString &inputTypeString);
};
#endif // JSONTYPES_H

View File

@ -0,0 +1,43 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "logginghandler.h"
LoggingHandler::LoggingHandler(QObject *parent) :
JsonHandler(parent)
{
}
QString LoggingHandler::nameSpace() const
{
return "Logging";
}
void LoggingHandler::processLogEntryAdded(const QVariantMap &params)
{
Q_UNUSED(params);
}
void LoggingHandler::processLogDatabaseUpdated(const QVariantMap &params)
{
Q_UNUSED(params);
}

View File

@ -0,0 +1,41 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef LOGGINGHANDLER_H
#define LOGGINGHANDLER_H
#include <QObject>
#include "jsonhandler.h"
class LoggingHandler : public JsonHandler
{
Q_OBJECT
public:
explicit LoggingHandler(QObject *parent = 0);
QString nameSpace() const;
Q_INVOKABLE void processLogEntryAdded(const QVariantMap &params);
Q_INVOKABLE void processLogDatabaseUpdated(const QVariantMap &params);
};
#endif // LOGGINGHANDLER_H

View File

@ -0,0 +1,19 @@
#include "networkmanagerhandler.h"
#include <QDebug>
NetworkManagerHandler::NetworkManagerHandler(QObject *parent) :
JsonHandler(parent)
{
}
QString NetworkManagerHandler::nameSpace() const
{
return "NetworkManager";
}
void NetworkManagerHandler::processWirelessNetworkDeviceChanged(const QVariantMap &params)
{
Q_UNUSED(params);
}

View File

@ -0,0 +1,23 @@
#ifndef NETWORKMANAGERHANDLER_H
#define NETWORKMANAGERHANDLER_H
#include <QObject>
#include "jsonhandler.h"
class NetworkManagerHandler : public JsonHandler
{
Q_OBJECT
public:
explicit NetworkManagerHandler(QObject *parent = 0);
QString nameSpace() const;
Q_INVOKABLE void processWirelessNetworkDeviceChanged(const QVariantMap &params);
signals:
public slots:
};
#endif // NETWORKMANAGERHANDLER_H

View File

@ -1,13 +1,81 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <QGuiApplication>
#include <QCommandLineParser>
#include <QtQml/QQmlContext>
#include <QQmlApplicationEngine>
#include <QtQuickControls2>
#include "engine.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QGuiApplication application(argc, argv);
// backend
qmlRegisterSingletonType<Engine>("Guh", 1, 0, "Engine", Engine::qmlInstance);
qmlRegisterUncreatableType<DeviceManager>("Guh", 1, 0, "DeviceManager", "Can't create this in QML. Get it from the Core.");
qmlRegisterUncreatableType<JsonRpcClient>("Guh", 1, 0, "JsonRpcClient", "Can't create this in QML. Get it from the Core.");
qmlRegisterUncreatableType<GuhInterface>("Guh", 1, 0, "GuhInterface", "Can't create this in QML. Get it from the Core.");
qmlRegisterUncreatableType<WebsocketInterface>("Guh", 1, 0, "WebsocketInterface", "Can't create this in QML. Get it from the Core.");
// libguh-common
qmlRegisterUncreatableType<Types>("Guh", 1, 0, "Types", "Can't create this in QML. Get it from the Core.");
qmlRegisterUncreatableType<ParamType>("Guh", 1, 0, "ParamType", "Can't create this in QML. Get it from the ParamTypes.");
qmlRegisterUncreatableType<ParamTypes>("Guh", 1, 0, "ParamTypes", "Can't create this in QML. Get it from the DeviceClass.");
qmlRegisterUncreatableType<EventType>("Guh", 1, 0, "EventType", "Can't create this in QML. Get it from the EventTypes.");
qmlRegisterUncreatableType<EventTypes>("Guh", 1, 0, "EventTypes", "Can't create this in QML. Get it from the DeviceClass.");
qmlRegisterUncreatableType<StateType>("Guh", 1, 0, "StateType", "Can't create this in QML. Get it from the StateTypes.");
qmlRegisterUncreatableType<StateTypes>("Guh", 1, 0, "StateTypes", "Can't create this in QML. Get it from the DeviceClass.");
qmlRegisterUncreatableType<ActionType>("Guh", 1, 0, "ActionType", "Can't create this in QML. Get it from the ActionTypes.");
qmlRegisterUncreatableType<ActionTypes>("Guh", 1, 0, "ActionTypes", "Can't create this in QML. Get it from the DeviceClass.");
qmlRegisterUncreatableType<State>("Guh", 1, 0, "State", "Can't create this in QML. Get it from the States.");
qmlRegisterUncreatableType<States>("Guh", 1, 0, "States", "Can't create this in QML. Get it from the Device.");
qmlRegisterUncreatableType<StatesProxy>("Guh", 1, 0, "StatesProxy", "Can't create this in QML. Get it from the Device.");
qmlRegisterUncreatableType<Vendor>("Guh", 1, 0, "Vendor", "Can't create this in QML. Get it from the Vendors.");
qmlRegisterUncreatableType<Vendors>("Guh", 1, 0, "Vendors", "Can't create this in QML. Get it from the DeviceManager.");
qmlRegisterUncreatableType<VendorsProxy>("Guh", 1, 0, "VendorsProxy", "Can't create this in QML. Get it from the DeviceManager.");
qmlRegisterUncreatableType<Device>("Guh", 1, 0, "Device", "Can't create this in QML. Get it from the Devices.");
qmlRegisterUncreatableType<Devices>("Guh", 1, 0, "Devices", "Can't create this in QML. Get it from the DeviceManager.");
qmlRegisterUncreatableType<DevicesProxy>("Guh", 1, 0, "DevicesProxy", "Can't create this in QML. Get it from the DeviceManager.");
qmlRegisterUncreatableType<DeviceClass>("Guh", 1, 0, "DeviceClass", "Can't create this in QML. Get it from the DeviceClasses.");
qmlRegisterUncreatableType<DeviceClasses>("Guh", 1, 0, "DeviceClasses", "Can't create this in QML. Get it from the DeviceManager.");
qmlRegisterUncreatableType<DeviceClassesProxy>("Guh", 1, 0, "DeviceClassesProxy", "Can't create this in QML. Get it from the DeviceManager.");
qmlRegisterUncreatableType<Plugin>("Guh", 1, 0, "Plugin", "Can't create this in QML. Get it from the Plugins.");
qmlRegisterUncreatableType<Plugins>("Guh", 1, 0, "Plugins", "Can't create this in QML. Get it from the DeviceManager.");
qmlRegisterUncreatableType<PluginsProxy>("Guh", 1, 0, "PluginsProxy", "Can't create this in QML. Get it from the DeviceManager.");
QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
return app.exec();
Engine::instance();
return application.exec();
}

View File

@ -1,52 +0,0 @@
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("guh control")
SwipeView {
id: swipeView
anchors.fill: parent
currentIndex: tabBar.currentIndex
Page {
id: devicePage
Label {
text: qsTr("Devices list")
anchors.centerIn: parent
}
}
Page {
Label {
text: qsTr("Rules")
anchors.centerIn: parent
}
}
Page {
Label {
text: qsTr("Settings")
anchors.centerIn: parent
}
}
}
footer: TabBar {
id: tabBar
currentIndex: swipeView.currentIndex
TabButton {
text: qsTr("Devices")
}
TabButton {
text: qsTr("Rules")
}
TabButton {
text: qsTr("Settings")
}
}
}

View File

@ -0,0 +1,114 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "websocketinterface.h"
#include "engine.h"
#include <QGuiApplication>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QSettings>
WebsocketInterface::WebsocketInterface(QObject *parent) :
GuhInterface(parent)
{
m_socket = new QWebSocket(QGuiApplication::applicationName(), QWebSocketProtocol::Version13, this);
connect(m_socket, SIGNAL(connected()), this, SLOT(onConnected()));
connect(m_socket, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onError(QAbstractSocket::SocketError)));
connect(m_socket, SIGNAL(textMessageReceived(QString)), this, SLOT(onTextMessageReceived(QString)));
}
void WebsocketInterface::sendData(const QByteArray &data)
{
m_socket->sendTextMessage(QString::fromUtf8(data));
}
void WebsocketInterface::sendRequest(const QVariantMap &request)
{
sendData(QJsonDocument::fromVariant(request).toJson(QJsonDocument::Compact));
}
void WebsocketInterface::setUrl(const QString &url)
{
m_urlString = url;
emit urlChanged();
}
QString WebsocketInterface::url() const
{
return m_urlString;
}
void WebsocketInterface::enable()
{
if (connected())
disable();
qDebug() << "Connecting to" << QUrl(m_urlString).toString();
m_socket->open(QUrl(m_urlString));
emit connecting();
}
void WebsocketInterface::disable()
{
m_socket->close();
}
void WebsocketInterface::onConnected()
{
qDebug() << "Connected to" << m_urlString;
QSettings settings;
qDebug() << "Save last connection" << settings.fileName();
settings.beginGroup("Connections");
settings.setValue("webSocketUrl", m_urlString);
settings.endGroup();
setConnected(true);
//Engine::instance()->connections()->addConnection("guhIO", m_socket->peerAddress().toString(), m_urlString);
}
void WebsocketInterface::onDisconnected()
{
qDebug() << "Disconnected from" << m_urlString << ": reason:" << m_socket->closeReason();
setConnected(false);
}
void WebsocketInterface::onTextMessageReceived(const QString &data)
{
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(data.toUtf8(), &error);
if (error.error != QJsonParseError::NoError) {
qWarning() << "Could not parse json data from guh" << data << error.errorString();
return;
}
emit dataReady(jsonDoc.toVariant().toMap());
}
void WebsocketInterface::onError(QAbstractSocket::SocketError error)
{
qWarning() << "Websocket error:" << error << m_socket->errorString();
emit websocketError(m_socket->errorString());
emit connectionFailed();
}

View File

@ -0,0 +1,65 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control. *
* *
* guh-control is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* guh-control is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh-control. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef WEBSOCKETINTERFACE_H
#define WEBSOCKETINTERFACE_H
#include <QObject>
#include <QWebSocket>
#include "guhinterface.h"
class WebsocketInterface : public GuhInterface
{
Q_OBJECT
Q_PROPERTY(QString url READ url WRITE setUrl NOTIFY urlChanged)
public:
explicit WebsocketInterface(QObject *parent = 0);
void sendData(const QByteArray &data) override;
void sendRequest(const QVariantMap &request) override;
void setUrl(const QString &url);
QString url() const;
private:
QWebSocket *m_socket;
QString m_urlString;
signals:
void urlChanged();
void disconnected();
void connecting();
void connectionFailed();
void websocketError(const QString &errorString);
public slots:
Q_INVOKABLE void enable() override;
Q_INVOKABLE void disable() override;
private slots:
void onConnected();
void onDisconnected();
void onTextMessageReceived(const QString &data);
void onError(QAbstractSocket::SocketError error);
};
#endif // WEBSOCKETINTERFACE_H

View File

@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>data/icons/busy-indicator.svg</file>
</qresource>
</RCC>

View File

@ -0,0 +1,195 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="100"
height="100"
viewBox="0 0 100 100"
id="svg2"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="busy-indicator.svg">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="7.9195959"
inkscape:cx="47.618004"
inkscape:cy="28.551323"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
units="px"
inkscape:window-width="2880"
inkscape:window-height="1752"
inkscape:window-x="0"
inkscape:window-y="48"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-952.36216)">
<g
id="g7211"
transform="matrix(0.03708988,0,0,0.03708988,50.490111,1016.2974)">
<rect
inkscape:tile-y0="-771.42855"
inkscape:tile-x0="-103.92857"
inkscape:tile-h="791.42859"
inkscape:tile-w="181.42857"
inkscape:tile-cy="-375.71426"
inkscape:tile-cx="-13.214287"
ry="108.89703"
y="292.05038"
x="-103.92857"
height="680.31183"
width="217.79407"
id="rect4154"
style="opacity:1;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
<use
id="use7187"
xlink:href="#rect4154"
inkscape:tiled-clone-of="#rect4154"
y="0"
x="0"
width="100%"
height="100%" />
<use
id="use7189"
transform="matrix(0.8660254,0.5,-0.5,0.8660254,-189.62751,-43.729022)"
xlink:href="#rect4154"
inkscape:tiled-clone-of="#rect4154"
y="0"
x="0"
style="opacity:0.92000002"
width="100%"
height="100%" />
<use
id="use7191"
transform="matrix(0.5,0.8660254,-0.8660254,0.5,-331.98523,-176.41322)"
xlink:href="#rect4154"
inkscape:tiled-clone-of="#rect4154"
y="0"
x="0"
style="opacity:0.83999999"
width="100%"
height="100%" />
<use
id="use7193"
transform="matrix(0,1,-1,0,-388.92854,-362.49997)"
xlink:href="#rect4154"
inkscape:tiled-clone-of="#rect4154"
y="0"
x="0"
style="opacity:0.76000001"
width="100%"
height="100%" />
<use
id="use7195"
transform="matrix(-0.5,0.8660254,-0.8660254,-0.5,-345.19952,-552.12748)"
xlink:href="#rect4154"
inkscape:tiled-clone-of="#rect4154"
y="0"
x="0"
style="opacity:0.68000022"
width="100%"
height="100%" />
<use
id="use7197"
transform="matrix(-0.8660254,0.5,-0.5,-0.8660254,-212.51532,-694.4852)"
xlink:href="#rect4154"
inkscape:tiled-clone-of="#rect4154"
y="0"
x="0"
style="opacity:0.6"
width="100%"
height="100%" />
<use
id="use7199"
transform="matrix(-1,0,0,-1,-26.428574,-751.42851)"
xlink:href="#rect4154"
inkscape:tiled-clone-of="#rect4154"
y="0"
x="0"
style="opacity:0.51999996"
width="100%"
height="100%" />
<use
id="use7201"
transform="matrix(-0.8660254,-0.5,0.5,-0.8660254,163.19893,-707.69949)"
xlink:href="#rect4154"
inkscape:tiled-clone-of="#rect4154"
y="0"
x="0"
style="opacity:0.43999999"
width="100%"
height="100%" />
<use
id="use7203"
transform="matrix(-0.5,-0.8660254,0.8660254,-0.5,305.55666,-575.01529)"
xlink:href="#rect4154"
inkscape:tiled-clone-of="#rect4154"
y="0"
x="0"
style="opacity:0.36000001"
width="100%"
height="100%" />
<use
id="use7205"
transform="matrix(0,-1,1,0,362.49997,-388.92854)"
xlink:href="#rect4154"
inkscape:tiled-clone-of="#rect4154"
y="0"
x="0"
style="opacity:0.28000004"
width="100%"
height="100%" />
<use
id="use7207"
transform="matrix(0.5,-0.8660254,0.8660254,0.5,318.77095,-199.30104)"
xlink:href="#rect4154"
inkscape:tiled-clone-of="#rect4154"
y="0"
x="0"
style="opacity:0.2"
width="100%"
height="100%" />
<use
id="use7209"
transform="matrix(0.8660254,-0.5,0.5,0.8660254,186.08675,-56.943309)"
xlink:href="#rect4154"
inkscape:tiled-clone-of="#rect4154"
y="0"
x="0"
style="opacity:0.12000002"
width="100%"
height="100%" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 5.7 KiB

4
guh-control.pri Normal file
View File

@ -0,0 +1,4 @@
CONFIG += c++11
top_srcdir=$$PWD
top_builddir=$$shadowed($$PWD)

View File

@ -1,3 +1,5 @@
include(guh-control.pri)
TEMPLATE=subdirs
SUBDIRS += backend libguh-common

View File

@ -1,3 +1,5 @@
include(../guh-control.pri)
TARGET = guh-common
TEMPLATE = lib
@ -59,7 +61,6 @@ SOURCES += types/vendor.cpp \
types/plugins.cpp \
types/pluginsproxy.cpp \
# install header file with relative subdirectory
for(header, HEADERS) {
path = /usr/include/guh-common/$${dirname(header)}

View File

@ -47,6 +47,16 @@ void ActionType::setName(const QString &name)
m_name = name;
}
int ActionType::index() const
{
return m_index;
}
void ActionType::setIndex(const int &index)
{
m_index = index;
}
ParamTypes *ActionType::paramTypes() const
{
return m_paramTypes;

View File

@ -33,6 +33,7 @@ class ActionType : public QObject
Q_OBJECT
Q_PROPERTY(QUuid id READ id CONSTANT)
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(int index READ index CONSTANT)
Q_PROPERTY(ParamTypes *paramTypes READ paramTypes NOTIFY paramTypesChanged)
public:
@ -44,12 +45,16 @@ public:
QString name() const;
void setName(const QString &name);
int index() const;
void setIndex(const int &index);
ParamTypes *paramTypes() const;
void setParamTypes(ParamTypes *paramTypes);
private:
QUuid m_id;
QString m_name;
int m_index;
ParamTypes *m_paramTypes;
signals:

View File

@ -47,6 +47,16 @@ void EventType::setName(const QString &name)
m_name = name;
}
int EventType::index() const
{
return m_index;
}
void EventType::setIndex(const int &index)
{
m_index = index;
}
ParamTypes *EventType::paramTypes() const
{
return m_paramTypes;

View File

@ -33,6 +33,7 @@ class EventType : public QObject
Q_OBJECT
Q_PROPERTY(QUuid id READ id CONSTANT)
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(int index READ index CONSTANT)
Q_PROPERTY(ParamTypes paramTypes READ paramTypes CONSTANT)
public:
@ -44,12 +45,16 @@ public:
QString name() const;
void setName(const QString &name);
int index() const;
void setIndex(const int &index);
ParamTypes *paramTypes() const;
void setParamTypes(ParamTypes *paramTypes);
private:
QUuid m_id;
QString m_name;
int m_index;
ParamTypes *m_paramTypes;
};

View File

@ -57,6 +57,16 @@ void ParamType::setType(const QString &type)
m_type = type;
}
int ParamType::index() const
{
return m_index;
}
void ParamType::setIndex(const int &index)
{
m_index = index;
}
QVariant ParamType::defaultValue() const
{
return m_defaultValue;

View File

@ -34,6 +34,7 @@ class ParamType : public QObject
Q_OBJECT
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QString type READ type CONSTANT)
Q_PROPERTY(int index READ index CONSTANT)
Q_PROPERTY(QVariant defaultValue READ defaultValue CONSTANT)
Q_PROPERTY(QVariant minValue READ minValue CONSTANT)
Q_PROPERTY(QVariant maxValue READ maxValue CONSTANT)
@ -52,6 +53,9 @@ public:
QString type() const;
void setType(const QString &type);
int index() const;
void setIndex(const int &index);
QVariant defaultValue() const;
void setDefaultValue(const QVariant &defaultValue);
@ -79,6 +83,7 @@ public:
private:
QString m_name;
QString m_type;
int m_index;
QVariant m_defaultValue;
QVariant m_minValue;
QVariant m_maxValue;

View File

@ -57,6 +57,16 @@ void StateType::setType(const QString &type)
m_type = type;
}
int StateType::index() const
{
return m_index;
}
void StateType::setIndex(const int &index)
{
m_index = index;
}
QVariant StateType::defaultValue() const
{
return m_defaultValue;

View File

@ -35,6 +35,7 @@ class StateType : public QObject
Q_PROPERTY(QUuid id READ id CONSTANT)
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QString type READ type CONSTANT)
Q_PROPERTY(int index READ index CONSTANT)
Q_PROPERTY(QVariant defaultValue READ defaultValue CONSTANT)
Q_PROPERTY(Types::Unit unit READ unit CONSTANT)
Q_PROPERTY(QString unitString READ unitString CONSTANT)
@ -51,6 +52,9 @@ public:
QString type() const;
void setType(const QString &type);
int index() const;
void setIndex(const int &index);
QVariant defaultValue() const;
void setDefaultValue(const QVariant &defaultValue);
@ -64,6 +68,7 @@ private:
QUuid m_id;
QString m_name;
QString m_type;
int m_index;
QVariant m_defaultValue;
Types::Unit m_unit;
QString m_unitString;

47
ui/ConnectionPage.qml Normal file
View File

@ -0,0 +1,47 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
import Guh 1.0
Page {
id: root
Connections {
target: Engine
onConnectedChanged: {
if (connected) {
mainStack.push(Qt.resolvedUrl("MainPage.qml"))
}
}
}
Button {
text: qsTr("Connect")
anchors.centerIn: parent
onClicked: {
Engine.connectGuh()
}
}
}

104
ui/DevicePage.qml Normal file
View File

@ -0,0 +1,104 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
import Guh 1.0
Page {
id: root
property var device: null
property var deviceClass: Engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId)
Rectangle {
id: header
color: "lightgray"
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
height: 40
Button {
id: backButton
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
width: parent.height
height: parent.height
text: "🡰"
onClicked: mainStack.pop()
}
Label {
anchors.centerIn: parent
text: device.name
}
}
Flickable {
id: flickable
anchors.fill: parent
anchors.topMargin: header.height
anchors.leftMargin: 5
anchors.rightMargin: 5
contentHeight: stateColumn.height
contentWidth: parent.width
clip: true
Column {
id: stateColumn
anchors.fill: parent
spacing: 5
Repeater {
anchors.fill: parent
model: deviceClass.stateTypes
delegate: Item {
width: parent.width / 2
height: 20
Rectangle { anchors.fill: parent; color: "green"; opacity: 0.5 }
Label {
id: stateLable
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 5
text: name
}
Label {
id: valueLable
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: 5
text: device.states.getState(id).value + " " + deviceClass.stateTypes.getStateType(id).unitString
}
}
}
}
}
}

73
ui/DevicesPage.qml Normal file
View File

@ -0,0 +1,73 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
import Guh 1.0
Page {
id: root
GridView {
id: gridView
anchors.fill: parent
anchors.margins: 10
property real cellSize: width / 5
cellWidth: cellSize
cellHeight: cellSize
model: Engine.deviceManager.devicesProxy
clip: true
delegate: Item {
height: gridView.cellSize
width: gridView.cellSize
Button {
anchors.fill: parent
anchors.margins: 5
text: model.name
onClicked: mainStack.push(Qt.resolvedUrl("DevicePage.qml"), { device: Engine.deviceManager.devices.getDevice(model.id)})
}
// Rectangle {
// anchors.fill: parent
// anchors.margins: 4
// color: "lightgray"
// radius: width / 8
// border.width: 1
// border.color: "darkgray"
// }
}
}
}

72
ui/MainPage.qml Normal file
View File

@ -0,0 +1,72 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
Page {
id: root
TabBar {
id: tabBar
currentIndex: swipeView.currentIndex
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
TabButton {
text: qsTr("Devices")
}
TabButton {
text: qsTr("Rules")
}
TabButton {
text: qsTr("Settings")
}
}
SwipeView {
id: swipeView
anchors.fill: parent
anchors.topMargin: tabBar.height
currentIndex: tabBar.currentIndex
DevicesPage { id: devicePage }
Page {
Label {
text: qsTr("Rules")
anchors.centerIn: parent
}
}
Page {
Label {
text: qsTr("Settings")
anchors.centerIn: parent
}
}
}
}

126
ui/main.qml Normal file
View File

@ -0,0 +1,126 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stuerz <simon.stuerz@guh.io> *
* *
* This file is part of guh-control *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.1
import Guh 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("guh control")
Connections {
target: Engine
onConnectedChanged: {
if (!connected) {
mainStack.clear()
mainStack.push(Qt.resolvedUrl("ConnectionPage.qml"))
}
}
}
StackView {
id: mainStack
initialItem: ConnectionPage { }
anchors.fill: parent
}
footer: Item {
id: footerItem
height: 20
Rectangle { anchors.fill: parent; color: "darkgray"}
RowLayout {
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.leftMargin: 5
anchors.rightMargin: 5
spacing: 5
Item {
id: busyIndicator
Layout.preferredHeight: parent.height
Layout.preferredWidth: parent.height
Layout.alignment: Qt.AlignVCenter
RotationAnimation {
target: busyIndicatorImage
duration: 2000
from: 360
to: 0
running: true
loops: RotationAnimation.Infinite
}
Image {
id: busyIndicatorImage
anchors.fill: parent
anchors.margins: 2
source: "qrc:/data/icons/busy-indicator.svg"
}
}
Label {
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
anchors.verticalCenter: parent.verticalCenter
text: "guh-control"
color: "white"
}
Item {
id: connectionStatusItem
Layout.preferredHeight: parent.height
Layout.preferredWidth: parent.height
Layout.alignment: Qt.AlignVCenter
Rectangle {
anchors.fill: parent
anchors.margins: parent.height / 10
radius: height / 2
color: Engine.connected ? "green" : "red"
Behavior on color {
ColorAnimation {
duration: 300
easing.type: Easing.InCubic
}
}
}
MouseArea {
anchors.fill: parent
onClicked: Engine.interface.disable()
}
}
}
}
}

9
ui/qml.qrc Normal file
View File

@ -0,0 +1,9 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>MainPage.qml</file>
<file>ConnectionPage.qml</file>
<file>DevicesPage.qml</file>
<file>DevicePage.qml</file>
</qresource>
</RCC>