intermediate
This commit is contained in:
parent
a2e6d9e185
commit
31cf425b79
@ -63,6 +63,23 @@ static PyTypeObject PyThingType = {
|
|||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void registerThingType(PyObject *module)
|
||||||
|
{
|
||||||
|
PyThingType.tp_new = PyType_GenericNew;
|
||||||
|
PyThingType.tp_dealloc= reinterpret_cast<destructor>(PyThing_dealloc);
|
||||||
|
PyThingType.tp_basicsize = sizeof(PyThing);
|
||||||
|
PyThingType.tp_flags = Py_TPFLAGS_DEFAULT;
|
||||||
|
PyThingType.tp_doc = "Thing class";
|
||||||
|
PyThingType.tp_methods = PyThing_methods;
|
||||||
|
// PyThingType.tp_members = PyThingSetupInfo_members;
|
||||||
|
PyThingType.tp_init = reinterpret_cast<initproc>(PyThing_init);
|
||||||
|
|
||||||
|
if (PyType_Ready(&PyThingType) < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PyModule_AddObject(module, "Thing", reinterpret_cast<PyObject*>(&PyThingType));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
|
|||||||
117
libnymea-core/integrations/python/pythingdescriptor.h
Normal file
117
libnymea-core/integrations/python/pythingdescriptor.h
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
#ifndef PYTHINGDESCRIPTOR_H
|
||||||
|
#define PYTHINGDESCRIPTOR_H
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
#include "structmember.h"
|
||||||
|
|
||||||
|
#include "integrations/thingdescriptor.h"
|
||||||
|
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
|
||||||
|
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PyObject_HEAD
|
||||||
|
PyObject* thingClassId;
|
||||||
|
PyObject* name;
|
||||||
|
PyObject* description;
|
||||||
|
ThingDescriptor descriptor;
|
||||||
|
} PyThingDescriptor;
|
||||||
|
|
||||||
|
static PyMethodDef PyThingDescriptor_methods[] = {
|
||||||
|
// { "finish", (PyCFunction)PyThingDiscoveryInfo_finish, METH_VARARGS, "finish a discovery" },
|
||||||
|
{nullptr, nullptr, 0, nullptr} // sentinel
|
||||||
|
};
|
||||||
|
|
||||||
|
static PyMemberDef PyThingDescriptor_members[] = {
|
||||||
|
{"thingClassId", T_OBJECT_EX, offsetof(PyThingDescriptor, thingClassId), 0, "Descriptor thingClassId"},
|
||||||
|
{"name", T_OBJECT_EX, offsetof(PyThingDescriptor, name), 0, "Descriptor name"},
|
||||||
|
{"description", T_OBJECT_EX, offsetof(PyThingDescriptor, description), 0, "Descriptor description"},
|
||||||
|
{nullptr, 0, 0, 0, nullptr} /* Sentinel */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static int PyThingDescriptor_init(PyThingDescriptor *self, PyObject *args, PyObject *kwds)
|
||||||
|
{
|
||||||
|
static char *kwlist[] = {"thingClassId", "name", "description", nullptr};
|
||||||
|
PyObject *thingClassId = nullptr, *name = nullptr, *description = nullptr, *tmp = nullptr;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", kwlist, &thingClassId, &name, &description))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (thingClassId) {
|
||||||
|
tmp = self->thingClassId;
|
||||||
|
Py_INCREF(thingClassId);
|
||||||
|
self->thingClassId = thingClassId;
|
||||||
|
Py_XDECREF(tmp);
|
||||||
|
}
|
||||||
|
if (name) {
|
||||||
|
tmp = self->name;
|
||||||
|
Py_INCREF(name);
|
||||||
|
self->name = name;
|
||||||
|
Py_XDECREF(tmp);
|
||||||
|
}
|
||||||
|
if (description) {
|
||||||
|
tmp = self->description;
|
||||||
|
Py_INCREF(description);
|
||||||
|
self->description = description;
|
||||||
|
Py_XDECREF(tmp);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//static PyGetSetDef PyThingDescriptor_getsetters[] = {
|
||||||
|
// {"name", (getter) PyThingDescriptor_getName, (setter) PyThingDescriptir_setName,
|
||||||
|
// "Descriptor name", NULL},
|
||||||
|
// {"last", (getter) Custom_getlast, (setter) Custom_setlast,
|
||||||
|
// "last name", NULL},
|
||||||
|
// {NULL} /* Sentinel */
|
||||||
|
//};
|
||||||
|
|
||||||
|
static PyTypeObject PyThingDescriptorType = {
|
||||||
|
PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
|
"nymea.ThingDescriptor", /* tp_name */
|
||||||
|
sizeof(PyThingDescriptor), /* tp_basicsize */
|
||||||
|
0, /* tp_itemsize */
|
||||||
|
0, /* tp_dealloc */
|
||||||
|
0, /* tp_print */
|
||||||
|
0, /* tp_getattr */
|
||||||
|
0, /* tp_setattr */
|
||||||
|
0, /* tp_reserved */
|
||||||
|
0, /* tp_repr */
|
||||||
|
0, /* tp_as_number */
|
||||||
|
0, /* tp_as_sequence */
|
||||||
|
0, /* tp_as_mapping */
|
||||||
|
0, /* tp_hash */
|
||||||
|
0, /* tp_call */
|
||||||
|
0, /* tp_str */
|
||||||
|
0, /* tp_getattro */
|
||||||
|
0, /* tp_setattro */
|
||||||
|
0, /* tp_as_buffer */
|
||||||
|
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
||||||
|
"Noddy objects", /* tp_doc */
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void registerThingDescriptorType(PyObject *module)
|
||||||
|
{
|
||||||
|
PyThingDescriptorType.tp_new = PyType_GenericNew;
|
||||||
|
PyThingDescriptorType.tp_basicsize = sizeof(PyThingDescriptor);
|
||||||
|
PyThingDescriptorType.tp_flags = Py_TPFLAGS_DEFAULT;
|
||||||
|
PyThingDescriptorType.tp_doc = "ThingDescriptor class";
|
||||||
|
PyThingDescriptorType.tp_methods = PyThingDescriptor_methods;
|
||||||
|
PyThingDescriptorType.tp_members = PyThingDescriptor_members;
|
||||||
|
PyThingDescriptorType.tp_init = reinterpret_cast<initproc>(PyThingDescriptor_init);
|
||||||
|
|
||||||
|
if (PyType_Ready(&PyThingDescriptorType) < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PyModule_AddObject(module, "ThingDescriptor", reinterpret_cast<PyObject*>(&PyThingDescriptorType));
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
|
#endif // PYTHINGDESCRIPTOR_H
|
||||||
@ -5,116 +5,18 @@
|
|||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include "structmember.h"
|
#include "structmember.h"
|
||||||
|
|
||||||
|
#include "pythingdescriptor.h"
|
||||||
|
|
||||||
#include "integrations/thingdiscoveryinfo.h"
|
#include "integrations/thingdiscoveryinfo.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QMetaEnum>
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
|
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
|
||||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
PyObject_HEAD
|
|
||||||
PyObject* thingClassId;
|
|
||||||
PyObject* name;
|
|
||||||
PyObject* description;
|
|
||||||
ThingDescriptor descriptor;
|
|
||||||
} PyThingDescriptor;
|
|
||||||
|
|
||||||
static PyMethodDef PyThingDescriptor_methods[] = {
|
|
||||||
// { "finish", (PyCFunction)PyThingDiscoveryInfo_finish, METH_VARARGS, "finish a discovery" },
|
|
||||||
{nullptr, nullptr, 0, nullptr} // sentinel
|
|
||||||
};
|
|
||||||
|
|
||||||
static PyMemberDef PyThingDescriptor_members[] = {
|
|
||||||
{"thingClassId", T_OBJECT_EX, offsetof(PyThingDescriptor, thingClassId), 0, "Descriptor thingClassId"},
|
|
||||||
{"name", T_OBJECT_EX, offsetof(PyThingDescriptor, name), 0, "Descriptor name"},
|
|
||||||
{"description", T_OBJECT_EX, offsetof(PyThingDescriptor, description), 0, "Descriptor description"},
|
|
||||||
{nullptr, 0, 0, 0, nullptr} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static int PyThingDescriptor_init(PyThingDescriptor *self, PyObject *args, PyObject *kwds)
|
|
||||||
{
|
|
||||||
static char *kwlist[] = {"thingClassId", "name", "description", nullptr};
|
|
||||||
PyObject *thingClassId = nullptr, *name = nullptr, *description = nullptr, *tmp = nullptr;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", kwlist, &thingClassId, &name, &description))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (thingClassId) {
|
|
||||||
tmp = self->thingClassId;
|
|
||||||
Py_INCREF(thingClassId);
|
|
||||||
self->thingClassId = thingClassId;
|
|
||||||
Py_XDECREF(tmp);
|
|
||||||
}
|
|
||||||
if (name) {
|
|
||||||
tmp = self->name;
|
|
||||||
Py_INCREF(name);
|
|
||||||
self->name = name;
|
|
||||||
Py_XDECREF(tmp);
|
|
||||||
}
|
|
||||||
if (description) {
|
|
||||||
tmp = self->description;
|
|
||||||
Py_INCREF(description);
|
|
||||||
self->description = description;
|
|
||||||
Py_XDECREF(tmp);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//static PyGetSetDef PyThingDescriptor_getsetters[] = {
|
|
||||||
// {"name", (getter) PyThingDescriptor_getName, (setter) PyThingDescriptir_setName,
|
|
||||||
// "Descriptor name", NULL},
|
|
||||||
// {"last", (getter) Custom_getlast, (setter) Custom_setlast,
|
|
||||||
// "last name", NULL},
|
|
||||||
// {NULL} /* Sentinel */
|
|
||||||
//};
|
|
||||||
|
|
||||||
static PyTypeObject PyThingDescriptorType = {
|
|
||||||
PyVarObject_HEAD_INIT(NULL, 0)
|
|
||||||
"nymea.ThingDescriptor", /* tp_name */
|
|
||||||
sizeof(PyThingDescriptor), /* tp_basicsize */
|
|
||||||
0, /* tp_itemsize */
|
|
||||||
0, /* tp_dealloc */
|
|
||||||
0, /* tp_print */
|
|
||||||
0, /* tp_getattr */
|
|
||||||
0, /* tp_setattr */
|
|
||||||
0, /* tp_reserved */
|
|
||||||
0, /* tp_repr */
|
|
||||||
0, /* tp_as_number */
|
|
||||||
0, /* tp_as_sequence */
|
|
||||||
0, /* tp_as_mapping */
|
|
||||||
0, /* tp_hash */
|
|
||||||
0, /* tp_call */
|
|
||||||
0, /* tp_str */
|
|
||||||
0, /* tp_getattro */
|
|
||||||
0, /* tp_setattro */
|
|
||||||
0, /* tp_as_buffer */
|
|
||||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
|
||||||
"Noddy objects", /* tp_doc */
|
|
||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
ThingDiscoveryInfo* ptrObj;
|
ThingDiscoveryInfo* ptrObj;
|
||||||
@ -221,9 +123,26 @@ static PyTypeObject PyThingDiscoveryInfoType = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void registerThingDiscoveryInfoType(PyObject *module)
|
||||||
|
{
|
||||||
|
PyThingDiscoveryInfoType.tp_new = PyType_GenericNew;
|
||||||
|
PyThingDiscoveryInfoType.tp_basicsize = sizeof(PyThingDiscoveryInfo);
|
||||||
|
PyThingDiscoveryInfoType.tp_dealloc = reinterpret_cast<destructor>(PyThingDiscoveryInfo_dealloc);
|
||||||
|
PyThingDiscoveryInfoType.tp_flags = Py_TPFLAGS_DEFAULT;
|
||||||
|
PyThingDiscoveryInfoType.tp_doc = "ThingDiscoveryInfo class";
|
||||||
|
PyThingDiscoveryInfoType.tp_methods = PyThingDiscoveryInfo_methods;
|
||||||
|
PyThingDiscoveryInfoType.tp_init = reinterpret_cast<initproc>(PyThingDiscoveryInfo_init);
|
||||||
|
|
||||||
|
if (PyType_Ready(&PyThingDiscoveryInfoType) < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PyModule_AddObject(module, "ThingDiscoveryInfo", (PyObject *)&PyThingDiscoveryInfoType);
|
||||||
|
|
||||||
|
QMetaEnum thingErrorEnum = QMetaEnum::fromType<Thing::ThingError>();
|
||||||
|
for (int i = 0; i < thingErrorEnum.keyCount(); i++) {
|
||||||
|
PyModule_AddObject(module, thingErrorEnum.key(i), PyLong_FromLong(thingErrorEnum.value(i)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -63,10 +63,10 @@ static PyTypeObject PyThingSetupInfoType = {
|
|||||||
sizeof(PyThingSetupInfo), /* tp_basicsize */
|
sizeof(PyThingSetupInfo), /* tp_basicsize */
|
||||||
0, /* tp_itemsize */
|
0, /* tp_itemsize */
|
||||||
0, /* tp_dealloc */
|
0, /* tp_dealloc */
|
||||||
0, /* tp_print */
|
0, /* tp_vectorcall_offset */
|
||||||
0, /* tp_getattr */
|
0, /* tp_getattr */
|
||||||
0, /* tp_setattr */
|
0, /* tp_setattr */
|
||||||
0, /* tp_reserved */
|
0, /* tp_as_async */
|
||||||
0, /* tp_repr */
|
0, /* tp_repr */
|
||||||
0, /* tp_as_number */
|
0, /* tp_as_number */
|
||||||
0, /* tp_as_sequence */
|
0, /* tp_as_sequence */
|
||||||
@ -82,6 +82,23 @@ static PyTypeObject PyThingSetupInfoType = {
|
|||||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void registerThingSetupInfoType(PyObject *module) {
|
||||||
|
PyThingSetupInfoType.tp_new = PyType_GenericNew;
|
||||||
|
PyThingSetupInfoType.tp_dealloc=(destructor) PyThingSetupInfo_dealloc;
|
||||||
|
PyThingSetupInfoType.tp_basicsize = sizeof(PyThingSetupInfo);
|
||||||
|
PyThingSetupInfoType.tp_flags = Py_TPFLAGS_DEFAULT;
|
||||||
|
PyThingSetupInfoType.tp_doc = "ThingSetupInfo class";
|
||||||
|
PyThingSetupInfoType.tp_methods = PyThingSetupInfo_methods;
|
||||||
|
// PyThingSetupInfoType.tp_members = PyThingSetupInfo_members;
|
||||||
|
PyThingSetupInfoType.tp_init = (initproc)PyThingSetupInfo_init;
|
||||||
|
|
||||||
|
if (PyType_Ready(&PyThingSetupInfoType) < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PyModule_AddObject(module, "ThingSetupInfo", (PyObject *)&PyThingSetupInfoType);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
|
||||||
|
#include "python/pything.h"
|
||||||
#include "python/pythingdiscoveryinfo.h"
|
#include "python/pythingdiscoveryinfo.h"
|
||||||
#include "python/pythingsetupinfo.h"
|
#include "python/pythingsetupinfo.h"
|
||||||
|
|
||||||
@ -57,40 +59,10 @@ PyMODINIT_FUNC PyInit_nymea(void)
|
|||||||
PySys_SetObject("stderr", m);
|
PySys_SetObject("stderr", m);
|
||||||
|
|
||||||
|
|
||||||
QMetaEnum thingErrorEnum = QMetaEnum::fromType<Thing::ThingError>();
|
registerThingType(m);
|
||||||
for (int i = 0; i < thingErrorEnum.keyCount(); i++) {
|
registerThingDescriptorType(m);
|
||||||
PyModule_AddObject(m, thingErrorEnum.key(i), PyLong_FromLong(thingErrorEnum.value(i)));
|
registerThingDiscoveryInfoType(m);
|
||||||
}
|
registerThingSetupInfoType(m);
|
||||||
|
|
||||||
|
|
||||||
PyThingDiscoveryInfoType.tp_new = PyType_GenericNew;
|
|
||||||
PyThingDiscoveryInfoType.tp_basicsize=sizeof(PyThingDiscoveryInfo);
|
|
||||||
PyThingDiscoveryInfoType.tp_dealloc=(destructor) PyThingDiscoveryInfo_dealloc;
|
|
||||||
PyThingDiscoveryInfoType.tp_flags=Py_TPFLAGS_DEFAULT;
|
|
||||||
PyThingDiscoveryInfoType.tp_doc="ThingDiscoveryInfo class";
|
|
||||||
PyThingDiscoveryInfoType.tp_methods=PyThingDiscoveryInfo_methods;
|
|
||||||
PyThingDiscoveryInfoType.tp_init=(initproc)PyThingDiscoveryInfo_init;
|
|
||||||
|
|
||||||
if (PyType_Ready(&PyThingDiscoveryInfoType) < 0) {
|
|
||||||
qCWarning(dcThingManager()) << "Error creating PyThingDiscoveryInfo";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
PyModule_AddObject(m, "ThingDiscoveryInfo", (PyObject *)&PyThingDiscoveryInfoType);
|
|
||||||
|
|
||||||
PyThingDescriptorType.tp_new = PyType_GenericNew;
|
|
||||||
PyThingDescriptorType.tp_basicsize = sizeof(PyThingDescriptor);
|
|
||||||
PyThingDescriptorType.tp_flags = Py_TPFLAGS_DEFAULT;
|
|
||||||
PyThingDescriptorType.tp_doc = "ThingDescriptor class";
|
|
||||||
PyThingDescriptorType.tp_methods = PyThingDescriptor_methods;
|
|
||||||
PyThingDescriptorType.tp_members = PyThingDescriptor_members;
|
|
||||||
PyThingDescriptorType.tp_init = (initproc)PyThingDescriptor_init;
|
|
||||||
|
|
||||||
if (PyType_Ready(&PyThingDescriptorType) < 0) {
|
|
||||||
qCWarning(dcThingManager()) << "Error creating PyThingDescriptor";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
PyModule_AddObject(m, "ThingDescriptor", (PyObject *)&PyThingDescriptorType);
|
|
||||||
|
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
@ -100,12 +72,16 @@ PythonIntegrationPlugin::PythonIntegrationPlugin(QObject *parent) : IntegrationP
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PythonIntegrationPlugin::~PythonIntegrationPlugin()
|
||||||
|
{
|
||||||
|
m_eventLoop.cancel();
|
||||||
|
m_eventLoop.waitForFinished();
|
||||||
|
}
|
||||||
|
|
||||||
void PythonIntegrationPlugin::initPython()
|
void PythonIntegrationPlugin::initPython()
|
||||||
{
|
{
|
||||||
// TODO: Call this just once and call Py_Finalize()
|
|
||||||
PyImport_AppendInittab("nymea", PyInit_nymea);
|
PyImport_AppendInittab("nymea", PyInit_nymea);
|
||||||
Py_InitializeEx(0);
|
Py_InitializeEx(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PythonIntegrationPlugin::loadScript(const QString &scriptFile)
|
bool PythonIntegrationPlugin::loadScript(const QString &scriptFile)
|
||||||
@ -154,19 +130,14 @@ bool PythonIntegrationPlugin::loadScript(const QString &scriptFile)
|
|||||||
|
|
||||||
s_modules.insert(m_module, m_interpreter);
|
s_modules.insert(m_module, m_interpreter);
|
||||||
|
|
||||||
QtConcurrent::run([=](){
|
// Start an event loop for this plugin in its own thread
|
||||||
|
m_eventLoop = QtConcurrent::run([=](){
|
||||||
PyObject *loop = PyObject_GetAttrString(m_module, "loop");
|
PyObject *loop = PyObject_GetAttrString(m_module, "loop");
|
||||||
dumpError();
|
dumpError();
|
||||||
// PyObject *stop = PyObject_GetAttrString(loop, "stop");
|
|
||||||
// PyObject *call_soon = PyObject_GetAttrString(loop, "call_soon");
|
|
||||||
PyObject *run_forever = PyObject_GetAttrString(loop, "run_forever");
|
PyObject *run_forever = PyObject_GetAttrString(loop, "run_forever");
|
||||||
// PyObject *run_until_complete = PyObject_GetAttrString(loop, "run_until_complete");
|
|
||||||
qCDebug(dcThingManager()) << "Starting python event loop";
|
|
||||||
dumpError();
|
dumpError();
|
||||||
PyObject_CallFunctionObjArgs(run_forever, nullptr);
|
PyObject_CallFunctionObjArgs(run_forever, nullptr);
|
||||||
qCDebug(dcThingManager()) << "stopped python event loop";
|
|
||||||
dumpError();
|
dumpError();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -176,7 +147,6 @@ bool PythonIntegrationPlugin::loadScript(const QString &scriptFile)
|
|||||||
QJsonObject PythonIntegrationPlugin::metaData() const
|
QJsonObject PythonIntegrationPlugin::metaData() const
|
||||||
{
|
{
|
||||||
return QJsonObject::fromVariantMap(m_metaData);
|
return QJsonObject::fromVariantMap(m_metaData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PythonIntegrationPlugin::init()
|
void PythonIntegrationPlugin::init()
|
||||||
@ -208,7 +178,7 @@ void PythonIntegrationPlugin::discoverThings(ThingDiscoveryInfo *info)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyThingDiscoveryInfo *pyInfo = (PyThingDiscoveryInfo*)_PyObject_New(&PyThingDiscoveryInfoType);
|
PyThingDiscoveryInfo *pyInfo = reinterpret_cast<PyThingDiscoveryInfo*>(_PyObject_New(&PyThingDiscoveryInfoType));
|
||||||
pyInfo->ptrObj = info;
|
pyInfo->ptrObj = info;
|
||||||
|
|
||||||
connect(info, &ThingDiscoveryInfo::finished, this, [=](){
|
connect(info, &ThingDiscoveryInfo::finished, this, [=](){
|
||||||
@ -241,7 +211,7 @@ void PythonIntegrationPlugin::setupThing(ThingSetupInfo *info)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyThingSetupInfo *pyInfo = (PyThingSetupInfo*)_PyObject_New(&PyThingSetupInfoType);
|
PyThingSetupInfo *pyInfo = reinterpret_cast<PyThingSetupInfo*>(_PyObject_New(&PyThingSetupInfoType));
|
||||||
pyInfo->ptrObj = info;
|
pyInfo->ptrObj = info;
|
||||||
|
|
||||||
connect(info, &ThingSetupInfo::finished, this, [=](){
|
connect(info, &ThingSetupInfo::finished, this, [=](){
|
||||||
@ -287,7 +257,6 @@ void PythonIntegrationPlugin::exportIds()
|
|||||||
QVariantMap vendor = vendorVariant.toMap();
|
QVariantMap vendor = vendorVariant.toMap();
|
||||||
QString vendorIdName = vendor.value("name").toString() + "VendorId";
|
QString vendorIdName = vendor.value("name").toString() + "VendorId";
|
||||||
QString vendorId = vendor.value("id").toString();
|
QString vendorId = vendor.value("id").toString();
|
||||||
qCDebug(dcThingManager()) << "Exporting:" << vendorIdName;
|
|
||||||
PyModule_AddStringConstant(m_module, vendorIdName.toUtf8(), vendorId.toUtf8());
|
PyModule_AddStringConstant(m_module, vendorIdName.toUtf8(), vendorId.toUtf8());
|
||||||
|
|
||||||
foreach (const QVariant &thingClassVariant, vendor.value("thingClasses").toList()) {
|
foreach (const QVariant &thingClassVariant, vendor.value("thingClasses").toList()) {
|
||||||
@ -297,6 +266,5 @@ void PythonIntegrationPlugin::exportIds()
|
|||||||
PyModule_AddStringConstant(m_module, thingClassIdName.toUtf8(), thingClassId.toUtf8());
|
PyModule_AddStringConstant(m_module, thingClassIdName.toUtf8(), thingClassId.toUtf8());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include <QFuture>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
typedef struct _object PyObject;
|
typedef struct _object PyObject;
|
||||||
@ -17,6 +18,7 @@ class PythonIntegrationPlugin : public IntegrationPlugin
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit PythonIntegrationPlugin(QObject *parent = nullptr);
|
explicit PythonIntegrationPlugin(QObject *parent = nullptr);
|
||||||
|
~PythonIntegrationPlugin();
|
||||||
|
|
||||||
static void initPython();
|
static void initPython();
|
||||||
|
|
||||||
@ -41,6 +43,7 @@ private:
|
|||||||
QVariantMap m_metaData;
|
QVariantMap m_metaData;
|
||||||
PyObject *m_module = nullptr;
|
PyObject *m_module = nullptr;
|
||||||
PyThreadState *m_interpreter = nullptr;
|
PyThreadState *m_interpreter = nullptr;
|
||||||
|
QFuture<void> m_eventLoop;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -21,6 +21,7 @@ RESOURCES += $$top_srcdir/icons.qrc \
|
|||||||
HEADERS += nymeacore.h \
|
HEADERS += nymeacore.h \
|
||||||
integrations/plugininfocache.h \
|
integrations/plugininfocache.h \
|
||||||
integrations/python/pything.h \
|
integrations/python/pything.h \
|
||||||
|
integrations/python/pythingdescriptor.h \
|
||||||
integrations/python/pythingdiscoveryinfo.h \
|
integrations/python/pythingdiscoveryinfo.h \
|
||||||
integrations/python/pythingsetupinfo.h \
|
integrations/python/pythingsetupinfo.h \
|
||||||
integrations/thingmanagerimplementation.h \
|
integrations/thingmanagerimplementation.h \
|
||||||
|
|||||||
@ -89,6 +89,9 @@ Q_DECLARE_LOGGING_CATEGORY(dcMqtt)
|
|||||||
Q_DECLARE_LOGGING_CATEGORY(dcTranslations)
|
Q_DECLARE_LOGGING_CATEGORY(dcTranslations)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(dcCoap)
|
Q_DECLARE_LOGGING_CATEGORY(dcCoap)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(dcI2C)
|
Q_DECLARE_LOGGING_CATEGORY(dcI2C)
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(dcIntegrations)
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(dcJsIntegrations)
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(dcPythonIntegrations)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user