/src/glib/gio/gdbusobject.c
Line | Count | Source (jump to first uncovered line) |
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 | | #include "gdbusutils.h" |
28 | | |
29 | | #include "glibintl.h" |
30 | | |
31 | | /** |
32 | | * SECTION:gdbusobject |
33 | | * @short_description: Base type for D-Bus objects |
34 | | * @include: gio/gio.h |
35 | | * |
36 | | * The #GDBusObject type is the base type for D-Bus objects on both |
37 | | * the service side (see #GDBusObjectSkeleton) and the client side |
38 | | * (see #GDBusObjectProxy). It is essentially just a container of |
39 | | * interfaces. |
40 | | */ |
41 | | |
42 | | /** |
43 | | * GDBusObject: |
44 | | * |
45 | | * #GDBusObject is an opaque data structure and can only be accessed |
46 | | * using the following functions. |
47 | | */ |
48 | | |
49 | | typedef GDBusObjectIface GDBusObjectInterface; |
50 | | G_DEFINE_INTERFACE (GDBusObject, g_dbus_object, G_TYPE_OBJECT) |
51 | | |
52 | | static void |
53 | | g_dbus_object_default_init (GDBusObjectIface *iface) |
54 | 0 | { |
55 | | /** |
56 | | * GDBusObject::interface-added: |
57 | | * @object: The #GDBusObject emitting the signal. |
58 | | * @interface: The #GDBusInterface that was added. |
59 | | * |
60 | | * Emitted when @interface is added to @object. |
61 | | * |
62 | | * Since: 2.30 |
63 | | */ |
64 | 0 | g_signal_new (I_("interface-added"), |
65 | 0 | G_TYPE_FROM_INTERFACE (iface), |
66 | 0 | G_SIGNAL_RUN_LAST, |
67 | 0 | G_STRUCT_OFFSET (GDBusObjectIface, interface_added), |
68 | 0 | NULL, |
69 | 0 | NULL, |
70 | 0 | NULL, |
71 | 0 | G_TYPE_NONE, |
72 | 0 | 1, |
73 | 0 | G_TYPE_DBUS_INTERFACE); |
74 | | |
75 | | /** |
76 | | * GDBusObject::interface-removed: |
77 | | * @object: The #GDBusObject emitting the signal. |
78 | | * @interface: The #GDBusInterface that was removed. |
79 | | * |
80 | | * Emitted when @interface is removed from @object. |
81 | | * |
82 | | * Since: 2.30 |
83 | | */ |
84 | 0 | g_signal_new (I_("interface-removed"), |
85 | 0 | G_TYPE_FROM_INTERFACE (iface), |
86 | 0 | G_SIGNAL_RUN_LAST, |
87 | 0 | G_STRUCT_OFFSET (GDBusObjectIface, interface_removed), |
88 | 0 | NULL, |
89 | 0 | NULL, |
90 | 0 | NULL, |
91 | 0 | G_TYPE_NONE, |
92 | 0 | 1, |
93 | 0 | G_TYPE_DBUS_INTERFACE); |
94 | 0 | } |
95 | | |
96 | | /* ---------------------------------------------------------------------------------------------------- */ |
97 | | |
98 | | /** |
99 | | * g_dbus_object_get_object_path: |
100 | | * @object: A #GDBusObject. |
101 | | * |
102 | | * Gets the object path for @object. |
103 | | * |
104 | | * Returns: A string owned by @object. Do not free. |
105 | | * |
106 | | * Since: 2.30 |
107 | | */ |
108 | | const gchar * |
109 | | g_dbus_object_get_object_path (GDBusObject *object) |
110 | 0 | { |
111 | 0 | GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object); |
112 | 0 | return iface->get_object_path (object); |
113 | 0 | } |
114 | | |
115 | | /** |
116 | | * g_dbus_object_get_interfaces: |
117 | | * @object: A #GDBusObject. |
118 | | * |
119 | | * Gets the D-Bus interfaces associated with @object. |
120 | | * |
121 | | * Returns: (element-type GDBusInterface) (transfer full): A list of #GDBusInterface instances. |
122 | | * The returned list must be freed by g_list_free() after each element has been freed |
123 | | * with g_object_unref(). |
124 | | * |
125 | | * Since: 2.30 |
126 | | */ |
127 | | GList * |
128 | | g_dbus_object_get_interfaces (GDBusObject *object) |
129 | 0 | { |
130 | 0 | GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object); |
131 | 0 | return iface->get_interfaces (object); |
132 | 0 | } |
133 | | |
134 | | /** |
135 | | * g_dbus_object_get_interface: |
136 | | * @object: A #GDBusObject. |
137 | | * @interface_name: A D-Bus interface name. |
138 | | * |
139 | | * Gets the D-Bus interface with name @interface_name associated with |
140 | | * @object, if any. |
141 | | * |
142 | | * Returns: (nullable) (transfer full): %NULL if not found, otherwise a |
143 | | * #GDBusInterface that must be freed with g_object_unref(). |
144 | | * |
145 | | * Since: 2.30 |
146 | | */ |
147 | | GDBusInterface * |
148 | | g_dbus_object_get_interface (GDBusObject *object, |
149 | | const gchar *interface_name) |
150 | 0 | { |
151 | 0 | GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object); |
152 | 0 | g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL); |
153 | 0 | return iface->get_interface (object, interface_name); |
154 | 0 | } |