Branch data Line data Source code
1 : : /* GDBus - GLib D-Bus Library
2 : : *
3 : : * Copyright (C) 2008-2010 Red Hat, Inc.
4 : : *
5 : : * SPDX-License-Identifier: LGPL-2.1-or-later
6 : : *
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.
11 : : *
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.
16 : : *
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/>.
19 : : *
20 : : * Author: David Zeuthen <davidz@redhat.com>
21 : : */
22 : :
23 : : #include "config.h"
24 : :
25 : : #include "gdbusobject.h"
26 : : #include "gdbusinterface.h"
27 : :
28 : : #include "glibintl.h"
29 : :
30 : : /**
31 : : * GDBusInterface:
32 : : *
33 : : * Base type for D-Bus interfaces.
34 : : *
35 : : * The `GDBusInterface` type is the base type for D-Bus interfaces both
36 : : * on the service side (see [class@Gio.DBusInterfaceSkeleton]) and client side
37 : : * (see [class@Gio.DBusProxy]).
38 : : *
39 : : * Since: 2.30
40 : : */
41 : :
42 : : typedef GDBusInterfaceIface GDBusInterfaceInterface;
43 : 569 : G_DEFINE_INTERFACE (GDBusInterface, g_dbus_interface, G_TYPE_OBJECT)
44 : :
45 : : static void
46 : 132 : g_dbus_interface_default_init (GDBusInterfaceIface *iface)
47 : : {
48 : 132 : }
49 : :
50 : : /* ---------------------------------------------------------------------------------------------------- */
51 : :
52 : : /**
53 : : * g_dbus_interface_get_info:
54 : : * @interface_: An exported D-Bus interface.
55 : : *
56 : : * Gets D-Bus introspection information for the D-Bus interface
57 : : * implemented by @interface_.
58 : : *
59 : : * This can return %NULL if no #GDBusInterfaceInfo was provided during
60 : : * construction of @interface_ and is also not made available otherwise.
61 : : * For example, #GDBusProxy implements #GDBusInterface but allows for a %NULL
62 : : * #GDBusInterfaceInfo.
63 : : *
64 : : * Returns: (transfer none) (nullable): A #GDBusInterfaceInfo. Do not free.
65 : : *
66 : : * Since: 2.30
67 : : */
68 : : GDBusInterfaceInfo *
69 : 69 : g_dbus_interface_get_info (GDBusInterface *interface_)
70 : : {
71 : 69 : g_return_val_if_fail (G_IS_DBUS_INTERFACE (interface_), NULL);
72 : 69 : return G_DBUS_INTERFACE_GET_IFACE (interface_)->get_info (interface_);
73 : : }
74 : :
75 : : /**
76 : : * g_dbus_interface_get_object: (skip)
77 : : * @interface_: An exported D-Bus interface
78 : : *
79 : : * Gets the #GDBusObject that @interface_ belongs to, if any.
80 : : *
81 : : * It is not safe to use the returned object if @interface_ or
82 : : * the returned object is being used from other threads. See
83 : : * g_dbus_interface_dup_object() for a thread-safe alternative.
84 : : *
85 : : * Returns: (nullable) (transfer none): A #GDBusObject or %NULL. The returned
86 : : * reference belongs to @interface_ and should not be freed.
87 : : *
88 : : * Since: 2.30
89 : : */
90 : : GDBusObject *
91 : 12 : g_dbus_interface_get_object (GDBusInterface *interface_)
92 : : {
93 : 12 : g_return_val_if_fail (G_IS_DBUS_INTERFACE (interface_), NULL);
94 : 12 : return G_DBUS_INTERFACE_GET_IFACE (interface_)->get_object (interface_);
95 : : }
96 : :
97 : : /**
98 : : * g_dbus_interface_dup_object: (rename-to g_dbus_interface_get_object)
99 : : * @interface_: An exported D-Bus interface.
100 : : *
101 : : * Gets the #GDBusObject that @interface_ belongs to, if any.
102 : : *
103 : : * Returns: (nullable) (transfer full): A #GDBusObject or %NULL. The returned
104 : : * reference should be freed with g_object_unref().
105 : : *
106 : : * Since: 2.32
107 : : */
108 : : GDBusObject *
109 : 3 : g_dbus_interface_dup_object (GDBusInterface *interface_)
110 : : {
111 : : GDBusObject *ret;
112 : 3 : g_return_val_if_fail (G_IS_DBUS_INTERFACE (interface_), NULL);
113 : 3 : if (G_LIKELY (G_DBUS_INTERFACE_GET_IFACE (interface_)->dup_object != NULL))
114 : : {
115 : 3 : ret = G_DBUS_INTERFACE_GET_IFACE (interface_)->dup_object (interface_);
116 : : }
117 : : else
118 : : {
119 : 0 : g_warning ("No dup_object() vfunc on type %s - using get_object() in a way that is not thread-safe.",
120 : : g_type_name_from_instance ((GTypeInstance *) interface_));
121 : 0 : ret = G_DBUS_INTERFACE_GET_IFACE (interface_)->get_object (interface_);
122 : 0 : if (ret != NULL)
123 : 0 : g_object_ref (ret);
124 : : }
125 : 3 : return ret;
126 : : }
127 : :
128 : : /**
129 : : * g_dbus_interface_set_object:
130 : : * @interface_: An exported D-Bus interface.
131 : : * @object: (nullable): A #GDBusObject or %NULL.
132 : : *
133 : : * Sets the #GDBusObject for @interface_ to @object.
134 : : *
135 : : * Note that @interface_ will hold a weak reference to @object.
136 : : *
137 : : * Since: 2.30
138 : : */
139 : : void
140 : 77 : g_dbus_interface_set_object (GDBusInterface *interface_,
141 : : GDBusObject *object)
142 : : {
143 : 77 : g_return_if_fail (G_IS_DBUS_INTERFACE (interface_));
144 : 77 : g_return_if_fail (object == NULL || G_IS_DBUS_OBJECT (object));
145 : 77 : G_DBUS_INTERFACE_GET_IFACE (interface_)->set_object (interface_, object);
146 : : }
|