summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2009-12-09 23:06:24 -0200
committerCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2009-12-09 23:06:24 -0200
commit436431fa929cea024a97421cb3029a565d17d313 (patch)
treef181b0264bb0a432ea8e4b277eab1384281d02f6 /src
parentc9fcb00489fe3546dd6c67ad142ee8396202a471 (diff)
downloadtelepathy-logger-436431fa929cea024a97421cb3029a565d17d313.tar.gz
Started code clean-up
* added register/unregistering methods channels * renamed old tpl-utils funcs to ref/unref using tpl_object prefix * tpl-headless-logger-init.c cleaned-up * tpl-observer.c cleaned-up * tpl-channel.c cleaned-up * added Closed signal handler for TpChannel
Diffstat (limited to 'src')
-rwxr-xr-xsrc/compile.sh2
-rw-r--r--src/tpl-channel.c160
-rw-r--r--src/tpl-contact.c4
-rw-r--r--src/tpl-headless-logger-init.c2
-rw-r--r--src/tpl-log-entry-text.c4
-rw-r--r--src/tpl-observer.c247
-rw-r--r--src/tpl-text-channel-context.c113
-rw-r--r--src/tpl-utils.c4
8 files changed, 361 insertions, 175 deletions
diff --git a/src/compile.sh b/src/compile.sh
index b20a496..358577b 100755
--- a/src/compile.sh
+++ b/src/compile.sh
@@ -5,7 +5,7 @@ CC=${CC:-gcc}
CCOPTS="-D__USE_POSIX -DPACKAGE_NAME=\"${PACKAGE_NAME}\" --std=c99 -g -I../include -Wall -Werror" # -pedantic"
PKGS="telepathy-glib libxml-2.0"
MODULES="tpl-observer.c tpl-headless-logger-init.c
- tpl-channel-data.c tpl-text-channel-data.c
+ tpl-channel.c tpl-text-channel-context.c
tpl-contact.c
tpl-utils.c
tpl-time.c
diff --git a/src/tpl-channel.c b/src/tpl-channel.c
index 4d97b55..7216d10 100644
--- a/src/tpl-channel.c
+++ b/src/tpl-channel.c
@@ -1,10 +1,48 @@
+#include <glib.h>
#include <tpl-observer.h>
#include <tpl-channel.h>
G_DEFINE_TYPE (TplChannel, tpl_channel, G_TYPE_OBJECT)
+
+static void tpl_channel_dispose (GObject* obj)
+{
+ TplChannel *self = TPL_CHANNEL(obj);
+
+ tpl_object_unref_if_not_null (self->channel);
+ self->channel = NULL;
+ tpl_object_unref_if_not_null (self->channel_properties);
+ self->channel_properties = NULL;
+ tpl_object_unref_if_not_null (self->account);
+ self->account = NULL;
+ tpl_object_unref_if_not_null (self->connection);
+ self->connection = NULL;
+ tpl_object_unref_if_not_null (self->observer);
+ self->observer = NULL;
+
+ G_OBJECT_CLASS (tpl_channel_parent_class)->dispose (obj);
+}
+
+static void tpl_channel_finalize (GObject* obj)
+{
+ TplChannel *self = TPL_CHANNEL(obj);
+
+ g_free ((gchar*) self->channel_path);
+ g_free ((gchar*) self->channel_type);
+ g_free ((gchar*) self->account_path);
+ g_free ((gchar*) self->connection_path);
+
+ G_OBJECT_CLASS (tpl_channel_parent_class)->finalize (obj);
+
+ g_debug("TplChannel instnace finalized\n");
+}
+
+
static void tpl_channel_class_init(TplChannelClass* klass) {
- //GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
+ GObjectClass* object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = tpl_channel_dispose;
+ object_class->finalize = tpl_channel_finalize;
}
@@ -23,93 +61,115 @@ static void tpl_channel_init(TplChannel* self) {
#undef TPL_SET_NULL
}
-TplChannel* tpl_channel_new(TpSvcClientObserver* observer) {
+TplChannel* tpl_channel_new(TpSvcClientObserver* observer)
+{
TplChannel *ret = g_object_new(TPL_TYPE_CHANNEL,NULL);
tpl_channel_set_observer(ret, observer);
return ret;
}
-void tpl_channel_free(TplChannel* tpl_text) {
- /* TODO free and unref other members */
- g_free(tpl_text);
-}
-
-
-TpSvcClientObserver* tpl_channel_get_observer(TplChannel *self) {
+TpSvcClientObserver* tpl_channel_get_observer(TplChannel *self)
+{
return self->observer;
}
-TpAccount *tpl_channel_get_account(TplChannel *self) {
+
+TpAccount *tpl_channel_get_account(TplChannel *self)
+{
return self->account;
}
-const gchar *tpl_channel_get_account_path(TplChannel *self) {
+
+const gchar *tpl_channel_get_account_path(TplChannel *self)
+{
return self->account_path;
}
-TpConnection *tpl_channel_get_connection(TplChannel *self) {
+
+TpConnection *tpl_channel_get_connection(TplChannel *self)
+{
return self->connection;
}
-const gchar *tpl_channel_get_connection_path(TplChannel *self) {
+
+const gchar *tpl_channel_get_connection_path(TplChannel *self)
+{
return self->connection_path;
}
-TpChannel *tpl_channel_get_channel(TplChannel *self) {
+
+TpChannel *tpl_channel_get_channel(TplChannel *self)
+{
return self->channel;
}
-const gchar *tpl_channel_get_channel_path(TplChannel *self) {
+
+const gchar *tpl_channel_get_channel_path(TplChannel *self)
+{
return self->channel_path;
}
-const gchar *tpl_channel_get_channel_type(TplChannel *self) {
+
+const gchar *tpl_channel_get_channel_type(TplChannel *self)
+{
return self->channel_type;
}
-GHashTable *tpl_channel_get_channel_properties(TplChannel *self) {
+
+GHashTable *tpl_channel_get_channel_properties(TplChannel *self)
+{
return self->channel_properties;
}
void tpl_channel_set_observer(TplChannel *self,
- TpSvcClientObserver *data) {
- //g_debug("SET observer\n");
- _unref_object_if_not_null(&(self->observer));
+ TpSvcClientObserver *data)
+{
+ tpl_object_unref_if_not_null(self->observer);
self->observer = data;
- _ref_object_if_not_null(data);
+ tpl_object_ref_if_not_null(data);
}
-void tpl_channel_set_account(TplChannel *self, TpAccount *data) {
- //g_debug("SET account\n");
- _unref_object_if_not_null(&(self->account));
- if (self->account!=NULL)
- g_object_unref(self->account);
+
+void tpl_channel_set_account(TplChannel *self, TpAccount *data)
+{
+ tpl_object_unref_if_not_null(self->account);
self->account = data;
- _ref_object_if_not_null(data);
+ tpl_object_ref_if_not_null(data);
}
-void tpl_channel_set_account_path(TplChannel *self, const gchar *data) {
- //g_debug("SET path\n");
- if (self->account!=NULL)
+
+void tpl_channel_set_account_path(TplChannel *self, const gchar *data)
+{
+ g_free ((gchar*) self->account_path);
self->account_path = data;
}
-void tpl_channel_set_connection(TplChannel *self, TpConnection *data) {
- //g_debug("SET connection\n");
- _unref_object_if_not_null(&(self->connection));
+
+void tpl_channel_set_connection(TplChannel *self, TpConnection *data)
+{
+ tpl_object_unref_if_not_null(self->connection);
self->connection = data;
- _ref_object_if_not_null(data);
-}
-void tpl_channel_set_connection_path(TplChannel *self, const gchar *data) {
- //g_debug("SET connectin path\n");
- self->connection_path = data;
+ tpl_object_ref_if_not_null(data);
}
-void tpl_channel_set_channel(TplChannel *self, TpChannel *data) {
- //g_debug("SET channel\n");
- _unref_object_if_not_null(&(self->channel));
+
+void tpl_channel_set_connection_path(TplChannel *self, const gchar *data)
+{
+ g_free((gchar*) self->connection_path);
+ self->connection_path = g_strdup (data);
+}
+void tpl_channel_set_channel(TplChannel *self, TpChannel *data)
+{
+ tpl_object_unref_if_not_null(self->channel);
self->channel = data;
- _ref_object_if_not_null(data);
+ tpl_object_ref_if_not_null(data);
}
-void tpl_channel_set_channel_path(TplChannel *self, const gchar *data) {
- //g_debug("SET channel path\n");
- self->channel_path = data;
+void tpl_channel_set_channel_path(TplChannel *self, const gchar *data)
+{
+ g_free((gchar*) self->channel_path);
+ self->channel_path = g_strdup (data);
}
-void tpl_channel_set_channel_type(TplChannel *self, const gchar *data) {
- //g_debug("SET channel type\n");
- self->channel_type = data;
+
+void tpl_channel_set_channel_type(TplChannel *self, const gchar *data)
+{
+ g_free((gchar*) self->channel_type);
+ self->channel_type = g_strdup (data);
}
-void tpl_channel_set_channel_properties(TplChannel *self, GHashTable *data) {
- //g_debug("SET channel prop\n");
+
+void tpl_channel_set_channel_properties(TplChannel *self, GHashTable *data)
+{
+ if (self->channel_properties != NULL)
+ g_hash_table_unref(self->channel_properties);
self->channel_properties = data;
+ g_hash_table_ref(data);
}
diff --git a/src/tpl-contact.c b/src/tpl-contact.c
index f3b00fb..162e47b 100644
--- a/src/tpl-contact.c
+++ b/src/tpl-contact.c
@@ -51,9 +51,9 @@ TplContact *tpl_contact_new() {
#undef ADD_GET
#define ADD_SET_PTR(member,y) void tpl_contact_set_##member(TplContact *self, y data) { \
- _unref_object_if_not_null(&(self->member)) ; \
+ tpl_object_unref_if_not_null(self->member) ; \
self->member = data; \
- _ref_object_if_not_null(data); }
+ tpl_object_ref_if_not_null(data); }
ADD_SET_PTR(contact, TpContact *);
ADD_SET_PTR(account, TpAccount *);
#undef ADD_SET_PTR
diff --git a/src/tpl-headless-logger-init.c b/src/tpl-headless-logger-init.c
index 82705d7..e82deaf 100644
--- a/src/tpl-headless-logger-init.c
+++ b/src/tpl-headless-logger-init.c
@@ -9,6 +9,8 @@
/*
* Initialization of TPL (TelePathy Logger), it futurely set all the
* inernal structs. tpl_headless_logger_deinit will free/unref them
+ *
+ * TplObserver *observer
*/
void tpl_headless_logger_init(void)
{
diff --git a/src/tpl-log-entry-text.c b/src/tpl-log-entry-text.c
index 932befa..0b67143 100644
--- a/src/tpl-log-entry-text.c
+++ b/src/tpl-log-entry-text.c
@@ -116,9 +116,9 @@ const gchar *tpl_log_entry_text_get_chat_id (TplLogEntryText *self)
void tpl_log_entry_text_set_tpl_text_channel(TplLogEntryText *self, TplTextChannel *data)
{
- _unref_object_if_not_null(self->tpl_text);
+ tpl_object_unref_if_not_null(self->tpl_text);
self->tpl_text = data;
- _ref_object_if_not_null(data);
+ tpl_object_ref_if_not_null(data);
}
void tpl_log_entry_text_set_sender (TplLogEntryText *self, TplContact *data)
diff --git a/src/tpl-observer.c b/src/tpl-observer.c
index 480e680..ea9a0a5 100644
--- a/src/tpl-observer.c
+++ b/src/tpl-observer.c
@@ -9,6 +9,8 @@
#include <tpl-channel.h>
#include <tpl-text-channel-context.h>
+static GHashTable *glob_map = NULL;
+
static void observer_iface_init (gpointer, gpointer);
G_DEFINE_TYPE_WITH_CODE (TplObserver, tpl_observer, G_TYPE_OBJECT,
@@ -32,39 +34,31 @@ enum
PROP_CHANNEL_FILTER
};
-static void _observe_channel_when_ready_cb(TpChannel *channel,
+
+static void
+_observe_channel_when_ready_cb(TpChannel *channel,
const GError *error,
gpointer user_data)
{
TplChannel *tpl_chan = TPL_CHANNEL(user_data);
- gpointer tpl_channel_instance;
- // TODO add a GHashTable mapping
- // channelpath:tpl_channel_instance to record observed channels
- // and a way to access (get/set) them
if(error!=NULL) {
- g_error("channel error: %s", error->message);
+ g_error("%s\n", error->message);
g_error("giving up observing channel '%s'",
tpl_chan->channel_path);
- // TODO free tpl_chan
- //tpl_channel_data_free(tpl_chan);
+ g_object_unref(tpl_chan);
return;
}
- tpl_channel_set_channel_type(tpl_chan,
- tp_channel_get_channel_type(tpl_chan->channel) );
+ tpl_channel_set_channel_type (tpl_chan,
+ tp_channel_get_channel_type (tpl_chan->channel));
- /* Instantiate and delegate channel handling to the right object */
- if(0==g_strcmp0(TP_IFACE_CHAN_TEXT, tpl_chan->channel_type)) {
- tpl_channel_instance = tpl_text_channel_new(tpl_chan);
- // TODO add to hash
- } else {
- g_warning("%s: channel not handled by TPL", tpl_chan->channel_type);
- }
+ tpl_channel_register_to_observer(tpl_chan);
}
-static void _tp_connection_called_when_ready_cb(TpConnection *connection,
+static void
+_get_ready_tp_channel(TpConnection *connection,
const GError *error,
gpointer user_data)
{
@@ -77,78 +71,93 @@ static void _tp_connection_called_when_ready_cb(TpConnection *connection,
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)
+ 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;
- TpDBusDaemon *tp_bus_daemon;
- GError *error = NULL;
-
- g_debug (" > tpl_observer_observe_channels\n");
- g_debug (" account = %s\n", account);
- g_debug (" connection = %s\n", connection);
- g_debug (" dispatchop = %s\n", dispatch_op);
-
- tp_bus_daemon = tp_dbus_daemon_dup(&error);
- if(tp_bus_daemon == NULL) {
- g_error("%s\n", error->message);
- g_clear_error(&error);
- g_error_free(error);
- }
-
- tp_acc = tp_account_new(tp_bus_daemon, account, &error);
- if(tp_acc == NULL) {
- g_error("%s\n", error->message);
- g_clear_error(&error);
- g_error_free(error);
- error=NULL;
- }
-
-
- tp_conn = tp_connection_new (tp_bus_daemon, NULL, connection, &error);
- if(tp_conn == NULL) {
- g_error("%s\n", error->message);
- g_clear_error(&error);
- g_error_free(error);
- error=NULL;
- }
-
- /* channels is of type a(oa{sv}) */
- for (guint i = 0; i < channels->len; i++)
- {
- GValueArray *channel = g_ptr_array_index (channels, i);
- TpChannel *tp_chan = NULL;
- TplChannel* tpl_chan = tpl_channel_new(self);
-
- char *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));
-
- g_debug (" channel = %s\n", path);
- tp_chan = tp_channel_new (tp_conn, path, NULL, TP_UNKNOWN_HANDLE_TYPE, 0,
- &error);
-
- 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,
- _tp_connection_called_when_ready_cb, tpl_chan);
- }
+ TpAccount *tp_acc;
+ TpConnection *tp_conn;
+ TpDBusDaemon *tp_bus_daemon;
+ GError *error = NULL;
+
+ tp_bus_daemon = tp_dbus_daemon_dup(&error);
+ if(tp_bus_daemon == NULL) {
+ g_error("%s\n", error->message);
+ g_clear_error(&error);
+ g_error_free(error);
+ return;
+ }
+
+ tp_acc = tp_account_new(tp_bus_daemon, account, &error);
+ if(tp_acc == NULL)
+ {
+ g_error("%s\n", error->message);
+ g_clear_error(&error);
+ g_error_free(error);
+ g_object_unref(tp_bus_daemon);
+ return;
+ }
+
+
+ tp_conn = tp_connection_new (tp_bus_daemon, NULL, connection, &error);
+ if(tp_conn == NULL)
+ {
+ g_error("%s\n", error->message);
+ g_clear_error(&error);
+ g_error_free(error);
+ g_object_unref(tp_bus_daemon);
+ g_object_unref(tp_acc);
+ return;
+ }
-
+ /* channels is of type a(oa{sv}) */
+ 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);
+ 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_svc_client_observer_return_from_observe_channels (context);
+ }
+
+ g_object_unref(tp_acc);
+ g_object_unref(tp_conn);
+ g_object_unref(tp_bus_daemon);
+
+ tp_svc_client_observer_return_from_observe_channels (context);
}
static void
@@ -157,18 +166,15 @@ tpl_observer_get_property (GObject *self,
GValue *value,
GParamSpec *pspec)
{
- g_print(" :: get_property\n");
switch (property_id)
{
GPtrArray *array;
GHashTable *map;
case PROP_INTERFACES:
- g_print (" :: interfaces\n");
g_value_set_boxed (value, client_interfaces);
break;
case PROP_CHANNEL_FILTER:
- g_print (" :: channel-filter\n");
/* create an empty filter - which means all channels */
array = g_ptr_array_new ();
@@ -239,9 +245,20 @@ tpl_observer_class_init (TplObserverClass *klass)
G_STRUCT_OFFSET (TplObserverClass, dbus_props_class));
}
+
+static gboolean tpl_str_are_eq(gconstpointer data, gconstpointer data2)
+{
+ return g_strcmp0(data, data2) ? FALSE : TRUE ;
+}
+
+
static void
tpl_observer_init (TplObserver *self)
{
+ //self->chan_map = g_hash_table_new_full (g_str_hash, g_strcmp0,
+ // g_free, g_object_unref);
+ glob_map = g_hash_table_new_full (g_str_hash, tpl_str_are_eq,
+ g_free, g_object_unref);
}
static void
@@ -259,3 +276,53 @@ TplObserver *tpl_observer_new (void)
{
return g_object_new (TYPE_TPL_OBSERVER, NULL);
}
+
+gboolean
+tpl_channel_register_to_observer(TplChannel *self)
+{
+ g_return_val_if_fail( self != NULL, FALSE);
+ g_assert(glob_map != NULL);
+
+ //TplObserver *obs = tpl_channel_get_observer(self);
+ gchar *key;
+
+ key = g_strdup (tpl_channel_get_channel_path (self));
+
+ if (g_hash_table_lookup(glob_map, key) != NULL) {
+ g_error("Channel path found, replacing %s\n", key);
+ g_hash_table_remove(glob_map, key);
+ } else {
+ g_message("Channel path not found, registering %s\n", key);
+ }
+
+ // Instantiate and delegate channel handling to the right object
+ if (0==g_strcmp0 (TP_IFACE_CHAN_TEXT,
+ tpl_channel_get_channel_type(self))) {
+ // when removed, automatically frees the Key and unrefs
+ // its Value
+ g_hash_table_insert(glob_map, key,
+ tpl_text_channel_new(self));
+ } else {
+ g_warning("%s: channel type not handled by this logger",
+ tpl_channel_get_channel_type(self));
+ }
+
+ g_object_unref(self);
+
+ return TRUE;
+}
+
+
+gboolean
+tpl_channel_unregister_from_observer(TplChannel *self)
+{
+ //TplObserver *obs = tpl_channel_get_observer(self);
+ const gchar *key;
+
+ g_return_val_if_fail( self != NULL, FALSE);
+
+ key = tpl_channel_get_channel_path (self);
+ g_message ("Unregistering channel path %s\n", key);
+
+ return g_hash_table_remove(glob_map, key);
+}
diff --git a/src/tpl-text-channel-context.c b/src/tpl-text-channel-context.c
index 125f520..f87bce8 100644
--- a/src/tpl-text-channel-context.c
+++ b/src/tpl-text-channel-context.c
@@ -25,9 +25,22 @@ static TpContactFeature features[TP_CONTACT_FEATURES_LEN] = {
TP_CONTACT_FEATURE_PRESENCE
};
+/* Signal's Callbacks */
+static void
+_channel_on_closed_cb (TpChannel *proxy,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ TplTextChannel *tpl_text = TPL_TEXT_CHANNEL(user_data);
+ TplChannel *tpl_chan = tpl_text_channel_get_tpl_channel(tpl_text);
+ gboolean is_unreg;
-/* Signal's Callbacks */
+ is_unreg = tpl_channel_unregister_from_observer(tpl_chan);
+ g_debug("%s has been unregistered? %d\n",
+ tpl_channel_get_channel_path(tpl_chan), is_unreg);
+ g_object_unref(tpl_text);
+}
static void
_channel_on_lost_message_cb (TpChannel *proxy,
@@ -262,42 +275,61 @@ _tpl_text_channel_pendingproc_connect_signals(TplTextChannel* self)
tpl_text_channel_get_tpl_channel (self) );
//TODO handle data destruction
- tp_cli_channel_type_text_connect_to_received(self->tpl_channel->channel,
- _channel_on_received_signal_cb, self, NULL, NULL, &error);
+ tp_cli_channel_type_text_connect_to_received(
+ channel, _channel_on_received_signal_cb,
+ self, NULL, NULL, &error);
if (error!=NULL) {
g_error("received signal connect: %s\n", error->message);
g_clear_error(&error);
g_error_free(error);
+ error = NULL;
}
//TODO handle data destruction
- tp_cli_channel_type_text_connect_to_sent(self->tpl_channel->channel,
- _channel_on_sent_signal_cb, self, NULL, NULL, &error);
+ tp_cli_channel_type_text_connect_to_sent(
+ channel, _channel_on_sent_signal_cb,
+ self, NULL, NULL, &error);
if (error!=NULL) {
g_error("sent signal connect: %s\n", error->message);
g_clear_error(&error);
g_error_free(error);
+ error = NULL;
}
//TODO handle data destruction
tp_cli_channel_type_text_connect_to_send_error(
- self->tpl_channel->channel,
- _channel_on_send_error_cb, self, NULL, NULL, &error);
+ channel, _channel_on_send_error_cb,
+ self, NULL, NULL, &error);
if (error!=NULL) {
g_error("send error signal connect: %s\n", error->message);
g_clear_error(&error);
g_error_free(error);
+ error = NULL;
}
//TODO handle data destruction
tp_cli_channel_type_text_connect_to_lost_message(
- self->tpl_channel->channel,
- _channel_on_lost_message_cb, self, NULL, NULL, &error);
+ channel, _channel_on_lost_message_cb,
+ self, NULL, NULL, &error);
if (error!=NULL) {
g_error("lost message signal connect: %s\n", error->message);
g_clear_error(&error);
g_error_free(error);
+ error = NULL;
}
+
+ tp_cli_channel_connect_to_closed (
+ channel, _channel_on_closed_cb,
+ self, NULL, NULL, &error);
+ if (error!=NULL) {
+ g_error("channel closed signal connect: %s\n", error->message);
+ g_clear_error(&error);
+ g_error_free(error);
+ error = NULL;
+ }
+
+
+
// TODO connect to TpContacts' notify::presence-type
@@ -442,12 +474,43 @@ _tpl_text_channel_pendingproc_get_my_contact(TplTextChannel *ctx)
G_DEFINE_TYPE (TplTextChannel, tpl_text_channel, G_TYPE_OBJECT)
-static void tpl_text_channel_class_init(TplTextChannelClass* klass) {
- //GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
+static void
+tpl_text_channel_dispose(GObject *obj) {
+ TplTextChannel *self = TPL_TEXT_CHANNEL(obj);
+
+ tpl_object_unref_if_not_null(self->tpl_channel);
+ self->tpl_channel = NULL;
+ tpl_object_unref_if_not_null(self->my_contact);
+ self->my_contact = NULL;
+ tpl_object_unref_if_not_null(self->remote_contact);
+ self->remote_contact = NULL;
+
+ g_queue_free(self->chain);
+ self->chain = NULL;
+
+ G_OBJECT_CLASS (tpl_text_channel_parent_class)->dispose (obj);
+}
+
+static void
+tpl_text_channel_finalize(GObject *obj) {
+ TplTextChannel *self = TPL_TEXT_CHANNEL(obj);
+
+ g_free ((gchar*) self->chatroom_id);
+ G_OBJECT_CLASS (tpl_text_channel_parent_class)->finalize (obj);
+
+}
+
+static void
+tpl_text_channel_class_init(TplTextChannelClass* klass) {
+ GObjectClass* object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = tpl_text_channel_dispose;
+ object_class->finalize = tpl_text_channel_finalize;
}
-static void tpl_text_channel_init(TplTextChannel* self) {
+static void
+tpl_text_channel_init(TplTextChannel* self) {
/* Init TplTextChannel's members to zero/NULL */
#define TPL_SET_NULL(x) tpl_text_channel_set_##x(self, NULL)
TPL_SET_NULL(tpl_channel);
@@ -458,7 +521,8 @@ static void tpl_text_channel_init(TplTextChannel* self) {
tpl_text_channel_set_chatroom(self, FALSE);
}
-TplTextChannel* tpl_text_channel_new(TplChannel* tpl_channel)
+TplTextChannel *
+tpl_text_channel_new(TplChannel* tpl_channel)
{
TplTextChannel *ret = g_object_new(TPL_TYPE_TEXT_CHANNEL,NULL);
tpl_text_channel_set_tpl_channel(ret, tpl_channel);
@@ -509,11 +573,6 @@ TplTextChannel* tpl_text_channel_new(TplChannel* tpl_channel)
return ret;
}
-void tpl_text_channel_free(TplTextChannel* tpl_text) {
- /* TODO free and unref other members */
- g_free(tpl_text);
-}
-
TplChannel *tpl_text_channel_get_tpl_channel(TplTextChannel *self)
{
@@ -537,26 +596,24 @@ const gchar *tpl_text_channel_get_chatroom_id(TplTextChannel *self)
return self->chatroom_id;
}
-void tpl_text_channel_set_tpl_channel(TplTextChannel *self, TplChannel *data) {
- //g_debug("SET TPL CHANNEL\n");
- _unref_object_if_not_null(&(self->tpl_channel));
+void tpl_text_channel_set_tpl_channel(TplTextChannel *self, TplChannel *data)
+{
+ tpl_object_unref_if_not_null(self->tpl_channel);
self->tpl_channel = data;
- _ref_object_if_not_null(data);
+ tpl_object_ref_if_not_null(data);
}
void tpl_text_channel_set_remote_contact(TplTextChannel *self, TpContact *data)
{
- //g_debug("SET remote contact\n");
- _unref_object_if_not_null(&(self->remote_contact));
+ tpl_object_unref_if_not_null(self->remote_contact);
self->remote_contact = data;
- _ref_object_if_not_null(data);
+ tpl_object_ref_if_not_null(data);
}
void tpl_text_channel_set_my_contact(TplTextChannel *self, TpContact *data)
{
- //g_debug("SET my contact\n");
- _unref_object_if_not_null(&(self->my_contact));
+ tpl_object_unref_if_not_null(self->my_contact);
self->my_contact = data;
- _ref_object_if_not_null(data);
+ tpl_object_ref_if_not_null(data);
}
void tpl_text_channel_set_chatroom(TplTextChannel *self, gboolean data)
{
diff --git a/src/tpl-utils.c b/src/tpl-utils.c
index 2f65476..a34ad8c 100644
--- a/src/tpl-utils.c
+++ b/src/tpl-utils.c
@@ -1,12 +1,12 @@
#include <tpl-utils.h>
-void _unref_object_if_not_null(void* data) {
+void tpl_object_unref_if_not_null(void* data) {
if (data && G_IS_OBJECT(data)) {
g_object_unref(data);
}
}
-void _ref_object_if_not_null(void* data) {
+void tpl_object_ref_if_not_null(void* data) {
if (data && G_IS_OBJECT(data)) {
g_object_ref(data);
}