10#include <CXX/Objects.hxx>
11#include <CXX/Extensions.hxx>
21#define RESIPROCATE_SUBSYSTEM resip::Subsystem::PYTHON
28 mExportModuleName(exportModuleName),
29 mThreadState(nullptr),
30 mLogPrefix(mExportModuleName)
38 PyEval_RestoreThread(mThreadState);
49 DebugLog(<<
"python invoked C method: " << method);
50 if(args.size() < minArgs)
52 ErrLog(<< method <<
" called with insufficient arguments");
55 if(args.size() > maxArgs)
57 ErrLog(<< method <<
" called with excess arguments, only using first argument(s)");
67 throw Py::TypeError(
"insufficient number of arguments");
69 const Py::String& text(args[0]);
70 StackLog(<<
'[' << mLogPrefix <<
"] " << text);
79 throw Py::TypeError(
"insufficient number of arguments");
81 const Py::String& text(args[0]);
82 DebugLog(<<
'[' << mLogPrefix <<
"] " << text);
91 throw Py::TypeError(
"insufficient number of arguments");
93 const Py::String& text(args[0]);
94 InfoLog(<<
'[' << mLogPrefix <<
"] " << text);
103 throw Py::TypeError(
"insufficient number of arguments");
105 const Py::String& text(args[0]);
106 WarningLog(<<
'[' << mLogPrefix <<
"] " << text);
115 throw Py::TypeError(
"insufficient number of arguments");
117 const Py::String& text(args[0]);
118 ErrLog(<<
'[' << mLogPrefix <<
"] " << text);
127 throw Py::TypeError(
"insufficient number of arguments");
129 const Py::String& text(args[0]);
130 CritLog(<<
'[' << mLogPrefix <<
"] " << text);
149 PyObject *sys_path = PySys_GetObject(
"path");
150 PyObject *addpath = PyUnicode_FromString(path.
c_str());
151 PyList_Append(sys_path, addpath);
157 if (PyErr_Occurred()) {
159 ErrLog(<<
"Python exception: " << Py::value(ex));
168 PyObject *thisModule = module().ptr();
169 PyDict_SetItemString(PyModule_GetDict(pyModule), moduleImport.
c_str(), thisModule);
172std::unique_ptr<Py::Module>
175 PyObject *_pyModule = PyImport_ImportModule(moduleName.
c_str());
178 ErrLog(<<
"Failed to load module "<< moduleName);
189 std::unique_ptr<Py::Module> pyModule(
new Py::Module(_pyModule));
194std::unique_ptr<PyExternalUser>
197 std::unique_ptr<PyExternalUser> p(
new PyExternalUser(mInterpreterState));
206#if PY_VERSION_HEX < 0x03070000
209 PyEval_InitThreads();
213 initialize(
"reSIProcate SIP stack API callbacks");
218 mThreadState = PyThreadState_GET();
220#if PY_VERSION_HEX < 0x03090000
221 mInterpreterState = mThreadState->interp;
224 mInterpreterState = PyInterpreterState_Get();
230 PyEval_ReleaseThread(mThreadState);
235 PyEval_ReleaseThread(mThreadState);
#define WarningLog(args_)
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
const char * c_str() const
Returns a null-terminated string representing.
virtual bool onStartup()=0
virtual std::unique_ptr< Py::Module > loadModule(const resip::Data &moduleName)
virtual void importModule(PyObject *pyModule, const resip::Data &moduleImport)
virtual bool checkPyArgs(const resip::Data &method, const Py::Tuple &args, unsigned int minArgs, unsigned int maxArgs)
Py::Object logErr(const Py::Tuple &args)
Py::Object logStack(const Py::Tuple &args)
virtual ~PyExtensionBase()
Py::Object logWarning(const Py::Tuple &args)
virtual bool logPythonErrorIfAny()
Py::Object logDebug(const Py::Tuple &args)
virtual void initMethods()
std::unique_ptr< PyExternalUser > createPyExternalUser()
Py::Object logCrit(const Py::Tuple &args)
virtual void appendPath(const resip::Data &path)
virtual bool init(const resip::Data &pyPath)
PyExtensionBase(const resip::Data &exportModuleName)
Py::Object logInfo(const Py::Tuple &args)
dcm! – add UnusedChecking(_enum) below;