Moved effect static wrapper methods into Effect class

Former-commit-id: bd0c51eb59d98b7ad41fd4e0a178f2d72374c519
This commit is contained in:
Johan 2013-11-28 14:15:52 +01:00
parent 80cdac2055
commit cec626f3ae
3 changed files with 36 additions and 37 deletions

View File

@ -35,7 +35,7 @@ include_directories(${CMAKE_SOURCE_DIR}/dependencies/include)
include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}/include)
# Prefer static linking over dynamic # Prefer static linking over dynamic
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so") #set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so")
set(CMAKE_BUILD_TYPE "Release") set(CMAKE_BUILD_TYPE "Release")

View File

@ -5,34 +5,12 @@
// effect engin eincludes // effect engin eincludes
#include "Effect.h" #include "Effect.h"
// Effect wrapper methods for Python interpreter extra build in methods // Python method table
static PyObject* Effect_setColor(PyObject *self, PyObject *args) PyMethodDef Effect::effectMethods[] = {
{ {"setColor", Effect::wrapSetColor, METH_VARARGS, "Set a new color for the leds."},
return Py_BuildValue("i", 42); {"setImage", Effect::wrapSetImage, METH_VARARGS, "Set a new image to process and determine new led colors."},
} {"getLedCount", Effect::wrapGetLedCount, METH_VARARGS, "Get the number of avaliable led channels."},
{"abort", Effect::wrapAbort, METH_NOARGS , "Check if the effect should abort execution."},
static PyObject* Effect_setImage(PyObject *self, PyObject *args)
{
return Py_BuildValue("i", 42);
}
static PyObject* Effect_getLedCount(PyObject *self, PyObject *args)
{
return Py_BuildValue("i", 42);
}
static PyObject* Effect_abort(PyObject *self, PyObject *)
{
Effect * effect = reinterpret_cast<Effect *>(PyCapsule_GetPointer(self, nullptr));
bool abort = effect->isAbortedRequested();
return Py_BuildValue("i", abort ? 1 : 0);
}
static PyMethodDef effectMethods[] = {
{"setColor", Effect_setColor, METH_VARARGS, "Set a new color for the leds."},
{"setImage", Effect_setImage, METH_VARARGS, "Set a new image to process and determine new led colors."},
{"getLedCount", Effect_getLedCount, METH_VARARGS, "Get the number of avaliable led channels."},
{"abort", Effect_abort, METH_NOARGS , "Check if the effect should abort execution."},
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
@ -61,7 +39,6 @@ void Effect::run()
// add methods extra builtin methods to the interpreter // add methods extra builtin methods to the interpreter
PyObject * thisCapsule = PyCapsule_New(this, nullptr, nullptr); PyObject * thisCapsule = PyCapsule_New(this, nullptr, nullptr);
Py_InitModule4("hyperion", effectMethods, nullptr, thisCapsule, PYTHON_API_VERSION); Py_InitModule4("hyperion", effectMethods, nullptr, thisCapsule, PYTHON_API_VERSION);
std::cout << this << std::endl;
// Run the effect script // Run the effect script
std::string script = "test.py"; std::string script = "test.py";
@ -74,11 +51,6 @@ void Effect::run()
PyEval_ReleaseLock(); PyEval_ReleaseLock();
} }
bool Effect::isAbortedRequested() const
{
return _abortRequested;
}
int Effect::getPriority() const int Effect::getPriority() const
{ {
return _priority; return _priority;
@ -93,3 +65,24 @@ void Effect::effectFinished()
{ {
emit effectFinished(this); emit effectFinished(this);
} }
PyObject* Effect::wrapSetColor(PyObject *self, PyObject *args)
{
return Py_BuildValue("i", 42);
}
PyObject* Effect::wrapSetImage(PyObject *self, PyObject *args)
{
return Py_BuildValue("i", 42);
}
PyObject* Effect::wrapGetLedCount(PyObject *self, PyObject *args)
{
return Py_BuildValue("i", 42);
}
PyObject* Effect::wrapAbort(PyObject *self, PyObject *)
{
Effect * effect = reinterpret_cast<Effect *>(PyCapsule_GetPointer(self, nullptr));
return Py_BuildValue("i", effect->_abortRequested ? 1 : 0);
}

View File

@ -16,8 +16,6 @@ public:
virtual void run(); virtual void run();
bool isAbortedRequested() const;
int getPriority() const; int getPriority() const;
public slots: public slots:
@ -29,6 +27,14 @@ signals:
private slots: private slots:
void effectFinished(); void effectFinished();
private:
// Wrapper methods for Python interpreter extra buildin methods
static PyMethodDef effectMethods[];
static PyObject* wrapSetColor(PyObject *self, PyObject *args);
static PyObject* wrapSetImage(PyObject *self, PyObject *args);
static PyObject* wrapGetLedCount(PyObject *self, PyObject *args);
static PyObject* wrapAbort(PyObject *self, PyObject *args);
private: private:
const int _priority; const int _priority;