]> sjero.net Git - linphone/commitdiff
add iterate hook
authorSimon Morlat <simon.morlat@linphone.org>
Tue, 12 Apr 2011 14:39:33 +0000 (16:39 +0200)
committerSimon Morlat <simon.morlat@linphone.org>
Tue, 12 Apr 2011 14:39:33 +0000 (16:39 +0200)
coreapi/linphonecore.c
coreapi/linphonecore_utils.h
coreapi/private.h

index b3eabe12ffe8446570226de01098432683d2b23c..b36245b9ad3bbe8ab108f3928d77828c82b42c41 100644 (file)
@@ -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.");
+}
+
 
index 0c7e3233bef46817f528d6742fd6132c4b263689..bd41ec2b9e9b1b9dd1440a39c3e98f5a9930bbc6 100644 (file)
@@ -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
+
index 305e5a05c84eb38926aee32045b8e9cad6b237d4..4fc4db22d6e56e4fbc9238bdad51b0bb9dd454b5 100644 (file)
@@ -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;