diff options
Diffstat (limited to 'telepathy-logger')
-rw-r--r-- | telepathy-logger/action-chain.c | 43 | ||||
-rw-r--r-- | telepathy-logger/action-chain.h | 8 | ||||
-rw-r--r-- | telepathy-logger/channel-text.c | 56 | ||||
-rw-r--r-- | telepathy-logger/channel.c | 24 |
4 files changed, 92 insertions, 39 deletions
diff --git a/telepathy-logger/action-chain.c b/telepathy-logger/action-chain.c index 7d4af57..e2dbbbb 100644 --- a/telepathy-logger/action-chain.c +++ b/telepathy-logger/action-chain.c @@ -22,6 +22,12 @@ #include "config.h" #include "action-chain.h" +typedef struct { + TplPendingAction action; + gpointer user_data; +} TplActionLink; + + TplActionChain * tpl_actionchain_new (GObject *obj, GAsyncReadyCallback cb, @@ -37,9 +43,18 @@ tpl_actionchain_new (GObject *obj, } +static void +link_free (gpointer data, + gpointer user_data) +{ + g_slice_free (TplActionLink, data); +} + + void tpl_actionchain_free (TplActionChain *self) { + g_queue_foreach (self->chain, link_free, NULL); g_queue_free (self->chain); /* TODO free self->simple, I canont understand how */ g_slice_free (TplActionChain, self); @@ -57,17 +72,31 @@ tpl_actionchain_get_object (TplActionChain *self) void tpl_actionchain_prepend (TplActionChain *self, - TplPendingAction func) + TplPendingAction func, + gpointer user_data) { - g_queue_push_head (self->chain, func); + TplActionLink *link; + + link = g_slice_new0 (TplActionLink); + link->action = func; + link->user_data = user_data; + + g_queue_push_head (self->chain, link); } void tpl_actionchain_append (TplActionChain *self, - TplPendingAction func) + TplPendingAction func, + gpointer user_data) { - g_queue_push_tail (self->chain, func); + TplActionLink *link; + + link = g_slice_new0 (TplActionLink); + link->action = func; + link->user_data = user_data; + + g_queue_push_tail (self->chain, link); } @@ -83,8 +112,10 @@ tpl_actionchain_continue (TplActionChain *self) } else { - TplPendingAction next_action = g_queue_pop_head (self->chain); - next_action (self); + TplActionLink *link = g_queue_pop_head (self->chain); + + link->action (self, link->user_data); + g_slice_free (TplActionLink, link); } } diff --git a/telepathy-logger/action-chain.h b/telepathy-logger/action-chain.h index f5027e1..75621fc 100644 --- a/telepathy-logger/action-chain.h +++ b/telepathy-logger/action-chain.h @@ -33,9 +33,11 @@ typedef struct { TplActionChain *tpl_actionchain_new (GObject *obj, GAsyncReadyCallback cb, gpointer user_data); void tpl_actionchain_free (TplActionChain *self); -typedef void (*TplPendingAction) (TplActionChain *ctx); -void tpl_actionchain_append (TplActionChain *self, TplPendingAction func); -void tpl_actionchain_prepend (TplActionChain *self, TplPendingAction func); +typedef void (*TplPendingAction) (TplActionChain *ctx, gpointer user_data); +void tpl_actionchain_append (TplActionChain *self, TplPendingAction func, + gpointer user_data); +void tpl_actionchain_prepend (TplActionChain *self, TplPendingAction func, + gpointer user_data); void tpl_actionchain_continue (TplActionChain *self); void tpl_actionchain_terminate (TplActionChain *self); gpointer tpl_actionchain_get_object (TplActionChain *self); diff --git a/telepathy-logger/channel-text.c b/telepathy-logger/channel-text.c index ee62527..159e237 100644 --- a/telepathy-logger/channel-text.c +++ b/telepathy-logger/channel-text.c @@ -78,16 +78,23 @@ static void on_sent_signal_cb (TpChannel *proxy, guint arg_Timestamp, static void on_send_error_cb (TpChannel *proxy, guint arg_Error, guint arg_Timestamp, guint arg_Type, const gchar *arg_Text, gpointer user_data, GObject *weak_object); -static void pendingproc_connect_signals (TplActionChain *ctx); -static void pendingproc_get_pending_messages (TplActionChain *ctx); -static void pendingproc_prepare_tpl_channel (TplActionChain *ctx); -static void pendingproc_get_chatroom_id (TplActionChain *ctx); +static void pendingproc_connect_signals (TplActionChain *ctx, + gpointer user_data); +static void pendingproc_get_pending_messages (TplActionChain *ctx, + gpointer user_data); +static void pendingproc_prepare_tpl_channel (TplActionChain *ctx, + gpointer user_data); +static void pendingproc_get_chatroom_id (TplActionChain *ctx, + gpointer user_data); static void get_chatroom_id_cb (TpConnection *proxy, const gchar **identifiers, const GError *error, gpointer user_data, GObject *weak_object); -static void pendingproc_get_my_contact (TplActionChain *ctx); -static void pendingproc_get_remote_contact (TplActionChain *ctx); -static void pendingproc_get_remote_handle_type (TplActionChain *ctx); +static void pendingproc_get_my_contact (TplActionChain *ctx, + gpointer user_data); +static void pendingproc_get_remote_contact (TplActionChain *ctx, + gpointer user_data); +static void pendingproc_get_remote_handle_type (TplActionChain *ctx, + gpointer user_data); static void keepon_on_receiving_signal (TplLogEntryText *log); @@ -157,7 +164,8 @@ got_contact_cb (TpConnection *connection, static void -pendingproc_get_remote_contact (TplActionChain *ctx) +pendingproc_get_remote_contact (TplActionChain *ctx, + gpointer user_data) { TplChannelText *tpl_text = tpl_actionchain_get_object (ctx); TplChannel *tpl_chan = TPL_CHANNEL (tpl_text); @@ -174,7 +182,8 @@ pendingproc_get_remote_contact (TplActionChain *ctx) static void -pendingproc_get_my_contact (TplActionChain *ctx) +pendingproc_get_my_contact (TplActionChain *ctx, + gpointer user_data) { TplChannelText *tpl_text = tpl_actionchain_get_object (ctx); TpConnection *tp_conn = tp_channel_borrow_connection ( @@ -188,7 +197,8 @@ pendingproc_get_my_contact (TplActionChain *ctx) static void -pendingproc_get_remote_handle_type (TplActionChain *ctx) +pendingproc_get_remote_handle_type (TplActionChain *ctx, + gpointer user_data) { TplChannelText *tpl_text = tpl_actionchain_get_object (ctx); TpHandleType remote_handle_type; @@ -198,10 +208,10 @@ pendingproc_get_remote_handle_type (TplActionChain *ctx) switch (remote_handle_type) { case TP_HANDLE_TYPE_CONTACT: - tpl_actionchain_prepend (ctx, pendingproc_get_remote_contact); + tpl_actionchain_prepend (ctx, pendingproc_get_remote_contact, NULL); break; case TP_HANDLE_TYPE_ROOM: - tpl_actionchain_prepend (ctx, pendingproc_get_chatroom_id); + tpl_actionchain_prepend (ctx, pendingproc_get_chatroom_id, NULL); break; case TP_HANDLE_TYPE_NONE: PATH_DEBUG (tpl_text, "HANDLE_TYPE_NONE received, probably an anonymous " @@ -472,18 +482,19 @@ tpl_channel_text_call_when_ready (TplChannelText *self, * are unreferenced by g_object_unref but used by a next action AND what object are actually not * prepared but used anyway */ actions = tpl_actionchain_new (G_OBJECT (self), cb, user_data); - tpl_actionchain_append (actions, pendingproc_connect_signals); - tpl_actionchain_append (actions, pendingproc_prepare_tpl_channel); - tpl_actionchain_append (actions, pendingproc_get_my_contact); - tpl_actionchain_append (actions, pendingproc_get_remote_handle_type); - tpl_actionchain_append (actions, pendingproc_get_pending_messages); + tpl_actionchain_append (actions, pendingproc_connect_signals, NULL); + tpl_actionchain_append (actions, pendingproc_prepare_tpl_channel, NULL); + tpl_actionchain_append (actions, pendingproc_get_my_contact, NULL); + tpl_actionchain_append (actions, pendingproc_get_remote_handle_type, NULL); + tpl_actionchain_append (actions, pendingproc_get_pending_messages, NULL); /* start the chain consuming */ tpl_actionchain_continue (actions); } static void -pendingproc_prepare_tpl_channel (TplActionChain *ctx) +pendingproc_prepare_tpl_channel (TplActionChain *ctx, + gpointer user_data) { TplChannel *tpl_chan = TPL_CHANNEL (tpl_actionchain_get_object (ctx)); @@ -509,7 +520,8 @@ got_tpl_chan_ready_cb (GObject *obj, static void -pendingproc_get_pending_messages (TplActionChain *ctx) +pendingproc_get_pending_messages (TplActionChain *ctx, + gpointer user_data) { TplChannelText *chan_text = tpl_actionchain_get_object (ctx); @@ -567,7 +579,8 @@ got_pending_messages_cb (TpChannel *proxy, static void -pendingproc_get_chatroom_id (TplActionChain *ctx) +pendingproc_get_chatroom_id (TplActionChain *ctx, + gpointer user_data) { TplChannelText *tpl_text = tpl_actionchain_get_object (ctx); TplChannel *tpl_chan = TPL_CHANNEL (tpl_text); @@ -612,7 +625,8 @@ get_chatroom_id_cb (TpConnection *proxy, static void -pendingproc_connect_signals (TplActionChain *ctx) +pendingproc_connect_signals (TplActionChain *ctx, + gpointer user_data) { TplChannelText *tpl_text = tpl_actionchain_get_object (ctx); GError *error = NULL; diff --git a/telepathy-logger/channel.c b/telepathy-logger/channel.c index 7772f4c..814d73e 100644 --- a/telepathy-logger/channel.c +++ b/telepathy-logger/channel.c @@ -41,13 +41,16 @@ static void tpl_channel_set_account (TplChannel *self, TpAccount *data); static void call_when_ready_protected (TplChannel *self, GAsyncReadyCallback cb, gpointer user_data); -static void pendingproc_get_ready_tp_connection (TplActionChain *ctx); +static void pendingproc_get_ready_tp_connection (TplActionChain *ctx, + gpointer user_data); static void got_ready_tp_connection_cb (TpConnection *connection, const GError *error, gpointer user_data); -static void pendingproc_get_ready_tp_channel (TplActionChain *ctx); +static void pendingproc_get_ready_tp_channel (TplActionChain *ctx, + gpointer user_data); static void got_ready_tp_channel_cb (TpChannel *channel, const GError *error, gpointer user_data); -static void pendingproc_register_tpl_channel (TplActionChain *ctx); +static void pendingproc_register_tpl_channel (TplActionChain *ctx, + gpointer user_data); G_DEFINE_ABSTRACT_TYPE (TplChannel, tpl_channel, TP_TYPE_CHANNEL) @@ -229,15 +232,16 @@ call_when_ready_protected (TplChannel *self, TplActionChain *actions; actions = tpl_actionchain_new (G_OBJECT (self), cb, user_data); - tpl_actionchain_append (actions, pendingproc_get_ready_tp_connection); - tpl_actionchain_append (actions, pendingproc_get_ready_tp_channel); - tpl_actionchain_append (actions, pendingproc_register_tpl_channel); + tpl_actionchain_append (actions, pendingproc_get_ready_tp_connection, NULL); + tpl_actionchain_append (actions, pendingproc_get_ready_tp_channel, NULL); + tpl_actionchain_append (actions, pendingproc_register_tpl_channel, NULL); tpl_actionchain_continue (actions); } static void -pendingproc_get_ready_tp_connection (TplActionChain *ctx) +pendingproc_get_ready_tp_connection (TplActionChain *ctx, + gpointer user_data) { TplChannel *tpl_chan = tpl_actionchain_get_object (ctx); TpConnection *tp_conn = tp_channel_borrow_connection (TP_CHANNEL ( @@ -272,7 +276,8 @@ got_ready_tp_connection_cb (TpConnection *connection, } static void -pendingproc_get_ready_tp_channel (TplActionChain *ctx) +pendingproc_get_ready_tp_channel (TplActionChain *ctx, + gpointer user_data) { TplChannel *tpl_chan = tpl_actionchain_get_object (ctx); @@ -311,7 +316,8 @@ got_ready_tp_channel_cb (TpChannel *channel, static void -pendingproc_register_tpl_channel (TplActionChain *ctx) +pendingproc_register_tpl_channel (TplActionChain *ctx, + gpointer user_data) { /* singleton */ TplObserver *observer = tpl_observer_new (); |