reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
PyExtensionBase.hxx
Go to the documentation of this file.
1#ifndef PY_EXTENSION_BASE_HXX
2#define PY_EXTENSION_BASE_HXX
3
4/* Using the PyCXX API for C++ Python integration
5 * It is extremely convenient and avoids the need to write boilerplate
6 * code for handling the Python reference counts.
7 * It is licensed under BSD terms compatible with reSIProcate */
8
9/* Python C API:
10 * https://docs.python.org/3/c-api/init.html
11 *
12 * PyCXX API:
13 * https://cxx.sourceforge.net/PyCXX-Python3.html */
14
15#include <Python.h>
16#include <CXX/Objects.hxx>
17#include <CXX/Extensions.hxx>
18
19#include "PyThreadSupport.hxx"
20
21namespace resip
22{
23
24class PyExtensionBase : public Py::ExtensionModule<PyExtensionBase>
25{
26
27 public:
28 PyExtensionBase(const resip::Data& exportModuleName);
29 virtual ~PyExtensionBase();
30
31 // methods that can be called from Python
32 Py::Object logStack(const Py::Tuple &args);
33 Py::Object logDebug(const Py::Tuple &args);
34 Py::Object logInfo(const Py::Tuple &args);
35 Py::Object logWarning(const Py::Tuple &args);
36 Py::Object logErr(const Py::Tuple &args);
37 Py::Object logCrit(const Py::Tuple &args);
38
39 std::unique_ptr<PyExternalUser> createPyExternalUser();
40
41 protected:
42 virtual void initMethods();
43 virtual void appendPath(const resip::Data& path);
44 virtual bool checkPyArgs(const resip::Data& method, const Py::Tuple &args, unsigned int minArgs, unsigned int maxArgs);
45 virtual bool logPythonErrorIfAny();
46 virtual std::unique_ptr<Py::Module> loadModule(const resip::Data& moduleName);
47 virtual void importModule(PyObject *pyModule, const resip::Data& moduleImport);
48 virtual bool init(const resip::Data& pyPath);
49
50 virtual bool onStartup() = 0;
51
52 private:
53 const resip::Data mExportModuleName;
54 PyThreadState* mThreadState;
55 const resip::Data mLogPrefix;
56 PyInterpreterState* mInterpreterState;
57
58};
59
60};
61
62#endif
63
64/* ====================================================================
65
66 Copyright (c) 2022, Software Freedom Institute https://softwarefreedom.institute
67 Copyright (c) 2022, Daniel Pocock https://danielpocock.com
68 All rights reserved.
69
70 Redistribution and use in source and binary forms, with or without
71 modification, are permitted provided that the following conditions are
72 met:
73
74 1. Redistributions of source code must retain the above copyright
75 notice, this list of conditions and the following disclaimer.
76
77 2. Redistributions in binary form must reproduce the above copyright
78 notice, this list of conditions and the following disclaimer in the
79 documentation and/or other materials provided with the distribution.
80
81 3. Neither the name of Plantronics nor the names of its contributors
82 may be used to endorse or promote products derived from this
83 software without specific prior written permission.
84
85 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
86 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
87 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
88 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
89 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
90 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
91 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
92 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
93 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
94 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
95 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
96
97 ==================================================================== */
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
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)
Py::Object logWarning(const Py::Tuple &args)
virtual bool logPythonErrorIfAny()
Py::Object logDebug(const Py::Tuple &args)
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)
Py::Object logInfo(const Py::Tuple &args)
dcm! – add UnusedChecking(_enum) below;