[Nice] [nice/master] Make the g_timeout_add use agent_timeout_add_with_context instead...

Youness Alaoui youness.alaoui at collabora.co.uk
Wed Nov 5 14:01:00 PST 2008


darcs-hash:20080422205137-4f0f6-8911d8cc165b0298a3e009834fe2dbed68cc1ca1.gz
---
 agent/agent-priv.h |    2 ++
 agent/agent.c      |   18 ++++++++++++++++++
 agent/conncheck.c  |   10 ++--------
 agent/discovery.c  |    5 +----
 4 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/agent/agent-priv.h b/agent/agent-priv.h
index e766cf9..ec753ce 100644
--- a/agent/agent-priv.h
+++ b/agent/agent-priv.h
@@ -131,4 +131,6 @@ void agent_signal_initial_binding_request_received (NiceAgent *agent, Stream *st
 
 guint64 agent_candidate_pair_priority (NiceAgent *agent, NiceCandidate *local, NiceCandidate *remote);
 
+guint agent_timeout_add_with_context (NiceAgent *agent, guint interval, GSourceFunc function, gpointer data);
+
 #endif /*_NICE_AGENT_PRIV_H */
diff --git a/agent/agent.c b/agent/agent.c
index 84e4f0c..86a7407 100644
--- a/agent/agent.c
+++ b/agent/agent.c
@@ -1853,3 +1853,21 @@ nice_agent_set_selected_pair (
   g_mutex_unlock (agent->mutex);
   return ret;
 }
+
+
+guint agent_timeout_add_with_context (NiceAgent *agent, guint interval,
+    GSourceFunc function, gpointer data)
+{
+  GSource *source;
+  guint id;
+
+  g_return_val_if_fail (function != NULL, 0);
+
+  source = g_timeout_source_new (interval);
+
+  g_source_set_callback (source, function, data, NULL);
+  id = g_source_attach (source, agent->main_context);
+  g_source_unref (source);
+
+  return id;
+}
diff --git a/agent/conncheck.c b/agent/conncheck.c
index 7ef087d..00d6998 100644
--- a/agent/conncheck.c
+++ b/agent/conncheck.c
@@ -485,18 +485,12 @@ gboolean conn_check_schedule_next (NiceAgent *agent)
 
     /* step: schedule timer if not running yet */
     if (res && agent->conncheck_timer_id == 0) {
-      GSource *source = g_timeout_source_new (agent->timer_ta);
-      g_source_set_callback (source, priv_conn_check_tick, agent, NULL);
-      agent->conncheck_timer_id = g_source_attach (source, agent->main_context);
-      g_source_unref (source);
+      agent->conncheck_timer_id = agent_timeout_add_with_context (agent, agent->timer_ta, priv_conn_check_tick, agent);
     }
 
     /* step: also start the keepalive timer */
     if (agent->keepalive_timer_id == 0) {
-      GSource *source = g_timeout_source_new (NICE_AGENT_TIMER_TR_DEFAULT);
-      g_source_set_callback (source, priv_conn_keepalive_tick, agent, NULL);
-      agent->keepalive_timer_id = g_source_attach (source, agent->main_context);
-      g_source_unref (source);
+      agent->keepalive_timer_id = agent_timeout_add_with_context (agent, NICE_AGENT_TIMER_TR_DEFAULT, priv_conn_keepalive_tick, agent);
     }
 
   }
diff --git a/agent/discovery.c b/agent/discovery.c
index 17d86b3..2281dd7 100644
--- a/agent/discovery.c
+++ b/agent/discovery.c
@@ -597,10 +597,7 @@ void discovery_schedule (NiceAgent *agent)
       /* step: run first iteration immediately */
       gboolean res = priv_discovery_tick_unlocked (agent);
       if (res == TRUE) {
-        GSource *source = g_timeout_source_new (agent->timer_ta);
-        g_source_set_callback (source, priv_discovery_tick, agent, NULL);
-        agent->discovery_timer_id = g_source_attach (source, agent->main_context);
-        g_source_unref (source);
+        agent->discovery_timer_id = agent_timeout_add_with_context (agent, agent->timer_ta, priv_discovery_tick, agent);
       }
     }
   }
-- 
1.5.6.5




More information about the Nice mailing list