add cloud interface and design API
This commit is contained in:
parent
9edc4395d6
commit
4080ac3b9c
8
server/cloud/cloudclient.cpp
Normal file
8
server/cloud/cloudclient.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "cloudclient.h"
|
||||||
|
|
||||||
|
CloudClient::CloudClient(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
17
server/cloud/cloudclient.h
Normal file
17
server/cloud/cloudclient.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef CLOUDCLIENT_H
|
||||||
|
#define CLOUDCLIENT_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class CloudClient : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit CloudClient(QObject *parent = 0);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CLOUDCLIENT_H
|
||||||
@ -19,10 +19,11 @@
|
|||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "cloudconnection.h"
|
#include "cloudconnection.h"
|
||||||
|
|
||||||
#include "loggingcategories.h"
|
#include "loggingcategories.h"
|
||||||
#include "guhsettings.h"
|
#include "guhsettings.h"
|
||||||
|
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
namespace guhserver {
|
namespace guhserver {
|
||||||
|
|
||||||
CloudConnection::CloudConnection(QObject *parent) :
|
CloudConnection::CloudConnection(QObject *parent) :
|
||||||
@ -36,8 +37,14 @@ CloudConnection::CloudConnection(QObject *parent) :
|
|||||||
m_proxyUrl = QUrl("ws://127.0.0.1:1212");
|
m_proxyUrl = QUrl("ws://127.0.0.1:1212");
|
||||||
m_keystoneUrl = QUrl("http://localhost:8000/oauth2/token");
|
m_keystoneUrl = QUrl("http://localhost:8000/oauth2/token");
|
||||||
|
|
||||||
// GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
GuhSettings settings(GuhSettings::SettingsRoleDevices);
|
||||||
// settings.beginGroup("CloudConnection");
|
settings.beginGroup("guhd");
|
||||||
|
m_guhUuid = settings.value("uuid", QVariant()).toUuid();
|
||||||
|
if (m_guhUuid.isNull()) {
|
||||||
|
m_guhUuid = QUuid::createUuid().toString();
|
||||||
|
settings.setValue("uuid", m_guhUuid);
|
||||||
|
}
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
m_connection = new QWebSocket("guhd", QWebSocketProtocol::Version13, this);
|
m_connection = new QWebSocket("guhd", QWebSocketProtocol::Version13, this);
|
||||||
connect(m_connection, SIGNAL(connected()), this, SLOT(onConnected()));
|
connect(m_connection, SIGNAL(connected()), this, SLOT(onConnected()));
|
||||||
@ -49,6 +56,8 @@ CloudConnection::CloudConnection(QObject *parent) :
|
|||||||
m_authenticator->setUrl(m_keystoneUrl);
|
m_authenticator->setUrl(m_keystoneUrl);
|
||||||
|
|
||||||
connect(m_authenticator, &CloudAuthenticator::authenticationChanged, this, &CloudConnection::onAuthenticationChanged);
|
connect(m_authenticator, &CloudAuthenticator::authenticationChanged, this, &CloudConnection::onAuthenticationChanged);
|
||||||
|
|
||||||
|
connectToCloud("simon.stuerz@guh.guru", "wshslwshsl");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloudConnection::connectToCloud(const QString &username, const QString &password)
|
void CloudConnection::connectToCloud(const QString &username, const QString &password)
|
||||||
@ -135,12 +144,30 @@ void CloudConnection::onConnected()
|
|||||||
qCDebug(dcCloud()) << "Connected to cloud proxy server" << m_proxyUrl.toString();
|
qCDebug(dcCloud()) << "Connected to cloud proxy server" << m_proxyUrl.toString();
|
||||||
setConnected(true);
|
setConnected(true);
|
||||||
|
|
||||||
// TODO: authenticate cloud connection
|
QVariantMap introspectMap;
|
||||||
|
introspectMap.insert("id", 0);
|
||||||
|
introspectMap.insert("method", "Interface.Introspect");
|
||||||
|
m_connection->sendTextMessage(QJsonDocument::fromVariant(introspectMap).toJson());
|
||||||
|
|
||||||
|
QVariantMap authenticationMap;
|
||||||
|
authenticationMap.insert("id", 1);
|
||||||
|
authenticationMap.insert("method", "Authentication.Authenticate");
|
||||||
|
|
||||||
|
QVariantMap params;
|
||||||
|
// TODO: use server name
|
||||||
|
params.insert("name", "guhIO");
|
||||||
|
params.insert("id", m_guhUuid);
|
||||||
|
params.insert("token", m_authenticator->token());
|
||||||
|
params.insert("type", "ConnectionTypeServer");
|
||||||
|
|
||||||
|
authenticationMap.insert("params", params);
|
||||||
|
|
||||||
|
m_connection->sendTextMessage(QJsonDocument::fromVariant(authenticationMap).toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloudConnection::onDisconnected()
|
void CloudConnection::onDisconnected()
|
||||||
{
|
{
|
||||||
qCDebug(dcCloud()) << "Disconnected from cloud connection:" << m_connection->closeReason();
|
qCDebug(dcCloud()) << "Disconnected from cloud:" << m_connection->closeReason();
|
||||||
setConnected(false);
|
setConnected(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +178,7 @@ void CloudConnection::onError(const QAbstractSocket::SocketError &error)
|
|||||||
|
|
||||||
void CloudConnection::onTextMessageReceived(const QString &message)
|
void CloudConnection::onTextMessageReceived(const QString &message)
|
||||||
{
|
{
|
||||||
qCDebug(dcCloud()) << "Cloud message received" << message;
|
qCDebug(dcCloud()) << "Cloud message -> " << qUtf8Printable(message.toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
#define CLOUDCONNECTION_H
|
#define CLOUDCONNECTION_H
|
||||||
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QUuid>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QWebSocket>
|
#include <QWebSocket>
|
||||||
|
|
||||||
@ -59,7 +60,7 @@ private:
|
|||||||
QWebSocket *m_connection;
|
QWebSocket *m_connection;
|
||||||
CloudAuthenticator *m_authenticator;
|
CloudAuthenticator *m_authenticator;
|
||||||
CloudConnectionError m_error;
|
CloudConnectionError m_error;
|
||||||
|
QUuid m_guhUuid;
|
||||||
QUrl m_proxyUrl;
|
QUrl m_proxyUrl;
|
||||||
QUrl m_keystoneUrl;
|
QUrl m_keystoneUrl;
|
||||||
|
|
||||||
|
|||||||
8
server/cloud/cloudinterface.cpp
Normal file
8
server/cloud/cloudinterface.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "cloudinterface.h"
|
||||||
|
|
||||||
|
CloudInterface::CloudInterface(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
17
server/cloud/cloudinterface.h
Normal file
17
server/cloud/cloudinterface.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef CLOUDINTERFACE_H
|
||||||
|
#define CLOUDINTERFACE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class CloudInterface : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit CloudInterface(QObject *parent = 0);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CLOUDINTERFACE_H
|
||||||
@ -41,6 +41,8 @@ HEADERS += $$top_srcdir/server/guhcore.h \
|
|||||||
$$top_srcdir/server/time/timemanager.h \
|
$$top_srcdir/server/time/timemanager.h \
|
||||||
$$top_srcdir/server/cloud/cloudconnection.h \
|
$$top_srcdir/server/cloud/cloudconnection.h \
|
||||||
$$top_srcdir/server/cloud/cloudauthenticator.h \
|
$$top_srcdir/server/cloud/cloudauthenticator.h \
|
||||||
|
$$PWD/cloud/cloudinterface.h \
|
||||||
|
$$PWD/cloud/cloudclient.h
|
||||||
|
|
||||||
|
|
||||||
SOURCES += $$top_srcdir/server/guhcore.cpp \
|
SOURCES += $$top_srcdir/server/guhcore.cpp \
|
||||||
@ -82,3 +84,5 @@ SOURCES += $$top_srcdir/server/guhcore.cpp \
|
|||||||
$$top_srcdir/server/time/timemanager.cpp \
|
$$top_srcdir/server/time/timemanager.cpp \
|
||||||
$$top_srcdir/server/cloud/cloudconnection.cpp \
|
$$top_srcdir/server/cloud/cloudconnection.cpp \
|
||||||
$$top_srcdir/server/cloud/cloudauthenticator.cpp \
|
$$top_srcdir/server/cloud/cloudauthenticator.cpp \
|
||||||
|
$$PWD/cloud/cloudinterface.cpp \
|
||||||
|
$$PWD/cloud/cloudclient.cpp
|
||||||
|
|||||||
Reference in New Issue
Block a user