mirror of https://github.com/nymea/nymea.git
48 lines
977 B
C++
48 lines
977 B
C++
#ifndef JSONRPCSERVER_H
|
|
#define JSONRPCSERVER_H
|
|
|
|
#include "deviceclass.h"
|
|
#include "action.h"
|
|
#include "event.h"
|
|
|
|
#include <QObject>
|
|
#include <QVariantMap>
|
|
#include <QString>
|
|
|
|
#ifdef TESTING_ENABLED
|
|
class MockTcpServer;
|
|
#else
|
|
class TcpServer;
|
|
#endif
|
|
class Device;
|
|
class JsonHandler;
|
|
|
|
class JsonRPCServer: public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
JsonRPCServer(QObject *parent = 0);
|
|
|
|
signals:
|
|
void commandReceived(const QString &targetNamespace, const QString &command, const QVariantMap ¶ms);
|
|
|
|
private slots:
|
|
void processData(int clientId, const QByteArray &jsonData);
|
|
|
|
private:
|
|
void registerHandler(JsonHandler *handler);
|
|
|
|
void sendResponse(int clientId, int commandId, const QVariantMap ¶ms = QVariantMap());
|
|
void sendErrorResponse(int clientId, int commandId, const QString &error);
|
|
|
|
private:
|
|
#ifdef TESTING_ENABLED
|
|
MockTcpServer *m_tcpServer;
|
|
#else
|
|
TcpServer *m_tcpServer;
|
|
#endif
|
|
QHash<QString, JsonHandler*> m_handlers;
|
|
};
|
|
|
|
#endif
|