summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2010-02-12 19:28:52 +0000
committerCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2010-02-12 19:28:52 +0000
commite2263c445821df94b3ad37665a67d3e50cc89baa (patch)
tree7e14a5a9096bc71f2b9381e91675d13ba7487df7
parentf98202be757469238c311aa952fd3d01f40bd69b (diff)
Action chain module created
* moved action-chain related funcs to action-chain module * remove action-chain related funcs from utils * included action-chain.h where needed and added to Makefile.am
-rw-r--r--telepathy-logger/Makefile.am2
-rw-r--r--telepathy-logger/action-chain.c106
-rw-r--r--telepathy-logger/action-chain.h44
-rw-r--r--telepathy-logger/channel-text.c1
-rw-r--r--telepathy-logger/channel.c1
-rw-r--r--telepathy-logger/util.c100
-rw-r--r--telepathy-logger/util.h28
7 files changed, 162 insertions, 120 deletions
diff --git a/telepathy-logger/Makefile.am b/telepathy-logger/Makefile.am
index 5ffeb4453..91ef407cd 100644
--- a/telepathy-logger/Makefile.am
+++ b/telepathy-logger/Makefile.am
@@ -17,6 +17,7 @@ lib_LTLIBRARIES = libtelepathy-logger.la
LIBTPLdir = $(includedir)/telepathy-logger
LIBTPL_HEADERS = \
+ action-chain.h \
contact.h \
channel.h \
channel-text.h \
@@ -32,6 +33,7 @@ LIBTPL_HEADERS = \
libtelepathy_logger_la_SOURCES = \
+ action-chain.c \
channel.c \
channel-factory.c \
channel-text.c \
diff --git a/telepathy-logger/action-chain.c b/telepathy-logger/action-chain.c
new file mode 100644
index 000000000..f5975db40
--- /dev/null
+++ b/telepathy-logger/action-chain.c
@@ -0,0 +1,106 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk>
+ */
+
+#include "action-chain.h"
+
+TplActionChain *
+tpl_actionchain_new (GObject *obj,
+ GAsyncReadyCallback cb,
+ gpointer user_data)
+{
+ TplActionChain *ret = g_slice_new0 (TplActionChain);
+
+ ret->chain = g_queue_new ();
+ ret->simple = g_simple_async_result_new (obj, cb, user_data,
+ tpl_actionchain_finish);
+
+ return ret;
+}
+
+
+void
+tpl_actionchain_free (TplActionChain *self)
+{
+ g_queue_free (self->chain);
+ /* TODO free self->simple, I canont understand how */
+ g_slice_free (TplActionChain, self);
+}
+
+
+gpointer
+tpl_actionchain_get_object (TplActionChain *self)
+{
+ g_return_val_if_fail (self != NULL && self->simple != NULL, NULL);
+
+ return g_async_result_get_source_object (G_ASYNC_RESULT (self->simple));
+}
+
+
+void
+tpl_actionchain_prepend (TplActionChain *self,
+ TplPendingAction func)
+{
+ g_queue_push_head (self->chain, func);
+}
+
+
+void
+tpl_actionchain_append (TplActionChain *self,
+ TplPendingAction func)
+{
+ g_queue_push_tail (self->chain, func);
+}
+
+
+void
+tpl_actionchain_continue (TplActionChain *self)
+{
+ if (g_queue_is_empty (self->chain))
+ {
+ GSimpleAsyncResult *simple = self->simple;
+ tpl_actionchain_free (self);
+ g_simple_async_result_set_op_res_gboolean ((GSimpleAsyncResult *) simple, TRUE);
+ g_simple_async_result_complete (simple);
+ }
+ else
+ {
+ TplPendingAction next_action = g_queue_pop_head (self->chain);
+ next_action (self);
+ }
+}
+
+
+void
+tpl_actionchain_terminate (TplActionChain *self)
+{
+ GSimpleAsyncResult *simple = self->simple;
+
+ tpl_actionchain_free (self);
+ g_simple_async_result_set_op_res_gboolean ((GSimpleAsyncResult *) simple, FALSE);
+ g_simple_async_result_complete (simple);
+}
+
+
+gboolean
+tpl_actionchain_finish (GAsyncResult *result)
+{
+ return g_simple_async_result_get_op_res_gboolean ((GSimpleAsyncResult *) result);
+}
diff --git a/telepathy-logger/action-chain.h b/telepathy-logger/action-chain.h
new file mode 100644
index 000000000..f5027e1d6
--- /dev/null
+++ b/telepathy-logger/action-chain.h
@@ -0,0 +1,44 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk>
+ */
+
+#ifndef __TPL_ACTION_CHAIN_H__
+#define __TPL_ACTION_CHAIN_H__
+
+#include <glib-object.h>
+#include <gio/gio.h>
+
+typedef struct {
+ GQueue *chain;
+ GSimpleAsyncResult *simple;
+} TplActionChain;
+
+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);
+void tpl_actionchain_continue (TplActionChain *self);
+void tpl_actionchain_terminate (TplActionChain *self);
+gpointer tpl_actionchain_get_object (TplActionChain *self);
+gboolean tpl_actionchain_finish (GAsyncResult *result);
+
+#endif // __TPL_ACTION_CHAIN_H__
diff --git a/telepathy-logger/channel-text.c b/telepathy-logger/channel-text.c
index d8de7edd3..e270042ad 100644
--- a/telepathy-logger/channel-text.c
+++ b/telepathy-logger/channel-text.c
@@ -32,6 +32,7 @@
#include <telepathy-glib/contact.h>
#include <telepathy-glib/enums.h>
+#include <telepathy-logger/action-chain.h>
#include <telepathy-logger/contact.h>
#include <telepathy-logger/channel.h>
#include <telepathy-logger/observer.h>
diff --git a/telepathy-logger/channel.c b/telepathy-logger/channel.c
index cc524d0fe..7bc4d9bc3 100644
--- a/telepathy-logger/channel.c
+++ b/telepathy-logger/channel.c
@@ -26,6 +26,7 @@
#include <glib.h>
#include <telepathy-glib/util.h>
+#include <telepathy-logger/action-chain.h>
#include <telepathy-logger/channel-text.h>
#include <telepathy-logger/observer.h>
diff --git a/telepathy-logger/util.c b/telepathy-logger/util.c
index 5a48d80b1..8a7ac7795 100644
--- a/telepathy-logger/util.c
+++ b/telepathy-logger/util.c
@@ -23,109 +23,9 @@
#include <telepathy-glib/util.h>
-void
-tpl_object_unref_if_not_null (gpointer data)
-{
- if (data && G_IS_OBJECT (data))
- g_object_unref (data);
-}
-
-
-void
-tpl_object_ref_if_not_null (gpointer data)
-{
- if (data && G_IS_OBJECT (data))
- g_object_ref (data);
-}
-
-
gboolean
tpl_strequal (const gchar *left,
const gchar *right)
{
return !tp_strdiff (left, right);
}
-
-
-TplActionChain *
-tpl_actionchain_new (GObject *obj,
- GAsyncReadyCallback cb,
- gpointer user_data)
-{
- TplActionChain *ret = g_slice_new0 (TplActionChain);
-
- ret->chain = g_queue_new ();
- ret->simple = g_simple_async_result_new (obj, cb, user_data,
- tpl_actionchain_finish);
-
- return ret;
-}
-
-
-void
-tpl_actionchain_free (TplActionChain *self)
-{
- g_queue_free (self->chain);
- /* TODO free self->simple, I canont understand how */
- g_slice_free (TplActionChain, self);
-}
-
-
-gpointer
-tpl_actionchain_get_object (TplActionChain *self)
-{
- g_return_val_if_fail (self != NULL && self->simple != NULL, NULL);
-
- return g_async_result_get_source_object (G_ASYNC_RESULT (self->simple));
-}
-
-
-void
-tpl_actionchain_prepend (TplActionChain *self,
- TplPendingAction func)
-{
- g_queue_push_head (self->chain, func);
-}
-
-
-void
-tpl_actionchain_append (TplActionChain *self,
- TplPendingAction func)
-{
- g_queue_push_tail (self->chain, func);
-}
-
-
-void
-tpl_actionchain_continue (TplActionChain *self)
-{
- if (g_queue_is_empty (self->chain))
- {
- GSimpleAsyncResult *simple = self->simple;
- tpl_actionchain_free (self);
- g_simple_async_result_set_op_res_gboolean ((GSimpleAsyncResult *) simple, TRUE);
- g_simple_async_result_complete (simple);
- }
- else
- {
- TplPendingAction next_action = g_queue_pop_head (self->chain);
- next_action (self);
- }
-}
-
-
-void
-tpl_actionchain_terminate (TplActionChain *self)
-{
- GSimpleAsyncResult *simple = self->simple;
-
- tpl_actionchain_free (self);
- g_simple_async_result_set_op_res_gboolean ((GSimpleAsyncResult *) simple, FALSE);
- g_simple_async_result_complete (simple);
-}
-
-gboolean
-tpl_actionchain_finish (GAsyncResult *result)
-{
- return g_simple_async_result_get_op_res_gboolean ((GSimpleAsyncResult *) result);
-}
diff --git a/telepathy-logger/util.h b/telepathy-logger/util.h
index 678004752..190207af1 100644
--- a/telepathy-logger/util.h
+++ b/telepathy-logger/util.h
@@ -19,14 +19,15 @@
* Authors: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk>
*/
-#ifndef __TPL_UTILS_H__
-#define __TPL_UTILS_H__
+#ifndef __TPL_UTIL_H__
+#define __TPL_UTIL_H__
#include <glib-object.h>
#include <gio/gio.h>
#define TPL_GET_PRIV(obj,type) ((type##Priv *) ((type *) obj)->priv)
#define TPL_STR_EMPTY(x) ((x) == NULL || (x)[0] == '\0')
+
#define tpl_call_with_err_if_fail(guard, obj, PREFIX, POSTFIX, msg, func, user_data) \
if (!(guard)) \
{ \
@@ -41,25 +42,12 @@
return; \
}
-typedef struct {
- GQueue *chain;
- GSimpleAsyncResult *simple;
-} TplActionChain;
+#define tpl_object_unref_if_not_null(obj) if (obj != NULL && G_IS_OBJECT (obj)) \
+ g_object_unref (obj);
+#define tpl_object_ref_if_not_null(obj) if (obj != NULL && G_IS_OBJECT (obj)) \
+ g_object_ref (obj);
-void tpl_object_unref_if_not_null (void *data);
-void tpl_object_ref_if_not_null (void *data);
gboolean tpl_strequal (const gchar *left, const gchar *right);
-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);
-void tpl_actionchain_continue (TplActionChain *self);
-void tpl_actionchain_terminate (TplActionChain *self);
-gpointer tpl_actionchain_get_object (TplActionChain *self);
-gboolean tpl_actionchain_finish (GAsyncResult *result);
-
-#endif // __TPL_UTILS_H__
+#endif // __TPL_UTIL_H__