mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
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:
parent
d4dda2dcc4
commit
bb9b02cf05
15
include/effectengine/ActiveEffectDefinition.h
Normal file
15
include/effectengine/ActiveEffectDefinition.h
Normal 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;
|
||||
};
|
@ -11,6 +11,7 @@
|
||||
|
||||
// Effect engine includes
|
||||
#include <effectengine/EffectDefinition.h>
|
||||
#include <effectengine/ActiveEffectDefinition.h>
|
||||
|
||||
// pre-declarioation
|
||||
class Effect;
|
||||
@ -25,6 +26,8 @@ public:
|
||||
virtual ~EffectEngine();
|
||||
|
||||
const std::list<EffectDefinition> & getEffects() const;
|
||||
|
||||
const std::list<ActiveEffectDefinition> & getActiveEffects();
|
||||
|
||||
static bool loadEffectDefinition(const std::string & path, const std::string & effectConfigFile, EffectDefinition &effectDefinition);
|
||||
|
||||
@ -54,6 +57,8 @@ private:
|
||||
std::list<EffectDefinition> _availableEffects;
|
||||
|
||||
std::list<Effect *> _activeEffects;
|
||||
|
||||
std::list<ActiveEffectDefinition> _availableActiveEffects;
|
||||
|
||||
PyThreadState * _mainThreadState;
|
||||
};
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
// Effect engine includes
|
||||
#include <effectengine/EffectDefinition.h>
|
||||
#include <effectengine/ActiveEffectDefinition.h>
|
||||
|
||||
// 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<EffectDefinition> &getEffects() const;
|
||||
|
||||
/// Get the list of active effects
|
||||
/// @return The list of active effects
|
||||
const std::list<ActiveEffectDefinition> &getActiveEffects();
|
||||
|
||||
public slots:
|
||||
///
|
||||
|
@ -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;
|
||||
|
||||
|
@ -73,6 +73,23 @@ const std::list<EffectDefinition> &EffectEngine::getEffects() const
|
||||
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)
|
||||
{
|
||||
#ifdef ENABLE_QT5
|
||||
|
@ -833,6 +833,11 @@ const std::list<EffectDefinition> & Hyperion::getEffects() const
|
||||
return _effectEngine->getEffects();
|
||||
}
|
||||
|
||||
const std::list<ActiveEffectDefinition> & Hyperion::getActiveEffects()
|
||||
{
|
||||
return _effectEngine->getActiveEffects();
|
||||
}
|
||||
|
||||
int Hyperion::setEffect(const std::string &effectName, int priority, int timeout)
|
||||
{
|
||||
return _effectEngine->runEffect(effectName, priority, timeout);
|
||||
|
@ -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<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
|
||||
sendMessage(result);
|
||||
|
Loading…
Reference in New Issue
Block a user