Commit e2ffd505 authored by Pekka Pessi's avatar Pekka Pessi
Browse files

su-glib/su_source.c: fixed whitespace

darcs-hash:20081127230555-db55f-7d863efab2f0b0b0650b74b8b8d880c7f1e688d8.gz
parent ebeb77ba
...@@ -25,15 +25,15 @@ ...@@ -25,15 +25,15 @@
/** /**
* @file su_source.c * @file su_source.c
* @brief Wrapper for glib GSource. * @brief Wrapper for glib GSource.
* *
* Refs: * Refs:
* - http://sofia-sip.sourceforge.net/refdocs/su/group__su__wait.html * - http://sofia-sip.sourceforge.net/refdocs/su/group__su__wait.html
* - http://developer.gnome.org/doc/API/glib/glib-the-main-event-loop.html * - http://developer.gnome.org/doc/API/glib/glib-the-main-event-loop.html
* *
* @author Pekka Pessi <Pekka.Pessi@nokia.com>. * @author Pekka Pessi <Pekka.Pessi@nokia.com>.
* *
* @date Created: Thu Mar 4 15:15:15 2004 ppessi * @date Created: Thu Mar 4 15:15:15 2004 ppessi
* *
*/ */
#include "config.h" #include "config.h"
...@@ -100,28 +100,28 @@ static struct _GSource *su_source_gsource(su_port_t *port); ...@@ -100,28 +100,28 @@ 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_send(su_port_t *self, su_msg_r rmsg);
static int su_source_register(su_port_t *self, static int su_source_register(su_port_t *self,
su_root_t *root, su_root_t *root,
su_wait_t *wait, su_wait_t *wait,
su_wakeup_f callback, su_wakeup_f callback,
su_wakeup_arg_t *arg, su_wakeup_arg_t *arg,
int priority); int priority);
static int su_source_unregister(su_port_t *port, static int su_source_unregister(su_port_t *port,
su_root_t *root, su_root_t *root,
su_wait_t *wait, su_wait_t *wait,
su_wakeup_f callback, su_wakeup_f callback,
su_wakeup_arg_t *arg); su_wakeup_arg_t *arg);
static int su_source_deregister(su_port_t *self, int i); static int su_source_deregister(su_port_t *self, int i);
static int su_source_unregister_all(su_port_t *self, static int su_source_unregister_all(su_port_t *self,
su_root_t *root); su_root_t *root);
static int su_source_eventmask(su_port_t *self, static int su_source_eventmask(su_port_t *self,
int index, int socket, int events); int index, int socket, int events);
static void su_source_run(su_port_t *self); static void su_source_run(su_port_t *self);
static void su_source_break(su_port_t *self); static void su_source_break(su_port_t *self);
static su_duration_t su_source_step(su_port_t *self, su_duration_t tout); static su_duration_t su_source_step(su_port_t *self, su_duration_t tout);
static int su_source_thread(su_port_t *self, enum su_port_thread_op op); static int su_source_thread(su_port_t *self, enum su_port_thread_op op);
static int su_source_add_prepoll(su_port_t *port, static int su_source_add_prepoll(su_port_t *port,
su_root_t *root, su_root_t *root,
su_prepoll_f *, su_prepoll_f *,
su_prepoll_magic_t *); su_prepoll_magic_t *);
static int su_source_remove_prepoll(su_port_t *port, static int su_source_remove_prepoll(su_port_t *port,
su_root_t *root); su_root_t *root);
...@@ -129,7 +129,7 @@ static int su_source_multishot(su_port_t *self, int multishot); ...@@ -129,7 +129,7 @@ static int su_source_multishot(su_port_t *self, int multishot);
static char const *su_source_name(su_port_t const *self); static char const *su_source_name(su_port_t const *self);
static static
su_port_vtable_t const su_source_port_vtable[1] = su_port_vtable_t const su_source_port_vtable[1] =
{{ {{
/* su_vtable_size: */ sizeof su_source_port_vtable, /* su_vtable_size: */ sizeof su_source_port_vtable,
...@@ -169,14 +169,14 @@ static char const *su_source_name(su_port_t const *self) ...@@ -169,14 +169,14 @@ static char const *su_source_name(su_port_t const *self)
return "GSource"; return "GSource";
} }
/** /**
* Port is a per-thread reactor. * Port is a per-thread reactor.
* *
* Multiple root objects executed by single thread share a su_port_t object. * Multiple root objects executed by single thread share a su_port_t object.
*/ */
struct su_source_s { struct su_source_s {
su_base_port_t sup_base[1]; su_base_port_t sup_base[1];
GThread *sup_tid; GThread *sup_tid;
GStaticMutex sup_obtained[1]; GStaticMutex sup_obtained[1];
...@@ -184,20 +184,20 @@ struct su_source_s { ...@@ -184,20 +184,20 @@ struct su_source_s {
GSource *sup_source; /**< Backpointer to source */ GSource *sup_source; /**< Backpointer to source */
GMainLoop *sup_main_loop; /**< Reference to mainloop while running */ GMainLoop *sup_main_loop; /**< Reference to mainloop while running */
/* Waits */ /* Waits */
unsigned sup_registers; /** Counter incremented by unsigned sup_registers; /** Counter incremented by
su_port_register() or su_port_register() or
su_port_unregister() su_port_unregister()
*/ */
unsigned sup_n_waits; unsigned sup_n_waits;
unsigned sup_size_waits; unsigned sup_size_waits;
unsigned sup_max_index; unsigned sup_max_index;
unsigned *sup_indices; unsigned *sup_indices;
su_wait_t *sup_waits; su_wait_t *sup_waits;
su_wakeup_f *sup_wait_cbs; su_wakeup_f *sup_wait_cbs;
su_wakeup_arg_t**sup_wait_args; su_wakeup_arg_t**sup_wait_args;
su_root_t **sup_wait_roots; su_root_t **sup_wait_roots;
}; };
typedef struct _SuSource typedef struct _SuSource
...@@ -243,13 +243,13 @@ su_root_t *su_root_source_create(su_root_magic_t *magic) ...@@ -243,13 +243,13 @@ su_root_t *su_root_source_create(su_root_magic_t *magic)
return su_glib_root_create(magic); return su_glib_root_create(magic);
} }
/** /**
* Returns a GSource object for the root * Returns a GSource object for the root
* *
* Note that you need to unref the GSource with g_source_unref() * Note that you need to unref the GSource with g_source_unref()
* before destroying the root object. * before destroying the root object.
* *
* @return NULL on error (for instance if root was not created with * @return NULL on error (for instance if root was not created with
* su_glib_root_create()) * su_glib_root_create())
*/ */
GSource *su_glib_root_gsource(su_root_t *root) GSource *su_glib_root_gsource(su_root_t *root)
...@@ -299,7 +299,7 @@ static void su_source_port_deinit(su_port_t *self) ...@@ -299,7 +299,7 @@ static void su_source_port_deinit(su_port_t *self)
/** @internal Destroy a port. */ /** @internal Destroy a port. */
static static
void su_source_finalize(GSource *gs) void su_source_finalize(GSource *gs)
{ {
SuSource *ss = (SuSource *)gs; SuSource *ss = (SuSource *)gs;
...@@ -315,7 +315,7 @@ void su_source_port_lock(su_port_t *self, char const *who) ...@@ -315,7 +315,7 @@ void su_source_port_lock(su_port_t *self, char const *who)
g_static_mutex_lock(self->sup_mutex); g_static_mutex_lock(self->sup_mutex);
PORT_LOCK_DEBUG((" ...%p at %s locked(%p)...", PORT_LOCK_DEBUG((" ...%p at %s locked(%p)...",
(void *)g_thread_self(), who, self)); (void *)g_thread_self(), who, self));
} }
...@@ -323,7 +323,7 @@ void su_source_port_unlock(su_port_t *self, char const *who) ...@@ -323,7 +323,7 @@ void su_source_port_unlock(su_port_t *self, char const *who)
{ {
g_static_mutex_unlock(self->sup_mutex); g_static_mutex_unlock(self->sup_mutex);
PORT_LOCK_DEBUG((" ...%p at %s unlocked(%p)\n", PORT_LOCK_DEBUG((" ...%p at %s unlocked(%p)\n",
(void *)g_thread_self(), who, self)); (void *)g_thread_self(), who, self));
} }
...@@ -351,7 +351,7 @@ int su_source_send(su_port_t *self, su_msg_r rmsg) ...@@ -351,7 +351,7 @@ int su_source_send(su_port_t *self, su_msg_r rmsg)
* Change or query ownership of the port object. * Change or query ownership of the port object.
* *
* @param self pointer to a port object * @param self pointer to a port object
* @param op operation * @param op operation
* *
* @ERRORS * @ERRORS
* @ERROR EALREADY port already has an owner (or has no owner) * @ERROR EALREADY port already has an owner (or has no owner)
...@@ -392,7 +392,7 @@ static int su_source_thread(su_port_t *self, enum su_port_thread_op op) ...@@ -392,7 +392,7 @@ static int su_source_thread(su_port_t *self, enum su_port_thread_op op)
/* -- Registering and unregistering ------------------------------------- */ /* -- Registering and unregistering ------------------------------------- */
/* Seconds from 1.1.1900 to 1.1.1970 */ /* Seconds from 1.1.1900 to 1.1.1970 */
#define NTP_EPOCH 2208988800UL #define NTP_EPOCH 2208988800UL
/** Prepare to wait - calculate time to next timer */ /** Prepare to wait - calculate time to next timer */
static static
...@@ -402,7 +402,7 @@ gboolean su_source_prepare(GSource *gs, gint *return_tout) ...@@ -402,7 +402,7 @@ gboolean su_source_prepare(GSource *gs, gint *return_tout)
su_port_t *self = ss->ss_port; su_port_t *self = ss->ss_port;
enter; enter;
if (self->sup_base->sup_head) { if (self->sup_base->sup_head) {
*return_tout = 0; *return_tout = 0;
return TRUE; return TRUE;
...@@ -450,7 +450,7 @@ gboolean su_source_check(GSource *gs) ...@@ -450,7 +450,7 @@ gboolean su_source_check(GSource *gs)
return su_source_prepare(gs, &tout); return su_source_prepare(gs, &tout);
} }
static static
gboolean su_source_dispatch(GSource *gs, gboolean su_source_dispatch(GSource *gs,
GSourceFunc callback, GSourceFunc callback,
gpointer user_data) gpointer user_data)
...@@ -489,8 +489,8 @@ gboolean su_source_dispatch(GSource *gs, ...@@ -489,8 +489,8 @@ gboolean su_source_dispatch(GSource *gs,
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (waits[i].revents) { if (waits[i].revents) {
root = self->sup_wait_roots[i]; root = self->sup_wait_roots[i];
self->sup_wait_cbs[i](root ? su_root_magic(root) : NULL, self->sup_wait_cbs[i](root ? su_root_magic(root) : NULL,
&waits[i], &waits[i],
self->sup_wait_args[i]); self->sup_wait_args[i]);
/* Callback used su_register()/su_unregister() */ /* Callback used su_register()/su_unregister() */
if (version != self->sup_registers) if (version != self->sup_registers)
...@@ -512,7 +512,7 @@ static void su_source_lock(su_port_t *self, char const *who) ...@@ -512,7 +512,7 @@ static void su_source_lock(su_port_t *self, char const *who)
(void *)g_thread_self(), who, self)); (void *)g_thread_self(), who, self));
g_static_mutex_lock(self->sup_mutex); g_static_mutex_lock(self->sup_mutex);
PORT_LOCK_DEBUG((" ...%p at %s locked(%p)...", PORT_LOCK_DEBUG((" ...%p at %s locked(%p)...",
(void *)g_thread_self(), who, self)); (void *)g_thread_self(), who, self));
} }
...@@ -520,7 +520,7 @@ static void su_source_unlock(su_port_t *self, char const *who) ...@@ -520,7 +520,7 @@ static void su_source_unlock(su_port_t *self, char const *who)
{ {
g_static_mutex_unlock(self->sup_mutex); g_static_mutex_unlock(self->sup_mutex);
PORT_LOCK_DEBUG((" ...%p at %s unlocked(%p)\n", PORT_LOCK_DEBUG((" ...%p at %s unlocked(%p)\n",
(void *)g_thread_self(), who, self)); (void *)g_thread_self(), who, self));
} }
...@@ -548,21 +548,21 @@ GSource *su_source_gsource(su_port_t *self) ...@@ -548,21 +548,21 @@ GSource *su_source_gsource(su_port_t *self)
* *
* Please note if identical wait objects are inserted, only first one is * Please note if identical wait objects are inserted, only first one is
* ever signalled. * ever signalled.
* *
* @param self pointer to port * @param self pointer to port
* @param root pointer to root object * @param root pointer to root object
* @param waits pointer to wait object * @param waits pointer to wait object
* @param callback callback function pointer * @param callback callback function pointer
* @param arg argument given to callback function when it is invoked * @param arg argument given to callback function when it is invoked
* @param priority relative priority of the wait object * @param priority relative priority of the wait object
* (0 is normal, 1 important, 2 realtime) * (0 is normal, 1 important, 2 realtime)
* *
* @return * @return
* The function @su_source_register returns nonzero index of the wait object, * The function @su_source_register returns nonzero index of the wait object,
* or -1 upon an error. */ * or -1 upon an error. */
int su_source_register(su_port_t *self, int su_source_register(su_port_t *self,
su_root_t *root, su_root_t *root,
su_wait_t *wait, su_wait_t *wait,
su_wakeup_f callback, su_wakeup_f callback,
su_wakeup_arg_t *arg, su_wakeup_arg_t *arg,
int priority) int priority)
...@@ -571,7 +571,7 @@ int su_source_register(su_port_t *self, ...@@ -571,7 +571,7 @@ int su_source_register(su_port_t *self,
unsigned n; unsigned n;
enter; enter;
assert(SU_SOURCE_OWN_THREAD(self)); assert(SU_SOURCE_OWN_THREAD(self));
n = self->sup_n_waits; n = self->sup_n_waits;
...@@ -587,7 +587,7 @@ int su_source_register(su_port_t *self, ...@@ -587,7 +587,7 @@ int su_source_register(su_port_t *self,
if (self->sup_size_waits == 0) if (self->sup_size_waits == 0)
size = SU_WAIT_MIN; size = SU_WAIT_MIN;
else else
size = 2 * self->sup_size_waits; size = 2 * self->sup_size_waits;
indices = realloc(self->sup_indices, size * sizeof(*indices)); indices = realloc(self->sup_indices, size * sizeof(*indices));
...@@ -600,14 +600,14 @@ int su_source_register(su_port_t *self, ...@@ -600,14 +600,14 @@ int su_source_register(su_port_t *self,
for (i = 0; i < self->sup_n_waits; i++) for (i = 0; i < self->sup_n_waits; i++)
g_source_remove_poll(self->sup_source, (GPollFD*)&self->sup_waits[i]); g_source_remove_poll(self->sup_source, (GPollFD*)&self->sup_waits[i]);
waits = realloc(self->sup_waits, size * sizeof(*waits)); waits = realloc(self->sup_waits, size * sizeof(*waits));
if (waits) if (waits)
self->sup_waits = waits; self->sup_waits = waits;
for (i = 0; i < self->sup_n_waits; i++) for (i = 0; i < self->sup_n_waits; i++)
g_source_add_poll(self->sup_source, (GPollFD*)&waits[i]); g_source_add_poll(self->sup_source, (GPollFD*)&waits[i]);
wait_cbs = realloc(self->sup_wait_cbs, size * sizeof(*wait_cbs)); wait_cbs = realloc(self->sup_wait_cbs, size * sizeof(*wait_cbs));
if (wait_cbs) if (wait_cbs)
self->sup_wait_cbs = wait_cbs; self->sup_wait_cbs = wait_cbs;
...@@ -618,7 +618,7 @@ int su_source_register(su_port_t *self, ...@@ -618,7 +618,7 @@ int su_source_register(su_port_t *self,
/* Add sup_wait_roots array, if needed */ /* Add sup_wait_roots array, if needed */
wait_tasks = realloc(self->sup_wait_roots, size * sizeof(*wait_tasks)); wait_tasks = realloc(self->sup_wait_roots, size * sizeof(*wait_tasks));
if (wait_tasks) if (wait_tasks)
self->sup_wait_roots = wait_tasks; self->sup_wait_roots = wait_tasks;
if (!(indices && waits && wait_cbs && wait_args && wait_tasks)) { if (!(indices && waits && wait_cbs && wait_args && wait_tasks)) {
...@@ -638,7 +638,7 @@ int su_source_register(su_port_t *self, ...@@ -638,7 +638,7 @@ int su_source_register(su_port_t *self,
g_source_add_poll(self->sup_source, (GPollFD*)&self->sup_waits[n]); g_source_add_poll(self->sup_source, (GPollFD*)&self->sup_waits[n]);
self->sup_wait_cbs[n] = self->sup_wait_cbs[n-1]; self->sup_wait_cbs[n] = self->sup_wait_cbs[n-1];
self->sup_wait_args[n] = self->sup_wait_args[n-1]; self->sup_wait_args[n] = self->sup_wait_args[n-1];
self->sup_wait_roots[n] = self->sup_wait_roots[n-1]; self->sup_wait_roots[n] = self->sup_wait_roots[n-1];
} }
} }
else { else {
...@@ -653,13 +653,13 @@ int su_source_register(su_port_t *self, ...@@ -653,13 +653,13 @@ int su_source_register(su_port_t *self,
I = self->sup_max_index; I = self->sup_max_index;
for (i = 0; i < I; i++) for (i = 0; i < I; i++)
if (self->sup_indices[i] == UINT_MAX) if (self->sup_indices[i] == UINT_MAX)
break; break;
else if (self->sup_indices[i] >= n) else if (self->sup_indices[i] >= n)
self->sup_indices[i]++; self->sup_indices[i]++;
if (i == I) if (i == I)
self->sup_max_index++; self->sup_max_index++;
if (n + 1 < self->sup_n_waits) if (n + 1 < self->sup_n_waits)
...@@ -676,23 +676,23 @@ int su_source_register(su_port_t *self, ...@@ -676,23 +676,23 @@ int su_source_register(su_port_t *self,
} }
/** Unregister a su_wait_t object. /** Unregister a su_wait_t object.
* *
* The function su_source_unregister() unregisters a su_wait_t object. The * The function su_source_unregister() unregisters a su_wait_t object. The
* wait object, a callback function and a argument are removed from the * wait object, a callback function and a argument are removed from the
* port object. * port object.
* *
* @param self - pointer to port object * @param self - pointer to port object
* @param root - pointer to root object * @param root - pointer to root object
* @param wait - pointer to wait object * @param wait - pointer to wait object
* @param callback - callback function pointer (may be NULL) * @param callback - callback function pointer (may be NULL)
* @param arg - argument given to callback function when it is invoked * @param arg - argument given to callback function when it is invoked
* (may be NULL) * (may be NULL)
* *
* @return Nonzero index of the wait object, or -1 upon an error. * @return Nonzero index of the wait object, or -1 upon an error.
*/ */
int su_source_unregister(su_port_t *self, int su_source_unregister(su_port_t *self,
su_root_t *root, su_root_t *root,
su_wait_t *wait, su_wait_t *wait,
su_wakeup_f callback, /* XXX - ignored */ su_wakeup_f callback, /* XXX - ignored */
su_wakeup_arg_t *arg) su_wakeup_arg_t *arg)
{ {
...@@ -700,7 +700,7 @@ int su_source_unregister(su_port_t *self, ...@@ -700,7 +700,7 @@ int su_source_unregister(su_port_t *self,
unsigned i, I, j, *indices; unsigned i, I, j, *indices;
enter; enter;
assert(self); assert(self);
assert(SU_SOURCE_OWN_THREAD(self)); assert(SU_SOURCE_OWN_THREAD(self));
...@@ -733,14 +733,14 @@ int su_source_unregister(su_port_t *self, ...@@ -733,14 +733,14 @@ int su_source_unregister(su_port_t *self,
if (self->sup_indices[j] != UINT_MAX && if (self->sup_indices[j] != UINT_MAX &&
self->sup_indices[j] > n) self->sup_indices[j] > n)
self->sup_indices[j]--; self->sup_indices[j]--;
for (; n < N; n++) { for (; n < N; n++) {
g_source_remove_poll(self->sup_source, (GPollFD*)&self->sup_waits[n+1]); g_source_remove_poll(self->sup_source, (GPollFD*)&self->sup_waits[n+1]);
self->sup_waits[n] = self->sup_waits[n+1]; self->sup_waits[n] = self->sup_waits[n+1];
g_source_add_poll(self->sup_source, (GPollFD*)&self->sup_waits[n]); g_source_add_poll(self->sup_source, (GPollFD*)&self->sup_waits[n]);
self->sup_wait_cbs[n] = self->sup_wait_cbs[n+1]; self->sup_wait_cbs[n] = self->sup_wait_cbs[n+1];
self->sup_wait_args[n] = self->sup_wait_args[n+1]; self->sup_wait_args[n] = self->sup_wait_args[n+1];
self->sup_wait_roots[n] = self->sup_wait_roots[n+1]; self->sup_wait_roots[n] = self->sup_wait_roots[n+1];
} }
i += 1; /* 0 is failure */ i += 1; /* 0 is failure */
...@@ -757,14 +757,14 @@ int su_source_unregister(su_port_t *self, ...@@ -757,14 +757,14 @@ int su_source_unregister(su_port_t *self,
} }
/** Deregister a su_wait_t object. /** Deregister a su_wait_t object.
* *
* The function su_source_deregister() deregisters a su_wait_t registrattion. * The function su_source_deregister() deregisters a su_wait_t registrattion.
* The wait object, a callback function and a argument are removed from the * The wait object, a callback function and a argument are removed from the
* port object. * port object.
* *
* @param self - pointer to port object * @param self - pointer to port object
* @param i - registration index * @param i - registration index
* *
* @return Index of the wait object, or -1 upon an error. * @return Index of the wait object, or -1 upon an error.
*/ */
int su_source_deregister(su_port_t *self, int i) int su_source_deregister(su_port_t *self, int i)
...@@ -774,7 +774,7 @@ int su_source_deregister(su_port_t *self, int i) ...@@ -774,7 +774,7 @@ int su_source_deregister(su_port_t *self, int i)
su_wait_t wait[1]; su_wait_t wait[1];
enter; enter;
assert(self); assert(self);
assert(SU_SOURCE_OWN_THREAD(self)); assert(SU_SOURCE_OWN_THREAD(self));
...@@ -810,7 +810,7 @@ int su_source_deregister(su_port_t *self, int i) ...@@ -810,7 +810,7 @@ int su_source_deregister(su_port_t *self, int i)
g_source_add_poll(self->sup_source, (GPollFD*)&self->sup_waits[n]); g_source_add_poll(self->sup_source, (GPollFD*)&self->sup_waits[n]);
self->sup_wait_cbs[n] = self->sup_wait_cbs[n+1]; self->sup_wait_cbs[n] = self->sup_wait_cbs[n+1];
self->sup_wait_args[n] = self->sup_wait_args[n+1]; self->sup_wait_args[n] = self->sup_wait_args[n+1];
self->sup_wait_roots[n] = self->sup_wait_roots[n+1]; self->sup_wait_roots[n] = self->sup_wait_roots[n+1];
} }
indices[i - 1] = UINT_MAX; indices[i - 1] = UINT_MAX;
...@@ -830,13 +830,13 @@ int su_source_deregister(su_port_t *self, int i) ...@@ -830,13 +830,13 @@ int su_source_deregister(su_port_t *self, int i)
* *
* The function su_source_unregister_all() unregisters all su_wait_t objects * The function su_source_unregister_all() unregisters all su_wait_t objects
* associated with given root object destroys all queued timers. * associated with given root object destroys all queued timers.
* *
* @param self - pointer to port object * @param self - pointer to port object
* @param root - pointer to root object * @param root - pointer to root object
* *
* @return Number of wait objects removed. * @return Number of wait objects removed.
*/ */
int su_source_unregister_all(su_port_t *self, int su_source_unregister_all(su_port_t *self,
su_root_t *root) su_root_t *root)
{ {
unsigned i, j; unsigned i, j;
...@@ -847,15 +847,15 @@ int su_source_unregister_all(su_port_t *self, ...@@ -847,15 +847,15 @@ int su_source_unregister_all(su_port_t *self,
su_root_t **wait_roots; su_root_t **wait_roots;