* Call a python callback (if set) * @param callback the callback to call * @param arglist the arguments to pass to the callback * @return 0 if the callback failed, the result returned by python otherwise */
| 111 | * @return 0 if the callback failed, the result returned by python otherwise |
| 112 | */ |
| 113 | int CallPythonCallback(enum libcecSwigCallback callback, PyObject* arglist) |
| 114 | { |
| 115 | int retval = 0; |
| 116 | |
| 117 | if (callback >= NB_PYTHON_CB || !m_callbacks[callback]) |
| 118 | return retval; |
| 119 | |
| 120 | PyObject* result = nullptr; |
| 121 | if (!!m_callbacks[callback]) |
| 122 | { |
| 123 | /** call the callback */ |
| 124 | #if (PY_MAJOR_VERSION < 3) |
| 125 | result = PyEval_CallObject(m_callbacks[callback], arglist); |
| 126 | #else // (PY_MAJOR_VERSION >= 3) |
| 127 | result = PyObject_CallObject(m_callbacks[callback], arglist); |
| 128 | #endif |
| 129 | |
| 130 | /** unref the argument and result */ |
| 131 | if (!!arglist) |
| 132 | Py_DECREF(arglist); |
| 133 | if (!!result) |
| 134 | { |
| 135 | if (PyInt_Check(result)) |
| 136 | retval = (int)PyInt_AsLong(result); |
| 137 | Py_XDECREF(result); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | return retval; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Set a python callable as callback |
nothing calls this directly
no outgoing calls
no test coverage detected