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