Changes to be able to call lp_config_get_sections_names from python wrapper

This commit is contained in:
Sylvain Berfini 2015-10-21 14:50:10 +02:00
parent 8ab1343c16
commit 67c22d57ee
5 changed files with 47 additions and 16 deletions

View file

@ -878,15 +878,22 @@ err:
return -1;
}
static void get_sections_names_cb(const char *section, void *ctx) {
MSList **list = (MSList**)ctx;
*list = ms_list_append(*list, (void*)ms_strdup(section));
}
const MSList* lp_config_get_sections_names(LpConfig *lpconfig) {
MSList *result = NULL;
lp_config_for_each_section(lpconfig, get_sections_names_cb, &result);
return result;
const char** lp_config_get_sections_names(LpConfig *lpconfig) {
const char **sections_names;
const MSList *sections = lpconfig->sections;
int ndev;
int i;
ndev = ms_list_size(sections);
sections_names = ms_malloc((ndev + 1) * sizeof(const char *));
for (i = 0; sections != NULL; sections = sections->next, i++) {
LpSection *section = (LpSection *)sections->data;
sections_names[i] = ms_strdup(section->name);
}
sections_names[ndev] = NULL;
return sections_names;
}
char* lp_config_dump_as_xml(const LpConfig *lpconfig) {

View file

@ -201,15 +201,11 @@ LINPHONE_PUBLIC int lp_config_has_section(const LpConfig *lpconfig, const char *
LINPHONE_PUBLIC void lp_config_clean_section(LpConfig *lpconfig, const char *section);
/**
* Returns the list of the sections' names in the config.
* Returns the list of sections' names in the LpConfig.
* @param[in] lpconfig The LpConfig object
* @return \mslist{const char*}
*
* This list is unmodifiable. The ->data field of the MSList points to a const char*.
*
* @ingroup misc
* @return a null terminated static array of strings
**/
LINPHONE_PUBLIC const MSList * lp_config_get_sections_names(LpConfig *lpconfig);
LINPHONE_PUBLIC const char** lp_config_get_sections_names(LpConfig *lpconfig);
/**
* Call a function for each section present in the configuration.

View file

@ -83,6 +83,7 @@ hand_written_functions = [
HandWrittenProperty('Core', 'sip_transports_used', 'linphone_core_get_sip_transports_used', None, "[:py:class:`linphone.SipTransports`] Retrieves the real port number assigned for each sip transport (udp, tcp, tls). A zero value means that the transport is not activated. If LC_SIP_TRANSPORT_RANDOM was passed to :py:attr:`linphone.Core.sip_transports`, the random port choosed by the system is returned."),
HandWrittenProperty('Core', 'sound_devices', 'linphone_core_get_sound_devices', None, "[list of string] Get the available sound devices."),
HandWrittenProperty('Core', 'video_devices', 'linphone_core_get_video_devices', None, "[list of string] Get the available video capture devices."),
HandWrittenProperty('LpConfig', 'sections_names', 'lp_config_get_sections_names', None, "[list of string] Get the sections' names in the lp config."),
HandWrittenClassMethod('Core', 'new', 'linphone_core_new', "Instantiate a LinphoneCore object.\n\n:param vtable: The callbacks.\n:type vtable: dictionary\n:param configPath: A path to a config file. If it does not exists it will be created. The config file is used to store all settings, call logs, friends, proxies... so that all these settings become persistent over the life of the LinphoneCore object. It is allowed to set to None. In that case LinphoneCore will not store any settings.\n:type configPath: string\n:param factoryConfigPath: A path to a read-only config file that can be used to store hard-coded preference such as proxy settings or internal preferences. The settings in this factory file always override the one in the normal config file. It is OPTIONAL, use None if unneeded.\n:type factoryConfigPath: string\n:rtype: linphone.Core"),
HandWrittenClassMethod('Core', 'new_with_config', 'linphone_core_new_with_config', "Instantiate a LinphoneCore object from a LpConfig.\n\n:param vtable: The callbacks.\n:type vtable: dictionary\n:param config: A LpConfig object holding the configuration of the LinphoneCore to be instantiated.\n:rtype: linphone.Core"),
HandWrittenDeallocMethod('Core', 'linphone_core_destroy')

View file

@ -40,3 +40,5 @@ static int pylinphone_Buffer_set_content(PyObject *self, PyObject *value, void *
static PyObject * pylinphone_Content_get_buffer(PyObject *self, void *closure);
static int pylinphone_Content_set_buffer(PyObject *self, PyObject *value, void *closure);
static PyObject * pylinphone_LpConfig_get_sections_names(PyObject *self, void *closure);

View file

@ -970,3 +970,28 @@ static int pylinphone_Content_set_buffer(PyObject *self, PyObject *value, void *
pylinphone_trace(-1, "[PYLINPHONE] <<< %s -> 0", __FUNCTION__);
return 0;
}
static PyObject * pylinphone_LpConfig_get_sections_names(PyObject *self, void *closure) {
PyObject *_list;
const char **_names;
LpConfig *native_ptr = pylinphone_LpConfig_get_native_ptr(self);
if (native_ptr == NULL) {
PyErr_SetString(PyExc_TypeError, "Invalid linphone.LpConfig instance");
return NULL;
}
pylinphone_trace(1, "[PYLINPHONE] >>> %s(%p [%p])", __FUNCTION__, self, native_ptr);
_names = lp_config_get_sections_names(native_ptr);
pylinphone_dispatch_messages();
_list = PyList_New(0);
while (*_names != NULL) {
PyObject *_item = PyString_FromString(*_names);
PyList_Append(_list, _item);
_names++;
}
pylinphone_trace(-1, "[PYLINPHONE] <<< %s -> %p", __FUNCTION__, _list);
return _list;
}