[glibmm] Gio::DBus::AuthObserver: Add example from the C API docs in class docs



commit 0d3695bee8ab94a102e570c098f2243ec65e01a1
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Mon Dec 9 18:24:10 2013 +0100

    Gio::DBus::AuthObserver: Add example from the C API docs in class docs
    
    * gio/src/dbusauthobserver.hg: Add the example from the C API docs,
    translated to C++.

 gio/src/dbusauthobserver.hg |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)
---
diff --git a/gio/src/dbusauthobserver.hg b/gio/src/dbusauthobserver.hg
index 4e89c86..931af72 100644
--- a/gio/src/dbusauthobserver.hg
+++ b/gio/src/dbusauthobserver.hg
@@ -32,13 +32,40 @@ namespace DBus
 
 _GMMPROC_EXTRA_NAMESPACE(DBus)
 
-//TODO: Add example from the C API docs in class docs.
 /** AuthObserver - An object used for authenticating connections.
  * The AuthObserver type provides a mechanism for participating in how a
  * Server (or a Connection) authenticates remote peers.  Simply
  * instantiate an AuthObserver and connect to the signals you are
  * interested in. Note that new signals may be added in the future.
  *
+ * For example, if you only want to allow D-Bus connections from
+ * processes owned by the same uid as the server, you would use a
+ * signal handler like the following:
+ * @code
+ * bool on_authorize_authenticated_peer(
+ *   const Glib::RefPtr<const Gio::IOStream>&,
+ *   const Glib::RefPtr<const Gio::Credentials>& credentials)
+ * {
+ *   bool authorized = false;
+ *
+ *   if (credentials)
+ *   {
+ *     Glib::RefPtr<Gio::Credentials> own_credentials = Gio::Credentials::create();
+ *     try
+ *     {
+ *       if (credentials->is_same_user(own_credentials))
+ *         authorized = true;
+ *     }
+ *     catch (const Gio::Error& ex)
+ *     {
+ *       std::cerr << "Gio::Error: " << ex.what() << std::endl;
+ *     }
+ *   }
+ *
+ *   return authorized;
+ * }
+ * @endcode
+ *
  * @newin{2,28}
  * @ingroup DBus
  */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]