1 | /* GDBus - GLib D-Bus Library |
2 | * |
3 | * Copyright (C) 2008-2010 Red Hat, Inc. |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Lesser General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2.1 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Lesser General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Lesser General |
16 | * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
17 | * |
18 | * Author: David Zeuthen <davidz@redhat.com> |
19 | */ |
20 | |
21 | #include "config.h" |
22 | |
23 | #include "gdbusobject.h" |
24 | #include "gdbusinterface.h" |
25 | |
26 | #include "glibintl.h" |
27 | |
28 | /** |
29 | * SECTION:gdbusinterface |
30 | * @short_description: Base type for D-Bus interfaces |
31 | * @include: gio/gio.h |
32 | * |
33 | * The #GDBusInterface type is the base type for D-Bus interfaces both |
34 | * on the service side (see #GDBusInterfaceSkeleton) and client side |
35 | * (see #GDBusProxy). |
36 | */ |
37 | |
38 | typedef GDBusInterfaceIface GDBusInterfaceInterface; |
39 | G_DEFINE_INTERFACE (GDBusInterface, g_dbus_interface, G_TYPE_OBJECT) |
40 | |
41 | static void |
42 | g_dbus_interface_default_init (GDBusInterfaceIface *iface) |
43 | { |
44 | } |
45 | |
46 | /* ---------------------------------------------------------------------------------------------------- */ |
47 | |
48 | /** |
49 | * g_dbus_interface_get_info: |
50 | * @interface_: An exported D-Bus interface. |
51 | * |
52 | * Gets D-Bus introspection information for the D-Bus interface |
53 | * implemented by @interface_. |
54 | * |
55 | * Returns: (transfer none): A #GDBusInterfaceInfo. Do not free. |
56 | * |
57 | * Since: 2.30 |
58 | */ |
59 | GDBusInterfaceInfo * |
60 | g_dbus_interface_get_info (GDBusInterface *interface_) |
61 | { |
62 | g_return_val_if_fail (G_IS_DBUS_INTERFACE (interface_), NULL); |
63 | return G_DBUS_INTERFACE_GET_IFACE (interface_)->get_info (interface_); |
64 | } |
65 | |
66 | /** |
67 | * g_dbus_interface_get_object: (skip) |
68 | * @interface_: An exported D-Bus interface |
69 | * |
70 | * Gets the #GDBusObject that @interface_ belongs to, if any. |
71 | * |
72 | * It is not safe to use the returned object if @interface_ or |
73 | * the returned object is being used from other threads. See |
74 | * g_dbus_interface_dup_object() for a thread-safe alternative. |
75 | * |
76 | * Returns: (nullable) (transfer none): A #GDBusObject or %NULL. The returned |
77 | * reference belongs to @interface_ and should not be freed. |
78 | * |
79 | * Since: 2.30 |
80 | */ |
81 | GDBusObject * |
82 | g_dbus_interface_get_object (GDBusInterface *interface_) |
83 | { |
84 | g_return_val_if_fail (G_IS_DBUS_INTERFACE (interface_), NULL); |
85 | return G_DBUS_INTERFACE_GET_IFACE (interface_)->get_object (interface_); |
86 | } |
87 | |
88 | /** |
89 | * g_dbus_interface_dup_object: (rename-to g_dbus_interface_get_object) |
90 | * @interface_: An exported D-Bus interface. |
91 | * |
92 | * Gets the #GDBusObject that @interface_ belongs to, if any. |
93 | * |
94 | * Returns: (nullable) (transfer full): A #GDBusObject or %NULL. The returned |
95 | * reference should be freed with g_object_unref(). |
96 | * |
97 | * Since: 2.32 |
98 | */ |
99 | GDBusObject * |
100 | g_dbus_interface_dup_object (GDBusInterface *interface_) |
101 | { |
102 | GDBusObject *ret; |
103 | g_return_val_if_fail (G_IS_DBUS_INTERFACE (interface_), NULL); |
104 | if (G_LIKELY (G_DBUS_INTERFACE_GET_IFACE (interface_)->dup_object != NULL)) |
105 | { |
106 | ret = G_DBUS_INTERFACE_GET_IFACE (interface_)->dup_object (interface_); |
107 | } |
108 | else |
109 | { |
110 | g_warning ("No dup_object() vfunc on type %s - using get_object() in a way that is not thread-safe." , |
111 | g_type_name_from_instance ((GTypeInstance *) interface_)); |
112 | ret = G_DBUS_INTERFACE_GET_IFACE (interface_)->get_object (interface_); |
113 | if (ret != NULL) |
114 | g_object_ref (ret); |
115 | } |
116 | return ret; |
117 | } |
118 | |
119 | /** |
120 | * g_dbus_interface_set_object: |
121 | * @interface_: An exported D-Bus interface. |
122 | * @object: (nullable): A #GDBusObject or %NULL. |
123 | * |
124 | * Sets the #GDBusObject for @interface_ to @object. |
125 | * |
126 | * Note that @interface_ will hold a weak reference to @object. |
127 | * |
128 | * Since: 2.30 |
129 | */ |
130 | void |
131 | g_dbus_interface_set_object (GDBusInterface *interface_, |
132 | GDBusObject *object) |
133 | { |
134 | g_return_if_fail (G_IS_DBUS_INTERFACE (interface_)); |
135 | g_return_if_fail (object == NULL || G_IS_DBUS_OBJECT (object)); |
136 | G_DBUS_INTERFACE_GET_IFACE (interface_)->set_object (interface_, object); |
137 | } |
138 | |