diff options
author | José Alburquerque <jaalburqu@svn.gnome.org> | 2011-01-10 02:27:31 -0500 |
---|---|---|
committer | José Alburquerque <jaalburqu@svn.gnome.org> | 2011-01-10 02:27:31 -0500 |
commit | d36542c993bf2abaeef926f31b5736856c413f79 (patch) | |
tree | 3975da8b82bef81d822d1dace1e7b97d8a3d675f /gio | |
parent | f23cecd5a7a242688abf36b433ae8c4c099f06c5 (diff) | |
download | glibmm-d36542c993bf2abaeef926f31b5736856c413f79.tar.gz |
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.
Diffstat (limited to 'gio')
-rw-r--r-- | gio/src/dbusconnection.ccg | 8 | ||||
-rw-r--r-- | gio/src/dbusconnection.hg | 18 | ||||
-rw-r--r-- | gio/src/dbusintrospection.hg | 16 | ||||
-rw-r--r-- | gio/src/dbusserver.ccg | 71 | ||||
-rw-r--r-- | gio/src/dbusserver.hg | 21 |
5 files changed, 113 insertions, 21 deletions
diff --git a/gio/src/dbusconnection.ccg b/gio/src/dbusconnection.ccg index 039a0b8b..c467501e 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 ff3576a2..0b8a3ba4 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 0bea10b0..757392dc 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 2914f9da..985811af 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 936a1324..321b7973 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) |