From 3a9a0a0abc2c7b1f40300fdcd6c4b422cfb848a4 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 19 Nov 2019 20:03:48 +0100 Subject: [PATCH] Add scripts api namespace --- .../jsonrpc/jsonrpcserverimplementation.cpp | 1 + .../jsonrpc/jsonrpcserverimplementation.h | 2 +- libnymea-core/jsonrpc/scriptshandler.cpp | 106 +++++++++ libnymea-core/jsonrpc/scriptshandler.h | 31 +++ libnymea-core/libnymea-core.pro | 4 + libnymea-core/nymeacore.cpp | 6 +- libnymea-core/nymeacore.h | 2 + libnymea-core/scriptengine/script.cpp | 51 +++++ libnymea-core/scriptengine/script.h | 53 +++++ libnymea-core/scriptengine/scriptengine.cpp | 206 +++++++++++++++++- libnymea-core/scriptengine/scriptengine.h | 32 ++- libnymea/jsonrpc/jsonrpcserver.h | 1 + 12 files changed, 488 insertions(+), 7 deletions(-) create mode 100644 libnymea-core/jsonrpc/scriptshandler.cpp create mode 100644 libnymea-core/jsonrpc/scriptshandler.h create mode 100644 libnymea-core/scriptengine/script.cpp create mode 100644 libnymea-core/scriptengine/script.h diff --git a/libnymea-core/jsonrpc/jsonrpcserverimplementation.cpp b/libnymea-core/jsonrpc/jsonrpcserverimplementation.cpp index 8aded8dc..47f5bcb9 100644 --- a/libnymea-core/jsonrpc/jsonrpcserverimplementation.cpp +++ b/libnymea-core/jsonrpc/jsonrpcserverimplementation.cpp @@ -52,6 +52,7 @@ #include "devicehandler.h" #include "actionhandler.h" #include "ruleshandler.h" +#include "scriptshandler.h" #include "eventhandler.h" #include "logginghandler.h" #include "statehandler.h" diff --git a/libnymea-core/jsonrpc/jsonrpcserverimplementation.h b/libnymea-core/jsonrpc/jsonrpcserverimplementation.h index 097066e7..d8bcf3c4 100644 --- a/libnymea-core/jsonrpc/jsonrpcserverimplementation.h +++ b/libnymea-core/jsonrpc/jsonrpcserverimplementation.h @@ -72,10 +72,10 @@ public: void registerTransportInterface(TransportInterface *interface, bool authenticationRequired); void unregisterTransportInterface(TransportInterface *interface); + bool registerHandler(JsonHandler *handler) override; bool registerExperienceHandler(JsonHandler *handler, int majorVersion, int minorVersion) override; private: - bool registerHandler(JsonHandler *handler); QHash handlers() const; void sendResponse(TransportInterface *interface, const QUuid &clientId, int commandId, const QVariantMap ¶ms = QVariantMap(), const QString &deprecationWarning = QString()); diff --git a/libnymea-core/jsonrpc/scriptshandler.cpp b/libnymea-core/jsonrpc/scriptshandler.cpp new file mode 100644 index 00000000..17f03d25 --- /dev/null +++ b/libnymea-core/jsonrpc/scriptshandler.cpp @@ -0,0 +1,106 @@ +#include "scriptshandler.h" + +#include "loggingcategories.h" + +#include "scriptengine/scriptengine.h" + +namespace nymeaserver { + +ScriptsHandler::ScriptsHandler(ScriptEngine *scriptEngine, QObject *parent): + JsonHandler(parent), + m_engine(scriptEngine) +{ + registerEnum(); + + registerObject(); + + QVariantMap params, returns; + QString description; + + params.clear(); returns.clear(); + description = "Get all script, that is, their names and properties, but no content."; + returns.insert("scripts", objectRef()); + registerMethod("GetScripts", description, params, returns); + + params.clear(); returns.clear(); + description = "Add a script"; + params.insert("name", enumValueName(String)); + params.insert("content", enumValueName(String)); + returns.insert("scriptError", enumRef()); + returns.insert("o:script", objectRef