add cloud interface and design API

This commit is contained in:
Simon Stürz 2016-06-08 20:04:06 +02:00 committed by Michael Zanetti
parent 9edc4395d6
commit 4080ac3b9c
7 changed files with 89 additions and 7 deletions

View File

@ -0,0 +1,8 @@
#include "cloudclient.h"
CloudClient::CloudClient(QObject *parent) :
QObject(parent)
{
}

View 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

View File

@ -19,10 +19,11 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "cloudconnection.h"
#include "loggingcategories.h"
#include "guhsettings.h"
#include <QJsonDocument>
namespace guhserver {
CloudConnection::CloudConnection(QObject *parent) :
@ -36,8 +37,14 @@ CloudConnection::CloudConnection(QObject *parent) :
m_proxyUrl = QUrl("ws://127.0.0.1:1212");
m_keystoneUrl = QUrl("http://localhost:8000/oauth2/token");
// GuhSettings settings(GuhSettings::SettingsRoleGlobal);
// settings.beginGroup("CloudConnection");
GuhSettings settings(GuhSettings::SettingsRoleDevices);
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);
connect(m_connection, SIGNAL(connected()), this, SLOT(onConnected()));
@ -49,6 +56,8 @@ CloudConnection::CloudConnection(QObject *parent) :
m_authenticator->setUrl(m_keystoneUrl);
connect(m_authenticator, &CloudAuthenticator::authenticationChanged, this, &CloudConnection::onAuthenticationChanged);
connectToCloud("simon.stuerz@guh.guru", "wshslwshsl");
}
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();
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()
{
qCDebug(dcCloud()) << "Disconnected from cloud connection:" << m_connection->closeReason();
qCDebug(dcCloud()) << "Disconnected from cloud:" << m_connection->closeReason();
setConnected(false);
}
@ -151,7 +178,7 @@ void CloudConnection::onError(const QAbstractSocket::SocketError &error)
void CloudConnection::onTextMessageReceived(const QString &message)
{
qCDebug(dcCloud()) << "Cloud message received" << message;
qCDebug(dcCloud()) << "Cloud message -> " << qUtf8Printable(message.toUtf8());
}
}

View File

@ -22,6 +22,7 @@
#define CLOUDCONNECTION_H
#include <QUrl>
#include <QUuid>
#include <QObject>
#include <QWebSocket>
@ -59,7 +60,7 @@ private:
QWebSocket *m_connection;
CloudAuthenticator *m_authenticator;
CloudConnectionError m_error;
QUuid m_guhUuid;
QUrl m_proxyUrl;
QUrl m_keystoneUrl;

View File

@ -0,0 +1,8 @@
#include "cloudinterface.h"
CloudInterface::CloudInterface(QObject *parent) :
QObject(parent)
{
}

View 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

View File

@ -41,6 +41,8 @@ HEADERS += $$top_srcdir/server/guhcore.h \
$$top_srcdir/server/time/timemanager.h \
$$top_srcdir/server/cloud/cloudconnection.h \
$$top_srcdir/server/cloud/cloudauthenticator.h \
$$PWD/cloud/cloudinterface.h \
$$PWD/cloud/cloudclient.h
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/cloud/cloudconnection.cpp \
$$top_srcdir/server/cloud/cloudauthenticator.cpp \
$$PWD/cloud/cloudinterface.cpp \
$$PWD/cloud/cloudclient.cpp