mirror of https://github.com/nymea/nymea.git
60 lines
1.4 KiB
C++
60 lines
1.4 KiB
C++
#ifndef JSONRPCSERVER_H
|
|
#define JSONRPCSERVER_H
|
|
|
|
#include "deviceclass.h"
|
|
#include "action.h"
|
|
#include "event.h"
|
|
#include "jsonhandler.h"
|
|
|
|
#include <QObject>
|
|
#include <QVariantMap>
|
|
#include <QString>
|
|
|
|
#ifdef TESTING_ENABLED
|
|
class MockTcpServer;
|
|
#else
|
|
class TcpServer;
|
|
#endif
|
|
class Device;
|
|
|
|
class JsonRPCServer: public JsonHandler
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
JsonRPCServer(QObject *parent = 0);
|
|
|
|
// JsonHandler API implementation
|
|
QString name() const;
|
|
Q_INVOKABLE QVariantMap Introspect(const QVariantMap ¶ms) const;
|
|
Q_INVOKABLE QVariantMap Version(const QVariantMap ¶ms) const;
|
|
Q_INVOKABLE QVariantMap SetNotificationStatus(const QVariantMap ¶ms);
|
|
|
|
signals:
|
|
void commandReceived(const QString &targetNamespace, const QString &command, const QVariantMap ¶ms);
|
|
|
|
private slots:
|
|
void clientConnected(const QUuid &clientId);
|
|
void clientDisconnected(const QUuid &clientId);
|
|
|
|
void processData(const QUuid &clientId, const QByteArray &jsonData);
|
|
|
|
private:
|
|
void registerHandler(JsonHandler *handler);
|
|
|
|
void sendResponse(const QUuid &clientId, int commandId, const QVariantMap ¶ms = QVariantMap());
|
|
void sendErrorResponse(const QUuid &clientId, int commandId, const QString &error);
|
|
|
|
private:
|
|
#ifdef TESTING_ENABLED
|
|
MockTcpServer *m_tcpServer;
|
|
#else
|
|
TcpServer *m_tcpServer;
|
|
#endif
|
|
QHash<QString, JsonHandler*> m_handlers;
|
|
|
|
// clientId, notificationsEnabled
|
|
QHash<QUuid, bool> m_clients;
|
|
};
|
|
|
|
#endif
|