summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanielle Madeley <danielle.madeley@collabora.co.uk>2010-08-13 18:50:51 +1000
committerDanielle Madeley <danielle.madeley@collabora.co.uk>2010-08-13 18:50:51 +1000
commit231cc54febb459b2a7478b63fd5bf04a7ccbf7ac (patch)
tree0e5cbe81cfa8759e183f9122cb3b61724016e377
parentb700c61e4e11b25a24c7df076ff161c831b86ced (diff)
Update glib_dbus_tube to use the TpAccount, Channel Dispatcher etc.
-rw-r--r--docs/examples/glib_dbus_tube/accept-tube.c438
-rw-r--r--docs/examples/glib_dbus_tube/offer-tube.c433
2 files changed, 328 insertions, 543 deletions
diff --git a/docs/examples/glib_dbus_tube/accept-tube.c b/docs/examples/glib_dbus_tube/accept-tube.c
index 7b5a337..d846bf5 100644
--- a/docs/examples/glib_dbus_tube/accept-tube.c
+++ b/docs/examples/glib_dbus_tube/accept-tube.c
@@ -2,334 +2,222 @@
#include <glib.h>
-#include <telepathy-glib/connection-manager.h>
-#include <telepathy-glib/connection.h>
-#include <telepathy-glib/channel.h>
-#include <telepathy-glib/contact.h>
-#include <telepathy-glib/interfaces.h>
-#include <telepathy-glib/gtypes.h>
-#include <telepathy-glib/util.h>
-#include <telepathy-glib/enums.h>
-#include <telepathy-glib/debug.h>
+#include <telepathy-glib/telepathy-glib.h>
static GMainLoop *loop = NULL;
-static TpDBusDaemon *bus_daemon = NULL;
-static TpConnection *conn = NULL;
static void
handle_error (const GError *error)
{
- if (error)
- {
- g_print ("ERROR: %s\n", error->message);
- tp_cli_connection_call_disconnect (conn, -1, NULL,
- NULL, NULL, NULL);
- }
+ if (error != NULL)
+ {
+ g_error ("ERROR: %s", error->message);
+ }
}
static void
tube_state_changed_cb (TpChannel *channel,
- guint state,
- gpointer user_data,
- GObject *weak_obj)
+ guint state,
+ gpointer user_data,
+ GObject *weak_obj)
{
- g_print ("Tube state changed %i\n", state);
+ g_print ("Tube state changed %i\n", state);
}
static void
dbus_names_changed_cb (TpChannel *channel,
- GHashTable *added,
- const GArray *removed,
- gpointer user_data,
- GObject *weak_obj)
+ GHashTable *added,
+ const GArray *removed,
+ gpointer user_data,
+ GObject *weak_obj)
{
- g_print ("::DBusNamesChanged\n");
-
- GHashTableIter iter;
- gpointer key, value;
- guint handle;
- char *address;
-
- g_print ("Added:\n");
- g_hash_table_iter_init (&iter, added);
- while (g_hash_table_iter_next (&iter, &key, &value))
- {
- handle = GPOINTER_TO_UINT (key);
- address = (char *) value;
-
- g_print (" - %u: %s\n", handle, address);
- }
+ GHashTableIter iter;
+ gpointer key, value;
+ guint handle;
+ char *address;
+
+ g_print ("::DBusNamesChanged\n");
+
+ g_print ("Added:\n");
+ g_hash_table_iter_init (&iter, added);
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ {
+ handle = GPOINTER_TO_UINT (key);
+ address = (char *) value;
+
+ g_print (" - %u: %s\n", handle, address);
+ }
}
static void
-tube_accept_cb (TpChannel *channel,
- const char *address,
- const GError *in_error,
- gpointer user_data,
- GObject *weak_obj)
+tube_accept_cb (TpChannel *channel,
+ const char *address,
+ const GError *in_error,
+ gpointer user_data,
+ GObject *weak_obj)
{
- handle_error (in_error);
+ handle_error (in_error);
- g_print (" > tube_accept_cb (%s)\n", address);
+ g_print (" > tube_accept_cb (%s)\n", address);
}
static void
-channel_ready (TpChannel *channel,
- const GError *in_error,
- gpointer user_data)
+_handle_dbus_channel (TpSimpleHandler *handler,
+ TpAccount *account,
+ TpConnection *connection,
+ GList *channels,
+ GList *requests,
+ gint64 user_action_time,
+ TpHandleChannelsContext *context,
+ gpointer user_data)
{
- GError *error = NULL;
- g_print (" > channel_ready (%s)\n",
- tp_channel_get_identifier (channel));
-
- tp_cli_channel_interface_tube_connect_to_tube_channel_state_changed (
- channel, tube_state_changed_cb,
- NULL, NULL, NULL, &error);
- handle_error (error);
-
- tp_cli_channel_type_dbus_tube_connect_to_dbus_names_changed (
- channel, dbus_names_changed_cb,
- NULL, NULL, NULL, &error);
- handle_error (error);
-
- /* accept the channel */
- tp_cli_channel_type_dbus_tube_call_accept (channel, -1,
- TP_SOCKET_ACCESS_CONTROL_LOCALHOST,
- tube_accept_cb, NULL, NULL, NULL);
-}
-
-static void
-new_channels_cb (TpConnection *conn,
- const GPtrArray *channels,
- gpointer user_data,
- GObject *weak_obj)
-{
- GError *error = NULL;
-
- /* channels has the D-Bus type a(oa{sv}), which decomposes to:
- * - a GPtrArray containing a GValueArray for each channel
- * - each GValueArray contains
- * - an object path
- * - an a{sv} map
- */
-
- int i;
- for (i = 0; i < channels->len; i++)
- {
- GValueArray *channel = g_ptr_array_index (channels, i);
- char *object_path;
- GHashTable *map;
-
- tp_value_array_unpack (channel, 2,
- &object_path,
- &map);
-
- const char *type = tp_asv_get_string (map,
- TP_IFACE_CHANNEL ".ChannelType");
- guint handle_type = tp_asv_get_uint32 (map,
- TP_IFACE_CHANNEL ".TargetHandleType", NULL);
-
- /* if this channel is a contact list, we want to know
- * about it */
- if (!strcmp (type, TP_IFACE_CHANNEL_TYPE_DBUS_TUBE))
- {
- g_print ("New D-Bus Tube channel created\n");
- tp_asv_dump (map);
-
- TpChannel *channel = tp_channel_new_from_properties (
- conn, object_path, map,
- &error);
- handle_error (error);
-
- tp_channel_call_when_ready (channel,
- channel_ready, NULL);
- }
- else if (!strcmp (type, TP_IFACE_CHANNEL_TYPE_TEXT) &&
- handle_type == TP_HANDLE_TYPE_ROOM)
- {
- g_print ("Got MUC channel\n");
- }
- }
-}
-
-static void
-conn_ready (TpConnection *conn,
- const GError *in_error,
- gpointer user_data)
-{
- char **argv = (char **) user_data;
- GError *error = NULL;
-
- g_print (" > conn_ready\n");
-
- handle_error (in_error);
-
- /* check if the Requests interface is available */
- if (tp_proxy_has_interface_by_id (conn,
- TP_IFACE_QUARK_CONNECTION_INTERFACE_REQUESTS))
- {
- tp_cli_connection_interface_requests_connect_to_new_channels (
- conn, new_channels_cb,
- NULL, NULL, NULL, &error);
- handle_error (error);
-
- char *targetid = argv[2];
-
-#if 0
- g_print ("Dialling %s...\n", targetid);
-
- GHashTable *request = tp_asv_new (
- TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_DBUS_TUBE,
- TP_IFACE_CHANNEL ".TargetHandleType", TP_TYPE_HANDLE, TP_HANDLE_TYPE_CONTACT,
- TP_IFACE_CHANNEL ".TargetID", G_TYPE_STRING, targetid,
- TP_IFACE_CHANNEL_TYPE_DBUS_TUBE ".ServiceName", G_TYPE_STRING, "com.example.Telepathy.DbusTube",
- NULL);
-
- /* the 'publish' list */
- tp_cli_connection_interface_requests_call_create_channel (
- conn, -1, request, NULL, NULL, NULL, NULL);
-
- g_hash_table_destroy (request);
-#endif
- GHashTable *request = tp_asv_new (
- TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
- TP_IFACE_CHANNEL ".TargetHandleType", TP_TYPE_HANDLE, TP_HANDLE_TYPE_ROOM,
- TP_IFACE_CHANNEL ".TargetID", G_TYPE_STRING, targetid,
- NULL);
-
- tp_cli_connection_interface_requests_call_ensure_channel (
- conn, -1, request, NULL, NULL, NULL, NULL);
- g_hash_table_destroy (request);
- }
-}
-
-static void
-status_changed_cb (TpConnection *conn,
- guint status,
- guint reason,
- gpointer user_data,
- GObject *weak_object)
-{
- if (status == TP_CONNECTION_STATUS_DISCONNECTED)
- {
- g_print ("Disconnected\n");
- g_main_loop_quit (loop);
- }
- else if (status == TP_CONNECTION_STATUS_CONNECTED)
- {
- g_print ("Connected\n");
- }
-}
+ GList *l;
+ GError *error = NULL;
-static void
-request_connection_cb (TpConnectionManager *cm,
- const char *bus_name,
- const char *object_path,
- const GError *in_error,
- gpointer user_data,
- GObject *weak_object)
-{
- char **argv = (char **) user_data;
- GError *error = NULL;
+ for (l = channels; l != NULL; l = l->next)
+ {
+ TpChannel *channel = TP_CHANNEL (l->data);
- g_print (" > request_connection_cb (%s, %s)\n", bus_name, object_path);
+ g_print (" > incoming channel (%s)\n",
+ tp_channel_get_identifier (channel));
- if (in_error) g_error ("%s", in_error->message);
+ if (tp_channel_get_channel_type_id (channel) !=
+ TP_IFACE_QUARK_CHANNEL_TYPE_DBUS_TUBE)
+ continue;
- conn = tp_connection_new (bus_daemon, bus_name, object_path, &error);
- if (error) g_error ("%s", error->message);
+ tp_cli_channel_interface_tube_connect_to_tube_channel_state_changed (
+ channel, tube_state_changed_cb,
+ NULL, NULL, NULL, &error);
+ handle_error (error);
- tp_connection_call_when_ready (conn, conn_ready, argv);
+ tp_cli_channel_type_dbus_tube_connect_to_dbus_names_changed (
+ channel, dbus_names_changed_cb,
+ NULL, NULL, NULL, &error);
+ handle_error (error);
- tp_cli_connection_connect_to_status_changed (conn, status_changed_cb,
- NULL, NULL, NULL, &error);
- handle_error (error);
+ /* accept the channel */
+ tp_cli_channel_type_dbus_tube_call_accept (channel, -1,
+ TP_SOCKET_ACCESS_CONTROL_LOCALHOST,
+ tube_accept_cb, NULL, NULL, NULL);
+ }
- /* initiate the connection */
- tp_cli_connection_call_connect (conn, -1, NULL, NULL, NULL, NULL);
+ tp_handle_channels_context_accept (context);
}
+
static void
-cm_ready (TpConnectionManager *cm,
- const GError *in_error,
- gpointer user_data,
- GObject *weak_obj)
+_muc_channel_ready (GObject *request,
+ GAsyncResult *res,
+ gpointer user_data)
{
- char **argv = (char **) user_data;
-
- g_print (" > cm_ready\n");
-
- if (in_error) g_error ("%s", in_error->message);
+ GError *error = NULL;
- const TpConnectionManagerProtocol *prot = tp_connection_manager_get_protocol (cm, "jabber");
- if (!prot) g_error ("Protocol is not supported");
+ if (!tp_account_channel_request_ensure_channel_finish (
+ TP_ACCOUNT_CHANNEL_REQUEST (request), res, &error))
+ handle_error (error);
- char *username = argv[1];
- char *password = getpass ("Password: ");
-
- /* request a new connection */
- GHashTable *parameters = tp_asv_new (
- "account", G_TYPE_STRING, username,
- "password", G_TYPE_STRING, password,
- NULL);
-
- tp_cli_connection_manager_call_request_connection (cm, -1,
- "jabber",
- parameters,
- request_connection_cb,
- argv, NULL, NULL);
-
- g_hash_table_destroy (parameters);
+ g_print ("MUC channel ensured\n");
}
+
static void
-interrupt_cb (int signal)
+_account_ready (GObject *account,
+ GAsyncResult *res,
+ gpointer user_data)
{
- g_print ("Interrupt\n");
- /* disconnect */
- tp_cli_connection_call_disconnect (conn, -1, NULL, NULL, NULL, NULL);
+ TpDBusDaemon *dbus;
+ TpBaseClient *handler;
+ TpAccountChannelRequest *request;
+ GHashTable *props;
+ char **argv = (char **) user_data;
+ char *targetid = argv[2];
+ GError *error = NULL;
+
+ if (!tp_proxy_prepare_finish (account, res, &error))
+ handle_error (error);
+
+ dbus = tp_dbus_daemon_dup (&error);
+ if (dbus == NULL)
+ handle_error (error);
+
+ /* set up a handler for the Tube we're going to receive */
+ handler = tp_simple_handler_new (dbus,
+ TRUE, FALSE, "DBusTubeHandler", TRUE,
+ _handle_dbus_channel, NULL, NULL);
+
+ tp_base_client_take_handler_filter (handler,
+ tp_asv_new (
+ TP_PROP_CHANNEL_CHANNEL_TYPE,
+ G_TYPE_STRING,
+ TP_IFACE_CHANNEL_TYPE_DBUS_TUBE,
+
+ TP_PROP_CHANNEL_TARGET_HANDLE_TYPE,
+ G_TYPE_UINT,
+ TP_HANDLE_TYPE_ROOM,
+
+ TP_PROP_CHANNEL_TARGET_ID,
+ G_TYPE_STRING,
+ targetid,
+
+ TP_PROP_CHANNEL_TYPE_DBUS_TUBE_SERVICE_NAME,
+ G_TYPE_STRING,
+ "com.example.Telepathy.DbusTube",
+
+ NULL));
+
+ if (!tp_base_client_register (handler, &error))
+ handle_error (error);
+
+ /* ensure the MUC channel, but let the default handler handle it */
+ props = tp_asv_new (
+ TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
+ TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_ROOM,
+ TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, targetid,
+ NULL);
+
+ request = tp_account_channel_request_new (TP_ACCOUNT (account),
+ props, G_MAXINT64 /* current time */);
+
+ tp_account_channel_request_ensure_channel_async (request,
+ NULL, NULL, _muc_channel_ready, NULL);
+
+ g_hash_table_destroy (props);
+ g_object_unref (request);
+ g_object_unref (dbus);
}
+
int
-main (int argc, char **argv)
+main (int argc,
+ char **argv)
{
- GError *error = NULL;
-
- g_type_init ();
+ TpDBusDaemon *dbus;
+ TpAccount *account;
+ char *account_path;
+ gpointer user_data = argv;
+ GError *error = NULL;
- if (argc != 3)
- {
- g_error ("Must provide username and target!");
- }
+ g_type_init ();
- /* create a main loop */
- loop = g_main_loop_new (NULL, FALSE);
+ loop = g_main_loop_new (NULL, FALSE);
- /* acquire a connection to the D-Bus daemon */
- bus_daemon = tp_dbus_daemon_dup (&error);
- if (bus_daemon == NULL)
- {
- g_error ("%s", error->message);
- }
+ dbus = tp_dbus_daemon_dup (&error);
+ if (dbus == NULL)
+ handle_error (error);
- /* begin ex.basics.language-bindings.telepathy-glib.ready */
- /* we want to request the gabble CM */
- TpConnectionManager *cm = tp_connection_manager_new (bus_daemon,
- "gabble", NULL, &error);
- if (error) g_error ("%s", error->message);
+ account_path = g_strconcat (TP_ACCOUNT_OBJECT_PATH_BASE, argv[1], NULL);
+ account = tp_account_new (dbus, account_path, &error);
+ if (account == NULL)
+ handle_error (error);
- tp_connection_manager_call_when_ready (cm, cm_ready,
- argv, NULL, NULL);
- /* end ex.basics.language-bindings.telepathy-glib.ready */
+ g_free (account_path);
- /* set up a signal handler */
- struct sigaction sa = { 0 };
- sa.sa_handler = interrupt_cb;
- sigaction (SIGINT, &sa, NULL);
+ tp_proxy_prepare_async (account, NULL, _account_ready, user_data);
- g_main_loop_run (loop);
+ g_main_loop_run (loop);
- g_object_unref (bus_daemon);
+ g_object_unref (dbus);
+ g_object_unref (account);
- return 0;
+ return 0;
}
diff --git a/docs/examples/glib_dbus_tube/offer-tube.c b/docs/examples/glib_dbus_tube/offer-tube.c
index 67d0645..a073390 100644
--- a/docs/examples/glib_dbus_tube/offer-tube.c
+++ b/docs/examples/glib_dbus_tube/offer-tube.c
@@ -2,337 +2,234 @@
#include <glib.h>
-#include <telepathy-glib/connection-manager.h>
-#include <telepathy-glib/connection.h>
-#include <telepathy-glib/channel.h>
-#include <telepathy-glib/contact.h>
-#include <telepathy-glib/interfaces.h>
-#include <telepathy-glib/gtypes.h>
-#include <telepathy-glib/util.h>
-#include <telepathy-glib/enums.h>
-#include <telepathy-glib/debug.h>
+#include <telepathy-glib/telepathy-glib.h>
static GMainLoop *loop = NULL;
-static TpDBusDaemon *bus_daemon = NULL;
-static TpConnection *conn = NULL;
static void
handle_error (const GError *error)
{
- if (error)
- {
- g_print ("ERROR: %s\n", error->message);
- tp_cli_connection_call_disconnect (conn, -1, NULL,
- NULL, NULL, NULL);
- }
+ if (error != NULL)
+ {
+ g_error ("ERROR: %s", error->message);
+ }
}
+
static void
tube_state_changed_cb (TpChannel *channel,
- guint state,
- gpointer user_data,
- GObject *weak_obj)
+ guint state,
+ gpointer user_data,
+ GObject *weak_obj)
{
- g_print ("Tube state changed %i\n", state);
+ g_print ("Tube state changed %i\n", state);
}
+
static void
dbus_names_changed_cb (TpChannel *channel,
- GHashTable *added,
- const GArray *removed,
- gpointer user_data,
- GObject *weak_obj)
+ GHashTable *added,
+ const GArray *removed,
+ gpointer user_data,
+ GObject *weak_obj)
{
- g_print ("::DBusNamesChanged\n");
-
- GHashTableIter iter;
- guint key;
- char *value;
-
- g_print ("Added:\n");
- g_hash_table_iter_init (&iter, added);
- while (g_hash_table_iter_next (&iter,
- (gpointer *) &key, (gpointer *) &value))
- {
- g_print (" - %u: %s\n", key, value);
- }
-}
+ GHashTableIter iter;
+ guint key;
+ char *value;
-static void
-tube_offer_cb (TpChannel *channel,
- const char *address,
- const GError *in_error,
- gpointer user_data,
- GObject *weak_obj)
-{
- handle_error (in_error);
+ g_print ("::DBusNamesChanged\n");
- g_print (" > tube_offer_cb (%s)\n", address);
+ g_print ("Added:\n");
+ g_hash_table_iter_init (&iter, added);
+ while (g_hash_table_iter_next (&iter,
+ (gpointer *) &key, (gpointer *) &value))
+ g_print (" - %u: %s\n", key, value);
}
-static void
-channel_ready (TpChannel *channel,
- const GError *in_error,
- gpointer user_data)
-{
- GError *error = NULL;
- g_print (" > channel_ready (%s)\n",
- tp_channel_get_identifier (channel));
-
- tp_cli_channel_interface_tube_connect_to_tube_channel_state_changed (
- channel, tube_state_changed_cb,
- NULL, NULL, NULL, &error);
- handle_error (error);
-
- tp_cli_channel_type_dbus_tube_connect_to_dbus_names_changed (
- channel, dbus_names_changed_cb,
- NULL, NULL, NULL, &error);
- handle_error (error);
-
- g_print ("Offering Tube...\n");
- GHashTable *parameters = tp_asv_new (
- "SomeKey", G_TYPE_STRING, "SomeValue",
- "IntKey", G_TYPE_INT, 42,
- NULL);
-
- tp_cli_channel_type_dbus_tube_call_offer (channel, -1,
- parameters, TP_SOCKET_ACCESS_CONTROL_LOCALHOST,
- tube_offer_cb, NULL, NULL, NULL);
-
- g_hash_table_destroy (parameters);
-}
static void
-new_channels_cb (TpConnection *conn,
- const GPtrArray *channels,
- gpointer user_data,
- GObject *weak_obj)
+tube_offer_cb (TpChannel *channel,
+ const char *address,
+ const GError *in_error,
+ gpointer user_data,
+ GObject *weak_obj)
{
- GError *error = NULL;
-
- /* channels has the D-Bus type a(oa{sv}), which decomposes to:
- * - a GPtrArray containing a GValueArray for each channel
- * - each GValueArray contains
- * - an object path
- * - an a{sv} map
- */
-
- int i;
- for (i = 0; i < channels->len; i++)
- {
- GValueArray *channel = g_ptr_array_index (channels, i);
- char *object_path;
- GHashTable *map;
-
- tp_value_array_unpack (channel, 2,
- &object_path,
- &map);
-
- const char *type = tp_asv_get_string (map,
- TP_IFACE_CHANNEL ".ChannelType");
- guint handle_type = tp_asv_get_uint32 (map,
- TP_IFACE_CHANNEL ".TargetHandleType", NULL);
- const char *targetid = tp_asv_get_string (map,
- TP_IFACE_CHANNEL ".TargetID");
-
- /* if this channel is a contact list, we want to know
- * about it */
- if (!strcmp (type, TP_IFACE_CHANNEL_TYPE_DBUS_TUBE))
- {
- g_print ("New D-Bus Tube channel created\n");
- TpChannel *channel = tp_channel_new_from_properties (
- conn, object_path, map,
- &error);
- handle_error (error);
-
- tp_channel_call_when_ready (channel,
- channel_ready, NULL);
- }
- else if (!strcmp (type, TP_IFACE_CHANNEL_TYPE_TEXT) &&
- handle_type == TP_HANDLE_TYPE_ROOM)
- {
- g_print ("Got MUC channel\n");
-
- /* Dial up a D-Bus Tube */
- GHashTable *request = tp_asv_new (
- TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_DBUS_TUBE,
- TP_IFACE_CHANNEL ".TargetHandleType", TP_TYPE_HANDLE, handle_type,
- TP_IFACE_CHANNEL ".TargetID", G_TYPE_STRING, targetid,
- TP_IFACE_CHANNEL_TYPE_DBUS_TUBE ".ServiceName", G_TYPE_STRING, "com.example.Telepathy.DbusTube",
- NULL);
-
- tp_cli_connection_interface_requests_call_create_channel (
- conn, -1, request, NULL, NULL, NULL, NULL);
-
- g_hash_table_destroy (request);
- }
- }
-}
+ handle_error (in_error);
-static void
-conn_ready (TpConnection *conn,
- const GError *in_error,
- gpointer user_data)
-{
- char **argv = (char **) user_data;
- GError *error = NULL;
-
- g_print (" > conn_ready\n");
-
- handle_error (in_error);
-
- /* check if the Requests interface is available */
- if (tp_proxy_has_interface_by_id (conn,
- TP_IFACE_QUARK_CONNECTION_INTERFACE_REQUESTS))
- {
- tp_cli_connection_interface_requests_connect_to_new_channels (
- conn, new_channels_cb,
- NULL, NULL, NULL, &error);
- handle_error (error);
-
- char *targetid = argv[2];
-
-#if 0
-#endif
- GHashTable *request = tp_asv_new (
- TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
- TP_IFACE_CHANNEL ".TargetHandleType", TP_TYPE_HANDLE, TP_HANDLE_TYPE_ROOM,
- TP_IFACE_CHANNEL ".TargetID", G_TYPE_STRING, targetid,
- NULL);
-
- tp_cli_connection_interface_requests_call_ensure_channel (
- conn, -1, request, NULL, NULL, NULL, NULL);
- g_hash_table_destroy (request);
- }
+ g_print (" > tube_offer_cb (%s)\n", address);
}
-static void
-status_changed_cb (TpConnection *conn,
- guint status,
- guint reason,
- gpointer user_data,
- GObject *weak_object)
-{
- if (status == TP_CONNECTION_STATUS_DISCONNECTED)
- {
- g_print ("Disconnected\n");
- g_main_loop_quit (loop);
- }
- else if (status == TP_CONNECTION_STATUS_CONNECTED)
- {
- g_print ("Connected\n");
- }
-}
static void
-request_connection_cb (TpConnectionManager *cm,
- const char *bus_name,
- const char *object_path,
- const GError *in_error,
- gpointer user_data,
- GObject *weak_object)
+_tube_channel_ready (GObject *request,
+ GAsyncResult *res,
+ gpointer user_data)
{
- char **argv = (char **) user_data;
- GError *error = NULL;
+ TpChannel *channel;
+ GHashTable *parameters;
+ GError *error = NULL;
+
+ channel = tp_account_channel_request_create_and_handle_channel_finish (
+ TP_ACCOUNT_CHANNEL_REQUEST (request), res, NULL, &error);
+ if (channel == NULL)
+ handle_error (error);
+
+ g_print (" > channel_ready (%s)\n",
+ tp_channel_get_identifier (channel));
+
+ /* FIXME: this will all be replaced by TpDBusTube */
+ tp_cli_channel_interface_tube_connect_to_tube_channel_state_changed (
+ channel, tube_state_changed_cb,
+ NULL, NULL, NULL, &error);
+ handle_error (error);
+
+ tp_cli_channel_type_dbus_tube_connect_to_dbus_names_changed (
+ channel, dbus_names_changed_cb,
+ NULL, NULL, NULL, &error);
+ handle_error (error);
+
+ g_print ("Offering Tube...\n");
+ parameters = tp_asv_new (
+ "SomeKey", G_TYPE_STRING, "SomeValue",
+ "IntKey", G_TYPE_INT, 42,
+ NULL);
+
+ tp_cli_channel_type_dbus_tube_call_offer (channel, -1,
+ parameters, TP_SOCKET_ACCESS_CONTROL_LOCALHOST,
+ tube_offer_cb, NULL, NULL, NULL);
+
+ g_hash_table_destroy (parameters);
+}
- g_print (" > request_connection_cb (%s, %s)\n", bus_name, object_path);
- if (in_error) g_error ("%s", in_error->message);
+static GHashTable *
+_tp_asv_copy (GHashTable *in)
+{
+ GHashTable *out;
- conn = tp_connection_new (bus_daemon, bus_name, object_path, &error);
- if (error) g_error ("%s", error->message);
+ if (in == NULL)
+ return NULL;
- tp_connection_call_when_ready (conn, conn_ready, argv);
+ out = tp_asv_new (NULL, NULL);
- tp_cli_connection_connect_to_status_changed (conn, status_changed_cb,
- NULL, NULL, NULL, &error);
- handle_error (error);
+ /* keys are not copied (always assumed to be static strings) */
+ tp_g_hash_table_update (out, in, NULL, (GBoxedCopyFunc) tp_g_value_slice_dup);
- /* initiate the connection */
- tp_cli_connection_call_connect (conn, -1, NULL, NULL, NULL, NULL);
+ return out;
}
+
static void
-cm_ready (TpConnectionManager *cm,
- const GError *in_error,
- gpointer user_data,
- GObject *weak_obj)
+_muc_channel_ready (GObject *request,
+ GAsyncResult *res,
+ gpointer user_data)
{
- char **argv = (char **) user_data;
+ TpAccountChannelRequest *request2;
+ GHashTable *props;
+ GError *error = NULL;
- g_print (" > cm_ready\n");
+ if (!tp_account_channel_request_ensure_channel_finish (
+ TP_ACCOUNT_CHANNEL_REQUEST (request), res, &error))
+ handle_error (error);
- if (in_error) g_error ("%s", in_error->message);
+ g_print ("MUC channel ensured\n");
- const TpConnectionManagerProtocol *prot = tp_connection_manager_get_protocol (cm, "jabber");
- if (!prot) g_error ("Protocol is not supported");
+ /* Dial up a D-Bus Tube using the same request */
+ props = _tp_asv_copy (tp_account_channel_request_get_request (
+ TP_ACCOUNT_CHANNEL_REQUEST (request)));
- char *username = argv[1];
- char *password = getpass ("Password: ");
+ tp_asv_set_string (props,
+ TP_PROP_CHANNEL_CHANNEL_TYPE,
+ TP_IFACE_CHANNEL_TYPE_DBUS_TUBE);
+ tp_asv_set_string (props,
+ TP_PROP_CHANNEL_TYPE_DBUS_TUBE_SERVICE_NAME,
+ "com.example.Telepathy.DbusTube");
- /* request a new connection */
- GHashTable *parameters = tp_asv_new (
- "account", G_TYPE_STRING, username,
- "password", G_TYPE_STRING, password,
- NULL);
+ request2 = tp_account_channel_request_new (
+ tp_account_channel_request_get_account (
+ TP_ACCOUNT_CHANNEL_REQUEST (request)),
+ props, G_MAXINT64 /* current time */);
- tp_cli_connection_manager_call_request_connection (cm, -1,
- "jabber",
- parameters,
- request_connection_cb,
- argv, NULL, NULL);
+ tp_account_channel_request_create_and_handle_channel_async (request2,
+ NULL, _tube_channel_ready, NULL);
- g_hash_table_destroy (parameters);
+ g_hash_table_destroy (props);
}
+
static void
-interrupt_cb (int signal)
+_account_ready (GObject *account,
+ GAsyncResult *res,
+ gpointer user_data)
{
- g_print ("Interrupt\n");
- /* disconnect */
- tp_cli_connection_call_disconnect (conn, -1, NULL, NULL, NULL, NULL);
+ TpAccountChannelRequest *request;
+ GHashTable *props;
+ char **argv = (char **) user_data;
+ char *targetid = argv[2];
+ GError *error = NULL;
+
+ if (!tp_proxy_prepare_finish (account, res, &error))
+ handle_error (error);
+
+ props = tp_asv_new (
+ TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
+ TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, TP_TYPE_HANDLE, TP_HANDLE_TYPE_ROOM,
+ TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, targetid,
+ NULL);
+
+ request = tp_account_channel_request_new (TP_ACCOUNT (account),
+ props, G_MAXINT64 /* current time */);
+
+ /* ensure this channel, but let the default handler handle it */
+ tp_account_channel_request_ensure_channel_async (request,
+ NULL, NULL, _muc_channel_ready, NULL);
+
+ g_hash_table_destroy (props);
+ g_object_unref (request);
}
+
int
main (int argc, char **argv)
{
- GError *error = NULL;
+ TpDBusDaemon *dbus;
+ TpAccount *account;
+ char *account_path;
+ gpointer user_data = argv;
+ GError *error = NULL;
+
+ g_type_init ();
- g_type_init ();
+ if (argc != 3)
+ g_error ("Must provide account and MUC name!");
- if (argc != 3)
- {
- g_error ("Must provide username and target!");
- }
+ /* create a main loop */
+ loop = g_main_loop_new (NULL, FALSE);
- /* create a main loop */
- loop = g_main_loop_new (NULL, FALSE);
+ /* acquire a connection to the D-Bus daemon */
+ dbus = tp_dbus_daemon_dup (&error);
+ if (dbus == NULL)
+ handle_error (error);
- /* acquire a connection to the D-Bus daemon */
- bus_daemon = tp_dbus_daemon_dup (&error);
- if (bus_daemon == NULL)
- {
- g_error ("%s", error->message);
- }
+ /* get the complete path of the account */
+ account_path = g_strconcat (TP_ACCOUNT_OBJECT_PATH_BASE, argv[1], NULL);
- /* begin ex.basics.language-bindings.telepathy-glib.ready */
- /* we want to request the gabble CM */
- TpConnectionManager *cm = tp_connection_manager_new (bus_daemon,
- "gabble", NULL, &error);
- if (error) g_error ("%s", error->message);
+ /* begin ex.basics.language-bindings.telepathy-glib.ready */
+ /* get the account */
+ account = tp_account_new (dbus, account_path, &error);
+ if (account == NULL)
+ handle_error (error);
- tp_connection_manager_call_when_ready (cm, cm_ready,
- argv, NULL, NULL);
- /* end ex.basics.language-bindings.telepathy-glib.ready */
+ /* prepare the core account features */
+ tp_proxy_prepare_async (account, NULL, _account_ready, user_data);
+ /* end ex.basics.language-bindings.telepathy-glib.ready */
- /* set up a signal handler */
- struct sigaction sa = { 0 };
- sa.sa_handler = interrupt_cb;
- sigaction (SIGINT, &sa, NULL);
+ g_free (account_path);
- g_main_loop_run (loop);
+ g_main_loop_run (loop);
- g_object_unref (bus_daemon);
+ g_object_unref (dbus);
+ g_object_unref (account);
- return 0;
+ return 0;
}