mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-04-23 07:58:30 +00:00
Define methods to get string representation of enum values in the Python wrapper.
This commit is contained in:
parent
c420236597
commit
123e4ccdfe
2 changed files with 30 additions and 4 deletions
|
|
@ -181,16 +181,42 @@ static PyTypeObject pylinphone_{{class_name}}Type = {
|
||||||
|
|
||||||
|
|
||||||
static PyMethodDef pylinphone_ModuleMethods[] = {
|
static PyMethodDef pylinphone_ModuleMethods[] = {
|
||||||
/* Sentinel */
|
|
||||||
{ "set_log_handler", pylinphone_module_method_set_log_handler, METH_VARARGS, "" },
|
{ "set_log_handler", pylinphone_module_method_set_log_handler, METH_VARARGS, "" },
|
||||||
|
/* Sentinel */
|
||||||
{ NULL, NULL, 0, NULL }
|
{ NULL, NULL, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static PyMethodDef pylinphone_NoMethods[] = {
|
{{#enums}}
|
||||||
|
static PyObject * pylinphone_{{enum_name}}_module_method_string(PyObject *self, PyObject *args) {
|
||||||
|
const char *value_str = "[invalid]";
|
||||||
|
int value;
|
||||||
|
PyObject *pyret;
|
||||||
|
if (!PyArg_ParseTuple(args, "i", &value)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
pylinphone_trace(1, "[PYLINPHONE] >>> %s(%d)", __FUNCTION__, value);
|
||||||
|
switch (value) {
|
||||||
|
{{#enum_values}}
|
||||||
|
case {{enum_value_cname}}:
|
||||||
|
value_str = "{{enum_value_name}}";
|
||||||
|
break;
|
||||||
|
{{/enum_values}}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pyret = Py_BuildValue("z", value_str);
|
||||||
|
pylinphone_trace(-1, "[PYLINPHONE] <<< %s -> %p", __FUNCTION__, pyret);
|
||||||
|
return pyret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyMethodDef pylinphone_{{enum_name}}_ModuleMethods[] = {
|
||||||
|
{ "string", pylinphone_{{enum_name}}_module_method_string, METH_VARARGS, "" },
|
||||||
/* Sentinel */
|
/* Sentinel */
|
||||||
{ NULL, NULL, 0, NULL }
|
{ NULL, NULL, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
{{/enums}}
|
||||||
|
|
||||||
PyMODINIT_FUNC initlinphone(void) {
|
PyMODINIT_FUNC initlinphone(void) {
|
||||||
PyObject *m;
|
PyObject *m;
|
||||||
PyObject *menum;
|
PyObject *menum;
|
||||||
|
|
@ -205,7 +231,7 @@ PyMODINIT_FUNC initlinphone(void) {
|
||||||
if (m == NULL) return;
|
if (m == NULL) return;
|
||||||
|
|
||||||
{{#enums}}
|
{{#enums}}
|
||||||
menum = Py_InitModule3("{{enum_name}}", pylinphone_NoMethods, {{{enum_doc}}});
|
menum = Py_InitModule3("{{enum_name}}", pylinphone_{{enum_name}}_ModuleMethods, {{{enum_doc}}});
|
||||||
if (menum == NULL) return;
|
if (menum == NULL) return;
|
||||||
if (PyModule_AddObject(m, "{{enum_name}}", menum) < 0) return;
|
if (PyModule_AddObject(m, "{{enum_name}}", menum) < 0) return;
|
||||||
{{#enum_values}}
|
{{#enum_values}}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ class RegisterStatusResponse(Response):
|
||||||
self.body += \
|
self.body += \
|
||||||
"""Id: {id}
|
"""Id: {id}
|
||||||
State: {state}
|
State: {state}
|
||||||
""".format(id=id, state=str(proxy_cfg.state))
|
""".format(id=id, state=str(linphone.RegistrationState.string(proxy_cfg.state)))
|
||||||
|
|
||||||
class CommandExample:
|
class CommandExample:
|
||||||
def __init__(self, command, output):
|
def __init__(self, command, output):
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue