mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Details coming soon.
This commit is contained in:
38
libsrc/webserver/WebJsonRpc.cpp
Normal file
38
libsrc/webserver/WebJsonRpc.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "WebJsonRpc.h"
|
||||
#include "QtHttpReply.h"
|
||||
#include "QtHttpRequest.h"
|
||||
#include "QtHttpServer.h"
|
||||
#include "QtHttpClientWrapper.h"
|
||||
|
||||
#include <api/JsonAPI.h>
|
||||
|
||||
WebJsonRpc::WebJsonRpc(QtHttpRequest* request, QtHttpServer* server, QtHttpClientWrapper* parent)
|
||||
: QObject(parent)
|
||||
, _server(server)
|
||||
, _wrapper(parent)
|
||||
, _log(Logger::getInstance("HTTPJSONRPC"))
|
||||
{
|
||||
const QString client = request->getClientInfo().clientAddress.toString();
|
||||
_jsonAPI = new JsonAPI(client, _log, this, true);
|
||||
connect(_jsonAPI, &JsonAPI::callbackMessage, this, &WebJsonRpc::handleCallback);
|
||||
}
|
||||
|
||||
void WebJsonRpc::handleMessage(QtHttpRequest* request)
|
||||
{
|
||||
QByteArray data = request->getRawData();
|
||||
_unlocked = true;
|
||||
_jsonAPI->handleMessage(data);
|
||||
}
|
||||
|
||||
void WebJsonRpc::handleCallback(QJsonObject obj)
|
||||
{
|
||||
// guard against wrong callbacks; TODO: Remove when JSONAPI is more solid
|
||||
if(!_unlocked) return;
|
||||
_unlocked = false;
|
||||
// construct reply with headers timestamp and server name
|
||||
QtHttpReply reply(_server);
|
||||
QJsonDocument doc(obj);
|
||||
reply.addHeader ("Content-Type", "application/json");
|
||||
reply.appendRawData (doc.toJson());
|
||||
_wrapper->sendToClientWithReply(&reply);
|
||||
}
|
Reference in New Issue
Block a user