[glibmm] DBus: Add a peer example to test the DBusServer class.



commit d36542c993bf2abaeef926f31b5736856c413f79
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Mon Jan 10 02:27:31 2011 -0500

    DBus: Add a peer example to test the DBusServer class.
    
    	* gio/src/dbusconnection.{ccg,hg}:  Reorder the VariantBase
    	'parameters' parameter in the call*() methods to come after the
    	method_name parameter.
    	* gio/src/dbusintrospection.hg: Use refreturn for methods where the C
    	API does not automatically reference the return.
    	* gio/src/dbusserver.{ccg,hg}: Add non-observable constructors and
    	create() methods.
    	* glib/src/variant.{ccg,hg} (create_tuple): Renamed from create().
    	Write this method to be more specific for tuples (it's probably the
    	only case where this method might be used).  Dealing with tuples still
    	feels awkward with the method.  Maybe there's a better way.
    
    	* examples/Makefile.am:
    	* examples/dbus/peer.cc:
    	* examples/dbus/userbus.cc:
    	* examples/dbus/well-known-address-client.cc: Add the new
    	server/client peer example (named peer).  The example crashes because
    	the C API seems to not deal with empty strings "" well, but at least
    	there is now an example.  Making sure it runs well is necessary.  Also
    	rename the previous example to userbus.cc.

 ChangeLog                                          |   25 ++
 examples/Makefile.am                               |    9 +-
 examples/dbus/peer.cc                              |  258 ++++++++++++++++++++
 .../{well-known-address-client.cc => userbus.cc}   |    2 +-
 gio/src/dbusconnection.ccg                         |    8 +-
 gio/src/dbusconnection.hg                          |   18 +-
 gio/src/dbusintrospection.hg                       |   16 +-
 gio/src/dbusserver.ccg                             |   71 ++++++
 gio/src/dbusserver.hg                              |   21 ++
 glib/src/variant.ccg                               |   30 +--
 glib/src/variant.hg                                |   11 +-
 11 files changed, 419 insertions(+), 50 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9d2fe10..7b18283 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2011-01-10  José Alburquerque  <jaalburqu svn gnome org>
+
+	DBus: Add a peer example to test the DBusServer class.
+
+	* gio/src/dbusconnection.{ccg,hg}:  Reorder the VariantBase
+	'parameters' parameter in the call*() methods to come after the
+	method_name parameter.
+	* gio/src/dbusintrospection.hg: Use refreturn for methods where the C
+	API does not automatically reference the return.
+	* gio/src/dbusserver.{ccg,hg}: Add non-observable constructors and
+	create() methods.
+	* glib/src/variant.{ccg,hg} (create_tuple): Renamed from create().
+	Write this method to be more specific for tuples (it's probably the
+	only case where this method might be used).  Dealing with tuples still
+	feels awkward with the method.  Maybe there's a better way.
+
+	* examples/Makefile.am:
+	* examples/dbus/peer.cc:
+	* examples/dbus/userbus.cc:
+	* examples/dbus/well-known-address-client.cc: Add the new
+	server/client peer example (named peer).  The example crashes because
+	the C API seems to not deal with empty strings "" well, but at least
+	there is now an example.  Making sure it runs well is necessary.  Also
+	rename the previous example to userbus.cc.
+
 2011-01-08  Krzesimir Nowak  <qdlacz gmail com>
 
 	Tools: Added a defs fixer tool.
diff --git a/examples/Makefile.am b/examples/Makefile.am
index d8733af..e65dbfb 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -20,7 +20,8 @@ AUTOMAKE_OPTIONS = subdir-objects
 check_PROGRAMS =			\
 	child_watch/child_watch		\
 	compose/example			\
-	dbus/well-known-address-client	\
+	dbus/peer			\
+	dbus/userbus			\
 	iochannel_stream/example	\
 	keyfile/example			\
 	markup/parser			\
@@ -74,8 +75,10 @@ thread_threadpool_SOURCES  = thread/threadpool.cc
 thread_threadpool_LDADD    = $(thread_ldadd)
 
 # giomm examples
-dbus_well_known_address_client_SOURCES = dbus/well-known-address-client.cc
-dbus_well_known_address_client_LDADD   = $(giomm_ldadd)
+dbus_peer_SOURCES = dbus/peer.cc
+dbus_peer_LDADD = $(giomm_ldadd)
+dbus_userbus_SOURCES = dbus/userbus.cc
+dbus_userbus_LDADD   = $(giomm_ldadd)
 
 network_resolver_SOURCES   = network/resolver.cc
 network_resolver_LDADD     = $(giomm_ldadd)
diff --git a/examples/dbus/peer.cc b/examples/dbus/peer.cc
new file mode 100644
index 0000000..ea04b2a
--- /dev/null
+++ b/examples/dbus/peer.cc
@@ -0,0 +1,258 @@
+/* Copyright (C) 2011 The giomm Development Team
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/* For some usage examples see the C API's GDBusServer's example from which
+ * this example was adapted.
+ */
+
+#include <giomm.h>
+#include <glibmm.h>
+#include <iostream>
+
+static Glib::RefPtr<Gio::DBusNodeInfo> introspection_data;
+
+static Glib::ustring introspection_xml =
+  "<node>"
+  "  <interface name='org.glibmm.GDBus.TestPeerInterface'>"
+  "    <method name='HelloWorld'>"
+  "      <arg type='s' name='greeting' direction='in'/>"
+  "      <arg type='s' name='response' direction='out'/>"
+  "    </method>"
+  "  </interface>"
+  "</node>";
+
+// This variable is used to keep an incoming connection active.
+Glib::RefPtr<Gio::DBusConnection> keep_connection;
+
+static void on_method_call(const Glib::RefPtr<Gio::DBusConnection>&,
+  const Glib::ustring& /* sender */, const Glib::ustring& /* object_path */,
+  const Glib::ustring& /* interface_name */, const Glib::ustring& method_name,
+  // Since the parameters are generally tuples, get them from the invocation.
+  const Glib::VariantBase& /* parameters */,
+  const Glib::RefPtr<Gio::DBusMethodInvocation>& invocation)
+{
+  if(method_name == "HelloWorld")
+  {
+    // Get parameters.
+    Glib::VariantContainerBase parameters;
+    invocation->get_parameters(parameters);
+
+    // Get (expected) single string in tupple.
+    Glib::Variant<Glib::ustring> param;
+    parameters.get(param);
+
+    Glib::ustring response = "You said: '" + param.get() + "'.";
+
+    Glib::Variant<Glib::ustring> answer =
+      Glib::Variant<Glib::ustring>::create(response);
+
+    invocation->return_value(answer);
+
+    std::cout << "Client said '" << param.get() << "'." << std::endl;
+  }
+}
+
+// Create the interface VTable.
+static const Gio::DBusInterfaceVTable
+  interface_vtable(sigc::ptr_fun(&on_method_call));
+
+bool on_new_connection(const Glib::RefPtr<Gio::DBusConnection>& connection)
+{
+  Glib::RefPtr<Gio::Credentials> credentials =
+    connection->get_peer_credentials();
+
+  std::string credentials_str;
+
+  if(!credentials)
+    credentials_str = "(no credentials received)";
+  else
+    credentials_str = credentials->to_string();
+
+  std::cout <<
+    "Client connected." << std::endl <<
+    "Peer credentials: " << credentials_str << std::endl <<
+    "Negotiated capabilities: unix-fd-passing=" << (connection->get_capabilities() & Gio::DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING) << std::endl;
+
+  // In order for the connection to stay active the reference to the
+  // connection must be kept so store the connection in a global variable.
+  keep_connection = connection;
+
+  guint reg_id = connection->register_object("/org/glibmm/GDBus/TestObject",
+    introspection_data->lookup_interface("org.glibmm.GDBus.TestPeerInterface"),
+    &interface_vtable);
+
+  if(reg_id == 0)
+  {
+    std::cerr << "Registration of object for incoming connection not "
+      "possible." << std::endl;
+    return false;
+  }
+
+  return true;
+}
+
+void run_as_server(Glib::ustring address, bool allow_anonymous)
+{
+  Glib::ustring guid = Gio::DBus::generate_guid();
+  Gio::DBusServerFlags flags = Gio::DBUS_SERVER_FLAGS_NONE;
+
+  if(allow_anonymous)
+    flags |= Gio::DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS;
+
+  Glib::RefPtr<Gio::DBusServer> server;
+
+  try
+  {
+    server = Gio::DBusServer::create_sync(address, guid, flags);
+  }
+  catch(const Glib::Error& ex)
+  {
+    std::cerr << "Error creating server at address: " << address <<
+      ": " << ex.what() << "." << std::endl;
+  }
+
+  server->start();
+
+  std::cout << "Server is listening at: " << server->get_client_address() <<
+    "." << std::endl;
+
+  server->signal_new_connection().connect(sigc::ptr_fun(&on_new_connection));
+
+  Glib::RefPtr<Glib::MainLoop> loop = Glib::MainLoop::create();
+  loop->run();
+}
+
+void run_as_client(Glib::ustring address)
+{
+  Glib::RefPtr<Gio::DBusConnection> connection;
+
+  try
+  {
+    connection = Gio::DBusConnection::create_for_address_sync(address,
+      Gio::DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT);
+  }
+  catch(const Glib::Error& ex)
+  {
+    std::cerr << "Error connecting to D-Bus address " << address << ": " <<
+      ex.what() << "." << std::endl;
+  }
+
+  std::cout << "Connected. " << std::endl <<
+    "Negotiated capabilities: unix-fd-passing=" <<
+    static_cast<bool>(connection->get_capabilities() & Gio::DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING) << "." << std::endl;
+
+  // Get the current time to send as a greeting when calling a server's method.
+  Glib::TimeVal time;
+  time.assign_current_time();
+
+  // Create the single string tuple parameter for the method call.
+
+  Glib::ustring greeting("Hello, it's: "  + time.as_iso8601() + '.');
+
+  Glib::Variant<Glib::ustring> param =
+    Glib::Variant<Glib::ustring>::create(greeting);
+
+  std::vector<Glib::VariantBase> variants;
+  variants.push_back(param);
+
+  Glib::VariantContainerBase parameters =
+    Glib::VariantContainerBase::create_tuple(variants);
+
+  try
+  {
+    Glib::VariantContainerBase result;
+    connection->call_sync(result, "/org/glibmm/GDBus/TestObject",
+      "org.glibmm.GDBus.TestPeerInterface",
+      "HelloWorld", parameters);
+
+    Glib::Variant<Glib::ustring> child;
+    result.get(child);
+
+    std::cout << "The server said: " << child.get() << "." << std::endl;
+  }
+  catch(const Glib::Error& ex)
+  {
+    std::cerr << "Error calling the server's method: " << ex.what() << "." <<
+      std::endl;
+  }
+}
+
+int main(int argc, char** argv)
+{
+  std::locale::global(std::locale(""));
+  Gio::init();
+
+  bool opt_server = false;
+  char* opt_address = 0;
+  bool opt_allow_anonymous = false;
+
+  static const GOptionEntry opt_entries[] =
+  {
+    { "server", 's', 0, G_OPTION_ARG_NONE, &opt_server, "Start a server instead of a client", NULL },
+      { "address", 'a', 0, G_OPTION_ARG_STRING, &opt_address, "D-Bus address to use", NULL },
+      { "allow-anonymous", 'n', 0, G_OPTION_ARG_NONE, &opt_allow_anonymous, "Allow anonymous authentication", NULL },
+      { 0, '\0', 0, G_OPTION_ARG_NONE, 0, 0, 0 }
+  };
+
+  Glib::OptionContext opt_context("DBus peer-to-peer example");
+  g_option_context_add_main_entries(opt_context.gobj(), opt_entries, 0);
+
+  try
+  {
+    if(!opt_context.parse(argc, argv))
+    {
+      std::cerr << "Error parsing options and initializing.  Sorry." <<
+        std::endl;
+      return 1;
+    }
+  }
+  catch(const Glib::OptionError& ex)
+  {
+    std::cerr << "Error parsing options: " << ex.what() << std::endl;
+    return 1;
+  }
+
+  if(!opt_address)
+  {
+    std::cerr << "Incorrect usage, try the --help options." << std::endl;
+    return 1;
+  }
+
+  if(!opt_server && opt_allow_anonymous)
+  {
+    std::cerr << "The --allow-anonymous option is only valid with the "
+      "--server option." << std::endl;
+    return 1;
+  }
+
+  try
+  {
+    introspection_data = Gio::DBusNodeInfo::create_for_xml(introspection_xml);
+  }
+  catch(const Glib::Error& ex)
+  {
+    std::cerr << "Unable to create introspection data: " << ex.what() <<
+      "." << std::endl;
+  }
+
+  if(opt_server)
+    run_as_server(opt_address, opt_allow_anonymous);
+  else
+    run_as_client(opt_address);
+
+  return 0;
+}
diff --git a/examples/dbus/well-known-address-client.cc b/examples/dbus/userbus.cc
similarity index 98%
rename from examples/dbus/well-known-address-client.cc
rename to examples/dbus/userbus.cc
index b8358ff..6369854 100644
--- a/examples/dbus/well-known-address-client.cc
+++ b/examples/dbus/userbus.cc
@@ -64,7 +64,7 @@ void dbus_proxy_available(Glib::RefPtr<Gio::AsyncResult>& result)
     for(unsigned i = 0; i < names.size(); i++)
       std::cout << names[i] << "." << std::endl;
   }
-  catch (const Glib::Error& error)
+  catch(const Glib::Error& error)
   {
     std::cerr << "Got an error: '" << error.what() << "'." << std::endl;
   }
diff --git a/gio/src/dbusconnection.ccg b/gio/src/dbusconnection.ccg
index 039a0b8..c467501 100644
--- a/gio/src/dbusconnection.ccg
+++ b/gio/src/dbusconnection.ccg
@@ -822,12 +822,12 @@ void DBusConnection::call(
   const Glib::ustring&                  object_path,
   const Glib::ustring&                  interface_name,
   const Glib::ustring&                  method_name,
+  const Glib::VariantBase&              parameters,
   const SlotAsyncReady&                 slot,
   const Glib::RefPtr<Cancellable>&      cancellable,
   int                                   timeout_msec,
   const Glib::ustring&                  bus_name,
   DBusCallFlags                         flags,
-  const Glib::VariantBase&              parameters,
   const Glib::VariantType&              reply_type
 )
 {
@@ -848,11 +848,11 @@ void DBusConnection::call(
   const Glib::ustring&                  object_path,
   const Glib::ustring&                  interface_name,
   const Glib::ustring&                  method_name,
+  const Glib::VariantBase&              parameters,
   const SlotAsyncReady&                 slot,
   int                                   timeout_msec,
   const Glib::ustring&                  bus_name,
   DBusCallFlags                         flags,
-  const Glib::VariantBase&              parameters,
   const Glib::VariantType&              reply_type
 )
 {
@@ -886,11 +886,11 @@ void DBusConnection::call_sync(
   const Glib::ustring&                  object_path,
   const Glib::ustring&                  interface_name,
   const Glib::ustring&                  method_name,
+  const Glib::VariantBase&              parameters,
   const Glib::RefPtr<Cancellable>&      cancellable,
   int                                   timeout_msec,
   const Glib::ustring&                  bus_name,
   DBusCallFlags                         flags,
-  const Glib::VariantBase&              parameters,
   const Glib::VariantType&              reply_type
 )
 {
@@ -915,10 +915,10 @@ void DBusConnection::call_sync(
   const Glib::ustring&                  object_path,
   const Glib::ustring&                  interface_name,
   const Glib::ustring&                  method_name,
+  const Glib::VariantBase&              parameters,
   int                                   timeout_msec,
   const Glib::ustring&                  bus_name,
   DBusCallFlags                         flags,
-  const Glib::VariantBase&              parameters,
   const Glib::VariantType&              reply_type
 )
 {
diff --git a/gio/src/dbusconnection.hg b/gio/src/dbusconnection.hg
index ff3576a..0b8a3ba 100644
--- a/gio/src/dbusconnection.hg
+++ b/gio/src/dbusconnection.hg
@@ -630,6 +630,8 @@ public:
    * @param object_path Path of remote object.
    * @param interface_name D-Bus interface to invoke method on.
    * @param method_name The name of the method to invoke.
+   * @param parameters A Glib::VariantBase tuple with parameters for the
+   * method or <tt>0</tt> if not passing parameters.
    * @param slot A SlotAsyncReady to call when the request is satisfied.
    * @param cancellable A Cancellable.
    * @param bus_name A unique or well-known bus name or <tt>0</tt> if the
@@ -637,8 +639,6 @@ public:
    * @param timeout_msec The timeout in milliseconds, -1 to use the default
    * timeout or G_MAXINT for no timeout.
    * @param flags Flags from the Gio::DBusCallFlags enumeration.
-   * @param parameters A Glib::VariantBase tuple with parameters for the
-   * method or <tt>0</tt> if not passing parameters.
    * @param reply_type The expected type of the reply, or <tt>0</tt>.
    * @newin{2,28}
    */
@@ -646,12 +646,12 @@ public:
     const Glib::ustring&                object_path,
     const Glib::ustring&                interface_name,
     const Glib::ustring&                method_name,
+    const Glib::VariantBase&            parameters,
     const SlotAsyncReady&               slot,
     const Glib::RefPtr<Cancellable>&    cancellable,
     int                                 timeout_msec = -1,
     const Glib::ustring&                bus_name = Glib::ustring(),
     DBusCallFlags                       flags = Gio::DBUS_CALL_FLAGS_NONE,
-    const Glib::VariantBase&            parameters = Glib::VariantBase(),
     const Glib::VariantType&            reply_type = Glib::VariantType()
   );
   _IGNORE(g_dbus_connection_call)
@@ -661,11 +661,11 @@ public:
     const Glib::ustring&                object_path,
     const Glib::ustring&                interface_name,
     const Glib::ustring&                method_name,
+    const Glib::VariantBase&            parameters,
     const SlotAsyncReady&               slot,
     int                                 timeout_msec = -1,
     const Glib::ustring&                bus_name = Glib::ustring(),
     DBusCallFlags                       flags = Gio::DBUS_CALL_FLAGS_NONE,
-    const Glib::VariantBase&            parameters = Glib::VariantBase(),
     const Glib::VariantType&            reply_type = Glib::VariantType()
   );
 
@@ -704,14 +704,14 @@ public:
    * @param object_path Path of remote object.
    * @param interface_name D-Bus interface to invoke method on.
    * @param method_name The name of the method to invoke.
+   * @param parameters A Glib::VariantBase tuple with parameters for the
+   * method or <tt>0</tt> if not passing parameters.
    * @param cancellable A Cancellable.
    * @param bus_name A unique or well-known bus name or <tt>0</tt> if the
    * connection is not a message bus connection.
    * @param timeout_msec The timeout in milliseconds, -1 to use the default
    * timeout or G_MAXINT for no timeout.
    * @param flags Flags from the Gio::DBusCallFlags enumeration.
-   * @param parameters A Glib::VariantBase tuple with parameters for the
-   * method or <tt>0</tt> if not passing parameters.
    * @param reply_type The expected type of the reply, or <tt>0</tt>.
    * @throw Glib::Error.
    * @newin{2,28}
@@ -721,11 +721,11 @@ public:
     const Glib::ustring&                object_path,
     const Glib::ustring&                interface_name,
     const Glib::ustring&                method_name,
+    const Glib::VariantBase&            parameters,
     const Glib::RefPtr<Cancellable>&    cancellable,
     int                                 timeout_msec = -1,
     const Glib::ustring&                bus_name = Glib::ustring(),
     DBusCallFlags                       flags = Gio::DBUS_CALL_FLAGS_NONE,
-    const Glib::VariantBase&            parameters = Glib::VariantBase(),
     const Glib::VariantType&            reply_type = Glib::VariantType()
   );
   _IGNORE(g_dbus_connection_call_sync)
@@ -736,10 +736,10 @@ public:
     const Glib::ustring&                object_path,
     const Glib::ustring&                interface_name,
     const Glib::ustring&                method_name,
+    const Glib::VariantBase&            parameters,
     int                                 timeout_msec = -1,
     const Glib::ustring&                bus_name = Glib::ustring(),
     DBusCallFlags                       flags = Gio::DBUS_CALL_FLAGS_NONE,
-    const Glib::VariantBase&            parameters = Glib::VariantBase(),
     const Glib::VariantType&            reply_type = Glib::VariantType()
   );
 
@@ -1014,7 +1014,7 @@ public:
     const Glib::VariantBase&
   > SlotInterfaceSetProperty;
 
-  /** Constructs a new DBusInterfaceVTable using specified slots.
+  /** Constructs a new DBusInterfaceVTable using the specified slots.
    * @param slot_method_call The slot for handling incoming method calls.
    * @param slot_get_property The slot for getting a property.
    * @param slot_set_property The slot for setting a property.
diff --git a/gio/src/dbusintrospection.hg b/gio/src/dbusintrospection.hg
index 0bea10b..757392d 100644
--- a/gio/src/dbusintrospection.hg
+++ b/gio/src/dbusintrospection.hg
@@ -100,14 +100,14 @@ class DBusInterfaceInfo
   _CLASS_OPAQUE_REFCOUNTED(DBusInterfaceInfo, GDBusInterfaceInfo, NONE, g_dbus_interface_info_ref, g_dbus_interface_info_unref)
 
 public:
-  _WRAP_METHOD(Glib::RefPtr<DBusMethodInfo> lookup_method(const Glib::ustring& name), g_dbus_interface_info_lookup_method)
-  _WRAP_METHOD(Glib::RefPtr<const DBusMethodInfo> lookup_method(const Glib::ustring& name) const, g_dbus_interface_info_lookup_method, constversion)
+  _WRAP_METHOD(Glib::RefPtr<DBusMethodInfo> lookup_method(const Glib::ustring& name), g_dbus_interface_info_lookup_method, refreturn)
+  _WRAP_METHOD(Glib::RefPtr<const DBusMethodInfo> lookup_method(const Glib::ustring& name) const, g_dbus_interface_info_lookup_method, constversion, refreturn)
 
-  _WRAP_METHOD(Glib::RefPtr<DBusSignalInfo> lookup_signal(const Glib::ustring& name), g_dbus_interface_info_lookup_signal)
-  _WRAP_METHOD(Glib::RefPtr<const DBusSignalInfo> lookup_signal(const Glib::ustring& name) const, g_dbus_interface_info_lookup_signal, constversion)
+  _WRAP_METHOD(Glib::RefPtr<DBusSignalInfo> lookup_signal(const Glib::ustring& name), g_dbus_interface_info_lookup_signal, refreturn)
+  _WRAP_METHOD(Glib::RefPtr<const DBusSignalInfo> lookup_signal(const Glib::ustring& name) const, g_dbus_interface_info_lookup_signal, constversion, refreturn)
 
-  _WRAP_METHOD(Glib::RefPtr<DBusPropertyInfo> lookup_property(const Glib::ustring& name), g_dbus_interface_info_lookup_property)
-  _WRAP_METHOD(Glib::RefPtr<const DBusPropertyInfo> lookup_property(const Glib::ustring& name) const, g_dbus_interface_info_lookup_property, constversion)
+  _WRAP_METHOD(Glib::RefPtr<DBusPropertyInfo> lookup_property(const Glib::ustring& name), g_dbus_interface_info_lookup_property, refreturn)
+  _WRAP_METHOD(Glib::RefPtr<const DBusPropertyInfo> lookup_property(const Glib::ustring& name) const, g_dbus_interface_info_lookup_property, constversion, refreturn)
 
   //TODO: _WRAP_METHOD(void generate_xml(guint indent, GString* string_builder), g_dbus_interface_info_generate_xml)
 };
@@ -127,8 +127,8 @@ public:
   /// @throw Glib::Error.
   _WRAP_METHOD(static Glib::RefPtr<DBusNodeInfo> create_for_xml(const Glib::ustring& xml_data), g_dbus_node_info_new_for_xml, errthrow)
 
-  _WRAP_METHOD(Glib::RefPtr<DBusInterfaceInfo> lookup_interface(const Glib::ustring& name), g_dbus_node_info_lookup_interface)
-  _WRAP_METHOD(Glib::RefPtr<const DBusInterfaceInfo> lookup_interface(const Glib::ustring& name) const, g_dbus_node_info_lookup_interface, constversion)
+  _WRAP_METHOD(Glib::RefPtr<DBusInterfaceInfo> lookup_interface(const Glib::ustring& name), g_dbus_node_info_lookup_interface, refreturn)
+  _WRAP_METHOD(Glib::RefPtr<const DBusInterfaceInfo> lookup_interface(const Glib::ustring& name) const, g_dbus_node_info_lookup_interface, constversion, refreturn)
 
   //TODO: _WRAP_METHOD(void generate_xml(guint indent, GString* string_builder), g_dbus_node_info_generate_xml)
 };
diff --git a/gio/src/dbusserver.ccg b/gio/src/dbusserver.ccg
index 2914f9d..985811a 100644
--- a/gio/src/dbusserver.ccg
+++ b/gio/src/dbusserver.ccg
@@ -40,6 +40,19 @@ DBusServer::DBusServer(const Glib::ustring& address,
 
 DBusServer::DBusServer(const Glib::ustring& address,
   const Glib::ustring& guid,
+  const Glib::RefPtr<Cancellable>& cancellable,
+  DBusServerFlags flags)
+  : _CONSTRUCT("address",
+    (address.empty() ? static_cast<char*>(0) : address.c_str()),
+    "flags", static_cast<GDBusServerFlags>(flags),
+    "guid", (guid.empty() ? static_cast<char*>(0) : guid.c_str()),
+    "authentication-observer", static_cast<GDBusAuthObserver*>(0))
+{
+  init(cancellable);
+}
+
+DBusServer::DBusServer(const Glib::ustring& address,
+  const Glib::ustring& guid,
   const Glib::RefPtr<DBusAuthObserver>& observer,
   DBusServerFlags flags)
   : _CONSTRUCT("address",
@@ -51,6 +64,18 @@ DBusServer::DBusServer(const Glib::ustring& address,
   init();
 }
 
+DBusServer::DBusServer(const Glib::ustring& address,
+  const Glib::ustring& guid,
+  DBusServerFlags flags)
+  : _CONSTRUCT("address",
+    (address.empty() ? static_cast<char*>(0) : address.c_str()),
+    "flags", static_cast<GDBusServerFlags>(flags),
+    "guid", (guid.empty() ? static_cast<char*>(0) : guid.c_str()),
+    "authentication-observer", static_cast<GDBusAuthObserver*>(0))
+{
+  init();
+}
+
 Glib::RefPtr<DBusServer> DBusServer::create_sync(const Glib::ustring& address,
   const Glib::ustring& guid,
   const Glib::RefPtr<DBusAuthObserver>& observer,
@@ -80,6 +105,31 @@ Glib::RefPtr<DBusServer> DBusServer::create_sync(const Glib::ustring& address,
 
 Glib::RefPtr<DBusServer> DBusServer::create_sync(const Glib::ustring& address,
   const Glib::ustring& guid,
+  const Glib::RefPtr<Cancellable>& cancellable,
+  DBusServerFlags flags)
+{
+  //TODO: Use the constructor instead of the code underneath when
+  //g_dbus_server_new_sync() does not do more than call g_initable_new().
+  //return Glib::RefPtr<DBusServer>(new DBusServer(address, guid,
+    //cancellable, flags));
+
+  GError* gerror = 0;
+
+  Glib::RefPtr<DBusServer> result =
+    Glib::wrap(g_dbus_server_new_sync(address.c_str(),
+                                      static_cast<GDBusServerFlags>(flags),
+                                      guid.c_str(), 0,
+                                      Glib::unwrap(cancellable),
+                                      &gerror));
+
+  if(gerror)
+    ::Glib::Error::throw_exception(gerror);
+
+  return result;
+}
+
+Glib::RefPtr<DBusServer> DBusServer::create_sync(const Glib::ustring& address,
+  const Glib::ustring& guid,
   const Glib::RefPtr<DBusAuthObserver>& observer,
   DBusServerFlags flags)
 {
@@ -104,4 +154,25 @@ Glib::RefPtr<DBusServer> DBusServer::create_sync(const Glib::ustring& address,
   return result;
 }
 
+Glib::RefPtr<DBusServer> DBusServer::create_sync(const Glib::ustring& address,
+  const Glib::ustring& guid,
+  DBusServerFlags flags)
+{
+  //TODO: Use the constructor instead of the code underneath when
+  //g_dbus_server_new_sync() does not do more than call g_initable_new().
+  //return Glib::RefPtr<DBusServer>(new DBusServer(address, guid, flags));
+
+  GError* gerror = 0;
+
+  Glib::RefPtr<DBusServer> result =
+    Glib::wrap(g_dbus_server_new_sync(address.c_str(),
+                                      static_cast<GDBusServerFlags>(flags),
+                                      guid.c_str(), 0, 0, &gerror));
+
+  if(gerror)
+    ::Glib::Error::throw_exception(gerror);
+
+  return result;
+}
+
 } // namespace Gio
diff --git a/gio/src/dbusserver.hg b/gio/src/dbusserver.hg
index 936a132..321b797 100644
--- a/gio/src/dbusserver.hg
+++ b/gio/src/dbusserver.hg
@@ -55,9 +55,18 @@ protected:
 
   DBusServer(const Glib::ustring& address,
     const Glib::ustring& guid,
+    const Glib::RefPtr<Cancellable>& cancellable,
+    DBusServerFlags flags);
+
+  DBusServer(const Glib::ustring& address,
+    const Glib::ustring& guid,
     const Glib::RefPtr<DBusAuthObserver>& observer,
     DBusServerFlags flags);
 
+  DBusServer(const Glib::ustring& address,
+    const Glib::ustring& guid,
+    DBusServerFlags flags);
+
 public:
 
   _WRAP_METHOD_DOCS_ONLY(g_dbus_server_new_sync)
@@ -68,12 +77,24 @@ public:
     const Glib::RefPtr<Cancellable>& cancellable,
     DBusServerFlags flags = Gio::DBUS_SERVER_FLAGS_NONE);
 
+  _WRAP_METHOD_DOCS_ONLY(g_dbus_server_new_sync)
+  /// @throw Glib::Error.
+  static Glib::RefPtr<DBusServer> create_sync(const Glib::ustring& address,
+    const Glib::ustring& guid,
+    const Glib::RefPtr<Cancellable>& cancellable,
+    DBusServerFlags flags = Gio::DBUS_SERVER_FLAGS_NONE);
+
   /// Non-cancellable version of create_sync().
   static Glib::RefPtr<DBusServer> create_sync(const Glib::ustring& address,
     const Glib::ustring& guid,
     const Glib::RefPtr<DBusAuthObserver>& observer,
     DBusServerFlags flags = Gio::DBUS_SERVER_FLAGS_NONE);
 
+  /// Non-cancellable version of create_sync().
+  static Glib::RefPtr<DBusServer> create_sync(const Glib::ustring& address,
+    const Glib::ustring& guid,
+    DBusServerFlags flags = Gio::DBUS_SERVER_FLAGS_NONE);
+
   _WRAP_METHOD(void start(), g_dbus_server_start)
   _WRAP_METHOD(void stop(), g_dbus_server_stop)
   _WRAP_METHOD(bool is_active() const, g_dbus_server_is_active)
diff --git a/glib/src/variant.ccg b/glib/src/variant.ccg
index 249e469..bcd4315 100644
--- a/glib/src/variant.ccg
+++ b/glib/src/variant.ccg
@@ -59,29 +59,25 @@ void VariantStringBase::create_signature(VariantStringBase& output,
 }
 
 //static
-void VariantContainerBase::create(VariantContainerBase& output,
-  const Glib::VariantType& container_type,
-  const std::vector<VariantBase>& children)
+VariantContainerBase
+VariantContainerBase::create_tuple(const std::vector<VariantBase>& children)
 {
-  g_return_if_fail(container_type.is_container());
+  typedef GVariant* var_ptr;
+  var_ptr* const var_array = new var_ptr[children.size()];
 
-  // Create a builder to create the container (as is done in the
-  // Variant< std::map<K, V> >::create() method.
-  GVariantBuilder* builder = g_variant_builder_new(container_type.gobj());
-
-  for(std::vector<VariantBase>::const_iterator iter = children.begin();
-    iter < children.end(); iter++)
+  for(std::vector<VariantBase>::size_type i = 0; i < children.size(); i++)
   {
-    g_variant_builder_add_value(builder,
-      const_cast<GVariant*>((*iter).gobj()));
+    var_array[i] = const_cast<GVariant*>(children[i].gobj());
   }
 
-  GVariant* result = g_variant_new(
-    reinterpret_cast<char*>(const_cast<GVariantType*>(container_type.gobj())),
-    builder);
+  VariantContainerBase result = VariantContainerBase(g_variant_new_tuple(
+    var_array, children.size()));
 
-  g_variant_ref_sink(result);
-  output.init(result);
+  g_variant_ref_sink(result.gobj());
+
+  delete[] var_array;
+
+  return result;
 }
 
 void VariantContainerBase::get(VariantBase& child, gsize index) const
diff --git a/glib/src/variant.hg b/glib/src/variant.hg
index 9086e99..af42bd7 100644
--- a/glib/src/variant.hg
+++ b/glib/src/variant.hg
@@ -209,16 +209,11 @@ public:
   : VariantBase(castitem, take_a_reference)
   {}
 
-  /** Create a container variant from a vector of its variant children.  Since
-   * the children are variant and can be of any variant type, it is possible
-   * to create a variant tuple with this method.
-   * @param output A location in which to store the newly created variant.
-   * @param container_type The container type to be created.
+  /** Create a tuple variant from a vector of its variant children.
    * @param children The vector containing the children of the container.
+   * @return The newly created tuple variant (as a VariantContainerBase).
    */
-  static void create(VariantContainerBase& output,
-    const Glib::VariantType& container_type,
-    const std::vector<VariantBase>& children);
+  static VariantContainerBase create_tuple(const std::vector<VariantBase>& children);
 
   _WRAP_METHOD(gsize get_n_children() const, g_variant_n_children)
 



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