[Telepathy-commits] [telepathy-doc/master] telepathy-glib list protocols example
Davyd Madeley
davyd at madeley.id.au
Mon Mar 23 22:31:54 PDT 2009
---
configure.ac | 19 ++-----
docs/examples/Makefile.am | 18 +++++-
docs/examples/Makefile.am_fragment | 12 ----
docs/examples/glib_list_protocols/Makefile.am | 7 +++
docs/examples/glib_list_protocols/example.c | 72 +++++++++++++++++++++++++
5 files changed, 98 insertions(+), 30 deletions(-)
delete mode 100644 docs/examples/Makefile.am_fragment
create mode 100644 docs/examples/glib_list_protocols/Makefile.am
create mode 100644 docs/examples/glib_list_protocols/example.c
diff --git a/configure.ac b/configure.ac
index 44dd9f5..1415ad7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -10,10 +10,9 @@ GNOME_DOC_INIT([0.9.0])
PKG_CHECK_MODULES(GNOME_DOC_UTILS, gnome-doc-utils)
-# We depend on GTK+ too, because that allows us to create more realistic
-# examples that are easier to play with. But we will try to write only a small
-# amount of UI code.
-PKG_CHECK_MODULES(TELEPATHY_DOCS, telepathy-glib >= 0.7.3 gtk+-2.0 >= 2.12.0)
+PKG_CHECK_MODULES(TELEPATHY_GLIB, telepathy-glib >= 0.7.3 gtk+-2.0 >= 2.12.0)
+AC_SUBST(TELEPATHY_GLIB_CFLAGS)
+AC_SUBST(TELEPATHY_GLIB_LIBS)
# Use C:
AC_PROG_CC()
@@ -24,17 +23,7 @@ AC_OUTPUT([
docs/Makefile
docs/examples/Makefile
- docs/examples/basics_dbus_glib_methods/Makefile
- docs/examples/basics_dbus_glib_properties/Makefile
- docs/examples/basics_dbus_glib_signals/Makefile
- docs/examples/basics_dbus_python_methods/Makefile
- docs/examples/basics_dbus_python_properties/Makefile
- docs/examples/basics_dbus_python_signals/Makefile
- docs/examples/connect/Makefile
- docs/examples/list_all_protocols/Makefile
- docs/examples/list_contacts/Makefile
- docs/examples/set_presence/Makefile
- docs/examples/send_message/Makefile
+ docs/examples/glib_list_protocols/Makefile
docs/book/Makefile
])
diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am
index 25b31bd..560e5df 100644
--- a/docs/examples/Makefile.am
+++ b/docs/examples/Makefile.am
@@ -1,12 +1,24 @@
include $(top_srcdir)/docs/rsync-properties.make
-example_dirs = basics_dbus_glib_methods basics_dbus_glib_properties basics_dbus_python_methods basics_dbus_python_properties basics_dbus_python_signals connect list_all_protocols list_contacts set_presence send_message
+example_dirs = \
+ glib_list_protocols
SUBDIRS = $(example_dirs)
-EXTRA_DIST = Makefile.am_fragment
+exclude_args = \
+ --delete-excluded \
+ --exclude *.o \
+ --exclude .libs \
+ --exclude .deps \
+ --exclude core \
+ --exclude .cvsignore \
+ --exclude a.out \
+ --exclude Makefile \
+ --exclude Makefile.in \
+ --exclude example \
+ --exclude .svn \
+ --exclude .git
-exclude_args = --delete-excluded --exclude *.o --exclude .libs --exclude .deps --exclude core --exclude .cvsignore --exclude a.out --exclude Makefile --exclude Makefile.in --exclude example --exclude .svn --exclude .git
post-html:
rsync $(rsync_args) -a $(exclude_args) $(example_dirs) $(rsync_target_html)/examples/
diff --git a/docs/examples/Makefile.am_fragment b/docs/examples/Makefile.am_fragment
deleted file mode 100644
index 153b7a9..0000000
--- a/docs/examples/Makefile.am_fragment
+++ /dev/null
@@ -1,12 +0,0 @@
-LIBS = $(TELEPATHY_DOCS_LIBS)
-
-all_includes = $(TELEPATHY_DOCS_CFLAGS) $(TELEPATHY_DOCS_WARNING_FLAGS)
-
-DEFS = @DEFS@
-DEFAULT_INCLUDES =
-INCLUDES = -I. -I$(srcdir) $(strip $(all_includes))
-
-
-post-html:
- rsync $(rsync_options) $(example_dirs) $$USER@$(web_host):$(web_path)
-
diff --git a/docs/examples/glib_list_protocols/Makefile.am b/docs/examples/glib_list_protocols/Makefile.am
new file mode 100644
index 0000000..2fa83cd
--- /dev/null
+++ b/docs/examples/glib_list_protocols/Makefile.am
@@ -0,0 +1,7 @@
+INCLUDES = $(TELEPATHY_GLIB_CFLAGS)
+LDADD = $(TELEPATHY_GLIB_LIBS)
+
+noinst_PROGRAMS = example
+
+example_SOURCES = \
+ example.c
diff --git a/docs/examples/glib_list_protocols/example.c b/docs/examples/glib_list_protocols/example.c
new file mode 100644
index 0000000..d9272f0
--- /dev/null
+++ b/docs/examples/glib_list_protocols/example.c
@@ -0,0 +1,72 @@
+#include <glib.h>
+
+#include <telepathy-glib/connection-manager.h>
+#include <telepathy-glib/debug.h>
+
+static GMainLoop *loop = NULL;
+
+static void
+got_connection_managers (TpConnectionManager * const * cms,
+ gsize ncms,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ g_print (" > got_connection_managers\n");
+
+ /* From the documentation:
+ * tp_list_connection_managers() will wait for each
+ * TpConnectionManager to become ready, so all connection managers
+ * passed to callback will be ready */
+
+ int i;
+ for (i = 0; i < ncms; i++)
+ {
+ TpConnectionManager *cm = cms[i];
+
+ if (!tp_connection_manager_is_ready (cm))
+ {
+ /* this should never happen, unless there is an
+ * error */
+ g_print ("CM not ready!\n");
+ continue;
+ }
+
+ g_print (" - %s\n", cm->name);
+
+ /* get the protocols */
+ const TpConnectionManagerProtocol * const *iter;
+ for (iter = cm->protocols; iter && *iter; iter++)
+ {
+ const TpConnectionManagerProtocol *prot = *iter;
+ g_print (" . %s\n", prot->name);
+ }
+ }
+}
+
+int main (int argc, char **argv)
+{
+ GError *error = NULL;
+
+ g_type_init ();
+
+ /* create a main loop */
+ loop = g_main_loop_new (NULL, FALSE);
+
+ /* acquire a connection to the D-Bus daemon */
+ TpDBusDaemon *bus_daemon = tp_dbus_daemon_dup (&error);
+ if (bus_daemon == NULL)
+ {
+ g_error ("%s", error->message);
+ }
+
+ /* let's get a list of the connection managers */
+ tp_list_connection_managers (bus_daemon, got_connection_managers,
+ NULL, NULL, NULL);
+
+ g_main_loop_run (loop);
+
+ g_object_unref (bus_daemon);
+
+ return 0;
+}
--
1.5.6.5
More information about the telepathy-commits
mailing list