/src/glib/gio/gdbusobjectmanager.c
Line | Count | Source |
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 "gdbusobjectmanager.h" |
25 | | #include "gdbusinterface.h" |
26 | | #include "gdbusutils.h" |
27 | | |
28 | | #include "glibintl.h" |
29 | | #include "gmarshal-internal.h" |
30 | | |
31 | | /** |
32 | | * SECTION:gdbusobjectmanager |
33 | | * @short_description: Base type for D-Bus object managers |
34 | | * @include: gio/gio.h |
35 | | * |
36 | | * The #GDBusObjectManager type is the base type for service- and |
37 | | * client-side implementations of the standardized |
38 | | * [org.freedesktop.DBus.ObjectManager](http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager) |
39 | | * interface. |
40 | | * |
41 | | * See #GDBusObjectManagerClient for the client-side implementation |
42 | | * and #GDBusObjectManagerServer for the service-side implementation. |
43 | | */ |
44 | | |
45 | | /** |
46 | | * GDBusObjectManager: |
47 | | * |
48 | | * #GDBusObjectManager is an opaque data structure and can only be accessed |
49 | | * using the following functions. |
50 | | */ |
51 | | |
52 | | typedef GDBusObjectManagerIface GDBusObjectManagerInterface; |
53 | 0 | G_DEFINE_INTERFACE (GDBusObjectManager, g_dbus_object_manager, G_TYPE_OBJECT) |
54 | 0 |
|
55 | 0 | enum { |
56 | 0 | OBJECT_ADDED, |
57 | 0 | OBJECT_REMOVED, |
58 | 0 | INTERFACE_ADDED, |
59 | 0 | INTERFACE_REMOVED, |
60 | 0 | N_SIGNALS |
61 | 0 | }; |
62 | 0 |
|
63 | 0 | static guint signals[N_SIGNALS]; |
64 | 0 |
|
65 | 0 | static void |
66 | 0 | g_dbus_object_manager_default_init (GDBusObjectManagerIface *iface) |
67 | 0 | { |
68 | | /** |
69 | | * GDBusObjectManager::object-added: |
70 | | * @manager: The #GDBusObjectManager emitting the signal. |
71 | | * @object: The #GDBusObject that was added. |
72 | | * |
73 | | * Emitted when @object is added to @manager. |
74 | | * |
75 | | * Since: 2.30 |
76 | | */ |
77 | 0 | signals[OBJECT_ADDED] = |
78 | 0 | g_signal_new (I_("object-added"), |
79 | 0 | G_TYPE_FROM_INTERFACE (iface), |
80 | 0 | G_SIGNAL_RUN_LAST, |
81 | 0 | G_STRUCT_OFFSET (GDBusObjectManagerIface, object_added), |
82 | 0 | NULL, |
83 | 0 | NULL, |
84 | 0 | NULL, |
85 | 0 | G_TYPE_NONE, |
86 | 0 | 1, |
87 | 0 | G_TYPE_DBUS_OBJECT); |
88 | | |
89 | | /** |
90 | | * GDBusObjectManager::object-removed: |
91 | | * @manager: The #GDBusObjectManager emitting the signal. |
92 | | * @object: The #GDBusObject that was removed. |
93 | | * |
94 | | * Emitted when @object is removed from @manager. |
95 | | * |
96 | | * Since: 2.30 |
97 | | */ |
98 | 0 | signals[OBJECT_REMOVED] = |
99 | 0 | g_signal_new (I_("object-removed"), |
100 | 0 | G_TYPE_FROM_INTERFACE (iface), |
101 | 0 | G_SIGNAL_RUN_LAST, |
102 | 0 | G_STRUCT_OFFSET (GDBusObjectManagerIface, object_removed), |
103 | 0 | NULL, |
104 | 0 | NULL, |
105 | 0 | NULL, |
106 | 0 | G_TYPE_NONE, |
107 | 0 | 1, |
108 | 0 | G_TYPE_DBUS_OBJECT); |
109 | | |
110 | | /** |
111 | | * GDBusObjectManager::interface-added: |
112 | | * @manager: The #GDBusObjectManager emitting the signal. |
113 | | * @object: The #GDBusObject on which an interface was added. |
114 | | * @interface: The #GDBusInterface that was added. |
115 | | * |
116 | | * Emitted when @interface is added to @object. |
117 | | * |
118 | | * This signal exists purely as a convenience to avoid having to |
119 | | * connect signals to all objects managed by @manager. |
120 | | * |
121 | | * Since: 2.30 |
122 | | */ |
123 | 0 | signals[INTERFACE_ADDED] = |
124 | 0 | g_signal_new (I_("interface-added"), |
125 | 0 | G_TYPE_FROM_INTERFACE (iface), |
126 | 0 | G_SIGNAL_RUN_LAST, |
127 | 0 | G_STRUCT_OFFSET (GDBusObjectManagerIface, interface_added), |
128 | 0 | NULL, |
129 | 0 | NULL, |
130 | 0 | _g_cclosure_marshal_VOID__OBJECT_OBJECT, |
131 | 0 | G_TYPE_NONE, |
132 | 0 | 2, |
133 | 0 | G_TYPE_DBUS_OBJECT, |
134 | 0 | G_TYPE_DBUS_INTERFACE); |
135 | 0 | g_signal_set_va_marshaller (signals[INTERFACE_ADDED], |
136 | 0 | G_TYPE_FROM_INTERFACE (iface), |
137 | 0 | _g_cclosure_marshal_VOID__OBJECT_OBJECTv); |
138 | | |
139 | | /** |
140 | | * GDBusObjectManager::interface-removed: |
141 | | * @manager: The #GDBusObjectManager emitting the signal. |
142 | | * @object: The #GDBusObject on which an interface was removed. |
143 | | * @interface: The #GDBusInterface that was removed. |
144 | | * |
145 | | * Emitted when @interface has been removed from @object. |
146 | | * |
147 | | * This signal exists purely as a convenience to avoid having to |
148 | | * connect signals to all objects managed by @manager. |
149 | | * |
150 | | * Since: 2.30 |
151 | | */ |
152 | 0 | signals[INTERFACE_REMOVED] = |
153 | 0 | g_signal_new (I_("interface-removed"), |
154 | 0 | G_TYPE_FROM_INTERFACE (iface), |
155 | 0 | G_SIGNAL_RUN_LAST, |
156 | 0 | G_STRUCT_OFFSET (GDBusObjectManagerIface, interface_removed), |
157 | 0 | NULL, |
158 | 0 | NULL, |
159 | 0 | _g_cclosure_marshal_VOID__OBJECT_OBJECT, |
160 | 0 | G_TYPE_NONE, |
161 | 0 | 2, |
162 | 0 | G_TYPE_DBUS_OBJECT, |
163 | 0 | G_TYPE_DBUS_INTERFACE); |
164 | 0 | g_signal_set_va_marshaller (signals[INTERFACE_REMOVED], |
165 | 0 | G_TYPE_FROM_INTERFACE (iface), |
166 | 0 | _g_cclosure_marshal_VOID__OBJECT_OBJECTv); |
167 | |
|
168 | 0 | } |
169 | | |
170 | | /* ---------------------------------------------------------------------------------------------------- */ |
171 | | |
172 | | /** |
173 | | * g_dbus_object_manager_get_object_path: |
174 | | * @manager: A #GDBusObjectManager. |
175 | | * |
176 | | * Gets the object path that @manager is for. |
177 | | * |
178 | | * Returns: A string owned by @manager. Do not free. |
179 | | * |
180 | | * Since: 2.30 |
181 | | */ |
182 | | const gchar * |
183 | | g_dbus_object_manager_get_object_path (GDBusObjectManager *manager) |
184 | 0 | { |
185 | 0 | GDBusObjectManagerIface *iface = G_DBUS_OBJECT_MANAGER_GET_IFACE (manager); |
186 | 0 | return iface->get_object_path (manager); |
187 | 0 | } |
188 | | |
189 | | /** |
190 | | * g_dbus_object_manager_get_objects: |
191 | | * @manager: A #GDBusObjectManager. |
192 | | * |
193 | | * Gets all #GDBusObject objects known to @manager. |
194 | | * |
195 | | * Returns: (transfer full) (element-type GDBusObject): A list of |
196 | | * #GDBusObject objects. The returned list should be freed with |
197 | | * g_list_free() after each element has been freed with |
198 | | * g_object_unref(). |
199 | | * |
200 | | * Since: 2.30 |
201 | | */ |
202 | | GList * |
203 | | g_dbus_object_manager_get_objects (GDBusObjectManager *manager) |
204 | 0 | { |
205 | 0 | GDBusObjectManagerIface *iface = G_DBUS_OBJECT_MANAGER_GET_IFACE (manager); |
206 | 0 | return iface->get_objects (manager); |
207 | 0 | } |
208 | | |
209 | | /** |
210 | | * g_dbus_object_manager_get_object: |
211 | | * @manager: A #GDBusObjectManager. |
212 | | * @object_path: Object path to look up. |
213 | | * |
214 | | * Gets the #GDBusObjectProxy at @object_path, if any. |
215 | | * |
216 | | * Returns: (transfer full): A #GDBusObject or %NULL. Free with |
217 | | * g_object_unref(). |
218 | | * |
219 | | * Since: 2.30 |
220 | | */ |
221 | | GDBusObject * |
222 | | g_dbus_object_manager_get_object (GDBusObjectManager *manager, |
223 | | const gchar *object_path) |
224 | 0 | { |
225 | 0 | GDBusObjectManagerIface *iface = G_DBUS_OBJECT_MANAGER_GET_IFACE (manager); |
226 | 0 | g_return_val_if_fail (g_variant_is_object_path (object_path), NULL); |
227 | 0 | return iface->get_object (manager, object_path); |
228 | 0 | } |
229 | | |
230 | | /** |
231 | | * g_dbus_object_manager_get_interface: |
232 | | * @manager: A #GDBusObjectManager. |
233 | | * @object_path: Object path to look up. |
234 | | * @interface_name: D-Bus interface name to look up. |
235 | | * |
236 | | * Gets the interface proxy for @interface_name at @object_path, if |
237 | | * any. |
238 | | * |
239 | | * Returns: (transfer full): A #GDBusInterface instance or %NULL. Free |
240 | | * with g_object_unref(). |
241 | | * |
242 | | * Since: 2.30 |
243 | | */ |
244 | | GDBusInterface * |
245 | | g_dbus_object_manager_get_interface (GDBusObjectManager *manager, |
246 | | const gchar *object_path, |
247 | | const gchar *interface_name) |
248 | 0 | { |
249 | 0 | GDBusObjectManagerIface *iface = G_DBUS_OBJECT_MANAGER_GET_IFACE (manager); |
250 | 0 | g_return_val_if_fail (g_variant_is_object_path (object_path), NULL); |
251 | 0 | g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL); |
252 | 0 | return iface->get_interface (manager, object_path, interface_name); |
253 | 0 | } |