telepathy-glib: Examples: stop using tp_account/connection/channel_new()
Xavier Claessens
xclaesse at kemper.freedesktop.org
Tue Jul 3 04:55:40 PDT 2012
Module: telepathy-glib
Branch: master
Commit: 633b26af12ce440481b75ec4ce7ab9786033bc9a
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=633b26af12ce440481b75ec4ce7ab9786033bc9a
Author: Xavier Claessens <xavier.claessens at collabora.co.uk>
Date: Wed May 16 14:24:32 2012 +0200
Examples: stop using tp_account/connection/channel_new()
https://bugs.freedesktop.org/show_bug.cgi?id=49372
---
examples/client/dbus-tubes/offerer.c | 9 ++++---
examples/client/extended-client.c | 7 ++++-
examples/client/inspect-channel.c | 37 +++++++++----------------------
examples/client/inspect-connection.c | 35 ++++++------------------------
examples/client/inspect-contact.c | 34 +++++------------------------
examples/client/stream-tubes/offerer.c | 9 ++++---
6 files changed, 39 insertions(+), 92 deletions(-)
diff --git a/examples/client/dbus-tubes/offerer.c b/examples/client/dbus-tubes/offerer.c
index 87ffbb9..baa61d0 100644
--- a/examples/client/dbus-tubes/offerer.c
+++ b/examples/client/dbus-tubes/offerer.c
@@ -179,7 +179,7 @@ int
main (int argc,
const char **argv)
{
- TpDBusDaemon *dbus;
+ TpSimpleClientFactory *factory;
TpAccount *account;
char *account_path;
GError *error = NULL;
@@ -191,11 +191,11 @@ main (int argc,
if (argc != 3)
g_error ("Usage: offerer gabble/jabber/ladygaga t-pain at example.com");
- dbus = tp_dbus_daemon_dup (&error);
- g_assert_no_error (error);
+ factory = tp_simple_client_factory_new (NULL);
account_path = g_strconcat (TP_ACCOUNT_OBJECT_PATH_BASE, argv[1], NULL);
- account = tp_account_new (dbus, account_path, &error);
+ account = tp_simple_client_factory_ensure_account (factory, account_path,
+ NULL, &error);
g_assert_no_error (error);
g_free (account_path);
@@ -233,6 +233,7 @@ main (int argc,
g_object_unref (req);
g_hash_table_unref (request);
g_main_loop_unref (loop);
+ g_object_unref (factory);
return 0;
}
diff --git a/examples/client/extended-client.c b/examples/client/extended-client.c
index 3ebf401..8572b63 100644
--- a/examples/client/extended-client.c
+++ b/examples/client/extended-client.c
@@ -205,6 +205,7 @@ cm_requested_connection (TpConnectionManager *manager,
gpointer user_data,
GObject *weak_object)
{
+ TpSimpleClientFactory *factory;
GError *e = NULL;
TpConnection *conn;
@@ -212,8 +213,10 @@ cm_requested_connection (TpConnectionManager *manager,
return;
/* FIXME: there should be convenience API for this */
- conn = tp_connection_new (tp_proxy_get_dbus_daemon (manager),
- bus_name, object_path, &e);
+ factory = tp_simple_client_factory_new (NULL);
+ conn = tp_simple_client_factory_ensure_connection (factory, object_path, NULL,
+ &e);
+ g_object_unref (factory);
if (conn == NULL)
{
diff --git a/examples/client/inspect-channel.c b/examples/client/inspect-channel.c
index b449287..969a4f8 100644
--- a/examples/client/inspect-channel.c
+++ b/examples/client/inspect-channel.c
@@ -91,6 +91,7 @@ connection_ready_cb (GObject *source,
{
InspectChannelData *data = user_data;
GError *error = NULL;
+ TpSimpleClientFactory *factory;
TpConnection *connection = TP_CONNECTION (source);
TpChannel *channel = NULL;
@@ -104,8 +105,9 @@ connection_ready_cb (GObject *source,
return;
}
- channel = tp_channel_new (connection, data->object_path, NULL,
- TP_UNKNOWN_HANDLE_TYPE, 0, &error);
+ factory = tp_proxy_get_factory (connection);
+ channel = tp_simple_client_factory_ensure_channel (factory, connection,
+ data->object_path, NULL, &error);
if (channel == NULL)
{
@@ -130,8 +132,7 @@ main (int argc,
char **argv)
{
InspectChannelData data = { 1, NULL, NULL };
- const gchar *conn_name;
- TpDBusDaemon *dbus = NULL;
+ TpSimpleClientFactory *factory;
TpConnection *connection = NULL;
GError *error = NULL;
@@ -141,30 +142,15 @@ main (int argc,
if (argc < 3)
{
fputs ("Usage:\n"
- " telepathy-example-inspect-channel CONN OBJECT_PATH\n"
- "CONN may either be a connection's well-known bus name or object\n"
- "path.\n",
+ " telepathy-example-inspect-channel CONN_PATH CHANNEL_PATH\n",
stderr);
return 2;
}
- conn_name = argv[1];
data.object_path = argv[2];
-
- dbus = tp_dbus_daemon_dup (&error);
-
- if (dbus == NULL)
- {
- g_warning ("%s", error->message);
- g_error_free (error);
- data.exit_status = 1;
- goto out;
- }
-
- if (conn_name[0] == '/')
- connection = tp_connection_new (dbus, NULL, conn_name, &error);
- else
- connection = tp_connection_new (dbus, conn_name, NULL, &error);
+ factory = tp_simple_client_factory_new (NULL);
+ connection = tp_simple_client_factory_ensure_connection (factory,
+ argv[1], NULL, &error);
if (connection == NULL)
{
@@ -185,14 +171,13 @@ main (int argc,
g_main_loop_run (data.main_loop);
out:
- if (dbus != NULL)
- g_object_unref (dbus);
-
if (data.main_loop != NULL)
g_main_loop_unref (data.main_loop);
if (connection != NULL)
g_object_unref (connection);
+ g_object_unref (factory);
+
return data.exit_status;
}
diff --git a/examples/client/inspect-connection.c b/examples/client/inspect-connection.c
index edf0cfc..6b6fa81 100644
--- a/examples/client/inspect-connection.c
+++ b/examples/client/inspect-connection.c
@@ -81,10 +81,9 @@ int
main (int argc,
char **argv)
{
- const gchar *bus_name, *object_path;
TpConnection *connection = NULL;
GMainLoop *mainloop = NULL;
- TpDBusDaemon *dbus = NULL;
+ TpSimpleClientFactory *factory;
GError *error = NULL;
g_type_init ();
@@ -92,36 +91,17 @@ main (int argc,
if (argc < 2)
{
- fputs ("Usage: one of\n"
- " telepathy-example-inspect-connection BUS_NAME\n"
- " telepathy-example-inspect-connection OBJECT_PATH\n"
- " telepathy-example-inspect-connection BUS_NAME OBJECT_PATH\n",
+ fputs ("Usage:\n"
+ " telepathy-example-inspect-connection OBJECT_PATH\n",
stderr);
return 2;
}
mainloop = g_main_loop_new (NULL, FALSE);
- bus_name = argv[1];
- object_path = argv[2]; /* might be NULL */
-
- /* Cope with the arguments being a bus name, an object path or both */
- if (bus_name[0] == '/' && argc == 2)
- {
- object_path = bus_name;
- bus_name = NULL;
- }
-
- dbus = tp_dbus_daemon_dup (&error);
-
- if (dbus == NULL)
- {
- g_warning ("%s", error->message);
- g_error_free (error);
- goto out;
- }
-
- connection = tp_connection_new (dbus, bus_name, object_path, &error);
+ factory = tp_simple_client_factory_new (NULL);
+ connection = tp_simple_client_factory_ensure_connection (factory,
+ argv[1], NULL, &error);
if (connection == NULL)
{
@@ -145,8 +125,7 @@ out:
if (mainloop != NULL)
g_main_loop_unref (mainloop);
- if (dbus != NULL)
- g_object_unref (dbus);
+ g_object_unref (factory);
return exit_status;
}
diff --git a/examples/client/inspect-contact.c b/examples/client/inspect-contact.c
index 2b79da0..5c967c5 100644
--- a/examples/client/inspect-contact.c
+++ b/examples/client/inspect-contact.c
@@ -152,10 +152,9 @@ int
main (int argc,
char **argv)
{
- const gchar *bus_name, *object_path;
TpConnection *connection = NULL;
InspectContactData data = { NULL, 1, NULL };
- TpDBusDaemon *dbus = NULL;
+ TpSimpleClientFactory *factory;
GError *error = NULL;
g_type_init ();
@@ -164,36 +163,16 @@ main (int argc,
if (argc < 2)
{
fputs ("Usage:\n"
- " telepathy-example-inspect-connection OBJECT_PATH [CONTACT_ID]\n"
- "or\n"
- " telepathy-example-inspect-connection BUS_NAME [CONTACT_ID]\n",
+ " telepathy-example-inspect-connection OBJECT_PATH [CONTACT_ID]\n",
stderr);
return 2;
}
- /* Cope with the first argument being a bus name or an object path */
- if (argv[1][0] == '/')
- {
- object_path = argv[1];
- bus_name = NULL;
- }
- else
- {
- object_path = NULL;
- bus_name = argv[1];
- }
-
data.to_inspect = argv[2];
- dbus = tp_dbus_daemon_dup (&error);
-
- if (dbus == NULL)
- {
- g_warning ("%s", error->message);
- goto out;
- }
-
- connection = tp_connection_new (dbus, bus_name, object_path, &error);
+ factory = tp_simple_client_factory_new (NULL);
+ connection = tp_simple_client_factory_ensure_connection (factory,
+ argv[1], NULL, &error);
if (connection == NULL)
{
@@ -221,8 +200,7 @@ out:
if (connection != NULL)
g_object_unref (connection);
- if (dbus != NULL)
- g_object_unref (dbus);
+ g_object_unref (factory);
return data.exit_status;
}
diff --git a/examples/client/stream-tubes/offerer.c b/examples/client/stream-tubes/offerer.c
index 3ba0106..3b86f82 100644
--- a/examples/client/stream-tubes/offerer.c
+++ b/examples/client/stream-tubes/offerer.c
@@ -131,7 +131,7 @@ int
main (int argc,
const char **argv)
{
- TpDBusDaemon *dbus;
+ TpSimpleClientFactory *factory;
TpAccount *account;
char *account_path;
GError *error = NULL;
@@ -142,11 +142,11 @@ main (int argc,
g_type_init ();
- dbus = tp_dbus_daemon_dup (&error);
- g_assert_no_error (error);
+ factory = tp_simple_client_factory_new (NULL);
account_path = g_strconcat (TP_ACCOUNT_OBJECT_PATH_BASE, argv[1], NULL);
- account = tp_account_new (dbus, account_path, &error);
+ account = tp_simple_client_factory_ensure_account (factory, account_path,
+ NULL, &error);
g_assert_no_error (error);
g_free (account_path);
@@ -184,6 +184,7 @@ main (int argc,
g_object_unref (req);
g_hash_table_unref (request);
g_main_loop_unref (loop);
+ g_object_unref (factory);
return 0;
}
More information about the telepathy-commits
mailing list