summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2010-01-26 18:47:22 +0000
committerCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2010-01-26 18:47:22 +0000
commit70a0538a65ac9104cea1263e99f3a51ff098d7b3 (patch)
treed655b3b6c98b73eb49408595767128aba3c296ff
parentbc1357f1ae1bd00e9be7cfe000c605568e65afd0 (diff)
Refactring of TplChannel as subclass of TpChannel
-rw-r--r--telepathy-logger/channel-text.c127
-rw-r--r--telepathy-logger/channel.c332
-rw-r--r--telepathy-logger/channel.h41
-rw-r--r--telepathy-logger/log-entry-text.c4
-rw-r--r--telepathy-logger/log-entry.c13
-rw-r--r--telepathy-logger/observer.c109
-rw-r--r--telepathy-logger/observer.h12
7 files changed, 312 insertions, 326 deletions
diff --git a/telepathy-logger/channel-text.c b/telepathy-logger/channel-text.c
index 16d827593..55dc843a6 100644
--- a/telepathy-logger/channel-text.c
+++ b/telepathy-logger/channel-text.c
@@ -59,7 +59,9 @@ _channel_on_closed_cb (TpChannel *proxy,
TplChannel *tpl_chan = tpl_text_channel_get_tpl_channel (tpl_text);
gchar *chan_path;
- chan_path = g_strdup (tpl_channel_get_channel_path (tpl_chan));
+ /* set chan_path from the TpConnection's property */
+ g_object_get (G_OBJECT (tp_channel_borrow_connection (TP_CHANNEL (tpl_chan))),
+ "object-path", &chan_path, NULL);
if (!tpl_channel_unregister_from_observer (tpl_chan))
g_warning ("Channel %s couldn't be unregistered correctly (BUG?)",
@@ -288,11 +290,10 @@ _channel_on_received_signal_cb (TpChannel *proxy,
tpl_log_entry_text_set_timestamp (log, (time_t) arg_Timestamp);
- tp_connection_get_contacts_by_handle (tpl_channel_get_connection (tpl_chan),
- 1, &remote_handle,
- TP_CONTACT_FEATURES_LEN, features,
- _channel_on_received_signal_with_contact_cb,
- log, g_object_unref, NULL);
+ tp_connection_get_contacts_by_handle (tp_channel_borrow_connection (
+ TP_CHANNEL (tpl_chan)), 1, &remote_handle, TP_CONTACT_FEATURES_LEN,
+ features, _channel_on_received_signal_with_contact_cb, log,
+ g_object_unref, NULL);
g_object_unref (tpl_contact_receiver);
}
@@ -325,11 +326,10 @@ _tpl_text_channel_pendingproc_connect_signals (TplTextChannel *self)
GError *error = NULL;
TpChannel *channel = NULL;
- channel = tpl_channel_get_channel (tpl_text_channel_get_tpl_channel (self));
+ channel = TP_CHANNEL (tpl_text_channel_get_tpl_channel (self));
tp_cli_channel_type_text_connect_to_received (channel,
- _channel_on_received_signal_cb,
- self, NULL, NULL, &error);
+ _channel_on_received_signal_cb, self, NULL, NULL, &error);
if (error != NULL)
{
g_error ("received signal connect: %s", error->message);
@@ -339,8 +339,7 @@ _tpl_text_channel_pendingproc_connect_signals (TplTextChannel *self)
}
tp_cli_channel_type_text_connect_to_sent (channel,
- _channel_on_sent_signal_cb, self,
- NULL, NULL, &error);
+ _channel_on_sent_signal_cb, self, NULL, NULL, &error);
if (error != NULL)
{
g_error ("sent signal connect: %s", error->message);
@@ -350,8 +349,7 @@ _tpl_text_channel_pendingproc_connect_signals (TplTextChannel *self)
}
tp_cli_channel_type_text_connect_to_send_error (channel,
- _channel_on_send_error_cb,
- self, NULL, NULL, &error);
+ _channel_on_send_error_cb, self, NULL, NULL, &error);
if (error != NULL)
{
g_error ("send error signal connect: %s", error->message);
@@ -361,8 +359,7 @@ _tpl_text_channel_pendingproc_connect_signals (TplTextChannel *self)
}
tp_cli_channel_type_text_connect_to_lost_message (channel,
- _channel_on_lost_message_cb,
- self, NULL, NULL, &error);
+ _channel_on_lost_message_cb, self, NULL, NULL, &error);
if (error != NULL)
{
g_error ("lost message signal connect: %s", error->message);
@@ -372,7 +369,7 @@ _tpl_text_channel_pendingproc_connect_signals (TplTextChannel *self)
}
tp_cli_channel_connect_to_closed (channel, _channel_on_closed_cb,
- self, NULL, NULL, &error);
+ self, NULL, NULL, &error);
if (error != NULL)
{
g_error ("channel closed signal connect: %s", error->message);
@@ -381,15 +378,17 @@ _tpl_text_channel_pendingproc_connect_signals (TplTextChannel *self)
error = NULL;
}
- // TODO connect to TpContacts' notify::presence-type
+ /* TODO connect to TpContacts' notify::presence-type */
+
context_continue (self);
}
static void
_tpl_text_channel_get_chatroom_cb (TpConnection *proxy,
- const gchar **out_Identifiers,
- const GError *error,
- gpointer user_data, GObject *weak_object)
+ const gchar **out_Identifiers,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
{
TplTextChannel *tpl_text = TPL_TEXT_CHANNEL (user_data);
@@ -407,13 +406,13 @@ static void
_tpl_text_channel_pendingproc_get_chatroom_id (TplTextChannel *ctx)
{
TplChannel *tpl_chan = tpl_text_channel_get_tpl_channel (ctx);
- TpConnection *connection = tpl_channel_get_connection (tpl_chan);
+ TpConnection *connection = tp_channel_borrow_connection (TP_CHANNEL (
+ tpl_chan));
TpHandle room_handle;
GArray *handles;
handles = g_array_new (FALSE, FALSE, sizeof (TpHandle));
- room_handle = tp_channel_get_handle (tpl_channel_get_channel (tpl_chan),
- NULL);
+ room_handle = tp_channel_get_handle (TP_CHANNEL (tpl_chan), NULL);
g_array_append_val (handles, room_handle);
tpl_text_channel_set_chatroom (ctx, TRUE);
@@ -442,6 +441,9 @@ _tpl_text_channel_get_contact_cb (TpConnection *connection,
GObject *weak_object)
{
TplTextChannel *tpl_text = TPL_TEXT_CHANNEL (user_data);
+ TplChannel *tpl_chan = tpl_text_channel_get_tpl_channel (tpl_text);
+ TpChannel *tp_chan = TP_CHANNEL (tpl_chan);
+ gchar *conn_path, *chan_path;
g_assert_cmpuint (n_failed, ==, 0);
g_assert_cmpuint (n_contacts, ==, 1);
@@ -449,14 +451,17 @@ _tpl_text_channel_get_contact_cb (TpConnection *connection,
if (n_failed > 0)
{
- g_error ("Error resolving self handle for connection %s."
- " Aborting channel %s observation",
- tpl_channel_get_connection_path
- (tpl_text_channel_get_tpl_channel (tpl_text)),
- tpl_channel_get_channel_path (tpl_text_channel_get_tpl_channel
- (tpl_text)));
+ g_object_get (G_OBJECT (tp_channel_borrow_connection
+ (tp_chan)), "object-path", &conn_path, NULL);
+ g_object_get (G_OBJECT (tp_chan), "object-path", &chan_path, NULL);
+
+ g_debug ("Error resolving self handle for connection %s."
+ " Aborting channel %s observation", conn_path, chan_path);
tpl_channel_unregister_from_observer (tpl_text_channel_get_tpl_channel
(tpl_text));
+
+ g_free (conn_path);
+ g_free (chan_path);
return;
}
@@ -469,12 +474,11 @@ _tpl_text_channel_get_contact_cb (TpConnection *connection,
tpl_text_channel_set_remote_contact (tpl_text, *contacts);
break;
default:
- g_error ("retrieving TpContacts: passing invalid value "
- "for selector: %d"
- "Aborting channel %s observation",
- tpl_text->selector,
- tpl_channel_get_channel_path (tpl_text_channel_get_tpl_channel
- (tpl_text)));
+ g_object_get (G_OBJECT (tp_chan), "object-path", &chan_path, NULL);
+
+ g_error ("retrieving TpContacts: passing invalid value for selector: %d"
+ "Aborting channel %s observation", tpl_text->selector, chan_path);
+ g_free (chan_path);
tpl_channel_unregister_from_observer (tpl_text_channel_get_tpl_channel
(tpl_text));
return;
@@ -491,35 +495,36 @@ _tpl_text_channel_pendingproc_get_remote_contact (TplTextChannel *ctx)
TpHandleType remote_handle_type;
TpHandle remote_handle;
- remote_handle = tp_channel_get_handle (tpl_channel_get_channel (tpl_chan),
- &remote_handle_type);
+ remote_handle = tp_channel_get_handle (TP_CHANNEL (tpl_chan),
+ &remote_handle_type);
ctx->selector = TP_CONTACT_REMOTE;
- tp_connection_get_contacts_by_handle (tpl_channel_get_connection (tpl_chan),
- 1, &remote_handle,
- TP_CONTACT_FEATURES_LEN, features,
- _tpl_text_channel_get_contact_cb,
- ctx, NULL, NULL);
+ tp_connection_get_contacts_by_handle (tp_channel_borrow_connection (
+ TP_CHANNEL (tpl_chan)),
+ 1, &remote_handle,
+ TP_CONTACT_FEATURES_LEN, features,
+ _tpl_text_channel_get_contact_cb,
+ ctx, NULL, NULL);
}
static void
_tpl_text_channel_pendingproc_get_my_contact (TplTextChannel *ctx)
{
TplChannel *tpl_chan = tpl_text_channel_get_tpl_channel (ctx);
- TpHandle my_handle =
- tp_connection_get_self_handle (tpl_channel_get_connection (tpl_chan));
+ TpHandle my_handle = tp_connection_get_self_handle (
+ tp_channel_borrow_connection (TP_CHANNEL (tpl_chan)));
ctx->selector = TP_CONTACT_MYSELF;
- tp_connection_get_contacts_by_handle (tpl_channel_get_connection (tpl_chan),
- 1, &my_handle,
- TP_CONTACT_FEATURES_LEN, features,
- _tpl_text_channel_get_contact_cb,
- ctx, NULL, NULL);
+ tp_connection_get_contacts_by_handle (tp_channel_borrow_connection (
+ TP_CHANNEL (tpl_chan)),
+ 1, &my_handle,
+ TP_CONTACT_FEATURES_LEN, features,
+ _tpl_text_channel_get_contact_cb,
+ ctx, NULL, NULL);
}
/* end of async Callbacks */
-
G_DEFINE_TYPE (TplTextChannel, tpl_text_channel, G_TYPE_OBJECT)
static void tpl_text_channel_dispose (GObject *obj)
@@ -572,16 +577,15 @@ tpl_text_channel_new (TplChannel *tpl_channel)
to set some type's members and probably access (futurely) some
props */
TpHandleType remote_handle_type;
- tp_channel_get_handle (tpl_channel_get_channel (tpl_channel),
- &remote_handle_type);
+ tp_channel_get_handle (TP_CHANNEL (tpl_channel), &remote_handle_type);
ret->chain = g_queue_new ();
g_queue_push_tail (ret->chain,
- _tpl_text_channel_pendingproc_connect_signals);
+ _tpl_text_channel_pendingproc_connect_signals);
g_queue_push_tail (ret->chain,
- _tpl_text_channel_pendingproc_get_my_contact);
+ _tpl_text_channel_pendingproc_get_my_contact);
switch (remote_handle_type)
{
@@ -651,7 +655,8 @@ tpl_text_channel_get_chatroom_id (TplTextChannel *self)
}
void
-tpl_text_channel_set_tpl_channel (TplTextChannel *self, TplChannel *data)
+tpl_text_channel_set_tpl_channel (TplTextChannel *self,
+ TplChannel *data)
{
g_return_if_fail (TPL_IS_TEXT_CHANNEL (self));
g_return_if_fail (TPL_IS_CHANNEL (data));
@@ -662,7 +667,8 @@ tpl_text_channel_set_tpl_channel (TplTextChannel *self, TplChannel *data)
}
void
-tpl_text_channel_set_remote_contact (TplTextChannel *self, TpContact *data)
+tpl_text_channel_set_remote_contact (TplTextChannel *self,
+ TpContact *data)
{
g_return_if_fail (TPL_IS_TEXT_CHANNEL (self));
g_return_if_fail (TP_IS_CONTACT (data));
@@ -673,7 +679,8 @@ tpl_text_channel_set_remote_contact (TplTextChannel *self, TpContact *data)
}
void
-tpl_text_channel_set_my_contact (TplTextChannel *self, TpContact *data)
+tpl_text_channel_set_my_contact (TplTextChannel *self,
+ TpContact *data)
{
g_return_if_fail (TPL_IS_TEXT_CHANNEL (self));
g_return_if_fail (TP_IS_CONTACT (data));
@@ -684,7 +691,8 @@ tpl_text_channel_set_my_contact (TplTextChannel *self, TpContact *data)
}
void
-tpl_text_channel_set_chatroom (TplTextChannel *self, gboolean data)
+tpl_text_channel_set_chatroom (TplTextChannel *self,
+ gboolean data)
{
g_return_if_fail (TPL_IS_TEXT_CHANNEL (self));
@@ -692,7 +700,8 @@ tpl_text_channel_set_chatroom (TplTextChannel *self, gboolean data)
}
void
-tpl_text_channel_set_chatroom_id (TplTextChannel *self, const gchar *data)
+tpl_text_channel_set_chatroom_id (TplTextChannel *self,
+ const gchar *data)
{
g_return_if_fail (TPL_IS_TEXT_CHANNEL (self));
diff --git a/telepathy-logger/channel.c b/telepathy-logger/channel.c
index 33a737fcc..17735eb6b 100644
--- a/telepathy-logger/channel.c
+++ b/telepathy-logger/channel.c
@@ -21,255 +21,250 @@
#include "channel.h"
+#include <string.h>
+
#include <glib.h>
#include <telepathy-logger/channel-text.h>
#include <telepathy-logger/observer.h>
-G_DEFINE_TYPE (TplChannel, tpl_channel, G_TYPE_OBJECT)
+#define TPCHAN_PROP_PREFIX "org.freedesktop.Telepathy.Channel."
+#define TPCHAN_PROP_PREFIX_LEN strlen(TPCHAN_PROP_PREFIX)
-struct
-{
- TpChannel *channel;
- gchar *channel_path;
- gchar *channel_type;
- GHashTable *channel_properties;
+G_DEFINE_TYPE (TplChannel, tpl_channel, TP_TYPE_CHANNEL)
+#define GET_PRIV(obj) TPL_GET_PRIV (obj, TplChannel)
+struct _TplChannelPriv
+{
TpAccount *account;
gchar *account_path;
- TpConnection *connection;
- gchar *connection_path;
+ TplObserver *observer;
+};
- TpSvcClientObserver *observer;
-
-} _TplChannelPriv;
+enum
+{
+ PROP0,
+ PROP_OBSERVER,
+ PROP_ACCOUNT
+};
-static void tpl_channel_dispose (GObject * obj)
+static void
+get_prop (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- TplChannel *self = TPL_CHANNEL (obj);
+ TplChannelPriv *priv = GET_PRIV (object);
- tpl_object_unref_if_not_null (self->channel);
- self->channel = NULL;
+ switch (param_id)
+ {
+ case PROP_OBSERVER:
+ g_value_set_object (value, priv->observer);
+ break;
+ case PROP_ACCOUNT:
+ g_value_set_object (value, priv->account);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
- if (self->channel_properties != NULL)
- g_hash_table_unref (self->channel_properties);
- self->channel_properties = NULL;
+static void
+set_prop (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TplChannel *self = TPL_CHANNEL (object);
+
+ switch (param_id) {
+ case PROP_OBSERVER:
+ tpl_channel_set_observer (self, g_value_get_object (value));
+ break;
+ case PROP_ACCOUNT:
+ tpl_channel_set_account (self, g_value_get_object (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
- tpl_object_unref_if_not_null (self->account);
- self->account = NULL;
+static void
+tpl_channel_dispose (GObject *obj)
+{
+ TplChannelPriv *priv = GET_PRIV (obj);
- tpl_object_unref_if_not_null (self->connection);
- self->connection = NULL;
+ tpl_object_unref_if_not_null (priv->account);
+ priv->account = NULL;
- tpl_object_unref_if_not_null (self->observer);
- self->observer = NULL;
+ tpl_object_unref_if_not_null (priv->observer);
+ priv->observer = NULL;
G_OBJECT_CLASS (tpl_channel_parent_class)->dispose (obj);
}
static void
-tpl_channel_finalize (GObject * obj)
+tpl_channel_finalize (GObject *obj)
{
- TplChannel *self = TPL_CHANNEL (obj);
- g_free (self->channel_path);
- g_free (self->channel_type);
- g_free (self->account_path);
- g_free (self->connection_path);
+ TplChannelPriv *priv = GET_PRIV (obj);
+
+ g_free (priv->account_path);
G_OBJECT_CLASS (tpl_channel_parent_class)->finalize (obj);
}
static void
-tpl_channel_class_init (TplChannelClass * klass)
+tpl_channel_class_init (TplChannelClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GParamSpec *param_spec;
object_class->dispose = tpl_channel_dispose;
object_class->finalize = tpl_channel_finalize;
+ object_class->get_property = get_prop;
+ object_class->set_property = set_prop;
+
+ param_spec = g_param_spec_object ("observer",
+ "Observer",
+ "TplObserver instance owning the TplChannel",
+ TPL_TYPE_OBSERVER,
+ G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_OBSERVER, param_spec);
+
+ param_spec = g_param_spec_object ("account",
+ "Account",
+ "TpAccount instance associated with TplChannel",
+ TP_TYPE_ACCOUNT,
+ G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_ACCOUNT, param_spec);
+
+ g_type_class_add_private (object_class, sizeof (TplChannelPriv));
}
static void
-tpl_channel_init (TplChannel * self)
+tpl_channel_init (TplChannel *self)
{
+ TplChannelPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, TPL_TYPE_CHANNEL,
+ TplChannelPriv);
+ self->priv = priv;
}
TplChannel *
-tpl_channel_new (TpSvcClientObserver * observer)
+tpl_channel_new (TpConnection *conn,
+ const gchar *object_path,
+ GHashTable *tp_chan_props,
+ TplObserver *observer,
+ GError **error)
{
- g_return_val_if_fail (TP_IS_SVC_CLIENT_OBSERVER (observer), NULL);
+ TpProxy *conn_proxy = (TpProxy *) conn;
+ TplChannel *ret;
- TplChannel *ret = g_object_new (TPL_TYPE_CHANNEL, NULL);
- tpl_channel_set_observer (ret, observer);
- return ret;
-}
+ /* Do what tp_channel_new_from_properties does + I set TplChannel
+ * specific properties
+ */
-TpSvcClientObserver *
-tpl_channel_get_observer (TplChannel * self)
-{
- g_return_val_if_fail (TPL_IS_CHANNEL (self), NULL);
- return self->observer;
-}
+ g_return_val_if_fail (TP_IS_CONNECTION (conn), NULL);
+ g_return_val_if_fail (!TPL_STR_EMPTY (object_path), NULL);
+ g_return_val_if_fail (tp_chan_props != NULL, NULL);
+ g_return_val_if_fail (TPL_IS_OBSERVER (observer), NULL);
+
+ if (!tp_dbus_check_valid_object_path (object_path, error))
+ return NULL;
+
+ ret = g_object_new (TPL_TYPE_CHANNEL,
+ /* TplChannel properties */
+ "observer", observer,
+ /* TpChannel properties */
+ "connection", conn,
+ "dbus-daemon", conn_proxy->dbus_daemon,
+ "bus-name", conn_proxy->bus_name,
+ "object-path", object_path,
+ "handle-type", (guint) TP_UNKNOWN_HANDLE_TYPE,
+ "channel-properties", tp_chan_props,
+ NULL);
-TpAccount *
-tpl_channel_get_account (TplChannel * self)
-{
- g_return_val_if_fail (TPL_IS_CHANNEL (self), NULL);
- return self->account;
+ return ret;
}
-const gchar *
-tpl_channel_get_account_path (TplChannel * self)
+TplObserver *
+tpl_channel_get_observer (TplChannel *self)
{
- g_return_val_if_fail (TPL_IS_CHANNEL (self), NULL);
- return self->account_path;
-}
+ TplChannelPriv *priv = GET_PRIV(self);
-TpConnection *
-tpl_channel_get_connection (TplChannel * self)
-{
g_return_val_if_fail (TPL_IS_CHANNEL (self), NULL);
- return self->connection;
-}
-const gchar *
-tpl_channel_get_connection_path (TplChannel * self)
-{
- g_return_val_if_fail (TPL_IS_CHANNEL (self), NULL);
- return self->connection_path;
+ return priv->observer;
}
-TpChannel *
-tpl_channel_get_channel (TplChannel * self)
+TpAccount *
+tpl_channel_get_account (TplChannel *self)
{
- g_return_val_if_fail (TPL_IS_CHANNEL (self), NULL);
- return self->channel;
-}
+ TplChannelPriv *priv = GET_PRIV(self);
-const gchar *
-tpl_channel_get_channel_path (TplChannel * self)
-{
g_return_val_if_fail (TPL_IS_CHANNEL (self), NULL);
- return self->channel_path;
+
+ return priv->account;
}
const gchar *
-tpl_channel_get_channel_type (TplChannel * self)
+tpl_channel_get_account_path (TplChannel *self)
{
- g_return_val_if_fail (TPL_IS_CHANNEL (self), NULL);
- return self->channel_type;
-}
+ TplChannelPriv *priv = GET_PRIV(self);
-GHashTable *
-tpl_channel_get_channel_properties (TplChannel * self)
-{
g_return_val_if_fail (TPL_IS_CHANNEL (self), NULL);
- return self->channel_properties;
-}
-
-
-void
-tpl_channel_set_observer (TplChannel * self, TpSvcClientObserver * data)
-{
- g_return_if_fail (TPL_IS_CHANNEL (self));
- g_return_if_fail (TP_IS_SVC_CLIENT_OBSERVER (data) || data == NULL);
-
- tpl_object_unref_if_not_null (self->observer);
- self->observer = data;
- tpl_object_ref_if_not_null (data);
+ return priv->account_path;
}
-void
-tpl_channel_set_account (TplChannel * self, TpAccount * data)
-{
- g_return_if_fail (TPL_IS_CHANNEL (self));
- g_return_if_fail (TP_IS_ACCOUNT (data) || data == NULL);
-
- tpl_object_unref_if_not_null (self->account);
- self->account = data;
- tpl_object_ref_if_not_null (data);
-}
void
-tpl_channel_set_account_path (TplChannel * self, const gchar * data)
+tpl_channel_set_observer (TplChannel *self,
+ TplObserver *data)
{
- g_return_if_fail (TPL_IS_CHANNEL (self));
- // TODO check validity of data
-
- g_free (self->account_path);
- self->account_path = g_strdup (data);
-}
+ TplChannelPriv *priv = GET_PRIV(self);
-void
-tpl_channel_set_connection (TplChannel * self, TpConnection * data)
-{
g_return_if_fail (TPL_IS_CHANNEL (self));
- g_return_if_fail (TP_IS_CONNECTION (data) || data == NULL);
+ g_return_if_fail (TP_IS_SVC_CLIENT_OBSERVER (data) || data == NULL);
- tpl_object_unref_if_not_null (self->connection);
- self->connection = data;
+ tpl_object_unref_if_not_null (priv->observer);
+ priv->observer = data;
tpl_object_ref_if_not_null (data);
}
void
-tpl_channel_set_connection_path (TplChannel * self, const gchar * data)
+tpl_channel_set_account (TplChannel *self,
+ TpAccount *data)
{
- g_return_if_fail (TPL_IS_CHANNEL (self));
- // TODO check validity of data
+ TplChannelPriv *priv = GET_PRIV(self);
- g_free (self->connection_path);
- self->connection_path = g_strdup (data);
-}
-
-void
-tpl_channel_set_channel (TplChannel * self, TpChannel * data)
-{
g_return_if_fail (TPL_IS_CHANNEL (self));
- g_return_if_fail (TP_IS_CHANNEL (data) || data == NULL);
+ g_return_if_fail (TP_IS_ACCOUNT (data) || data == NULL);
- tpl_object_unref_if_not_null (self->channel);
- self->channel = data;
+ tpl_object_unref_if_not_null (priv->account);
+ priv->account = data;
tpl_object_ref_if_not_null (data);
}
void
-tpl_channel_set_channel_path (TplChannel * self, const gchar * data)
-{
- g_return_if_fail (TPL_IS_CHANNEL (self));
- // TODO check validity of data
-
- g_free (self->channel_path);
- self->channel_path = g_strdup (data);
-}
-
-void
-tpl_channel_set_channel_type (TplChannel * self, const gchar * data)
+tpl_channel_set_account_path (TplChannel *self,
+ const gchar *data)
{
- g_return_if_fail (TPL_IS_CHANNEL (self));
- // TODO check validity of data
+ TplChannelPriv *priv = GET_PRIV(self);
- g_free (self->channel_type);
- self->channel_type = g_strdup (data);
-}
-
-void
-tpl_channel_set_channel_properties (TplChannel * self, GHashTable * data)
-{
g_return_if_fail (TPL_IS_CHANNEL (self));
// TODO check validity of data
- if (self->channel_properties != NULL)
- g_hash_table_unref (self->channel_properties);
- self->channel_properties = data;
- if (data != NULL)
- g_hash_table_ref (data);
+ g_free (priv->account_path);
+ priv->account_path = g_strdup (data);
}
gboolean
-tpl_channel_register_to_observer (TplChannel * self)
+tpl_channel_register_to_observer (TplChannel *self)
{
TplObserver *obs = TPL_OBSERVER (tpl_channel_get_observer (self));
GHashTable *glob_map = tpl_observer_get_channel_map (obs);
@@ -278,7 +273,9 @@ tpl_channel_register_to_observer (TplChannel * self)
g_return_val_if_fail (TPL_IS_CHANNEL (self), FALSE);
g_return_val_if_fail (glob_map != NULL, FALSE);
- key = g_strdup (tpl_channel_get_channel_path (self));
+ /* 'key' will be freed by the hash table on key removal/destruction */
+ g_object_get (G_OBJECT (tp_channel_borrow_connection (TP_CHANNEL (self))),
+ "object-path", &key, NULL);
if (g_hash_table_lookup (glob_map, key) != NULL)
{
@@ -290,19 +287,21 @@ tpl_channel_register_to_observer (TplChannel * self)
g_debug ("Channel path not found, registering %s", key);
}
+
/* Instantiate and delegate channel handling to the right object */
- if (0 == g_strcmp0 (TP_IFACE_CHAN_TEXT,
- tpl_channel_get_channel_type (self)))
+ if (0 == g_strcmp0 (TP_IFACE_CHAN_TEXT, tp_channel_get_channel_type (
+ TP_CHANNEL (self))))
{
/* when removed, automatically frees the Key and unrefs
its Value */
TplTextChannel *chan_text = tpl_text_channel_new (self);
+
g_hash_table_insert (glob_map, key, chan_text);
}
else
{
g_warning ("%s: channel type not handled by this logger",
- tpl_channel_get_channel_type (self));
+ tp_channel_get_channel_type ( TP_CHANNEL (self)));
}
g_object_unref (self);
@@ -311,21 +310,26 @@ tpl_channel_register_to_observer (TplChannel * self)
}
gboolean
-tpl_channel_unregister_from_observer (TplChannel * self)
+tpl_channel_unregister_from_observer (TplChannel *self)
{
TplObserver *obs = TPL_OBSERVER (tpl_channel_get_observer (self));
GHashTable *glob_map = tpl_observer_get_channel_map (obs);
- const gchar *key;
+ gboolean retval = FALSE;
+ gchar *key;
g_return_val_if_fail (TPL_IS_CHANNEL (self), FALSE);
g_return_val_if_fail (glob_map != NULL, FALSE);
- key = tpl_channel_get_channel_path (self);
+ g_object_get ( G_OBJECT (tp_channel_borrow_connection (TP_CHANNEL (self))),
+ "object-path", &key, NULL);
+
g_debug ("Unregistering channel path %s", key);
/* this will destroy the associated value object: at this point
the hash table reference should be the only one for the
value's object
*/
- return g_hash_table_remove (glob_map, key);
+ retval = g_hash_table_remove (glob_map, key);
+ g_free (key);
+ return retval;
}
diff --git a/telepathy-logger/channel.h b/telepathy-logger/channel.h
index 6b1da88a3..b7fc7cac6 100644
--- a/telepathy-logger/channel.h
+++ b/telepathy-logger/channel.h
@@ -44,56 +44,33 @@ typedef struct _TplChannelPriv TplChannelPriv;
typedef struct
{
- GObject parent;
+ TpChannel parent;
/* private */
TplChannelPriv *priv;
-
- TpChannel *channel;
- gchar *channel_path;
- gchar *channel_type;
- GHashTable *channel_properties;
-
- TpAccount *account;
- gchar *account_path;
- TpConnection *connection;
- gchar *connection_path;
-
- TpSvcClientObserver *observer;
} TplChannel;
typedef struct
{
- GObjectClass parent_class;
+ TpChannelClass parent_class;
} TplChannelClass;
GType tpl_channel_get_type (void);
-TplChannel *tpl_channel_new (TpSvcClientObserver * observer);
-void tpl_channel_free (TplChannel * tpl_chan);
+TplChannel *tpl_channel_new (TpConnection *conn,
+ const gchar *object_path,
+ GHashTable *tp_chan_props,
+ TplObserver *observer,
+ GError **error);
-TpSvcClientObserver *tpl_channel_get_observer (TplChannel * self);
+TplObserver *tpl_channel_get_observer (TplChannel * self);
TpAccount *tpl_channel_get_account (TplChannel * self);
const gchar *tpl_channel_get_account_path (TplChannel * self);
-TpConnection *tpl_channel_get_connection (TplChannel * self);
-const gchar *tpl_channel_get_connection_path (TplChannel * self);
-TpChannel *tpl_channel_get_channel (TplChannel * self);
-const gchar *tpl_channel_get_channel_path (TplChannel * self);
-const gchar *tpl_channel_get_channel_type (TplChannel * self);
-GHashTable *tpl_channel_get_channel_properties (TplChannel * self);
-
-void tpl_channel_set_observer (TplChannel * self, TpSvcClientObserver * data);
+void tpl_channel_set_observer (TplChannel * self, TplObserver* data);
void tpl_channel_set_account (TplChannel * self, TpAccount * data);
void tpl_channel_set_account_path (TplChannel * self, const gchar * data);
-void tpl_channel_set_connection (TplChannel * self, TpConnection * data);
-void tpl_channel_set_connection_path (TplChannel * self, const gchar * data);
-void tpl_channel_set_channel (TplChannel * self, TpChannel * data);
-void tpl_channel_set_channel_path (TplChannel * self, const gchar * data);
-void tpl_channel_set_channel_type (TplChannel * self, const gchar * data);
-void tpl_channel_set_channel_properties (TplChannel * self,
- GHashTable * data);
gboolean tpl_channel_register_to_observer (TplChannel * self);
gboolean tpl_channel_unregister_from_observer (TplChannel * self);
diff --git a/telepathy-logger/log-entry-text.c b/telepathy-logger/log-entry-text.c
index eb71192f3..4b3bf8c52 100644
--- a/telepathy-logger/log-entry-text.c
+++ b/telepathy-logger/log-entry-text.c
@@ -53,7 +53,7 @@ tpl_log_entry_text_dispose (GObject * obj)
tpl_object_unref_if_not_null (priv->tpl_text);
priv->tpl_text = NULL;
- TPL_LOG_ENTRY_CLASS (tpl_log_entry_text_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (tpl_log_entry_text_parent_class)->finalize (obj);
}
@@ -66,7 +66,7 @@ tpl_log_entry_text_finalize (GObject * obj)
g_free (priv->message);
priv->message = NULL;
- TPL_LOG_ENTRY_CLASS (tpl_log_entry_text_parent_class)->dispose (obj);
+ G_OBJECT_CLASS (tpl_log_entry_text_parent_class)->dispose (obj);
}
diff --git a/telepathy-logger/log-entry.c b/telepathy-logger/log-entry.c
index 381ce52da..f1ec9fd07 100644
--- a/telepathy-logger/log-entry.c
+++ b/telepathy-logger/log-entry.c
@@ -100,7 +100,7 @@ tpl_log_entry_dispose (GObject *obj)
static void
-tpl_log_entry_get_prop (GObject *object,
+get_prop (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec)
@@ -138,7 +138,7 @@ tpl_log_entry_get_prop (GObject *object,
static void
-tpl_log_entry_set_prop (GObject *object,
+set_prop (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec)
@@ -181,11 +181,10 @@ tpl_log_entry_class_init (TplLogEntryClass * klass)
GParamSpec *param_spec;
/* to be used by subclasses */
- klass->finalize = tpl_log_entry_finalize;
- klass->dispose = tpl_log_entry_dispose;
-
- object_class->get_property = tpl_log_entry_get_prop;
- object_class->set_property = tpl_log_entry_set_prop;
+ object_class->finalize = tpl_log_entry_finalize;
+ object_class->dispose = tpl_log_entry_dispose;
+ object_class->get_property = get_prop;
+ object_class->set_property = set_prop;
param_spec = g_param_spec_uint ("timestamp",
"Timestamp",
diff --git a/telepathy-logger/observer.c b/telepathy-logger/observer.c
index ff0f17d94..a5a78d90d 100644
--- a/telepathy-logger/observer.c
+++ b/telepathy-logger/observer.c
@@ -66,45 +66,49 @@ enum
static void
-_observe_channel_when_ready_cb (TpChannel * channel,
- const GError * error, gpointer user_data)
+_observe_channel_when_ready_cb (TpChannel *channel,
+ const GError *error,
+ gpointer user_data)
{
TplChannel *tpl_chan = TPL_CHANNEL (user_data);
if (error != NULL)
{
- g_error ("%s", error->message);
- g_error ("giving up observing channel '%s'", tpl_chan->channel_path);
+ gchar *chan_path;
+
+ g_object_get (G_OBJECT (tpl_chan), "object-path", &chan_path, NULL);
+ g_debug ("%s. Giving up channel '%s' observation", error->message,
+ chan_path);
+
g_object_unref (tpl_chan);
+ g_free (chan_path);
return;
}
- tpl_channel_set_channel_type (tpl_chan,
- tp_channel_get_channel_type
- (tpl_chan->channel));
tpl_channel_register_to_observer (tpl_chan);
}
static void
-_get_ready_tp_channel (TpConnection * connection,
- const GError * error, gpointer user_data)
+_get_ready_tp_channel (TpConnection *connection,
+ const GError *error,
+ gpointer user_data)
{
TplChannel *tpl_chan = TPL_CHANNEL (user_data);
- tp_channel_call_when_ready (tpl_channel_get_channel (tpl_chan),
+ tp_channel_call_when_ready (TP_CHANNEL (tpl_chan),
_observe_channel_when_ready_cb, tpl_chan);
}
static void
-tpl_observer_observe_channels (TpSvcClientObserver * self,
- const char *account,
- const char *connection,
- const GPtrArray * channels,
- const char *dispatch_op,
- const GPtrArray * requests_satisfied,
- GHashTable * observer_info,
- DBusGMethodInvocation * context)
+tpl_observer_observe_channels (TpSvcClientObserver *self,
+ const char *account,
+ const char *connection,
+ const GPtrArray *channels,
+ const char *dispatch_op,
+ const GPtrArray *requests_satisfied,
+ GHashTable *observer_info,
+ DBusGMethodInvocation *context)
{
TpAccount *tp_acc;
TpConnection *tp_conn;
@@ -158,7 +162,6 @@ tpl_observer_observe_channels (TpSvcClientObserver * self,
return;
}
-
tp_conn = tp_connection_new (tp_bus_daemon, NULL, connection, &error);
if (tp_conn == NULL)
{
@@ -174,38 +177,28 @@ tpl_observer_observe_channels (TpSvcClientObserver * self,
for (guint i = 0; i < channels->len; i++)
{
GValueArray *channel = g_ptr_array_index (channels, i);
- TpChannel *tp_chan;
TplChannel *tpl_chan;
gchar *path = g_value_get_boxed (g_value_array_get_nth (channel, 0));
// propertyNameStr/value hash
GHashTable *map =
- g_value_get_boxed (g_value_array_get_nth (channel, 1));
-
- tp_chan = tp_channel_new (tp_conn, path, NULL,
- TP_UNKNOWN_HANDLE_TYPE, 0, &error);
- if (tp_conn == NULL)
- {
- // log and skip to next channel
- g_error ("%s", error->message);
- g_clear_error (&error);
- g_error_free (error);
- error = NULL;
- continue;
- }
-
- tpl_chan = tpl_channel_new (self);
+ g_value_get_boxed (g_value_array_get_nth (channel, 1));
+
+ tpl_chan = tpl_channel_new (tp_conn, path, map, TPL_OBSERVER (self), &error);
+ if (tpl_chan == NULL)
+ {
+ g_debug ("%s", error->message);
+ g_clear_error (&error);
+ g_error_free (error);
+ error = NULL;
+ continue;
+ }
+
tpl_channel_set_account (tpl_chan, tp_acc);
tpl_channel_set_account_path (tpl_chan, account);
- tpl_channel_set_connection (tpl_chan, tp_conn);
- tpl_channel_set_connection_path (tpl_chan, connection);
- tpl_channel_set_channel (tpl_chan, tp_chan);
- tpl_channel_set_channel_path (tpl_chan, path);
- tpl_channel_set_channel_properties (tpl_chan, map);
-
- tp_connection_call_when_ready (tp_conn,
- _get_ready_tp_channel, tpl_chan);
+ tp_connection_call_when_ready (tp_conn, _get_ready_tp_channel,
+ tpl_chan);
}
g_object_unref (tp_acc);
@@ -216,9 +209,10 @@ tpl_observer_observe_channels (TpSvcClientObserver * self,
}
static void
-tpl_observer_get_property (GObject * self,
- guint property_id,
- GValue * value, GParamSpec * pspec)
+tpl_observer_get_property (GObject *self,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
switch (property_id)
{
@@ -246,8 +240,9 @@ tpl_observer_get_property (GObject * self,
/* Singleton Constructor */
static GObject *
-tpl_observer_constructor (GType type, guint n_props,
- GObjectConstructParam * props)
+tpl_observer_constructor (GType type,
+ guint n_props,
+ GObjectConstructParam *props)
{
GObject *retval;
@@ -269,7 +264,7 @@ tpl_observer_constructor (GType type, guint n_props,
static void
-tpl_observer_class_init (TplObserverClass * klass)
+tpl_observer_class_init (TplObserverClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -329,7 +324,7 @@ tpl_observer_class_init (TplObserverClass * klass)
}
static void
-tpl_observer_init (TplObserver * self)
+tpl_observer_init (TplObserver *self)
{
DBusGConnection *bus;
TpDBusDaemon *tp_bus;
@@ -361,7 +356,8 @@ tpl_observer_init (TplObserver * self)
}
static void
-observer_iface_init (gpointer g_iface, gpointer iface_data)
+observer_iface_init (gpointer g_iface,
+ gpointer iface_data)
{
TpSvcClientObserverClass *klass = (TpSvcClientObserverClass *) g_iface;
@@ -370,7 +366,7 @@ observer_iface_init (gpointer g_iface, gpointer iface_data)
}
static void
-tpl_observer_dispose (GObject * obj)
+tpl_observer_dispose (GObject *obj)
{
TplObserver *self = TPL_OBSERVER (obj);
@@ -389,7 +385,7 @@ tpl_observer_dispose (GObject * obj)
}
static void
-tpl_observer_finalize (GObject * obj)
+tpl_observer_finalize (GObject *obj)
{
//TplObserver *self = TPL_OBSERVER(obj);
@@ -399,12 +395,12 @@ tpl_observer_finalize (GObject * obj)
TplObserver *
tpl_observer_new (void)
{
- return g_object_new (TYPE_TPL_OBSERVER, NULL);
+ return g_object_new (TPL_TYPE_OBSERVER, NULL);
}
GHashTable *
-tpl_observer_get_channel_map (TplObserver * self)
+tpl_observer_get_channel_map (TplObserver *self)
{
g_return_val_if_fail (TPL_IS_OBSERVER (self), NULL);
@@ -412,7 +408,8 @@ tpl_observer_get_channel_map (TplObserver * self)
}
void
-tpl_observer_set_channel_map (TplObserver * self, GHashTable * data)
+tpl_observer_set_channel_map (TplObserver *self,
+ GHashTable *data)
{
g_return_if_fail (TPL_IS_OBSERVER (self));
//TODO check data validity
diff --git a/telepathy-logger/observer.h b/telepathy-logger/observer.h
index 798c67477..b8867092e 100644
--- a/telepathy-logger/observer.h
+++ b/telepathy-logger/observer.h
@@ -33,12 +33,12 @@
G_BEGIN_DECLS
-#define TYPE_TPL_OBSERVER (tpl_observer_get_type ())
-#define TPL_OBSERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TPL_OBSERVER, TplObserver))
-#define TPL_OBSERVER_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), TYPE_TPL_OBSERVER, TplObserverClass))
-#define TPL_IS_OBSERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TPL_OBSERVER))
-#define TPL_IS_OBSERVER_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), TYPE_TPL_OBSERVER))
-#define TPL_OBSERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TPL_OBSERVER, TplObserverClass))
+#define TPL_TYPE_OBSERVER (tpl_observer_get_type ())
+#define TPL_OBSERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_OBSERVER, TplObserver))
+#define TPL_OBSERVER_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), TPL_TYPE_OBSERVER, TplObserverClass))
+#define TPL_IS_OBSERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_OBSERVER))
+#define TPL_IS_OBSERVER_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), TPL_TYPE_OBSERVER))
+#define TPL_OBSERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_OBSERVER, TplObserverClass))
typedef struct _TplObserver TplObserver;
struct _TplObserver
{