Commit dfb316ea authored by Ghislain MARY's avatar Ghislain MARY

Add the linphone_core_new_with_config() function to instantiate a LinphoneCore...

Add the linphone_core_new_with_config() function to instantiate a LinphoneCore given an already existing LpConfig.

This enables the creation of the LpConfig before creating the LinphoneCore.
It is useful on some systems to read some configuration parameters and perform some customization before creating the LinphoneCore.

The LpConfig can now also be created given a factory config filename using the new lp_config_new_with_factory() function.
parent 7db6daa1
...@@ -1218,11 +1218,11 @@ static void misc_config_read (LinphoneCore *lc) { ...@@ -1218,11 +1218,11 @@ static void misc_config_read (LinphoneCore *lc) {
static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, const char *config_path, static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, LpConfig *config, void * userdata)
const char *factory_config_path, void * userdata)
{ {
ms_message("Initializing LinphoneCore %s", linphone_core_get_version()); ms_message("Initializing LinphoneCore %s", linphone_core_get_version());
memset (lc, 0, sizeof (LinphoneCore)); memset (lc, 0, sizeof (LinphoneCore));
lc->config=config;
lc->data=userdata; lc->data=userdata;
lc->ringstream_autorelease=TRUE; lc->ringstream_autorelease=TRUE;
...@@ -1299,10 +1299,6 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta ...@@ -1299,10 +1299,6 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta
lc->msevq=ms_event_queue_new(); lc->msevq=ms_event_queue_new();
ms_set_global_event_queue(lc->msevq); ms_set_global_event_queue(lc->msevq);
lc->config=lp_config_new(config_path);
if (factory_config_path)
lp_config_read_file(lc->config,factory_config_path);
lc->sal=sal_init(); lc->sal=sal_init();
sal_set_user_pointer(lc->sal,lc); sal_set_user_pointer(lc->sal,lc);
sal_set_callbacks(lc->sal,&linphone_sal_callbacks); sal_set_callbacks(lc->sal,&linphone_sal_callbacks);
...@@ -1348,13 +1344,19 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta ...@@ -1348,13 +1344,19 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta
* It is OPTIONAL, use NULL if unneeded. * It is OPTIONAL, use NULL if unneeded.
* @param userdata an opaque user pointer that can be retrieved at any time (for example in * @param userdata an opaque user pointer that can be retrieved at any time (for example in
* callbacks) using linphone_core_get_user_data(). * callbacks) using linphone_core_get_user_data().
* * @see linphone_core_new_with_config
**/ **/
LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable, LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable,
const char *config_path, const char *factory_config_path, void * userdata) const char *config_path, const char *factory_config_path, void * userdata)
{ {
LinphoneCore *core=ms_new(LinphoneCore,1); LpConfig *config = lp_config_new_with_factory(config_path, factory_config_path);
linphone_core_init(core,vtable,config_path, factory_config_path, userdata); return linphone_core_new_with_config(vtable, config, userdata);
}
LinphoneCore *linphone_core_new_with_config(const LinphoneCoreVTable *vtable, struct _LpConfig *config, void *userdata)
{
LinphoneCore *core = ms_new(LinphoneCore, 1);
linphone_core_init(core, vtable, config, userdata);
return core; return core;
} }
......
...@@ -913,6 +913,20 @@ const char *linphone_core_get_user_agent_version(void); ...@@ -913,6 +913,20 @@ const char *linphone_core_get_user_agent_version(void);
LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable, LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable,
const char *config_path, const char *factory_config, void* userdata); const char *config_path, const char *factory_config, void* userdata);
/**
* Instantiates a LinphoneCore object with a given LpConfig.
* @ingroup initializing
*
* The LinphoneCore object is the primary handle for doing all phone actions.
* It should be unique within your application.
* @param vtable a LinphoneCoreVTable structure holding your application callbacks
* @param config a pointer to an LpConfig object holding the configuration of the LinphoneCore to be instantiated.
* @param userdata an opaque user pointer that can be retrieved at any time (for example in
* callbacks) using linphone_core_get_user_data().
* @see linphone_core_new
**/
LinphoneCore *linphone_core_new_with_config(const LinphoneCoreVTable *vtable, struct _LpConfig *config, void *userdata);
/* function to be periodically called in a main loop */ /* function to be periodically called in a main loop */
/* For ICE to work properly it should be called every 20ms */ /* For ICE to work properly it should be called every 20ms */
void linphone_core_iterate(LinphoneCore *lc); void linphone_core_iterate(LinphoneCore *lc);
......
...@@ -211,19 +211,23 @@ void lp_config_parse(LpConfig *lpconfig, FILE *file){ ...@@ -211,19 +211,23 @@ void lp_config_parse(LpConfig *lpconfig, FILE *file){
} }
LpConfig * lp_config_new(const char *filename){ LpConfig * lp_config_new(const char *filename){
return lp_config_new_with_factory(filename, NULL);
}
LpConfig *lp_config_new_with_factory(const char *config_filename, const char *factory_config_filename) {
LpConfig *lpconfig=lp_new0(LpConfig,1); LpConfig *lpconfig=lp_new0(LpConfig,1);
if (filename!=NULL){ if (config_filename!=NULL){
ms_message("Using (r/w) config information from %s", filename); ms_message("Using (r/w) config information from %s", config_filename);
lpconfig->filename=ortp_strdup(filename); lpconfig->filename=ortp_strdup(config_filename);
lpconfig->file=fopen(filename,"r+"); lpconfig->file=fopen(config_filename,"r+");
if (lpconfig->file!=NULL){ if (lpconfig->file!=NULL){
struct stat fileStat; struct stat fileStat;
lp_config_parse(lpconfig,lpconfig->file); lp_config_parse(lpconfig,lpconfig->file);
fclose(lpconfig->file); fclose(lpconfig->file);
#if !defined(_WIN32_WCE) #if !defined(_WIN32_WCE)
if ((stat(filename,&fileStat) == 0) && (S_ISREG(fileStat.st_mode))) { if ((stat(config_filename,&fileStat) == 0) && (S_ISREG(fileStat.st_mode))) {
/* make existing configuration files non-group/world-accessible */ /* make existing configuration files non-group/world-accessible */
if (chmod(filename, S_IRUSR | S_IWUSR) == -1) { if (chmod(config_filename, S_IRUSR | S_IWUSR) == -1) {
ms_warning("unable to correct permissions on " ms_warning("unable to correct permissions on "
"configuration file: %s", strerror(errno)); "configuration file: %s", strerror(errno));
} }
...@@ -233,6 +237,9 @@ LpConfig * lp_config_new(const char *filename){ ...@@ -233,6 +237,9 @@ LpConfig * lp_config_new(const char *filename){
lpconfig->modified=0; lpconfig->modified=0;
} }
} }
if (factory_config_filename != NULL) {
lp_config_read_file(lpconfig, factory_config_filename);
}
return lpconfig; return lpconfig;
} }
......
...@@ -65,7 +65,29 @@ extern "C" { ...@@ -65,7 +65,29 @@ extern "C" {
(config) ? (lp_config_get_float(config, "default_values", name, default)) : (default) (config) ? (lp_config_get_float(config, "default_values", name, default)) : (default)
/**
* Instantiates a LpConfig object from a user config file.
*
* @ingroup misc
* @param filename the filename of the config file to read to fill the instantiated LpConfig
* @see lp_config_new_with_factory
*/
LpConfig * lp_config_new(const char *filename); LpConfig * lp_config_new(const char *filename);
/**
* Instantiates a LpConfig object from a user config file and a factory config file.
*
* @ingroup misc
* @param config_filename the filename of the user config file to read to fill the instantiated LpConfig
* @param factory_config_filename the filename of the factory config file to read to fill the instantiated LpConfig
* @see lp_config_new
*
* The user config file is read first to fill the LpConfig and then the factory config file is read.
* Therefore the configuration parameters defined in the user config file will be overwritten by the parameters
* defined in the factory config file.
*/
LpConfig * lp_config_new_with_factory(const char *config_filename, const char *factory_config_filename);
int lp_config_read_file(LpConfig *lpconfig, const char *filename); int lp_config_read_file(LpConfig *lpconfig, const char *filename);
/** /**
* Retrieves a configuration item as a string, given its section, key, and default value. * Retrieves a configuration item as a string, given its section, key, and default value.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment