55 lines
1.7 KiB
C++
55 lines
1.7 KiB
C++
#ifndef JSONRPCSERVER_H
|
|
#define JSONRPCSERVER_H
|
|
|
|
#include <QObject>
|
|
|
|
#include "transportinterface.h"
|
|
#include "jsonrpc/jsonhandler.h"
|
|
#include "jsonrpc/authenticationhandler.h"
|
|
|
|
class JsonRpcServer : public JsonHandler
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit JsonRpcServer(QObject *parent = nullptr);
|
|
~JsonRpcServer() override;
|
|
|
|
QString name() const override;
|
|
|
|
QHash<QString, JsonHandler *> handlers() const;
|
|
|
|
void registerTransportInterface(TransportInterface *interface);
|
|
void unregisterTransportInterface(TransportInterface *interface);
|
|
|
|
Q_INVOKABLE JsonReply *Hello(const QVariantMap ¶ms) const;
|
|
Q_INVOKABLE JsonReply *Introspect(const QVariantMap ¶ms) const;
|
|
|
|
private:
|
|
QList<TransportInterface *> m_interfaces;
|
|
QHash<QString, JsonHandler *> m_handlers;
|
|
QHash<JsonReply *, TransportInterface *> m_asyncReplies;
|
|
QHash<QUuid, TransportInterface*> m_clientTransports;
|
|
QHash<QString, JsonReply*> m_pairingRequests;
|
|
|
|
int m_notificationId;
|
|
|
|
void sendResponse(TransportInterface *interface, const QUuid &clientId, int commandId, const QVariantMap ¶ms = QVariantMap());
|
|
void sendErrorResponse(TransportInterface *interface, const QUuid &clientId, int commandId, const QString &error);
|
|
QString formatAssertion(const QString &targetNamespace, const QString &method, JsonHandler *handler, const QVariantMap &data) const;
|
|
|
|
void registerHandler(JsonHandler *handler);
|
|
|
|
|
|
|
|
private slots:
|
|
void setup();
|
|
void clientConnected(const QUuid &clientId);
|
|
void clientDisconnected(const QUuid &clientId);
|
|
void processData(const QUuid &clientId, const QByteArray &data);
|
|
// void sendNotification(const QVariantMap ¶ms);
|
|
// void asyncReplyFinished();
|
|
|
|
};
|
|
|
|
#endif // JSONRPCSERVER_H
|