/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright (C) 2015 Simon Stuerz * * Copyright (C) 2014 Michael Zanetti * * * * This file is part of guh. * * * * Guh is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, version 2 of the License. * * * * Guh is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with guh. If not, see . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #ifndef JSONRPCSERVER_H #define JSONRPCSERVER_H #include "plugin/deviceclass.h" #include "jsonhandler.h" #include "transportinterface.h" #include "types/action.h" #include "types/event.h" #include #include #include class Device; class QSslConfiguration; #ifdef TESTING_ENABLED class MockTcpServer; #endif namespace guhserver { #ifdef WEBSOCKET class WebSocketServer; #endif #ifndef TESTING_ENABLED class TcpServer; #endif class JsonRPCServer: public JsonHandler { Q_OBJECT public: JsonRPCServer(const QSslConfiguration &sslConfiguration = QSslConfiguration(), QObject *parent = 0); // JsonHandler API implementation QString name() const; Q_INVOKABLE JsonReply* Introspect(const QVariantMap ¶ms) const; Q_INVOKABLE JsonReply* Version(const QVariantMap ¶ms) const; Q_INVOKABLE JsonReply* SetNotificationStatus(const QVariantMap ¶ms); QHash handlers() const; private slots: void setup(); void clientConnected(const QUuid &clientId); void clientDisconnected(const QUuid &clientId); void processData(const QUuid &clientId, const QString &targetNamespace, const QString &method, const QVariantMap &message); void sendNotification(const QVariantMap ¶ms); void asyncReplyFinished(); private: #ifdef TESTING_ENABLED MockTcpServer *m_tcpServer; #else TcpServer *m_tcpServer; #endif #ifdef WEBSOCKET WebSocketServer *m_websocketServer; #endif QList m_interfaces; QHash m_handlers; QHash m_asyncReplies; // clientId, notificationsEnabled QHash m_clients; int m_notificationId; void registerHandler(JsonHandler *handler); QString formatAssertion(const QString &targetNamespace, const QString &method, JsonHandler *handler, const QVariantMap &data) const; }; } #endif // JSONRPCSERVER_H