summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanielle Madeley <danielle.madeley@collabora.co.uk>2010-08-18 13:53:37 +1000
committerDanielle Madeley <danielle.madeley@collabora.co.uk>2010-08-20 10:52:28 +1000
commit75e0f172ab99dfb1ea3eb298015454f90f2c2903 (patch)
tree2f929826d6f0f5bc7647266a1a8ed5c05b47f374
parentae02a0c86a7f36aafc9fd62d0288147223f01334 (diff)
Update glib_mc5_ft_handler to use TpSimpleHandler
-rw-r--r--docs/examples/glib_mc5_ft_handler/Makefile.am1
-rw-r--r--docs/examples/glib_mc5_ft_handler/example.c84
2 files changed, 66 insertions, 19 deletions
diff --git a/docs/examples/glib_mc5_ft_handler/Makefile.am b/docs/examples/glib_mc5_ft_handler/Makefile.am
index e3b381c..409e2b6 100644
--- a/docs/examples/glib_mc5_ft_handler/Makefile.am
+++ b/docs/examples/glib_mc5_ft_handler/Makefile.am
@@ -4,7 +4,6 @@ LDADD = $(TELEPATHY_GLIB_LIBS)
noinst_PROGRAMS = example
example_SOURCES = \
- example-handler.c example-handler.h \
example.c
include $(top_srcdir)/docs/rsync-dist.make
diff --git a/docs/examples/glib_mc5_ft_handler/example.c b/docs/examples/glib_mc5_ft_handler/example.c
index c10c252..848c8fd 100644
--- a/docs/examples/glib_mc5_ft_handler/example.c
+++ b/docs/examples/glib_mc5_ft_handler/example.c
@@ -1,41 +1,89 @@
/*
- * An example of talking to MC5 to get available connections
+ * Example for using TpSimpleHandler
*/
#include <glib.h>
-#include <dbus/dbus-glib.h>
-#include <telepathy-glib/dbus.h>
-#include <telepathy-glib/defs.h>
-
-#include "example-handler.h"
+#include <telepathy-glib/telepathy-glib.h>
#define CLIENT_NAME "ExampleFTHandler"
static GMainLoop *loop = NULL;
+
+static void
+handle_channels (TpSimpleHandler *handler,
+ TpAccount *account,
+ TpConnection *conn,
+ GList *channels,
+ GList *requests,
+ gint64 user_action_time,
+ TpHandleChannelsContext *context,
+ gpointer user_data)
+{
+ GList *l;
+ GError *error = NULL;
+
+ g_print (" > handle_channels\n");
+ g_print (" account = %s\n", tp_proxy_get_object_path (account));
+ g_print (" connection = %s\n", tp_proxy_get_object_path (conn));
+
+ /* @channels is a GList<TpChannel> with the CORE feature prepared */
+ for (l = channels; l != NULL; l = l->next)
+ {
+ TpChannel *channel = TP_CHANNEL (l->data);
+
+ g_print (" channel = %s\n", tp_proxy_get_object_path (channel));
+ }
+
+ /* we need to accept, delay or fail the HandleChannels request */
+ g_set_error (&error, TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED,
+ "This handler doesn't actually handle channels");
+ tp_handle_channels_context_fail (context, error);
+ g_clear_error (&error);
+}
+
+
int
-main (int argc, char **argv)
+main (int argc,
+ char **argv)
{
+ TpDBusDaemon *dbus;
+ TpBaseClient *handler;
GError *error = NULL;
g_type_init ();
loop = g_main_loop_new (NULL, FALSE);
- TpDBusDaemon *tpdbus = tp_dbus_daemon_dup (NULL);
- DBusGConnection *dbus = tp_get_bus ();
+ dbus = tp_dbus_daemon_dup (&error);
+ if (dbus == NULL)
+ g_error ("%s", error->message);
- ExampleHandler *example_handler = example_handler_new ();
+ /* create a new Handler */
+ handler = tp_simple_handler_new (dbus, FALSE, FALSE, CLIENT_NAME, FALSE,
+ handle_channels, NULL, NULL);
- /* register well-known name */
- g_assert (tp_dbus_daemon_request_name (tpdbus,
- TP_CLIENT_BUS_NAME_BASE CLIENT_NAME,
- TRUE, NULL));
- /* register ExampleHandler on the bus */
- dbus_g_connection_register_g_object (dbus,
- TP_CLIENT_OBJECT_PATH_BASE CLIENT_NAME,
- G_OBJECT (example_handler));
+ /* add a channel filter */
+ tp_base_client_take_handler_filter (handler, tp_asv_new (
+ /* only FT channels */
+ TP_PROP_CHANNEL_CHANNEL_TYPE,
+ G_TYPE_STRING,
+ TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER,
+ /* we always need a TargetHandleType so that the Handler's
+ * capabilities are exported via the Connection Manager */
+ TP_PROP_CHANNEL_TARGET_HANDLE_TYPE,
+ G_TYPE_UINT,
+ TP_HANDLE_TYPE_CONTACT,
+
+ NULL));
+
+ /* register the Handler on the D-Bus */
+ if (!tp_base_client_register (handler, &error))
+ g_error ("%s", error->message);
g_main_loop_run (loop);
+
+ g_object_unref (dbus);
+ g_object_unref (handler);
}