Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
liblinphone
Commits
860b2344
Commit
860b2344
authored
Aug 11, 2014
by
Ghislain MARY
Browse files
Allow any callable as linphone core callbacks and log handler in the Python wrapper.
parent
87eb75d3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
6 deletions
+12
-6
tools/python/apixml2python/handwritten.mustache
tools/python/apixml2python/handwritten.mustache
+10
-4
tools/python/apixml2python/linphone.py
tools/python/apixml2python/linphone.py
+2
-2
No files found.
tools/python/apixml2python/handwritten.mustache
View file @
860b2344
...
...
@@ -17,7 +17,7 @@ static void pylinphone_log(const char *level, int indent, const char *fmt, va_li
linphone_module = PyImport_ImportModule("linphone");
if ((linphone_module != NULL)
&&
PyObject_HasAttrString(linphone_module, "__log_handler")) {
PyObject *log_handler = PyObject_GetAttrString(linphone_module, "__log_handler");
if ((log_handler != NULL)
&&
Py
Function
_Check(log_handler)) {
if ((log_handler != NULL)
&&
Py
Callable
_Check(log_handler)) {
char logstr[4096];
int i = 0;
if (indent == -1) current_indent--;
...
...
@@ -29,7 +29,9 @@ static void pylinphone_log(const char *level, int indent, const char *fmt, va_li
}
if
(indent =
=
1)
current_indent
++;
if
(
vsnprintf
(
logstr
+
i
,
sizeof
(
logstr
)
-
i
,
fmt
,
args
)
>
0) {
PyEval_CallFunction(log_handler, "ss", level, logstr);
if (PyEval_CallObject(log_handler, Py_BuildValue("ss", level, logstr)) == NULL) {
PyErr_Print();
}
}
Py_DECREF(log_handler);
}
...
...
@@ -73,10 +75,10 @@ static void pylinphone_module_log_handler(OrtpLogLevel lev, const char *fmt, va_
level = pylinphone_ortp_log_level_to_string(lev);
if ((linphone_module != NULL)
&&
PyObject_HasAttrString(linphone_module, "__log_handler")) {
PyObject *log_handler = PyObject_GetAttrString(linphone_module, "__log_handler");
if ((log_handler != NULL)
&&
Py
Function
_Check(log_handler)) {
if ((log_handler != NULL)
&&
Py
Callable
_Check(log_handler)) {
char logstr[4096];
if (vsnprintf(logstr, sizeof(logstr), fmt, args) > 0) {
if (PyEval_Call
Function
(log_handler, "ss", level, logstr) == NULL) {
if (PyEval_Call
Object
(log_handler,
Py_BuildValue(
"ss", level, logstr)
)
== NULL) {
PyErr_Print();
}
}
...
...
@@ -100,6 +102,10 @@ static PyObject * pylinphone_module_method_set_log_handler(PyObject *self, PyObj
if (!PyArg_ParseTuple(args, "O",
&
callback)) {
return NULL;
}
if (!PyCallable_Check(callback)) {
PyErr_SetString(PyExc_TypeError, "The argument must be a callable");
return NULL;
}
if (linphone_module != NULL) {
Py_INCREF(callback);
PyObject_SetAttrString(linphone_module, "__log_handler", callback);
...
...
tools/python/apixml2python/linphone.py
View file @
860b2344
...
...
@@ -635,8 +635,8 @@ class EventCallbackMethodDefinition(MethodDefinition):
args
.
append
(
arg_name
)
args
=
', '
.
join
(
args
)
return
\
""" if ((func != NULL) && Py
Function
_Check(func)) {{
if (PyEval_Call
Function(func,
"{fmt}", {args}) == NULL) {{
""" if ((func != NULL) && Py
Callable
_Check(func)) {{
if (PyEval_Call
Object(func, Py_BuildValue(
"{fmt}", {args})
)
== NULL) {{
PyErr_Print();
}}
}}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment