summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanielle Madeley <danielle.madeley@collabora.co.uk>2010-09-29 17:25:40 +1000
committerDanielle Madeley <danielle.madeley@collabora.co.uk>2010-09-29 17:25:40 +1000
commit992f4fb7b0e3c734f234e6ab2284484e244211c9 (patch)
treeb47556f3a4834d8d6ed834113a2270d5508adfd2
parentc70971e5255c6012f5afb0621fabe540e5dc5977 (diff)
Example to request VoIP calls from the Channel Dispatcher
-rw-r--r--configure.ac1
-rw-r--r--docs/examples/Makefile.am1
-rw-r--r--docs/examples/glib_mc5_request_call/Makefile.am9
-rw-r--r--docs/examples/glib_mc5_request_call/example.c150
4 files changed, 161 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 2f0ec40..77b0fcb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,6 +42,7 @@ AC_OUTPUT([
docs/examples/glib_blinkenlight_observer/Makefile
docs/examples/glib_mc5_ft_handler/Makefile
docs/examples/glib_mc5_presence_app/Makefile
+ docs/examples/glib_mc5_request_call/Makefile
docs/examples/gtk_presence_app/Makefile
docs/examples/pygtk_chat_client/Makefile
docs/examples/python_get_parameters/Makefile
diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am
index af0bc26..b36da94 100644
--- a/docs/examples/Makefile.am
+++ b/docs/examples/Makefile.am
@@ -14,6 +14,7 @@ example_dirs = \
glib_blinkenlight_observer \
glib_mc5_ft_handler \
glib_mc5_presence_app \
+ glib_mc5_request_call \
gtk_presence_app \
pygtk_chat_client \
python_get_parameters \
diff --git a/docs/examples/glib_mc5_request_call/Makefile.am b/docs/examples/glib_mc5_request_call/Makefile.am
new file mode 100644
index 0000000..409e2b6
--- /dev/null
+++ b/docs/examples/glib_mc5_request_call/Makefile.am
@@ -0,0 +1,9 @@
+INCLUDES = $(TELEPATHY_GLIB_CFLAGS)
+LDADD = $(TELEPATHY_GLIB_LIBS)
+
+noinst_PROGRAMS = example
+
+example_SOURCES = \
+ example.c
+
+include $(top_srcdir)/docs/rsync-dist.make
diff --git a/docs/examples/glib_mc5_request_call/example.c b/docs/examples/glib_mc5_request_call/example.c
new file mode 100644
index 0000000..cc67028
--- /dev/null
+++ b/docs/examples/glib_mc5_request_call/example.c
@@ -0,0 +1,150 @@
+#include <unistd.h>
+
+#include <glib.h>
+
+#include <telepathy-glib/telepathy-glib.h>
+
+static GMainLoop *loop = NULL;
+
+static void
+handle_error (const GError *error)
+{
+ if (error != NULL)
+ g_error ("ERROR: %s\n", error->message);
+}
+
+
+static void
+_completed_channel_request (GObject *request,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *error = NULL;
+
+ if (!tp_account_channel_request_create_channel_finish (
+ TP_ACCOUNT_CHANNEL_REQUEST (request), res, &error))
+ {
+ g_print ("Failed to request channel: %s\n", error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ g_print ("Successfully requested channel\n");
+ }
+
+ g_main_loop_quit (loop);
+}
+
+
+static void
+_account_ready (GObject *account,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TpAccountChannelRequest *request;
+ GHashTable *props;
+ const char *targetid = user_data;
+ GError *error = NULL;
+ gboolean call = FALSE, video = TRUE;
+
+ if (!tp_proxy_prepare_finish (account, res, &error))
+ handle_error (error);
+
+ g_message ("Using %s interface %s video",
+ call ? "Call" : "StreamedMedia",
+ video ? "with" : "without");
+
+ props = tp_asv_new (
+ TP_PROP_CHANNEL_TARGET_HANDLE_TYPE,
+ G_TYPE_UINT,
+ TP_HANDLE_TYPE_CONTACT,
+
+ TP_PROP_CHANNEL_TARGET_ID,
+ G_TYPE_STRING,
+ targetid,
+
+ NULL);
+
+ if (call)
+ {
+ tp_asv_set_string (props, TP_PROP_CHANNEL_CHANNEL_TYPE,
+ /* Future: TP_IFACE_CHANNEL_TYPE_CALL */
+ "org.freedesktop.Telepathy.Channel.Type.Call.DRAFT");
+ tp_asv_set_boolean (props,
+ /* Future: TP_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO */
+ "org.freedesktop.Telepathy.Channel.Type.Call.DRAFT.InitialAudio",
+ TRUE);
+
+ if (video)
+ tp_asv_set_boolean (props,
+ /* Future: TP_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO */
+ "org.freedesktop.Telepathy.Channel.Type.Call.DRAFT.InitialVideo",
+ TRUE);
+ }
+ else
+ {
+ tp_asv_set_string (props, TP_PROP_CHANNEL_CHANNEL_TYPE,
+ TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA);
+ tp_asv_set_boolean (props,
+ TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_AUDIO, TRUE);
+
+ if (video)
+ tp_asv_set_boolean (props,
+ TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_VIDEO, TRUE);
+ }
+
+ request = tp_account_channel_request_new (TP_ACCOUNT (account), props,
+ TP_USER_ACTION_TIME_CURRENT_TIME);
+
+ tp_account_channel_request_create_channel_async (request, NULL,
+ NULL, _completed_channel_request, NULL);
+
+ g_object_unref (request);
+ g_hash_table_destroy (props);
+}
+
+
+int
+main (int argc,
+ char **argv)
+{
+ TpDBusDaemon *dbus;
+ TpAccount *account;
+ char *account_path;
+ GError *error = NULL;
+
+ g_type_init ();
+
+ if (argc != 3)
+ g_error ("Must provide an account and target id!");
+
+ /* 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);
+
+ /* get the complete path of the account */
+ account_path = g_strconcat (TP_ACCOUNT_OBJECT_PATH_BASE, argv[1], NULL);
+
+ /* get the account */
+ account = tp_account_new (dbus, account_path, &error);
+ if (account == NULL)
+ {
+ handle_error (error);
+ }
+
+ g_free (account_path);
+
+ /* prepare the account */
+ tp_proxy_prepare_async (account, NULL, _account_ready, argv[2]);
+
+ g_main_loop_run (loop);
+
+ g_object_unref (dbus);
+ g_object_unref (account);
+
+ return 0;
+}