1 /* GDBus - GLib D-Bus Library
3 * Copyright (C) 2008-2010 Red Hat, Inc.
5 * SPDX-License-Identifier: LGPL-2.1-or-later
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 * Author: David Zeuthen <davidz@redhat.com>
25 #include "gdbusobject.h"
26 #include "gdbusinterface.h"
31 * SECTION:gdbusinterface
32 * @short_description: Base type for D-Bus interfaces
35 * The #GDBusInterface type is the base type for D-Bus interfaces both
36 * on the service side (see #GDBusInterfaceSkeleton) and client side
40 typedef GDBusInterfaceIface GDBusInterfaceInterface;
41 G_DEFINE_INTERFACE (GDBusInterface, g_dbus_interface, G_TYPE_OBJECT)
44 g_dbus_interface_default_init (GDBusInterfaceIface *iface)
48 /* ---------------------------------------------------------------------------------------------------- */
51 * g_dbus_interface_get_info:
52 * @interface_: An exported D-Bus interface.
54 * Gets D-Bus introspection information for the D-Bus interface
55 * implemented by @interface_.
57 * Returns: (transfer none): A #GDBusInterfaceInfo. Do not free.
62 g_dbus_interface_get_info (GDBusInterface *interface_)
64 g_return_val_if_fail (G_IS_DBUS_INTERFACE (interface_), NULL);
65 return G_DBUS_INTERFACE_GET_IFACE (interface_)->get_info (interface_);
69 * g_dbus_interface_get_object: (skip)
70 * @interface_: An exported D-Bus interface
72 * Gets the #GDBusObject that @interface_ belongs to, if any.
74 * It is not safe to use the returned object if @interface_ or
75 * the returned object is being used from other threads. See
76 * g_dbus_interface_dup_object() for a thread-safe alternative.
78 * Returns: (nullable) (transfer none): A #GDBusObject or %NULL. The returned
79 * reference belongs to @interface_ and should not be freed.
84 g_dbus_interface_get_object (GDBusInterface *interface_)
86 g_return_val_if_fail (G_IS_DBUS_INTERFACE (interface_), NULL);
87 return G_DBUS_INTERFACE_GET_IFACE (interface_)->get_object (interface_);
91 * g_dbus_interface_dup_object: (rename-to g_dbus_interface_get_object)
92 * @interface_: An exported D-Bus interface.
94 * Gets the #GDBusObject that @interface_ belongs to, if any.
96 * Returns: (nullable) (transfer full): A #GDBusObject or %NULL. The returned
97 * reference should be freed with g_object_unref().
102 g_dbus_interface_dup_object (GDBusInterface *interface_)
105 g_return_val_if_fail (G_IS_DBUS_INTERFACE (interface_), NULL);
106 if (G_LIKELY (G_DBUS_INTERFACE_GET_IFACE (interface_)->dup_object != NULL))
108 ret = G_DBUS_INTERFACE_GET_IFACE (interface_)->dup_object (interface_);
112 g_warning ("No dup_object() vfunc on type %s - using get_object() in a way that is not thread-safe.",
113 g_type_name_from_instance ((GTypeInstance *) interface_));
114 ret = G_DBUS_INTERFACE_GET_IFACE (interface_)->get_object (interface_);
122 * g_dbus_interface_set_object:
123 * @interface_: An exported D-Bus interface.
124 * @object: (nullable): A #GDBusObject or %NULL.
126 * Sets the #GDBusObject for @interface_ to @object.
128 * Note that @interface_ will hold a weak reference to @object.
133 g_dbus_interface_set_object (GDBusInterface *interface_,
136 g_return_if_fail (G_IS_DBUS_INTERFACE (interface_));
137 g_return_if_fail (object == NULL || G_IS_DBUS_OBJECT (object));
138 G_DBUS_INTERFACE_GET_IFACE (interface_)->set_object (interface_, object);