[Telepathy-commits] [telepathy-doc/master] 2009-12-27 Murray Cumming <murrayc at murrayc.com>

Murray Cumming murrayc at murrayc.com
Tue Jan 27 10:24:29 PST 2009


* docs/examples/:
* docs/book/C/telepathy.xml: Basics: USing D-Bus: Added sections with
examples of using D-Bus properties with dbus-glib and Python.
---
 ChangeLog                                          |    6 +
 configure.ac                                       |    6 +-
 docs/book/C/telepathy.xml                          |   33 +++++-
 docs/examples/Makefile.am                          |    2 +-
 docs/examples/basics_dbus_glib/Makefile.am         |    7 --
 docs/examples/basics_dbus_glib/main.c              |  105 -------------------
 docs/examples/basics_dbus_glib_methods/Makefile.am |    7 ++
 docs/examples/basics_dbus_glib_methods/main.c      |  106 ++++++++++++++++++++
 .../basics_dbus_glib_properties/Makefile.am        |    7 ++
 docs/examples/basics_dbus_glib_properties/main.c   |   99 ++++++++++++++++++
 docs/examples/basics_dbus_python/Makefile.am       |    4 -
 docs/examples/basics_dbus_python/example.py        |   73 --------------
 .../basics_dbus_python_methods/Makefile.am         |    4 +
 .../examples/basics_dbus_python_methods/example.py |   73 ++++++++++++++
 .../basics_dbus_python_properties/Makefile.am      |    4 +
 .../basics_dbus_python_properties/example.py       |   63 ++++++++++++
 16 files changed, 401 insertions(+), 198 deletions(-)
 delete mode 100644 docs/examples/basics_dbus_glib/Makefile.am
 delete mode 100644 docs/examples/basics_dbus_glib/main.c
 create mode 100644 docs/examples/basics_dbus_glib_methods/Makefile.am
 create mode 100644 docs/examples/basics_dbus_glib_methods/main.c
 create mode 100644 docs/examples/basics_dbus_glib_properties/Makefile.am
 create mode 100644 docs/examples/basics_dbus_glib_properties/main.c
 delete mode 100644 docs/examples/basics_dbus_python/Makefile.am
 delete mode 100644 docs/examples/basics_dbus_python/example.py
 create mode 100644 docs/examples/basics_dbus_python_methods/Makefile.am
 create mode 100644 docs/examples/basics_dbus_python_methods/example.py
 create mode 100644 docs/examples/basics_dbus_python_properties/Makefile.am
 create mode 100644 docs/examples/basics_dbus_python_properties/example.py

diff --git a/ChangeLog b/ChangeLog
index 2d1f0c5..93acb18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-12-27  Murray Cumming  <murrayc at murrayc.com>
 
+	* docs/examples/: 
+	* docs/book/C/telepathy.xml: Basics: USing D-Bus: Added sections with 
+	examples of using D-Bus properties with dbus-glib and Python.
+
+2009-12-27  Murray Cumming  <murrayc at murrayc.com>
+
 	* docs/book/C/telepathy.xml: Basics: Optional Interfaces: Mention how 
 	to check with telepathy-glib. We need dbus-glib and Python examples 
 	here too.
diff --git a/configure.ac b/configure.ac
index 56f6f4f..6abf2ce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,8 +25,10 @@ AC_OUTPUT([
 
   docs/Makefile
     docs/examples/Makefile
-      docs/examples/basics_dbus_glib/Makefile
-      docs/examples/basics_dbus_python/Makefile
+      docs/examples/basics_dbus_glib_methods/Makefile
+      docs/examples/basics_dbus_glib_properties/Makefile
+      docs/examples/basics_dbus_python_methods/Makefile
+      docs/examples/basics_dbus_python_properties/Makefile
       docs/examples/connect/Makefile
       docs/examples/list_all_protocols/Makefile
       docs/examples/list_contacts/Makefile
diff --git a/docs/book/C/telepathy.xml b/docs/book/C/telepathy.xml
index b4b9abc..981960e 100644
--- a/docs/book/C/telepathy.xml
+++ b/docs/book/C/telepathy.xml
@@ -166,18 +166,39 @@ of the Telapathy specification.
     <sect2 id="sec-basics-dbus-glib">
       <title>Using D-Bus from C, with glib</title>
 
-      <para>This example uses dbus-glib's <ulink url="http://dbus.freedesktop.org/doc/api/html/group__DBusGLib.html#gbd4dab5f4d66ab052c15862028502caf">dbus_g_proxy_begin_call()</ulink> function to call the <literal>Notify()</literal> method on the <literal>org.freedesktop.Notification</literal> interface of the desktop notification service at the <literal>/org/freedesktop/Notification</literal> path. Note that we must specify the types of each parameter.</para>
-      <para>We could have used the synchronous <ulink url="http://dbus.freedesktop.org/doc/api/html/group__DBusGLib.html#ge38c0fb788e874fcf88489c961480f38">dbus_g_proxy_call()</ulink> function instead but, as already mentioned, asynchronous calls are generally preferred with D-Bus.</para>
-      <para><ulink url="&url_examples_base;basics_dbus_glib">Source Code</ulink></para>
+      <sect3 id="sect-basics-dbus-glib-methods">
+        <title>Calling Methods</title>
+        <para>This example uses dbus-glib's <ulink url="http://dbus.freedesktop.org/doc/api/html/group__DBusGLib.html#gbd4dab5f4d66ab052c15862028502caf">dbus_g_proxy_begin_call()</ulink> function to call the <literal>Notify()</literal> method on the <literal>org.freedesktop.Notification</literal> interface of the desktop notification service at the <literal>/org/freedesktop/Notification</literal> path. Note that we must specify the types of each parameter.</para>
+        <para>We could have used the synchronous <ulink url="http://dbus.freedesktop.org/doc/api/html/group__DBusGLib.html#ge38c0fb788e874fcf88489c961480f38">dbus_g_proxy_call()</ulink> function instead but, as already mentioned, asynchronous calls are generally preferred with D-Bus.</para>
+        <para><ulink url="&url_examples_base;basics_dbus_glib_methods">Source Code</ulink></para>
+      </sect3>
+
+     <sect3 id="sect-basics-dbus-glib-properties">
+        <title>Using Properties</title>
+        <para>D-Bus properties are available via an additional <ulink url="&url_dbus_spec_base;standard-interfaces-properties">org.freedesktop.DBus.Properties</ulink> interface on some objects, which provides <function>Get()</function>, <function>Set()</function> and <function>GetAll</function> methods. You can call these methods to get or set property values for the object's other interfaces.</para>
+        <para>As of this writing, telepathy-glib has no simple API for dealing with properties so you must call these functions directly. Therefore this example is therefore very similar to the <link linkend="sect-basics-dbus-glib-methods">Calling Methods</link> example.</para>
+        <para><ulink url="&url_examples_base;basics_dbus_glib_properties">Source Code</ulink></para>
+      </sect3>
+
 
     </sect2>
 
     <sect2 id="sec-basics-dbus-python">
       <title>Using D-Bus from Python</title>
 
-      <para>This example uses <indexterm><primary>Python</primary></indexterm>Python to call the <literal>Notify()</literal> method on the <literal>org.freedesktop.Notification</literal> interface of the desktop notification service at the <literal>/org/freedesktop/Notification</literal> path.</para>
-      <para>Note that we specify reply and error handlers as keyword arguments, to call the method asynchronously because asynchronous calls are generally preferred with D-Bus.</para>
-      <para><ulink url="&url_examples_base;basics_dbus_python">Source Code</ulink></para>
+      <sect3 id="sect-basics-dbus-python-methods">
+        <title>Calling Methods</title>
+        <para>This example uses <indexterm><primary>Python</primary></indexterm>Python to call the <literal>Notify()</literal> method on the <literal>org.freedesktop.Notification</literal> interface of the desktop notification service at the <literal>/org/freedesktop/Notification</literal> path.</para>
+        <para>Note that we specify reply and error handlers as keyword arguments, to call the method asynchronously because asynchronous calls are generally preferred with D-Bus.</para>
+        <para><ulink url="&url_examples_base;basics_dbus_python_methods">Source Code</ulink></para>
+      </sect3>
+
+      <sect3 id="sect-basics-dbus-python-properties">
+        <title>Using Propertie</title>
+        <para>D-Bus properties are available via an additional <ulink url="&url_dbus_spec_base;standard-interfaces-properties">org.freedesktop.DBus.Properties</ulink> interface on some objects, which provides <function>Get()</function>, <function>Set()</function> and <function>GetAll</function> methods. You can call these methods to get or set property values for the object's other interfaces.</para>
+        <para>As of this writing, Python has no simple API for dealing with D-Bus properties so you must call these functions directly. Therefore this example is therefore very similar to the <link linkend="sect-basics-dbus-python-methods">Calling Methods</link> example.</para>
+        <para><ulink url="&url_examples_base;basics_dbus_python_properties">Source Code</ulink></para>
+      </sect3>
 
     </sect2>
    </sect1>
diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am
index de73ecf..3a9e443 100644
--- a/docs/examples/Makefile.am
+++ b/docs/examples/Makefile.am
@@ -1,6 +1,6 @@
 include $(top_srcdir)/docs/Makefile_web.am_fragment
 
-example_dirs = basics_dbus_glib basics_dbus_python connect list_all_protocols list_contacts set_presence send_message
+example_dirs = basics_dbus_glib_methods basics_dbus_glib_properties basics_dbus_python_methods basics_dbus_python_properties connect list_all_protocols list_contacts set_presence send_message
 
 SUBDIRS = $(example_dirs)
 
diff --git a/docs/examples/basics_dbus_glib/Makefile.am b/docs/examples/basics_dbus_glib/Makefile.am
deleted file mode 100644
index d0a304f..0000000
--- a/docs/examples/basics_dbus_glib/Makefile.am
+++ /dev/null
@@ -1,7 +0,0 @@
-include $(top_srcdir)/docs/examples/Makefile.am_fragment
-
-#Build the executable, but don't install it.
-noinst_PROGRAMS = example
-
-example_SOURCES = main.c
-
diff --git a/docs/examples/basics_dbus_glib/main.c b/docs/examples/basics_dbus_glib/main.c
deleted file mode 100644
index ed328e0..0000000
--- a/docs/examples/basics_dbus_glib/main.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/* Copyright 2009 Collabora Ltd
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <dbus/dbus-glib.h>
-#include <glib.h>
-
-GMainLoop *mainloop = NULL;
-
-void on_proxy_call_notify (DBusGProxy *proxy,
-  DBusGProxyCall *call_id,
-  void *user_data)
-{
-  GError *error = 0;
-  guint result = 0;
-  dbus_g_proxy_end_call (proxy, call_id, &error, 
-    G_TYPE_UINT, &result, /* Return value. */
-    G_TYPE_INVALID);
-
-  if (error)
-    {
-      g_printf ("dbus_g_proxy_begin_call() failed: %s\n", error->message);
-      g_clear_error (&error);
-    }
-  else
-    {
-      g_printf ("dbus_g_proxy_begin_call() succeeded, returning %u\n", result);
-    }
-
-  /* Stop the main loop to allow main() to finish, 
-   * stopping the program: */
-  g_main_loop_quit (mainloop);
-}
-
-int
-main (int argc, char **argv)
-{
-  g_type_init ();
-
-  /* Create the main loop: */
-  mainloop = g_main_loop_new (NULL, FALSE);
-
-  /* Connect to the bus: */
-  GError *error = 0;
-  DBusGConnection *connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
-  if (error)
-    {
-      g_printf ("dbus_g_bus_get() failed: %s\n", error->message);
-      g_clear_error (&error);
-      g_main_loop_quit (mainloop);
-      return 1;
-    }
-
-  /* Get a proxy for the remote object: */
-  DBusGProxy *proxy = dbus_g_proxy_new_for_name (connection,
-    "org.freedesktop.Notifications", /* name */
-    "/org/freedesktop/Notifications", /* path */
-    "org.freedesktop.Notifications"); /* interface */
-
-
-  /* Call a method on the interface  of the remote object: */
-
-  /* Create an empty GHashTable for one of the parameters: */
-  GHashTable* actions = g_hash_table_new (NULL, NULL);  
-
-  /* Call the method: */
-  dbus_g_proxy_begin_call (proxy, "Notify", 
-    &on_proxy_call_notify, NULL, /* user_data */ 
-    NULL, /* destroy notification */
-    G_TYPE_STRING, "dbus-glib example",
-    G_TYPE_UINT, 0,
-    G_TYPE_STRING, "", /* icon_name */ 
-    G_TYPE_STRING, "Example Notification",
-    G_TYPE_STRING, "This is an example notification via dbus-glib.",
-    G_TYPE_STRV, 0,
-    dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), actions,
-    G_TYPE_INT, 0,
-    G_TYPE_INVALID,
-    G_TYPE_INVALID);
-  g_hash_table_unref (actions);
-  actions = NULL;
-
-  /* Run the main loop, 
-   * to keep our application alive while we wait for responses from D-Bus.
-   * This function returns when we call g_main_loop_quit() from elsewhere.
-   */
-  g_main_loop_run (mainloop);
-
-  /* Clean up: */
-  g_main_loop_unref (mainloop);
-
-  return 0;
-}
diff --git a/docs/examples/basics_dbus_glib_methods/Makefile.am b/docs/examples/basics_dbus_glib_methods/Makefile.am
new file mode 100644
index 0000000..d0a304f
--- /dev/null
+++ b/docs/examples/basics_dbus_glib_methods/Makefile.am
@@ -0,0 +1,7 @@
+include $(top_srcdir)/docs/examples/Makefile.am_fragment
+
+#Build the executable, but don't install it.
+noinst_PROGRAMS = example
+
+example_SOURCES = main.c
+
diff --git a/docs/examples/basics_dbus_glib_methods/main.c b/docs/examples/basics_dbus_glib_methods/main.c
new file mode 100644
index 0000000..da57b54
--- /dev/null
+++ b/docs/examples/basics_dbus_glib_methods/main.c
@@ -0,0 +1,106 @@
+/* Copyright 2009 Collabora Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <dbus/dbus-glib.h>
+#include <glib.h>
+
+GMainLoop *mainloop = NULL;
+
+void on_proxy_call_notify (DBusGProxy *proxy,
+  DBusGProxyCall *call_id,
+  void *user_data)
+{
+  GError *error = 0;
+  guint result = 0;
+  dbus_g_proxy_end_call (proxy, call_id, &error, 
+    G_TYPE_UINT, &result, /* Return value. */
+    G_TYPE_INVALID);
+
+  if (error)
+    {
+      g_printf ("dbus_g_proxy_begin_call() failed: %s\n", error->message);
+      g_clear_error (&error);
+    }
+  else
+    {
+      g_printf ("dbus_g_proxy_begin_call() succeeded, returning %u\n", result);
+    }
+
+  /* Stop the main loop to allow main() to finish, 
+   * stopping the program: */
+  g_main_loop_quit (mainloop);
+}
+
+int
+main (int argc, char **argv)
+{
+  g_type_init ();
+
+  /* Create the main loop: */
+  mainloop = g_main_loop_new (NULL, FALSE);
+
+  /* Connect to the bus: */
+  GError *error = 0;
+  DBusGConnection *connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+  if (error)
+    {
+      g_printf ("dbus_g_bus_get() failed: %s\n", error->message);
+      g_clear_error (&error);
+      g_main_loop_quit (mainloop);
+      return 1;
+    }
+
+  /* Get a proxy for the remote object: */
+  DBusGProxy *proxy = dbus_g_proxy_new_for_name (connection,
+    "org.freedesktop.Notifications", /* name */
+    "/org/freedesktop/Notifications", /* path */
+    "org.freedesktop.Notifications"); /* interface */
+
+
+  /* Call a method on the interface  of the remote object: */
+
+  /* Create an empty GHashTable for one of the parameters: */
+  GHashTable* actions = g_hash_table_new (NULL, NULL);  
+
+  /* Call the method: */
+  dbus_g_proxy_begin_call (proxy, "Notify", 
+    &on_proxy_call_notify, NULL, /* user_data */ 
+    NULL, /* destroy notification */
+    G_TYPE_STRING, "dbus-glib example",
+    G_TYPE_UINT, 0,
+    G_TYPE_STRING, "", /* icon_name */ 
+    G_TYPE_STRING, "Example Notification",
+    G_TYPE_STRING, "This is an example notification via dbus-glib.",
+    G_TYPE_STRV, 0,
+    dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), actions,
+    G_TYPE_INT, 0,
+    G_TYPE_INVALID,
+    G_TYPE_INT,
+    G_TYPE_INVALID);
+  g_hash_table_unref (actions);
+  actions = NULL;
+
+  /* Run the main loop, 
+   * to keep our application alive while we wait for responses from D-Bus.
+   * This function returns when we call g_main_loop_quit() from elsewhere.
+   */
+  g_main_loop_run (mainloop);
+
+  /* Clean up: */
+  g_main_loop_unref (mainloop);
+
+  return 0;
+}
diff --git a/docs/examples/basics_dbus_glib_properties/Makefile.am b/docs/examples/basics_dbus_glib_properties/Makefile.am
new file mode 100644
index 0000000..d0a304f
--- /dev/null
+++ b/docs/examples/basics_dbus_glib_properties/Makefile.am
@@ -0,0 +1,7 @@
+include $(top_srcdir)/docs/examples/Makefile.am_fragment
+
+#Build the executable, but don't install it.
+noinst_PROGRAMS = example
+
+example_SOURCES = main.c
+
diff --git a/docs/examples/basics_dbus_glib_properties/main.c b/docs/examples/basics_dbus_glib_properties/main.c
new file mode 100644
index 0000000..b4a3547
--- /dev/null
+++ b/docs/examples/basics_dbus_glib_properties/main.c
@@ -0,0 +1,99 @@
+/* Copyright 2009 Collabora Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <dbus/dbus-glib.h>
+#include <glib.h>
+
+GMainLoop *mainloop = NULL;
+
+void on_proxy_call_get (DBusGProxy *proxy,
+  DBusGProxyCall *call_id,
+  void *user_data)
+{
+  GError *error = 0;
+  GValue result = {0, };
+  dbus_g_proxy_end_call (proxy, call_id, &error, 
+    G_TYPE_VALUE, &result, /* Return value. */
+    G_TYPE_INVALID);
+
+  if (error)
+    {
+      g_printf ("dbus_g_proxy_begin_call() failed: %s\n", error->message);
+      g_clear_error (&error);
+    }
+  else
+    {
+      gchar* as_string = g_strdup_value_contents (&result);
+      g_printf ("dbus_g_proxy_begin_call() succeeded, returning type=%s, value=%s\n", 
+        G_VALUE_TYPE_NAME(&result), as_string);
+      g_free (as_string);
+    }
+
+  g_value_unset (&result);
+
+  /* Stop the main loop to allow main() to finish, 
+   * stopping the program: */
+  g_main_loop_quit (mainloop);
+}
+
+int
+main (int argc, char **argv)
+{
+  g_type_init ();
+
+  /* Create the main loop: */
+  mainloop = g_main_loop_new (NULL, FALSE);
+
+  /* Connect to the bus: */
+  GError *error = 0;
+  DBusGConnection *connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+  if (error)
+    {
+      g_printf ("dbus_g_bus_get() failed: %s\n", error->message);
+      g_clear_error (&error);
+      g_main_loop_quit (mainloop);
+      return 1;
+    }
+
+  /* Get a proxy for the Properties interface of a remote object: */
+  DBusGProxy *proxy = dbus_g_proxy_new_for_name (connection,
+    "org.freedesktop.Telepathy.Connection.salut.local_xmpp.Murray_20Cumming", /* name */
+    "/org/freedesktop/Telepathy/Connection/salut/local_xmpp/Murray_20Cumming", /* path */
+    "org.freedesktop.DBus.Properties"); /* interface */
+
+  /* Call the Properties.Get method on the interface of the remote object: */
+
+  /* Call the Get method to get a property value: */
+  dbus_g_proxy_begin_call (proxy, "Get" /* property name */,
+    &on_proxy_call_get, NULL, /* user_data */ 
+    NULL, /* destroy notification */
+    G_TYPE_STRING, "org.freedesktop.Telepathy.Connection", /* interface name */
+    G_TYPE_STRING, "SelfHandle", /* property name */
+    G_TYPE_INVALID,
+    G_TYPE_VALUE,
+    G_TYPE_INVALID);
+
+  /* Run the main loop, 
+   * to keep our application alive while we wait for responses from D-Bus.
+   * This function returns when we call g_main_loop_quit() from elsewhere.
+   */
+  g_main_loop_run (mainloop);
+
+  /* Clean up: */
+  g_main_loop_unref (mainloop);
+
+  return 0;
+}
diff --git a/docs/examples/basics_dbus_python/Makefile.am b/docs/examples/basics_dbus_python/Makefile.am
deleted file mode 100644
index 6e633c3..0000000
--- a/docs/examples/basics_dbus_python/Makefile.am
+++ /dev/null
@@ -1,4 +0,0 @@
-include $(top_srcdir)/docs/examples/Makefile.am_fragment
-
-#Dist the example:
-EXTRA_DIST = example.py
diff --git a/docs/examples/basics_dbus_python/example.py b/docs/examples/basics_dbus_python/example.py
deleted file mode 100644
index b8bf78d..0000000
--- a/docs/examples/basics_dbus_python/example.py
+++ /dev/null
@@ -1,73 +0,0 @@
-# Copyright 2009 Collabora Ltd
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2
-# as published by the Free Software Foundation.
-#
-# This program 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 General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import dbus
-import dbus.mainloop.glib
-import gobject
-import sys
-import traceback
-
-def on_notify_reply(result):
-    print "Notify() result: %u \n" % result
-    loop.quit()
-
-def on_notify_error(error):
-    print "Notify() failed: %s\n" % str(error)
-    loop.quit()
-
-if __name__ == '__main__':
-
-    # Tell the dbus python module to use the Glib mainloop, 
-    # which we will start and stop later:
-    dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
-
-    # Connect to the bus:
-    bus = dbus.SessionBus()
-
-    # Get a proxy for the remote object:
-    try:
-        proxy = bus.get_object('org.freedesktop.Notifications',
-            '/org/freedesktop/Notifications',
-            'org.freedesktop.Notifications')
-    except dbus.DBusException:
-        traceback.print_exc()
-        sys.exit(1)
-
-
-    # Call a method on the interface of the remote object: */
-
-    # Create empty objects needed for some parameters:
-    actions = dbus.Array('s')
-    hints = dbus.Dictionary({}, signature=dbus.Signature('sv'))
-
-    # Call the method:
-    proxy.Notify(
-        "dbus python example", 
-        (dbus.UInt32)(0),
-        '', # icon-name
-        'Example Notification', 
-        'This is an example notification via dbus with Python.', 
-        actions, 
-        hints, 
-        0,
-        reply_handler = on_notify_reply, error_handler = on_notify_error)
-
-    # Start the mainloop so we can wait until the D-Bus method 
-    # returns. We stop the mainloop in our handlers.
-    loop = gobject.MainLoop()
-    loop.run()
-
-
-
diff --git a/docs/examples/basics_dbus_python_methods/Makefile.am b/docs/examples/basics_dbus_python_methods/Makefile.am
new file mode 100644
index 0000000..6e633c3
--- /dev/null
+++ b/docs/examples/basics_dbus_python_methods/Makefile.am
@@ -0,0 +1,4 @@
+include $(top_srcdir)/docs/examples/Makefile.am_fragment
+
+#Dist the example:
+EXTRA_DIST = example.py
diff --git a/docs/examples/basics_dbus_python_methods/example.py b/docs/examples/basics_dbus_python_methods/example.py
new file mode 100644
index 0000000..b8bf78d
--- /dev/null
+++ b/docs/examples/basics_dbus_python_methods/example.py
@@ -0,0 +1,73 @@
+# Copyright 2009 Collabora Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2
+# as published by the Free Software Foundation.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import dbus
+import dbus.mainloop.glib
+import gobject
+import sys
+import traceback
+
+def on_notify_reply(result):
+    print "Notify() result: %u \n" % result
+    loop.quit()
+
+def on_notify_error(error):
+    print "Notify() failed: %s\n" % str(error)
+    loop.quit()
+
+if __name__ == '__main__':
+
+    # Tell the dbus python module to use the Glib mainloop, 
+    # which we will start and stop later:
+    dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
+
+    # Connect to the bus:
+    bus = dbus.SessionBus()
+
+    # Get a proxy for the remote object:
+    try:
+        proxy = bus.get_object('org.freedesktop.Notifications',
+            '/org/freedesktop/Notifications',
+            'org.freedesktop.Notifications')
+    except dbus.DBusException:
+        traceback.print_exc()
+        sys.exit(1)
+
+
+    # Call a method on the interface of the remote object: */
+
+    # Create empty objects needed for some parameters:
+    actions = dbus.Array('s')
+    hints = dbus.Dictionary({}, signature=dbus.Signature('sv'))
+
+    # Call the method:
+    proxy.Notify(
+        "dbus python example", 
+        (dbus.UInt32)(0),
+        '', # icon-name
+        'Example Notification', 
+        'This is an example notification via dbus with Python.', 
+        actions, 
+        hints, 
+        0,
+        reply_handler = on_notify_reply, error_handler = on_notify_error)
+
+    # Start the mainloop so we can wait until the D-Bus method 
+    # returns. We stop the mainloop in our handlers.
+    loop = gobject.MainLoop()
+    loop.run()
+
+
+
diff --git a/docs/examples/basics_dbus_python_properties/Makefile.am b/docs/examples/basics_dbus_python_properties/Makefile.am
new file mode 100644
index 0000000..6e633c3
--- /dev/null
+++ b/docs/examples/basics_dbus_python_properties/Makefile.am
@@ -0,0 +1,4 @@
+include $(top_srcdir)/docs/examples/Makefile.am_fragment
+
+#Dist the example:
+EXTRA_DIST = example.py
diff --git a/docs/examples/basics_dbus_python_properties/example.py b/docs/examples/basics_dbus_python_properties/example.py
new file mode 100644
index 0000000..fa82233
--- /dev/null
+++ b/docs/examples/basics_dbus_python_properties/example.py
@@ -0,0 +1,63 @@
+# Copyright 2009 Collabora Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2
+# as published by the Free Software Foundation.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import dbus
+import dbus.mainloop.glib
+import gobject
+import sys
+import traceback
+
+def on_get_reply(result):
+    print "Get() result: %u \n" % result
+    loop.quit()
+
+def on_get_error(error):
+    print "Get() failed: %s\n" % str(error)
+    loop.quit()
+
+if __name__ == '__main__':
+
+    # Tell the dbus python module to use the Glib mainloop, 
+    # which we will start and stop later:
+    dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
+
+    # Connect to the bus:
+    bus = dbus.SessionBus()
+
+    # Get a proxy for the Properties interface of a remote object:
+    try:
+        proxy = bus.get_object('org.freedesktop.Telepathy.Connection.salut.local_xmpp.Murray_20Cumming',
+            '/org/freedesktop/Telepathy/Connection/salut/local_xmpp/Murray_20Cumming',
+            'org.freedesktop.DBus.Properties')
+    except dbus.DBusException:
+        traceback.print_exc()
+        sys.exit(1)
+
+
+    # Call the Properties.Get method on the interface of the remote object: */
+
+    # Call the method:
+    proxy.Get(
+        "org.freedesktop.Telepathy.Connection", 
+        "SelfHandle",
+        reply_handler = on_get_reply, error_handler = on_get_error)
+
+    # Start the mainloop so we can wait until the D-Bus method 
+    # returns. We stop the mainloop in our handlers.
+    loop = gobject.MainLoop()
+    loop.run()
+
+
+
-- 
1.5.6.5



More information about the telepathy-commits mailing list