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
52typedef GDBusObjectManagerIface GDBusObjectManagerInterface;
53G_DEFINE_INTERFACE (GDBusObjectManager, g_dbus_object_manager, G_TYPE_OBJECT)
54
55enum {
56 OBJECT_ADDED,
57 OBJECT_REMOVED,
58 INTERFACE_ADDED,
59 INTERFACE_REMOVED,
60 N_SIGNALS
61};
62
63static guint signals[N_SIGNALS];
64
65static void
66g_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 signal_flags: G_SIGNAL_RUN_LAST,
81 G_STRUCT_OFFSET (GDBusObjectManagerIface, object_added),
82 NULL,
83 NULL,
84 NULL,
85 G_TYPE_NONE,
86 n_params: 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 signal_flags: G_SIGNAL_RUN_LAST,
102 G_STRUCT_OFFSET (GDBusObjectManagerIface, object_removed),
103 NULL,
104 NULL,
105 NULL,
106 G_TYPE_NONE,
107 n_params: 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 signal_flags: G_SIGNAL_RUN_LAST,
127 G_STRUCT_OFFSET (GDBusObjectManagerIface, interface_added),
128 NULL,
129 NULL,
130 c_marshaller: _g_cclosure_marshal_VOID__OBJECT_OBJECT,
131 G_TYPE_NONE,
132 n_params: 2,
133 G_TYPE_DBUS_OBJECT,
134 G_TYPE_DBUS_INTERFACE);
135 g_signal_set_va_marshaller (signal_id: signals[INTERFACE_ADDED],
136 G_TYPE_FROM_INTERFACE (iface),
137 va_marshaller: _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 signal_flags: G_SIGNAL_RUN_LAST,
156 G_STRUCT_OFFSET (GDBusObjectManagerIface, interface_removed),
157 NULL,
158 NULL,
159 c_marshaller: _g_cclosure_marshal_VOID__OBJECT_OBJECT,
160 G_TYPE_NONE,
161 n_params: 2,
162 G_TYPE_DBUS_OBJECT,
163 G_TYPE_DBUS_INTERFACE);
164 g_signal_set_va_marshaller (signal_id: signals[INTERFACE_REMOVED],
165 G_TYPE_FROM_INTERFACE (iface),
166 va_marshaller: _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 */
182const gchar *
183g_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 */
202GList *
203g_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 */
221GDBusObject *
222g_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 */
244GDBusInterface *
245g_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

source code of gtk/subprojects/glib/gio/gdbusobjectmanager.c