blob: 106558ac1e649f883263a7a783b1ee4ad00e8ec8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include <lib/base/nconfig.h>
#include <lib/python/python.h>
ePyObject ePythonConfigQuery::m_queryFunc;
void ePythonConfigQuery::setQueryFunc(ePyObject queryFunc)
{
if (m_queryFunc)
Py_DECREF(m_queryFunc);
m_queryFunc = queryFunc;
if (m_queryFunc)
Py_INCREF(m_queryFunc);
}
RESULT ePythonConfigQuery::getConfigValue(const char *key, std::string &value)
{
if (key && PyCallable_Check(m_queryFunc))
{
ePyObject pArgs = PyTuple_New(1);
PyTuple_SET_ITEM(pArgs, 0, PyString_FromString(key));
ePyObject pRet = PyObject_CallObject(m_queryFunc, pArgs);
Py_DECREF(pArgs);
if (pRet)
{
if (PyString_Check(pRet))
{
value.assign(PyString_AS_STRING(pRet));
Py_DECREF(pRet);
return 0;
}
Py_DECREF(pRet);
}
}
return -1;
}
|