diff options
author | Stef Walter <stefw@collaora.co.uk> | 2011-03-28 17:30:27 +0200 |
---|---|---|
committer | Stef Walter <stefw@collaora.co.uk> | 2011-03-28 17:33:16 +0200 |
commit | 5af6f3d4d7099f5323a24176eafef4212215a33e (patch) | |
tree | d640694775fdbe00cf78a17e537ddfba585ecb85 | |
parent | 12fdc690617cb68f8ec95556c645e8ad804b8b52 (diff) | |
parent | 301824e23eb919b5f5ca67e6e7912eab66b99906 (diff) |
Merge branch 'cli-proxy'
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | configure.ac | 7 | ||||
-rw-r--r-- | telepathy-ytstenut-glib/Makefile.am | 18 | ||||
-rw-r--r-- | telepathy-ytstenut-glib/account-manager.c | 273 | ||||
-rw-r--r-- | telepathy-ytstenut-glib/account-manager.h | 89 | ||||
-rw-r--r-- | telepathy-ytstenut-glib/telepathy-ytstenut-glib-uninstalled.pc.in | 2 | ||||
-rw-r--r-- | telepathy-ytstenut-glib/telepathy-ytstenut-glib.c | 4 | ||||
-rw-r--r-- | telepathy-ytstenut-glib/telepathy-ytstenut-glib.h | 6 | ||||
-rw-r--r-- | telepathy-ytstenut-glib/telepathy-ytstenut-glib.pc.in | 2 | ||||
-rw-r--r-- | telepathy-ytstenut-glib/tests/Makefile.am | 18 | ||||
-rw-r--r-- | telepathy-ytstenut-glib/tests/diddle-account-manager.c | 108 |
11 files changed, 526 insertions, 3 deletions
@@ -40,3 +40,5 @@ tags telepathy-ytstenut-glib/telepathy-ytstenut-glib-uninstalled.pc telepathy-ytstenut-glib/telepathy-ytstenut-glib.pc tp-glib-tools/telepathy-glib-env + +/telepathy-ytstenut-glib/tests/diddle-account-manager diff --git a/configure.ac b/configure.ac index 85374f1..9e25228 100644 --- a/configure.ac +++ b/configure.ac @@ -147,7 +147,11 @@ TP_YTSTENUT_QT4_CFLAGS='-I${top_builddir}/TelepathyYtstenutQt4 -I${top_srcdir}' AC_SUBST(TP_YTSTENUT_QT4_CFLAGS) dnl Check for Glib -PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.16, gobject-2.0 >= 2.16, gthread-2.0 >= 2.16]) +PKG_CHECK_MODULES(GLIB, [ + glib-2.0 >= 2.16, + gobject-2.0 >= 2.16, + gthread-2.0 >= 2.16, + gio-2.0 >= 2.16]) AC_SUBST(GLIB_CFLAGS) AC_SUBST(GLIB_LIBS) @@ -198,4 +202,5 @@ AC_OUTPUT([ telepathy-ytstenut-glib/Makefile telepathy-ytstenut-glib/telepathy-ytstenut-glib.pc telepathy-ytstenut-glib/telepathy-ytstenut-glib-uninstalled.pc + telepathy-ytstenut-glib/tests/Makefile ]) diff --git a/telepathy-ytstenut-glib/Makefile.am b/telepathy-ytstenut-glib/Makefile.am index 798e9d6..521d9ca 100644 --- a/telepathy-ytstenut-glib/Makefile.am +++ b/telepathy-ytstenut-glib/Makefile.am @@ -1,3 +1,5 @@ +SUBDIRS = . tests + pkgconfigdir = ${libdir}/pkgconfig pkgconfig_DATA = telepathy-ytstenut-glib.pc @@ -8,6 +10,8 @@ tools_dir = $(top_srcdir)/tp-glib-tools lib_LTLIBRARIES = libtelepathy-ytstenut-glib.la libtelepathy_ytstenut_glib_la_SOURCES = \ + account-manager.c \ + account-manager.h \ errors.c \ errors.h \ telepathy-ytstenut-glib.c \ @@ -22,6 +26,8 @@ nodist_libtelepathy_ytstenut_glib_la_SOURCES = \ _gen/gtypes-body.h \ _gen/interfaces.h \ _gen/interfaces-body.h \ + _gen/cli-account-manager.h \ + _gen/cli-account-manager-body.h \ _gen/svc.h \ _gen/svc.c @@ -33,6 +39,7 @@ BUILT_SOURCES = \ $(nodist_libtelepathy_ytstenut_glib_la_SOURCES) tpytstenutglibinclude_HEADERS = \ + account-manager.h \ errors.h \ telepathy-ytstenut-glib.h @@ -40,6 +47,7 @@ nodist_geninclude_HEADERS = \ _gen/enums.h \ _gen/gtypes.h \ _gen/interfaces.h \ + _gen/cli-account-manager.h \ _gen/svc.h EXTRA_DIST = \ @@ -59,6 +67,16 @@ _gen/all.xml: all.xml $(wildcard $(top_srcdir)/spec/*.xml) $(AM_V_GEN)$(PYTHON) $(tools_dir)/xincludator.py \ $< > $@.tmp && mv $@.tmp $@ +_gen/cli-account-manager-body.h _gen/cli-account-manager.h: _gen/all.xml \ + $(tools_dir)/glib-client-gen.py + $(AM_V_GEN)$(PYTHON) $(tools_dir)/glib-client-gen.py \ + --group=account_manager \ + --subclass=TpYtsAccountManager \ + --subclass-assert=TP_IS_YTS_ACCOUNT_MANAGER \ + --iface-quark-prefix=TP_YTS_IFACE_QUARK \ + --tp-proxy-api=0.10.0 \ + $< Tp_Yts _gen/cli-account-manager + _gen/svc.c _gen/svc.h: _gen/all.xml $(tools_dir)/glib-ginterface-gen.py \ Makefile.am $(AM_V_GEN)$(PYTHON) $(tools_dir)/glib-ginterface-gen.py \ diff --git a/telepathy-ytstenut-glib/account-manager.c b/telepathy-ytstenut-glib/account-manager.c new file mode 100644 index 0000000..27604e1 --- /dev/null +++ b/telepathy-ytstenut-glib/account-manager.c @@ -0,0 +1,273 @@ +/* + * account-manager.c - proxy for the Ytstenut account manager + * + * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/> + * Copyright (C) 2009 Nokia Corporation + * Copyright (C) 2011 Intel Corp. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include "account-manager.h" + +#include <telepathy-glib/defs.h> +#include <telepathy-glib/gtypes.h> +#include <telepathy-glib/interfaces.h> +#include <telepathy-glib/proxy-subclass.h> +#include <telepathy-glib/util.h> + +#include "_gen/interfaces.h" +#include "_gen/cli-account-manager-body.h" + +#define DEBUG(msg, ...) \ + g_debug ("%s: " msg, G_STRFUNC, ##__VA_ARGS__) + +/** + * SECTION:account-manager + * @title: TpYtsAccountManager + * @short_description: proxy object for the Ytstenut account manager + * + * The #TpYtsAccountManager object is used to communicate with the Ytstenut + * AccountManager service. + */ + +/** + * TpYtsAccountManager: + * + * The Ytstenut Account Manager holds information about the Ytstenut account + * and controls its presence. + */ + +/** + * TpYtsAccountManagerClass: + * + * The class of a #TpYtsAccountManager. + */ + +#define MC5_BUS_NAME "org.freedesktop.Telepathy.MissionControl5" + +G_DEFINE_TYPE (TpYtsAccountManager, tp_yts_account_manager, TP_TYPE_PROXY); + +static void +tp_yts_account_manager_init (TpYtsAccountManager *self) +{ + +} + +static void +tp_yts_account_manager_class_init (TpYtsAccountManagerClass *klass) +{ + TpProxyClass *proxy_class = (TpProxyClass *) klass; + GType tp_type = TP_TYPE_YTS_ACCOUNT_MANAGER; + + proxy_class->interface = TP_YTS_IFACE_QUARK_ACCOUNT_MANAGER; + + tp_proxy_init_known_interfaces (); + tp_proxy_or_subclass_hook_on_interface_add (tp_type, + tp_yts_account_manager_add_signals); + tp_proxy_subclass_add_error_mapping (tp_type, + TP_ERROR_PREFIX, TP_ERRORS, TP_TYPE_ERROR); +} + +/** + * tp_yts_account_manager_new: + * @bus_daemon: Proxy for the D-Bus daemon + * + * Convenience function to create a new account manager proxy. + * + * Use tp_yts_account_manager_dup() instead if you want an account manager proxy + * on the starter or session bus (which is almost always the right thing for + * Telepathy). + * + * Returns: a new reference to an account manager proxy + */ +TpYtsAccountManager * +tp_yts_account_manager_new (TpDBusDaemon *bus_daemon) +{ + TpYtsAccountManager *self; + + g_return_val_if_fail (TP_IS_DBUS_DAEMON (bus_daemon), NULL); + + self = TP_YTS_ACCOUNT_MANAGER (g_object_new (TP_TYPE_YTS_ACCOUNT_MANAGER, + "dbus-daemon", bus_daemon, + "dbus-connection", ((TpProxy *) bus_daemon)->dbus_connection, + "bus-name", MC5_BUS_NAME, + "object-path", TP_YTS_ACCOUNT_MANAGER_OBJECT_PATH, + NULL)); + + return self; +} + +static gpointer starter_account_manager_proxy = NULL; + +/** + * tp_yts_account_manager_dup: + * + * Returns an account manager proxy on the D-Bus daemon on which this + * process was activated (if it was launched by D-Bus service activation), or + * the session bus (otherwise). + * + * The returned #TpYtsAccountManager is cached; the same #TpYtsAccountManager + * object will be returned by this function repeatedly, as long as at least one + * reference exists. + * + * Returns: (transfer full): an account manager proxy on the starter or session + * bus, or %NULL if it wasn't possible to get a dbus daemon proxy for + * the appropriate bus + */ +TpYtsAccountManager * +tp_yts_account_manager_dup (void) +{ + TpDBusDaemon *dbus; + + if (starter_account_manager_proxy != NULL) + return g_object_ref (starter_account_manager_proxy); + + dbus = tp_dbus_daemon_dup (NULL); + + if (dbus == NULL) + return NULL; + + starter_account_manager_proxy = tp_yts_account_manager_new (dbus); + g_assert (starter_account_manager_proxy != NULL); + g_object_add_weak_pointer (starter_account_manager_proxy, + &starter_account_manager_proxy); + + g_object_unref (dbus); + + return starter_account_manager_proxy; +} + +static void +on_account_manager_get_account_returned (TpProxy *proxy, + const GValue *value, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data); + TpAccount *account; + GError *err = NULL; + const gchar *path; + + if (error == NULL) + { + path = g_value_get_boxed (value); + account = tp_account_new (tp_proxy_get_dbus_daemon (proxy), path, &err); + if (err == NULL) + { + g_simple_async_result_set_op_res_gpointer (res, account, + g_object_unref); + } + else + { + DEBUG ("Failed to create TpAccount: %s", err->message); + g_simple_async_result_set_from_error (res, err); + g_clear_error (&err); + } + } + else + { + DEBUG ("Failed to get account path: %s", error->message); + g_simple_async_result_set_from_error (res, error); + } + + g_simple_async_result_complete (res); +} + +void +tp_yts_account_manager_get_account_async (TpYtsAccountManager *self, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *res; + + g_return_if_fail (TP_IS_YTS_ACCOUNT_MANAGER (self)); + + res = g_simple_async_result_new (G_OBJECT (self), callback, user_data, + tp_yts_account_manager_get_account_async); + + tp_cli_dbus_properties_call_get (TP_PROXY (self), -1, + TP_YTS_IFACE_ACCOUNT_MANAGER, "Account", + on_account_manager_get_account_returned, res, g_object_unref, + G_OBJECT (self)); +} + +TpAccount * +tp_yts_account_manager_get_account_finish (TpYtsAccountManager *self, + GAsyncResult *result, + GError **error) +{ + GSimpleAsyncResult *res; + + g_return_val_if_fail (TP_IS_YTS_ACCOUNT_MANAGER (self), NULL); + g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL); + + res = G_SIMPLE_ASYNC_RESULT (result); + g_return_val_if_fail (g_simple_async_result_is_valid (result, + G_OBJECT (self), tp_yts_account_manager_get_account_async), NULL); + + if (g_simple_async_result_propagate_error (res, error)) + return NULL; + + return g_object_ref (g_simple_async_result_get_op_res_gpointer (res)); +} + +static void +on_account_manager_hold_returned (TpYtsAccountManager *self, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + if (error != NULL) + { + DEBUG ("%s.Hold() call failed: %s", TP_YTS_IFACE_ACCOUNT_MANAGER, + error->message); + } +} + +void +tp_yts_account_manager_hold (TpYtsAccountManager *self) +{ + g_return_if_fail (TP_IS_YTS_ACCOUNT_MANAGER (self)); + + tp_yts_account_manager_call_hold (self, -1, + on_account_manager_hold_returned, NULL, NULL, G_OBJECT (self)); +} + +static void +on_account_manager_release_returned (TpYtsAccountManager *self, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + if (error != NULL) + { + DEBUG ("%s.Release() call failed: %s", TP_YTS_IFACE_ACCOUNT_MANAGER, + error->message); + } +} + +void +tp_yts_account_manager_release (TpYtsAccountManager *self) +{ + g_return_if_fail (TP_IS_YTS_ACCOUNT_MANAGER (self)); + + tp_yts_account_manager_call_release (self, -1, + on_account_manager_release_returned, NULL, NULL, G_OBJECT (self)); +} diff --git a/telepathy-ytstenut-glib/account-manager.h b/telepathy-ytstenut-glib/account-manager.h new file mode 100644 index 0000000..ec43bc8 --- /dev/null +++ b/telepathy-ytstenut-glib/account-manager.h @@ -0,0 +1,89 @@ +/* + * account-manager.h - proxy for the Ytstenut account manager + * + * Copyright (C) 2011 Intel Corp. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef TP_YTS_ACCOUNT_MANAGER_H +#define TP_YTS_ACCOUNT_MANAGER_H + +#include <telepathy-glib/account.h> +#include <telepathy-glib/dbus.h> +#include <telepathy-glib/defs.h> +#include <telepathy-glib/proxy.h> + +G_BEGIN_DECLS + +#define TP_YTS_ACCOUNT_MANAGER_OBJECT_PATH \ + "/com/meego/xpmn/ytstenut/AccountManager" + +typedef struct _TpYtsAccountManager TpYtsAccountManager; +typedef struct _TpYtsAccountManagerClass TpYtsAccountManagerClass; +typedef struct _TpYtsAccountManagerPrivate TpYtsAccountManagerPrivate; + +struct _TpYtsAccountManager { + /*<private>*/ + TpProxy parent; + TpYtsAccountManagerPrivate *priv; +}; + +struct _TpYtsAccountManagerClass { + /*<private>*/ + TpProxyClass parent_class; + GCallback _padding[7]; +}; + +GType tp_yts_account_manager_get_type (void); + +#define TP_TYPE_YTS_ACCOUNT_MANAGER \ + (tp_yts_account_manager_get_type ()) +#define TP_YTS_ACCOUNT_MANAGER(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), TP_TYPE_YTS_ACCOUNT_MANAGER, \ + TpYtsAccountManager)) +#define TP_YTS_ACCOUNT_MANAGER_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), TP_TYPE_YTS_ACCOUNT_MANAGER, \ + TpYtsAccountManagerClass)) +#define TP_IS_YTS_ACCOUNT_MANAGER(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TP_TYPE_YTS_ACCOUNT_MANAGER)) +#define TP_IS_YTS_ACCOUNT_MANAGER_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), TP_TYPE_YTS_ACCOUNT_MANAGER)) +#define TP_YTS_ACCOUNT_MANAGER_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), TP_TYPE_YTS_ACCOUNT_MANAGER, \ + TpYtsAccountManagerClass)) + +TpYtsAccountManager *tp_yts_account_manager_new (TpDBusDaemon *bus_daemon) + G_GNUC_WARN_UNUSED_RESULT; + +TpYtsAccountManager *tp_yts_account_manager_dup (void) + G_GNUC_WARN_UNUSED_RESULT; + +void tp_yts_account_manager_get_account_async (TpYtsAccountManager *self, + GCancellable *cancellable, GAsyncReadyCallback callback, + gpointer user_data); + +TpAccount *tp_yts_account_manager_get_account_finish (TpYtsAccountManager *self, + GAsyncResult *result, GError **error); + +void tp_yts_account_manager_hold (TpYtsAccountManager *self); + +void tp_yts_account_manager_release (TpYtsAccountManager *self); + +G_END_DECLS + +#include <telepathy-ytstenut-glib/_gen/cli-account-manager.h> + +#endif diff --git a/telepathy-ytstenut-glib/telepathy-ytstenut-glib-uninstalled.pc.in b/telepathy-ytstenut-glib/telepathy-ytstenut-glib-uninstalled.pc.in index c591fc2..63d86f7 100644 --- a/telepathy-ytstenut-glib/telepathy-ytstenut-glib-uninstalled.pc.in +++ b/telepathy-ytstenut-glib/telepathy-ytstenut-glib-uninstalled.pc.in @@ -6,6 +6,6 @@ abs_top_srcdir=@abs_top_srcdir@ Name: telepathy-ytstenut-glib (uninstalled copy) Description: Glib utility library for Ytstenut D-Bus interfaces Version: @VERSION@ -Requires: telepathy-glib, dbus-glib-1 >= 0.73, glib-2.0 >= 2.16, gobject-2.0 >= 2.16 +Requires: telepathy-glib, dbus-glib-1 >= 0.73, glib-2.0 >= 2.16, gobject-2.0 >= 2.16, gio-2.0 >= 2.16 Libs: ${abs_top_builddir}/telepathy-ytstenut-glib/libtelepathy-ytstenut-glib.la Cflags: -I${abs_top_srcdir} -I${abs_top_builddir} diff --git a/telepathy-ytstenut-glib/telepathy-ytstenut-glib.c b/telepathy-ytstenut-glib/telepathy-ytstenut-glib.c index 3e51c9a..31bf82c 100644 --- a/telepathy-ytstenut-glib/telepathy-ytstenut-glib.c +++ b/telepathy-ytstenut-glib/telepathy-ytstenut-glib.c @@ -1,5 +1,9 @@ #include "telepathy-ytstenut-glib.h" +#include <telepathy-glib/dbus.h> +#include <telepathy-glib/defs.h> +#include <telepathy-glib/proxy.h> + /* auto-generated stubs */ #include "_gen/gtypes-body.h" #include "_gen/interfaces-body.h" diff --git a/telepathy-ytstenut-glib/telepathy-ytstenut-glib.h b/telepathy-ytstenut-glib/telepathy-ytstenut-glib.h index 0f2bf24..334671f 100644 --- a/telepathy-ytstenut-glib/telepathy-ytstenut-glib.h +++ b/telepathy-ytstenut-glib/telepathy-ytstenut-glib.h @@ -1,10 +1,16 @@ #ifndef TP_YTSTENUT_H #define TP_YTSTENUT_H +#include <glib.h> + +#include <telepathy-glib/proxy-subclass.h> + #include "telepathy-ytstenut-glib/_gen/enums.h" #include "telepathy-ytstenut-glib/_gen/svc.h" #include "telepathy-ytstenut-glib/errors.h" +#include "telepathy-ytstenut-glib/account-manager.h" + G_BEGIN_DECLS #include "telepathy-ytstenut-glib/_gen/gtypes.h" diff --git a/telepathy-ytstenut-glib/telepathy-ytstenut-glib.pc.in b/telepathy-ytstenut-glib/telepathy-ytstenut-glib.pc.in index 048376b..6c6042e 100644 --- a/telepathy-ytstenut-glib/telepathy-ytstenut-glib.pc.in +++ b/telepathy-ytstenut-glib/telepathy-ytstenut-glib.pc.in @@ -6,6 +6,6 @@ includedir=@includedir@ Name: telepathy-ytstenut-glib Description: Glib utility library for Ytstenut D-Bus interfaces Version: @VERSION@ -Requires: telepathy-glib, dbus-glib-1 >= 0.73, glib-2.0 >= 2.16, gobject-2.0 >= 2.16 +Requires: telepathy-glib, dbus-glib-1 >= 0.73, glib-2.0 >= 2.16, gobject-2.0 >= 2.16, gio-2.0 >= 2.16 Libs: -L${libdir} -ltelepathy-ytstenut-glib Cflags: -I${includedir}/telepathy-ytstenut diff --git a/telepathy-ytstenut-glib/tests/Makefile.am b/telepathy-ytstenut-glib/tests/Makefile.am new file mode 100644 index 0000000..6333f6b --- /dev/null +++ b/telepathy-ytstenut-glib/tests/Makefile.am @@ -0,0 +1,18 @@ + +AM_CFLAGS = \ + $(ERROR_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(TP_GLIB_CFLAGS) \ + -I$(top_srcdir) + +AM_LDFLAGS = \ + $(DBUS_LIBS) \ + $(GLIB_LIBS) \ + $(TP_GLIB_LIBS) + +LDADD = \ + $(top_builddir)/telepathy-ytstenut-glib/libtelepathy-ytstenut-glib.la + +noinst_PROGRAMS = \ + diddle-account-manager diff --git a/telepathy-ytstenut-glib/tests/diddle-account-manager.c b/telepathy-ytstenut-glib/tests/diddle-account-manager.c new file mode 100644 index 0000000..ad0e38e --- /dev/null +++ b/telepathy-ytstenut-glib/tests/diddle-account-manager.c @@ -0,0 +1,108 @@ +/* + * diddle-account-manager.c - play around with the Ytstenut account manager + * + * Copyright (C) 2011 Intel Corp. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include <telepathy-ytstenut-glib/telepathy-ytstenut-glib.h> + + +static GMainLoop *loop = NULL; + +static void +on_get_account (GObject *object, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + TpAccount *account = NULL; + + g_assert (TP_IS_YTS_ACCOUNT_MANAGER (object)); + g_assert (G_IS_ASYNC_RESULT (res)); + g_assert (user_data == on_get_account); + + account = tp_yts_account_manager_get_account_finish ( + TP_YTS_ACCOUNT_MANAGER (object), res, &error); + g_assert_no_error (error); + g_assert (TP_IS_ACCOUNT (account)); + g_object_unref (account); + + g_main_loop_quit (loop); +} + +static void +diddle_get_account (TpYtsAccountManager *manager) +{ + tp_yts_account_manager_get_account_async (manager, NULL, on_get_account, + on_get_account); +} + +static gboolean +main_loop_quit_later (gpointer user_data) +{ + g_main_loop_quit (loop); + return FALSE; /* Remove this source */ +} + +static void +diddle_hold (TpYtsAccountManager *manager) +{ + tp_yts_account_manager_hold (manager); + g_timeout_add (100, main_loop_quit_later, NULL); +} + +static void +diddle_release (TpYtsAccountManager *manager) +{ + tp_yts_account_manager_release (manager); + g_timeout_add (100, main_loop_quit_later, NULL); +} + +struct { + const gchar *name; + void (*diddler) (TpYtsAccountManager *manager); +} the_diddlers[] = { + { "hold", diddle_hold }, + { "get-account", diddle_get_account }, + { "release", diddle_release }, +}; + +int +main (int argc, const char *argv[]) +{ + TpYtsAccountManager *manager; + guint i; + + g_type_init (); + loop = g_main_loop_new (NULL, FALSE); + + manager = tp_yts_account_manager_dup (); + g_assert (TP_IS_YTS_ACCOUNT_MANAGER (manager)); + + for (i = 0; i < G_N_ELEMENTS (the_diddlers); ++i) + { + g_printerr ("%s ... ", the_diddlers[i].name); + (the_diddlers[i].diddler) (manager); + g_main_loop_run (loop); + g_printerr ("DONE\n"); + } + + g_main_loop_unref (loop); + return 0; +} |