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 G_DEFINE_INTERFACE (GDBusObjectManager, g_dbus_object_manager, G_TYPE_OBJECT)
54
55 enum {
56 OBJECT_ADDED,
57 OBJECT_REMOVED,
58 INTERFACE_ADDED,
59 INTERFACE_REMOVED,
60 N_SIGNALS
61 };
62
63 static guint signals[N_SIGNALS];
64
65 static void
g_dbus_object_manager_default_init(GDBusObjectManagerIface * iface)66 g_dbus_object_manager_default_init (GDBusObjectManagerIface *iface)
67 {
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 signals[OBJECT_ADDED] =
78 g_signal_new (I_("object-added"),
79 G_TYPE_FROM_INTERFACE (iface),
80 G_SIGNAL_RUN_LAST,
81 G_STRUCT_OFFSET (GDBusObjectManagerIface, object_added),
82 NULL,
83 NULL,
84 NULL,
85 G_TYPE_NONE,
86 1,
87 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 signals[OBJECT_REMOVED] =
99 g_signal_new (I_("object-removed"),
100 G_TYPE_FROM_INTERFACE (iface),
101 G_SIGNAL_RUN_LAST,
102 G_STRUCT_OFFSET (GDBusObjectManagerIface, object_removed),
103 NULL,
104 NULL,
105 NULL,
106 G_TYPE_NONE,
107 1,
108 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 signals[INTERFACE_ADDED] =
124 g_signal_new (I_("interface-added"),
125 G_TYPE_FROM_INTERFACE (iface),
126 G_SIGNAL_RUN_LAST,
127 G_STRUCT_OFFSET (GDBusObjectManagerIface, interface_added),
128 NULL,
129 NULL,
130 _g_cclosure_marshal_VOID__OBJECT_OBJECT,
131 G_TYPE_NONE,
132 2,
133 G_TYPE_DBUS_OBJECT,
134 G_TYPE_DBUS_INTERFACE);
135 g_signal_set_va_marshaller (signals[INTERFACE_ADDED],
136 G_TYPE_FROM_INTERFACE (iface),
137 _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 signals[INTERFACE_REMOVED] =
153 g_signal_new (I_("interface-removed"),
154 G_TYPE_FROM_INTERFACE (iface),
155 G_SIGNAL_RUN_LAST,
156 G_STRUCT_OFFSET (GDBusObjectManagerIface, interface_removed),
157 NULL,
158 NULL,
159 _g_cclosure_marshal_VOID__OBJECT_OBJECT,
160 G_TYPE_NONE,
161 2,
162 G_TYPE_DBUS_OBJECT,
163 G_TYPE_DBUS_INTERFACE);
164 g_signal_set_va_marshaller (signals[INTERFACE_REMOVED],
165 G_TYPE_FROM_INTERFACE (iface),
166 _g_cclosure_marshal_VOID__OBJECT_OBJECTv);
167
168 }
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 *
g_dbus_object_manager_get_object_path(GDBusObjectManager * manager)183 g_dbus_object_manager_get_object_path (GDBusObjectManager *manager)
184 {
185 GDBusObjectManagerIface *iface = G_DBUS_OBJECT_MANAGER_GET_IFACE (manager);
186 return iface->get_object_path (manager);
187 }
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 *
g_dbus_object_manager_get_objects(GDBusObjectManager * manager)203 g_dbus_object_manager_get_objects (GDBusObjectManager *manager)
204 {
205 GDBusObjectManagerIface *iface = G_DBUS_OBJECT_MANAGER_GET_IFACE (manager);
206 return iface->get_objects (manager);
207 }
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 *
g_dbus_object_manager_get_object(GDBusObjectManager * manager,const gchar * object_path)222 g_dbus_object_manager_get_object (GDBusObjectManager *manager,
223 const gchar *object_path)
224 {
225 GDBusObjectManagerIface *iface = G_DBUS_OBJECT_MANAGER_GET_IFACE (manager);
226 g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
227 return iface->get_object (manager, object_path);
228 }
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 *
g_dbus_object_manager_get_interface(GDBusObjectManager * manager,const gchar * object_path,const gchar * interface_name)245 g_dbus_object_manager_get_interface (GDBusObjectManager *manager,
246 const gchar *object_path,
247 const gchar *interface_name)
248 {
249 GDBusObjectManagerIface *iface = G_DBUS_OBJECT_MANAGER_GET_IFACE (manager);
250 g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);
251 g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
252 return iface->get_interface (manager, object_path, interface_name);
253 }
254