summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2010-02-12 18:39:03 +0000
committerCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2010-02-12 19:26:07 +0000
commite5d921b41f216915d5b53097e269b2749842669f (patch)
treeb0ac331f5fbc04309c5242a5a554dcfb0df39ccd
parentcee3717ee97bfd4a3a116c4dd4d49a8d25c5c8d1 (diff)
downloadtelepathy-logger-e5d921b41f216915d5b53097e269b2749842669f.tar.gz
use tp_dbus_daemon_dup() and proper unref
-rw-r--r--src/telepathy-logger.c30
-rw-r--r--telepathy-logger/dbus-service.c45
-rw-r--r--telepathy-logger/observer.c67
3 files changed, 67 insertions, 75 deletions
diff --git a/src/telepathy-logger.c b/src/telepathy-logger.c
index 75b2411..7f3b832 100644
--- a/src/telepathy-logger.c
+++ b/src/telepathy-logger.c
@@ -39,6 +39,7 @@ static GMainLoop *loop = NULL;
static TpDebugSender *debug_sender = NULL;
static gboolean stamp_logs = FALSE;
+
static void
log_to_debug_sender (const gchar *log_domain,
GLogLevelFlags log_level,
@@ -54,6 +55,7 @@ log_to_debug_sender (const gchar *log_domain,
string);
}
+
static void
log_handler (const gchar *log_domain,
GLogLevelFlags log_level,
@@ -92,28 +94,34 @@ static void
telepathy_logger_dbus_init (void)
{
TplDBusService *dbus_srv = NULL;
- DBusGConnection *bus = NULL;
TpDBusDaemon *tp_bus = NULL;
GError *error = NULL;
- bus = tp_get_bus ();
- tp_bus = tp_dbus_daemon_new (bus);
- if (tp_dbus_daemon_request_name (tp_bus, TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME,
- TRUE, &error))
+ tp_bus = tp_dbus_daemon_dup (&error);
+ if (tp_bus == NULL)
{
- DEBUG ("%s DBus well known name registered",
- TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME);
+ g_critical ("Failed to acquire bus daemon: %s", error->message);
+ goto out;
}
- else
+
+ if (!tp_dbus_daemon_request_name (tp_bus, TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME,
+ FALSE, &error))
{
- DEBUG ("Well Known name request error: %s", error->message);
- g_error_free (error);
+ g_critical ("Failed to acquire bus name %s: %s",
+ TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME, error->message);
+ goto out;
}
dbus_srv = tpl_dbus_service_new ();
- dbus_g_connection_register_g_object (bus, TPL_DBUS_SRV_OBJECT_PATH,
+ dbus_g_connection_register_g_object (tp_get_bus(), TPL_DBUS_SRV_OBJECT_PATH,
G_OBJECT (dbus_srv));
+
+out:
+ if (error != NULL)
+ g_error_free (error);
+ g_object_unref (tp_bus);
+ g_object_unref (dbus_srv);
}
diff --git a/telepathy-logger/dbus-service.c b/telepathy-logger/dbus-service.c
index 8cacec0..d9dcc10 100644
--- a/telepathy-logger/dbus-service.c
+++ b/telepathy-logger/dbus-service.c
@@ -123,36 +123,33 @@ tpl_dbus_service_get_recent_messages (TplSvcLogger *self,
{
guint dates_idx;
gint msgs_idx;
- GError *error = NULL;
- TpAccount *account;
- DBusGConnection *dbus;
- TpDBusDaemon *tp_dbus;
+ TplDBusServicePriv *priv = GET_PRIV (self);
+ TpAccount *account = NULL;
+ TpDBusDaemon *tp_dbus = NULL;
GList *ret = NULL;
GPtrArray *answer = NULL;
GList *dates = NULL;
+ GError *error = NULL;
guint left_lines = lines;
TplDBusServicePriv *priv = GET_PRIV (self);
g_return_if_fail (TPL_IS_DBUS_SERVICE (self));
g_return_if_fail (context != NULL);
- dbus = tp_get_bus ();
- tp_dbus = tp_dbus_daemon_new (dbus);
+ tp_dbus = tp_dbus_daemon_dup (&error);
+ if (tp_dbus == NULL)
+ {
+ DEBUG ("Unable to acquire the bus daemon: %s", error->message);
+ goto out;
+ }
account = tp_account_new (tp_dbus, account_path, &error);
- if (error != NULL)
+ if (account == NULL)
{
- GError *loc_error = NULL;
-
- DEBUG ("TpAccount creation: %s", error->message);
- g_propagate_error (&loc_error, error);
- dbus_g_method_return_error (context, loc_error);
-
- g_error_free (error);
- g_error_free (loc_error);
- g_object_unref (tp_dbus);
- g_object_unref (dbus);
- return;
+ DEBUG ("Unable to acquire the account for %s: %s", account_path,
+ error->message);
+ dbus_g_method_return_error (context, error);
+ goto out;
}
dates = tpl_log_manager_get_dates (priv->manager, account, identifier,
@@ -163,11 +160,7 @@ tpl_dbus_service_get_recent_messages (TplSvcLogger *self,
TPL_DBUS_SERVICE_ERROR_FAILED, "Error during date list retrieving, "
"probably the account path or the identifier are does not exist");
dbus_g_method_return_error (context, error);
-
- g_object_unref (account);
- g_object_unref (tp_dbus);
- g_object_unref (dbus);
- return;
+ goto out;
}
dates = g_list_reverse (dates);
@@ -196,9 +189,9 @@ tpl_dbus_service_get_recent_messages (TplSvcLogger *self,
tpl_svc_logger_return_from_get_recent_messages (context, answer);
- g_object_unref (account);
- g_object_unref (tp_dbus);
- g_object_unref (dbus);
+out:
+ tpl_object_unref_if_not_null (account);
+ tpl_object_unref_if_not_null (tp_dbus);
}
diff --git a/telepathy-logger/observer.c b/telepathy-logger/observer.c
index 0427b41..33b769e 100644
--- a/telepathy-logger/observer.c
+++ b/telepathy-logger/observer.c
@@ -171,30 +171,30 @@ tpl_observer_observe_channels (TpSvcClientObserver *self,
goto error;
}
+ g_object_unref (conf);
- /* Instantiating objects to pass to - or needed by them - the Tpl Channel Factory in order to
- * obtain a TplChannelXXX instance */
+ /* Instantiating objects to pass to - or needed by them - the Tpl Channel
+ * Factory in order to obtain a TplChannelXXX instance */
tp_bus_daemon = tp_dbus_daemon_dup (&error);
if (tp_bus_daemon == NULL)
{
- DEBUG ("%s", error->message);
-
+ DEBUG ("Failed to acquire bus daemon: %s", error->message);
goto error;
}
tp_acc = tp_account_new (tp_bus_daemon, account, &error);
if (tp_acc == NULL)
{
- DEBUG ("%s", error->message);
-
+ DEBUG ("Failed to acquire account proxy for %s: %s", account,
+ error->message);
goto error;
}
tp_conn = tp_connection_new (tp_bus_daemon, NULL, connection, &error);
if (tp_conn == NULL)
{
- DEBUG ("%s", error->message);
-
+ DEBUG ("Failed to acquire connection proxy for %s: %s", connection,
+ error->message);
goto error;
}
@@ -239,13 +239,9 @@ tpl_observer_observe_channels (TpSvcClientObserver *self,
return;
error:
- if (tp_acc != NULL)
- g_object_unref (tp_acc);
- if (tp_conn != NULL)
- g_object_unref (tp_conn);
- if (tp_bus_daemon != NULL)
- g_object_unref (tp_bus_daemon);
-
+ tpl_object_unref_if_not_null (tp_acc);
+ tpl_object_unref_if_not_null (tp_conn);
+ tpl_object_unref_if_not_null (tp_bus_daemon);
g_clear_error (&error);
tp_svc_client_observer_return_from_observe_channels (dbus_context);
@@ -434,44 +430,39 @@ tpl_observer_init (TplObserver *self)
* Registers the object using #TPL_OBSERVER_WELL_KNOWN_BUS_NAME well known
* name.
*
- * Returns: %TRUE if registration suceeds or if the object is already
- * registered to DBus. or %FALSE if the object is not alerady registered and
- * the registration failed, in which case @error is set.
+ * Returns: %TRUE if the registration is successful, %FALSE with @error set if
+ * it fails.
*/
gboolean
tpl_observer_register_dbus (TplObserver *self,
GError **error)
{
- TplObserverPriv* priv = GET_PRIV (self);
- DBusGConnection *bus;
TpDBusDaemon *tp_bus;
+ gboolean ret = TRUE;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
g_return_val_if_fail (TPL_IS_OBSERVER (self), FALSE);
- /* just return TRUE if the Observer interface is actually already registered
- * to DBus */
- if (priv->dbus_registered)
- return TRUE;
-
- bus = tp_get_bus ();
- tp_bus = tp_dbus_daemon_new (bus);
+ tp_bus = tp_dbus_daemon_dup (error);
+ if (tp_bus == NULL)
+ {
+ ret = FALSE;
+ goto out;
+ }
if (!tp_dbus_daemon_request_name (tp_bus, TPL_OBSERVER_WELL_KNOWN_BUS_NAME,
- TRUE, error))
+ FALSE, error))
{
- g_assert (error == NULL || *error != NULL);
- return FALSE;
+ ret = FALSE;
+ goto out;
}
- priv->dbus_registered = TRUE;
- DEBUG ("%s DBus well known name registered",
- TPL_OBSERVER_WELL_KNOWN_BUS_NAME);
-
- dbus_g_connection_register_g_object (bus, TPL_OBSERVER_OBJECT_PATH,
- G_OBJECT (self));
-
- return TRUE;
+ dbus_g_connection_register_g_object (
+ tp_proxy_get_dbus_connection (TP_PROXY (tp_bus)),
+ TPL_OBSERVER_OBJECT_PATH, G_OBJECT (self));
+out:
+ g_object_unref (tp_bus);
+ return ret;
}