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
This commit is contained in:
Paulchen-Panther 2016-04-24 17:07:31 +02:00 committed by brindosch
parent d4dda2dcc4
commit bb9b02cf05
7 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,15 @@
#pragma once
// stl include
#include <string>
// json include
#include <json/value.h>
struct ActiveEffectDefinition
{
std::string script;
int priority;
int timeout;
Json::Value args;
};

View File

@ -11,6 +11,7 @@
// Effect engine includes // Effect engine includes
#include <effectengine/EffectDefinition.h> #include <effectengine/EffectDefinition.h>
#include <effectengine/ActiveEffectDefinition.h>
// pre-declarioation // pre-declarioation
class Effect; class Effect;
@ -25,6 +26,8 @@ public:
virtual ~EffectEngine(); virtual ~EffectEngine();
const std::list<EffectDefinition> & getEffects() const; const std::list<EffectDefinition> & getEffects() const;
const std::list<ActiveEffectDefinition> & getActiveEffects();
static bool loadEffectDefinition(const std::string & path, const std::string & effectConfigFile, EffectDefinition &effectDefinition); static bool loadEffectDefinition(const std::string & path, const std::string & effectConfigFile, EffectDefinition &effectDefinition);
@ -54,6 +57,8 @@ private:
std::list<EffectDefinition> _availableEffects; std::list<EffectDefinition> _availableEffects;
std::list<Effect *> _activeEffects; std::list<Effect *> _activeEffects;
std::list<ActiveEffectDefinition> _availableActiveEffects;
PyThreadState * _mainThreadState; PyThreadState * _mainThreadState;
}; };

View File

@ -20,6 +20,7 @@
// Effect engine includes // Effect engine includes
#include <effectengine/EffectDefinition.h> #include <effectengine/EffectDefinition.h>
#include <effectengine/ActiveEffectDefinition.h>
// Forward class declaration // Forward class declaration
class LedDevice; class LedDevice;
@ -99,6 +100,10 @@ public:
/// Get the list of available effects /// Get the list of available effects
/// @return The list of available effects /// @return The list of available effects
const std::list<EffectDefinition> &getEffects() const; const std::list<EffectDefinition> &getEffects() const;
/// Get the list of active effects
/// @return The list of active effects
const std::list<ActiveEffectDefinition> &getActiveEffects();
public slots: public slots:
/// ///

View File

@ -20,6 +20,12 @@ public:
virtual void run(); virtual void run();
int getPriority() const; int getPriority() const;
std::string getScript() const { return _script; }
int getTimeout() const {return _timeout; }
Json::Value getArgs() const { return _args; }
bool isAbortRequested() const; bool isAbortRequested() const;

View File

@ -73,6 +73,23 @@ const std::list<EffectDefinition> &EffectEngine::getEffects() const
return _availableEffects; return _availableEffects;
} }
const std::list<ActiveEffectDefinition> &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) bool EffectEngine::loadEffectDefinition(const std::string &path, const std::string &effectConfigFile, EffectDefinition & effectDefinition)
{ {
#ifdef ENABLE_QT5 #ifdef ENABLE_QT5

View File

@ -833,6 +833,11 @@ const std::list<EffectDefinition> & Hyperion::getEffects() const
return _effectEngine->getEffects(); return _effectEngine->getEffects();
} }
const std::list<ActiveEffectDefinition> & Hyperion::getActiveEffects()
{
return _effectEngine->getActiveEffects();
}
int Hyperion::setEffect(const std::string &effectName, int priority, int timeout) int Hyperion::setEffect(const std::string &effectName, int priority, int timeout)
{ {
return _effectEngine->runEffect(effectName, priority, timeout); return _effectEngine->runEffect(effectName, priority, timeout);

View File

@ -514,6 +514,20 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &)
effects.append(effect); effects.append(effect);
} }
// collect active effect info
Json::Value & activeEffects = info["activeEffects"] = Json::Value(Json::arrayValue);
const std::list<ActiveEffectDefinition> & 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 // send the result
sendMessage(result); sendMessage(result);