From bb9b02cf05a658eb4fcab23196d548e3a422f4ea Mon Sep 17 00:00:00 2001 From: Paulchen-Panther Date: Sun, 24 Apr 2016 17:07:31 +0200 Subject: [PATCH] get current state (active Effects) over JSON Interface (#608) * Create ActiveEffectDefinition.h * Update EffectEngine.h * Update Hyperion.h * Update Effect.h * Update EffectEngine.cpp * Update Hyperion.cpp * Update JsonClientConnection.cpp Former-commit-id: 5664b69da6893dd0d0de0e7c74c01cdcafd57310 --- include/effectengine/ActiveEffectDefinition.h | 15 +++++++++++++++ include/effectengine/EffectEngine.h | 5 +++++ include/hyperion/Hyperion.h | 5 +++++ libsrc/effectengine/Effect.h | 6 ++++++ libsrc/effectengine/EffectEngine.cpp | 17 +++++++++++++++++ libsrc/hyperion/Hyperion.cpp | 5 +++++ libsrc/jsonserver/JsonClientConnection.cpp | 14 ++++++++++++++ 7 files changed, 67 insertions(+) create mode 100644 include/effectengine/ActiveEffectDefinition.h diff --git a/include/effectengine/ActiveEffectDefinition.h b/include/effectengine/ActiveEffectDefinition.h new file mode 100644 index 00000000..345b226f --- /dev/null +++ b/include/effectengine/ActiveEffectDefinition.h @@ -0,0 +1,15 @@ +#pragma once + +// stl include +#include + +// json include +#include + +struct ActiveEffectDefinition +{ + std::string script; + int priority; + int timeout; + Json::Value args; +}; diff --git a/include/effectengine/EffectEngine.h b/include/effectengine/EffectEngine.h index c40732a1..7acb1eea 100644 --- a/include/effectengine/EffectEngine.h +++ b/include/effectengine/EffectEngine.h @@ -11,6 +11,7 @@ // Effect engine includes #include +#include // pre-declarioation class Effect; @@ -25,6 +26,8 @@ public: virtual ~EffectEngine(); const std::list & getEffects() const; + + const std::list & getActiveEffects(); static bool loadEffectDefinition(const std::string & path, const std::string & effectConfigFile, EffectDefinition &effectDefinition); @@ -54,6 +57,8 @@ private: std::list _availableEffects; std::list _activeEffects; + + std::list _availableActiveEffects; PyThreadState * _mainThreadState; }; diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index 57440cf9..aaf5bb87 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -20,6 +20,7 @@ // Effect engine includes #include +#include // Forward class declaration class LedDevice; @@ -99,6 +100,10 @@ public: /// Get the list of available effects /// @return The list of available effects const std::list &getEffects() const; + + /// Get the list of active effects + /// @return The list of active effects + const std::list &getActiveEffects(); public slots: /// diff --git a/libsrc/effectengine/Effect.h b/libsrc/effectengine/Effect.h index 8540d507..0ef49315 100644 --- a/libsrc/effectengine/Effect.h +++ b/libsrc/effectengine/Effect.h @@ -20,6 +20,12 @@ public: virtual void run(); int getPriority() const; + + std::string getScript() const { return _script; } + + int getTimeout() const {return _timeout; } + + Json::Value getArgs() const { return _args; } bool isAbortRequested() const; diff --git a/libsrc/effectengine/EffectEngine.cpp b/libsrc/effectengine/EffectEngine.cpp index f95e1822..97492a85 100644 --- a/libsrc/effectengine/EffectEngine.cpp +++ b/libsrc/effectengine/EffectEngine.cpp @@ -73,6 +73,23 @@ const std::list &EffectEngine::getEffects() const return _availableEffects; } +const std::list &EffectEngine::getActiveEffects() +{ + _availableActiveEffects.clear(); + + for (Effect * effect : _activeEffects) + { + ActiveEffectDefinition activeEffectDefinition; + activeEffectDefinition.script = effect->getScript(); + activeEffectDefinition.priority = effect->getPriority(); + activeEffectDefinition.timeout = effect->getTimeout(); + activeEffectDefinition.args = effect->getArgs(); + _availableActiveEffects.push_back(activeEffectDefinition); + } + + return _availableActiveEffects; +} + bool EffectEngine::loadEffectDefinition(const std::string &path, const std::string &effectConfigFile, EffectDefinition & effectDefinition) { #ifdef ENABLE_QT5 diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index a5a85ff4..45a2d322 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -833,6 +833,11 @@ const std::list & Hyperion::getEffects() const return _effectEngine->getEffects(); } +const std::list & Hyperion::getActiveEffects() +{ + return _effectEngine->getActiveEffects(); +} + int Hyperion::setEffect(const std::string &effectName, int priority, int timeout) { return _effectEngine->runEffect(effectName, priority, timeout); diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 62346623..34819367 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -514,6 +514,20 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &) effects.append(effect); } + + // collect active effect info + Json::Value & activeEffects = info["activeEffects"] = Json::Value(Json::arrayValue); + const std::list & activeEffectsDefinitions = _hyperion->getActiveEffects(); + for (const ActiveEffectDefinition & activeEffectDefinition : activeEffectsDefinitions) + { + Json::Value activeEffect; + activeEffect["script"] = activeEffectDefinition.script; + activeEffect["priority"] = activeEffectDefinition.priority; + activeEffect["timeout"] = activeEffectDefinition.timeout; + activeEffect["args"] = activeEffectDefinition.args; + + activeEffects.append(activeEffect); + } // send the result sendMessage(result);