[Freeswitch-svn] [commit] r11853 - in freeswitch/trunk/libs/sofia-sip: . libsofia-sip-ua-glib/su-glib libsofia-sip-ua/su libsofia-sip-ua/su/sofia-sip

FreeSWITCH SVN mikej at freeswitch.org
Wed Feb 11 09:17:50 PST 2009


Author: mikej
Date: Wed Feb 11 11:17:49 2009
New Revision: 11853

Log:
Wed Jan 28 12:07:02 CST 2009  Pekka Pessi <first.last at nokia.com>
  * su: added API functions su_timer_is_set() and su_timer_latest()
  



Modified:
   freeswitch/trunk/libs/sofia-sip/.update
   freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua-glib/su-glib/su_source.c
   freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_wait.h
   freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_timer.c

Modified: freeswitch/trunk/libs/sofia-sip/.update
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/.update	(original)
+++ freeswitch/trunk/libs/sofia-sip/.update	Wed Feb 11 11:17:49 2009
@@ -1 +1 @@
-Wed Feb 11 11:16:35 CST 2009
+Wed Feb 11 11:17:39 CST 2009

Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua-glib/su-glib/su_source.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua-glib/su-glib/su_source.c	(original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua-glib/su-glib/su_source.c	Wed Feb 11 11:17:49 2009
@@ -97,8 +97,6 @@
 static void su_source_decref(su_port_t *self, int blocking, char const *who);
 static struct _GSource *su_source_gsource(su_port_t *port);
 
-static int su_source_send(su_port_t *self, su_msg_r rmsg);
-
 static int su_source_register(su_port_t *self,
 			    su_root_t *root,
 			    su_wait_t *wait,
@@ -126,6 +124,8 @@
 static int su_source_remove_prepoll(su_port_t *port,
 				  su_root_t *root);
 static int su_source_multishot(su_port_t *self, int multishot);
+static int su_source_wakeup(su_port_t *self);
+static int su_source_is_running(su_port_t *self);
 
 static char const *su_source_name(su_port_t const *self);
 
@@ -141,7 +141,7 @@
 
       su_source_gsource,
 
-      su_source_send,
+      su_base_port_send,
       su_source_register,
       su_source_unregister,
       su_source_deregister,
@@ -162,6 +162,10 @@
       su_base_port_start_shared,
       su_base_port_wait,
       NULL,
+      su_base_port_deferrable,
+      su_base_port_max_defer,
+      su_source_wakeup,
+      su_source_is_running,
     }};
 
 static char const *su_source_name(su_port_t const *self)
@@ -308,37 +312,10 @@
   su_source_port_deinit(ss->ss_port);
 }
 
-void su_source_port_lock(su_port_t *self, char const *who)
-{
-  PORT_LOCK_DEBUG(("%p at %s locking(%p)...",
-		   (void *)g_thread_self(), who, self));
-
-  g_static_mutex_lock(self->sup_mutex);
-
-  PORT_LOCK_DEBUG((" ...%p at %s locked(%p)...",
-		   (void *)g_thread_self(), who, self));
-}
-
-void su_source_port_unlock(su_port_t *self, char const *who)
-{
-  g_static_mutex_unlock(self->sup_mutex);
-
-  PORT_LOCK_DEBUG((" ...%p at %s unlocked(%p)\n",
-		   (void *)g_thread_self(), who, self));
-}
-
 /** @internal Send a message to the port. */
-int su_source_send(su_port_t *self, su_msg_r rmsg)
+int su_source_wakeup(su_port_t *self)
 {
-  int wakeup = su_base_port_send(self, rmsg);
-  GMainContext *gmc;
-
-  if (wakeup < 0)
-    return -1;
-  if (wakeup == 0)
-    return 0;
-
-  gmc = g_source_get_context(self->sup_source);
+  GMainContext *gmc = g_source_get_context(self->sup_source);
 
   if (gmc)
     g_main_context_wakeup(gmc);
@@ -837,7 +814,7 @@
  * @return Number of wait objects removed.
  */
 int su_source_unregister_all(su_port_t *self,
-			   su_root_t *root)
+			     su_root_t *root)
 {
   unsigned i, j;
   unsigned         n_waits;
@@ -881,8 +858,7 @@
 
 /**Set mask for a registered event. @internal
  *
- * The function su_source_eventmask() sets the mask describing events that can
- * signal the registered callback.
+ * Sets the mask describing events that can signal the registered callback.
  *
  * @param port   pointer to port object
  * @param index  registration index
@@ -892,6 +868,7 @@
  * @retval 0 when successful,
  * @retval -1 upon an error.
  */
+static
 int su_source_eventmask(su_port_t *self, int index, int socket, int events)
 {
   unsigned n;
@@ -932,15 +909,13 @@
 }
 
 
-/** @internal Main loop.
- *
- * The function @c su_source_run() runs the main loop
+/** @internal Run the main loop.
  *
- * The function @c su_source_run() runs until @c su_source_break() is called
- * from a callback.
+ * The main loop runs until su_source_break() is called from a callback.
  *
- * @param self     pointer to root object
+ * @param self     pointer to port object
  * */
+static
 void su_source_run(su_port_t *self)
 {
   GMainContext *gmc;
@@ -959,6 +934,11 @@
   }
 }
 
+static int su_source_is_running(su_port_t *self)
+{
+  return self->sup_main_loop && g_main_loop_is_running(self->sup_main_loop);
+}
+
 /** @internal
  * The function @c su_source_break() is used to terminate execution of @c
  * su_source_run(). It can be called from a callback function.
@@ -966,6 +946,7 @@
  * @param self     pointer to port
  *
  */
+static
 void su_source_break(su_port_t *self)
 {
   enter;
@@ -1112,4 +1093,3 @@
 {
   su_port_prefer(su_source_port_create, NULL);
 }
-

Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_wait.h
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_wait.h	(original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_wait.h	Wed Feb 11 11:17:49 2009
@@ -491,6 +491,8 @@
 SOFIAPUBFUN su_timer_t *su_timer_create(su_task_r const, su_duration_t msec)
      __attribute__((__malloc__));
 SOFIAPUBFUN void su_timer_destroy(su_timer_t *);
+SOFIAPUBFUN int su_timer_is_set(su_timer_t const *t); /* 1.12.11 */
+SOFIAPUBFUN su_time_t su_timer_latest(su_timer_t const *t);
 SOFIAPUBFUN int su_timer_set(su_timer_t *, su_timer_f, su_timer_arg_t *);
 SOFIAPUBFUN int su_timer_set_interval(su_timer_t *t, su_timer_f,
 				      su_timer_arg_t *, su_duration_t);
@@ -506,7 +508,7 @@
 SOFIAPUBFUN int su_timer_expire(su_timer_queue_t * const,
 				su_duration_t *tout,
 				su_time_t now);
-SOFIAPUBFUN int su_timer_deferrable(su_timer_t *t, int value);
+SOFIAPUBFUN int su_timer_deferrable(su_timer_t *t, int value); /* 1.12.11 */
 
 /* Tasks */
 

Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_timer.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_timer.c	(original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_timer.c	Wed Feb 11 11:17:49 2009
@@ -157,12 +157,11 @@
 
 struct su_timer_s {
   su_task_r       sut_task;	/**< Task reference */
-  size_t          sut_heap_index; /**< Timer is set (inserted in heap) */
+  size_t          sut_set;	/**< Timer is set (inserted in heap) */
   su_time_t       sut_when;	/**< When timer should be waken up next time */
   su_duration_t   sut_duration;	/**< Timer duration */
   su_timer_f      sut_wakeup;	/**< Function to call when waken up */
   su_timer_arg_t *sut_arg;	/**< Pointer to argument data */
-  su_time_t       sut_run;	/**< When this timer was last waken up */
   unsigned        sut_woken;	/**< Timer has waken up this many times */
 
   unsigned        sut_running:2;/**< Timer is running */
@@ -176,13 +175,13 @@
   run_for_ever = 2	/**< Do not compensate  */
 };
 
-#define SU_TIMER_IS_SET(sut) ((sut)->sut_heap_index != 0)
+#define SU_TIMER_IS_SET(sut) ((sut)->sut_set != 0)
 
 HEAP_DECLARE(su_inline, su_timer_queue_t, timers_, su_timer_t *);
 
 su_inline void timers_set(su_timer_t **array, size_t index, su_timer_t *t)
 {
-  array[t->sut_heap_index = index] = t;
+  array[t->sut_set = index] = t;
 }
 
 su_inline int timers_less(su_timer_t *a, su_timer_t *b)
@@ -224,7 +223,7 @@
     return -1;
 
   if (SU_TIMER_IS_SET(t))
-    timers_remove(timers[0], t->sut_heap_index);
+    timers_remove(timers[0], t->sut_set);
 
   t->sut_wakeup = wakeup;
   t->sut_arg = arg;
@@ -328,6 +327,37 @@
   }
 }
 
+/** Check if the timer has been set.
+ *
+ * @param t pointer to a timer object
+ *
+ * @return Nonzero if set, zero if reset.
+ *
+ * @NEW_1_12_11
+ */
+int su_timer_is_set(su_timer_t const *t)
+{
+  return t && t->sut_set != 0;
+}
+
+/**Return when the timer has been last expired.
+ *
+ * @param t pointer to a timer object
+ *
+ * @return Timestamp (as returned by su_time()).
+ *
+ * @note If the timer is running (set with su_timer_run()), the returned
+ * timestamp not the actual time but it is rather calculated from the
+ * initial timestamp.
+ *
+ * @NEW_1_12_11
+ */
+su_time_t su_timer_latest(su_timer_t const *t)
+{
+  su_time_t tv = { 0, 0 };
+
+  return t ? t->sut_when : tv;
+}
 
 /** Set the timer for the given @a interval.
  *
@@ -415,16 +445,14 @@
 		 su_timer_arg_t *arg)
 {
   su_timer_queue_t *timers = su_timer_queue(t, 1, "su_timer_run");
-  su_time_t now;
 
   if (timers == NULL)
     return -1;
 
   t->sut_running = run_at_intervals;
-  t->sut_run = now = su_now();
   t->sut_woken = 0;
 
-  return su_timer_set0(timers, t, wakeup, arg, now, t->sut_duration);
+  return su_timer_set0(timers, t, wakeup, arg, su_now(), t->sut_duration);
 }
 
 /**Set the timer for regular intervals.
@@ -448,16 +476,14 @@
 			  su_timer_arg_t *arg)
 {
   su_timer_queue_t *timers = su_timer_queue(t, 1, "su_timer_set_for_ever");
-  su_time_t now;
 
   if (timers == NULL)
     return -1;
 
   t->sut_running = run_for_ever;
-  t->sut_run = now = su_now();
   t->sut_woken = 0;
 
-  return su_timer_set0(timers, t, wakeup, arg, now, t->sut_duration);
+  return su_timer_set0(timers, t, wakeup, arg, su_now(), t->sut_duration);
 }
 
 /**Reset the timer.
@@ -476,14 +502,12 @@
     return -1;
 
   if (SU_TIMER_IS_SET(t))
-    timers_remove(timers[0], t->sut_heap_index);
+    timers_remove(timers[0], t->sut_set);
 
   t->sut_wakeup = NULL;
   t->sut_arg = NULL;
   t->sut_running = reset;
 
-  memset(&t->sut_run, 0, sizeof(t->sut_run));
-
   return 0;
 }
 
@@ -528,12 +552,13 @@
 
     if (t->sut_running == run_at_intervals) {
       while (t->sut_running == run_at_intervals &&
+	     t->sut_set == 0 &&
 	     t->sut_duration > 0) {
 	if (su_time_diff(t->sut_when, now) > 0) {
-	  su_timer_set0(timers, t, f, t->sut_arg, t->sut_run, 0);
+	  su_timer_set0(timers, t, f, t->sut_arg, t->sut_when, 0);
 	  break;
 	}
-	t->sut_when = t->sut_run = su_time_add(t->sut_run, t->sut_duration);
+	t->sut_when = su_time_add(t->sut_when, t->sut_duration);
 	t->sut_woken++;
 	f(su_root_magic(su_task_root(t->sut_task)), t, t->sut_arg), n++;
       }
@@ -542,7 +567,7 @@
       t->sut_woken++;
       t->sut_when = now;
       f(su_root_magic(su_task_root(t->sut_task)), t, t->sut_arg), n++;
-      if (t->sut_running == run_for_ever)
+      if (t->sut_running == run_for_ever && t->sut_set == 0)
 	su_timer_set0(timers, t, f, t->sut_arg, now, t->sut_duration);
     }
     else {



More information about the Freeswitch-svn mailing list