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