diff options
author | David Zeuthen <davidz@redhat.com> | 2011-03-16 14:45:13 -0400 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2011-03-16 15:29:15 -0400 |
commit | bea5ff9e3a753cbbee0b12246bce79206049f0b4 (patch) | |
tree | 7c4471270f42e48751246d904542b69e94d48133 /src/gdbusinterfacestub.c | |
parent | b2b3375586152985c1d3bf49178419546f55c2af (diff) |
Rework object model significantly
Signed-off-by: David Zeuthen <davidz@redhat.com>
Diffstat (limited to 'src/gdbusinterfacestub.c')
-rw-r--r-- | src/gdbusinterfacestub.c | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/src/gdbusinterfacestub.c b/src/gdbusinterfacestub.c new file mode 100644 index 0000000..32f2d20 --- /dev/null +++ b/src/gdbusinterfacestub.c @@ -0,0 +1,188 @@ +/* GDBus - GLib D-Bus Library + * + * Copyright (C) 2008-2010 Red Hat, Inc. + * + * 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 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., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: David Zeuthen <davidz@redhat.com> + */ + +#include "config.h" + +#include "gdbusinterfacestub.h" + +/** + * SECTION:gdbusinterfacestub + * @short_description: Service-side D-Bus interface + * @include: gio/gio.h + * + * Abstract base class for D-Bus interfaces on the service side. + */ + +struct _GDBusInterfaceStubPrivate +{ + GDBusObject *object; +}; + +static void dbus_interface_interface_init (GDBusInterfaceIface *iface); + +G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GDBusInterfaceStub, g_dbus_interface_stub, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_INTERFACE, dbus_interface_interface_init)); + +static void +g_dbus_interface_stub_finalize (GObject *object) +{ + GDBusInterfaceStub *stub = G_DBUS_INTERFACE_STUB (object); + if (stub->priv->object != NULL) + g_object_remove_weak_pointer (G_OBJECT (stub->priv->object), (gpointer *) &stub->priv->object); + G_OBJECT_CLASS (g_dbus_interface_stub_parent_class)->finalize (object); +} + +static void +g_dbus_interface_stub_class_init (GDBusInterfaceStubClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->finalize = g_dbus_interface_stub_finalize; + + g_type_class_add_private (klass, sizeof (GDBusInterfaceStubPrivate)); +} + +static void +g_dbus_interface_stub_init (GDBusInterfaceStub *stub) +{ + stub->priv = G_TYPE_INSTANCE_GET_PRIVATE (stub, G_TYPE_DBUS_INTERFACE_STUB, GDBusInterfaceStubPrivate); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +/** + * g_dbus_interface_stub_get_info: + * @stub: A #GDBusInterfaceStub. + * + * Gets D-Bus introspection information for the D-Bus interface + * implemented by @interface. + * + * Returns: (transfer none): A #GDBusInterfaceInfo (never %NULL). Do not free. + */ +GDBusInterfaceInfo * +g_dbus_interface_stub_get_info (GDBusInterfaceStub *stub) +{ + GDBusInterfaceInfo *ret; + g_return_val_if_fail (G_IS_DBUS_INTERFACE_STUB (stub), NULL); + ret = G_DBUS_INTERFACE_STUB_GET_CLASS (stub)->get_info (stub); + g_warn_if_fail (ret != NULL); + return ret; +} + +/** + * g_dbus_interface_stub_get_properties: + * @stub: A #GDBusInterfaceStub. + * + * Gets all D-Bus properties for @stub. + * + * Returns: A new, floating, #GVariant. Free with g_variant_unref(). + */ +GVariant * +g_dbus_interface_stub_get_properties (GDBusInterfaceStub *stub) +{ + GVariant *ret; + g_return_val_if_fail (G_IS_DBUS_INTERFACE_STUB (stub), NULL); + ret = G_DBUS_INTERFACE_STUB_GET_CLASS (stub)->get_properties (stub); + g_warn_if_fail (g_variant_is_floating (ret)); + return ret; +} + +/** + * g_dbus_interface_stub_flush: + * @stub: A #GDBusInterfaceStub. + * + * If @stub has outstanding changes, request for these changes to be + * emitted immediately. + * + * For example, an exported D-Bus interface may queue up property + * changes and emit the + * <literal>org.freedesktop.DBus.Properties::PropertiesChanged</literal> + * signal later (e.g. in an idle handler). This technique is useful + * for collapsing multiple property changes into one. + */ +void +g_dbus_interface_stub_flush (GDBusInterfaceStub *stub) +{ + g_return_if_fail (G_IS_DBUS_INTERFACE_STUB (stub)); + G_DBUS_INTERFACE_STUB_GET_CLASS (stub)->flush (stub); +} + +/** + * g_dbus_interface_stub_export: + * @stub: The D-Bus interface to export. + * @connection: A #GDBusConnection to export @stub on. + * @object_path: The path to export the interface at. + * @error: Return location for error or %NULL. + * + * Exports @stubs at @object_path on @connection. + * + * Returns: 0 if @error is set, otherwise a registration id (never 0) + * that can be used with g_dbus_connection_unregister_object(). + */ +guint +g_dbus_interface_stub_export (GDBusInterfaceStub *stub, + GDBusConnection *connection, + const gchar *object_path, + GError **error) +{ + g_return_val_if_fail (G_IS_DBUS_INTERFACE_STUB (stub), 0); + g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), 0); + g_return_val_if_fail (g_variant_is_object_path (object_path), 0); + g_return_val_if_fail (error == NULL || *error == NULL, 0); + return G_DBUS_INTERFACE_STUB_GET_CLASS (stub)->export (stub, connection, object_path, error); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static GDBusInterfaceInfo * +_g_dbus_interface_stub_get_info (GDBusInterface *interface) +{ + GDBusInterfaceStub *stub = G_DBUS_INTERFACE_STUB (interface); + return g_dbus_interface_stub_get_info (stub); +} + +static GDBusObject * +g_dbus_interface_stub_get_object (GDBusInterface *interface) +{ + GDBusInterfaceStub *stub = G_DBUS_INTERFACE_STUB (interface); + return stub->priv->object; +} + +static void +g_dbus_interface_stub_set_object (GDBusInterface *interface, + GDBusObject *object) +{ + GDBusInterfaceStub *stub = G_DBUS_INTERFACE_STUB (interface); + if (stub->priv->object != NULL) + g_object_remove_weak_pointer (G_OBJECT (stub->priv->object), (gpointer *) &stub->priv->object); + stub->priv->object = object; + if (object != NULL) + g_object_add_weak_pointer (G_OBJECT (stub->priv->object), (gpointer *) &stub->priv->object); +} + +static void +dbus_interface_interface_init (GDBusInterfaceIface *iface) +{ + iface->get_info = _g_dbus_interface_stub_get_info; + iface->get_object = g_dbus_interface_stub_get_object; + iface->set_object = g_dbus_interface_stub_set_object; +} |