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