62 lines
1.8 KiB
C++
62 lines
1.8 KiB
C++
#ifndef JSONRPCSERVER_H
|
|
#define JSONRPCSERVER_H
|
|
|
|
#include <QObject>
|
|
#include <QVariant>
|
|
|
|
#include "proxyclient.h"
|
|
#include "jsonrpc/jsonreply.h"
|
|
#include "transportinterface.h"
|
|
#include "jsonrpc/jsonhandler.h"
|
|
#include "jsonrpc/authenticationhandler.h"
|
|
|
|
namespace remoteproxy {
|
|
|
|
class JsonRpcServer : public JsonHandler
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit JsonRpcServer(QObject *parent = nullptr);
|
|
~JsonRpcServer() override;
|
|
|
|
QString name() const override;
|
|
|
|
Q_INVOKABLE JsonReply *Hello(const QVariantMap ¶ms, ProxyClient *proxyClient = nullptr) const;
|
|
Q_INVOKABLE JsonReply *Introspect(const QVariantMap ¶ms, ProxyClient *proxyClient = nullptr) const;
|
|
|
|
signals:
|
|
void TunnelEstablished(const QVariantMap ¶ms);
|
|
|
|
private:
|
|
QHash<QString, JsonHandler *> m_handlers;
|
|
QHash<JsonReply *, ProxyClient *> m_asyncReplies;
|
|
QList<ProxyClient *> m_clients;
|
|
int m_notificationId = 0;
|
|
|
|
void sendResponse(ProxyClient *client, int commandId, const QVariantMap ¶ms = QVariantMap());
|
|
void sendErrorResponse(ProxyClient *client, int commandId, const QString &error);
|
|
|
|
QString formatAssertion(const QString &targetNamespace, const QString &method, JsonHandler *handler, const QVariantMap &data) const;
|
|
|
|
void registerHandler(JsonHandler *handler);
|
|
void unregisterHandler(JsonHandler *handler);
|
|
|
|
private slots:
|
|
void setup();
|
|
void asyncReplyFinished();
|
|
|
|
public slots:
|
|
// Client registration for JSON RPC traffic
|
|
void registerClient(ProxyClient *proxyClient);
|
|
void unregisterClient(ProxyClient *proxyClient);
|
|
|
|
// Process data from client
|
|
void processData(ProxyClient *proxyClient, const QByteArray &data);
|
|
void sendNotification(const QString &nameSpace, const QString &method, const QVariantMap ¶ms, ProxyClient *proxyClient = nullptr);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif // JSONRPCSERVER_H
|