From 818fe1306d5a8a52ba3661a6e711e1be21213666 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Tue, 12 Apr 2011 16:39:33 +0200 Subject: [PATCH] add iterate hook --- coreapi/linphonecore.c | 51 ++++++++++++++++++++++++++++++++++-- coreapi/linphonecore_utils.h | 9 ++++++- coreapi/private.h | 1 + 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index b3eabe12..b36245b9 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -39,6 +39,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static const char *liblinphone_version=LIBLINPHONE_VERSION; static void set_network_reachable(LinphoneCore* lc,bool_t isReachable, time_t curtime); +static void linphone_core_run_hooks(LinphoneCore *lc); +static void linphone_core_free_hooks(LinphoneCore *lc); #include "enum.h" const char *linphone_core_get_nat_address_resolved(LinphoneCore *lc); @@ -1734,6 +1736,7 @@ void linphone_core_iterate(LinphoneCore *lc){ if (disconnected) linphone_core_disconnected(lc,call); + linphone_core_run_hooks(lc); linphone_core_do_plugin_tasks(lc); if (lc->initial_subscribes_sent==FALSE && lc->netup_time!=0 && @@ -3901,6 +3904,7 @@ LpConfig *linphone_core_get_config(LinphoneCore *lc){ static void linphone_core_uninit(LinphoneCore *lc) { + linphone_core_free_hooks(lc); while(lc->calls) { LinphoneCall *the_call = lc->calls->data; @@ -4147,7 +4151,7 @@ const char *linphone_error_to_string(LinphoneReason err){ return "unknown error"; } /** - * enable signaling keep alive + * Enables signaling keep alive */ void linphone_core_enable_keep_alive(LinphoneCore* lc,bool_t enable) { if (enable > 0) { @@ -4157,7 +4161,7 @@ void linphone_core_enable_keep_alive(LinphoneCore* lc,bool_t enable) { } } /** - * Is signaling keep alive + * Is signaling keep alive enabled */ bool_t linphone_core_keep_alive_enabled(LinphoneCore* lc) { return sal_get_keepalive_period(lc->sal) > 0; @@ -4173,4 +4177,47 @@ void linphone_core_stop_dtmf_stream(LinphoneCore* lc) { lc->ringstream=NULL; } +typedef struct Hook{ + LinphoneCoreIterateHook fun; + void *data; +}Hook; + +static Hook *hook_new(LinphoneCoreIterateHook hook, void *hook_data){ + Hook *h=ms_new(Hook,1); + h->fun=hook; + h->data=hook_data; + return h; +} + +static void hook_invoke(Hook *h){ + h->fun(h->data); +} + +void linphone_core_add_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook hook, void *hook_data){ + lc->hooks=ms_list_append(lc->hooks,hook_new(hook,hook_data)); +} + +static void linphone_core_run_hooks(LinphoneCore *lc){ + ms_list_for_each(lc->hooks,(void (*)(void*))hook_invoke); +} + +static void linphone_core_free_hooks(LinphoneCore *lc){ + ms_list_for_each(lc->hooks,(void (*)(void*))ms_free); + ms_list_free(lc->hooks); + lc->hooks=NULL; +} + +void linphone_core_remove_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook hook, void *hook_data){ + MSList *elem; + for(elem=lc->hooks;elem!=NULL;elem=elem->next){ + Hook *h=(Hook*)elem->data; + if (h->fun==hook && h->data==hook_data){ + ms_list_remove_link(lc->hooks,elem); + ms_free(h); + return; + } + } + ms_error("linphone_core_remove_iterate_hook(): No such hook found."); +} + diff --git a/coreapi/linphonecore_utils.h b/coreapi/linphonecore_utils.h index 0c7e3233..bd41ec2b 100644 --- a/coreapi/linphonecore_utils.h +++ b/coreapi/linphonecore_utils.h @@ -80,8 +80,15 @@ void linphone_core_start_dtmf_stream(LinphoneCore* lc); */ void linphone_core_stop_dtmf_stream(LinphoneCore* lc); - + +typedef bool_t (*LinphoneCoreIterateHook)(void *data); + +void linphone_core_add_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook hook, void *hook_data); + +void linphone_core_remove_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook hook, void *hook_data); + #ifdef __cplusplus } #endif #endif + diff --git a/coreapi/private.h b/coreapi/private.h index 305e5a05..4fc4db22 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -429,6 +429,7 @@ struct _LinphoneCore unsigned long preview_window_id; time_t netup_time; /*time when network went reachable */ struct _EcCalibrator *ecc; + MSList *hooks; bool_t use_files; bool_t apply_nat_settings; bool_t initial_subscribes_sent; -- 2.39.2