GDBus: Use Skeleton instead of Stub
[platform/upstream/glib.git] / gio / gdbusobject.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 "gdbusinterface.h"
27 #include "gdbusutils.h"
28 #include "gio-marshal.h"
29
30 #include "glibintl.h"
31
32 /**
33  * SECTION:gdbusobject
34  * @short_description: Base type for D-Bus objects
35  * @include: gio/gio.h
36  *
37  * The #GDBusObject type is the base type for D-Bus objects on both
38  * the service side (see #GDBusObjectSkeleton) and the client side
39  * (see #GDBusObjectProxy). It is essentially just a container of
40  * interfaces.
41  */
42
43 typedef GDBusObjectIface GDBusObjectInterface;
44 G_DEFINE_INTERFACE (GDBusObject, g_dbus_object, G_TYPE_OBJECT)
45
46 static void
47 g_dbus_object_default_init (GDBusObjectIface *iface)
48 {
49   /**
50    * GDBusObject::interface-added:
51    * @object: The #GDBusObject emitting the signal.
52    * @interface: The #GDBusInterface that was added.
53    *
54    * Emitted when @interface is added to @object.
55    *
56    * Since: 2.30
57    */
58   g_signal_new ("interface-added",
59                 G_TYPE_FROM_INTERFACE (iface),
60                 G_SIGNAL_RUN_LAST,
61                 G_STRUCT_OFFSET (GDBusObjectIface, interface_added),
62                 NULL,
63                 NULL,
64                 g_cclosure_marshal_VOID__OBJECT,
65                 G_TYPE_NONE,
66                 1,
67                 G_TYPE_DBUS_INTERFACE);
68
69   /**
70    * GDBusObject::interface-removed:
71    * @object: The #GDBusObject emitting the signal.
72    * @interface: The #GDBusInterface that was removed.
73    *
74    * Emitted when @interface is removed from @object.
75    *
76    * Since: 2.30
77    */
78   g_signal_new ("interface-removed",
79                 G_TYPE_FROM_INTERFACE (iface),
80                 G_SIGNAL_RUN_LAST,
81                 G_STRUCT_OFFSET (GDBusObjectIface, interface_removed),
82                 NULL,
83                 NULL,
84                 g_cclosure_marshal_VOID__OBJECT,
85                 G_TYPE_NONE,
86                 1,
87                 G_TYPE_DBUS_INTERFACE);
88 }
89
90 /* ---------------------------------------------------------------------------------------------------- */
91
92 /**
93  * g_dbus_object_get_object_path:
94  * @object: A #GDBusObject.
95  *
96  * Gets the object path for @object.
97  *
98  * Returns: A string owned by @object. Do not free.
99  *
100  * Since: 2.30
101  */
102 const gchar *
103 g_dbus_object_get_object_path (GDBusObject *object)
104 {
105   GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object);
106   return iface->get_object_path (object);
107 }
108
109 /**
110  * g_dbus_object_get_interfaces:
111  * @object: A #GDBusObject.
112  *
113  * Gets the D-Bus interfaces associated with @object.
114  *
115  * Returns: (element-type GDBusInterface) (transfer full) : A list of #GDBusInterface instances.
116  *   The returned list must be freed by g_list_free() after each element has been freed
117  *   with g_object_unref().
118  *
119  * Since: 2.30
120  */
121 GList *
122 g_dbus_object_get_interfaces (GDBusObject *object)
123 {
124   GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object);
125   return iface->get_interfaces (object);
126 }
127
128 /**
129  * g_dbus_object_get_interface:
130  * @object: A #GDBusObject.
131  * @interface_name: A D-Bus interface name.
132  *
133  * Gets the D-Bus interface with name @interface_name associated with
134  * @object, if any.
135  *
136  * Returns: %NULL if not found, otherwise a #GDBusInterface that must
137  *   be freed with g_object_unref().
138  *
139  * Since: 2.30
140  */
141 GDBusInterface *
142 g_dbus_object_get_interface (GDBusObject *object,
143                              const gchar *interface_name)
144 {
145   GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object);
146   g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
147   return iface->get_interface (object, interface_name);
148 }
149
150
151 /**
152  * g_dbus_object_peek_with_typecheck:
153  * @object: A #GDBusObject.
154  * @interface_name: A D-Bus interface name.
155  * @type: The #GType that the returned object must conform to.
156  *
157  * Like g_dbus_object_lookup_with_typecheck() except that the caller
158  * does not own a reference to the returned object.
159  *
160  * <note><para>This function is intended to only be used in type
161  * implementations.</para></note>
162  *
163  * Returns: A #GDBusInterface implementing @type or %NULL if
164  * not found. Do not free the returned object, it is owned by
165  * @object.
166  *
167  * Since: 2.30
168  */
169 gpointer
170 g_dbus_object_peek_with_typecheck (GDBusObject *object,
171                                    const gchar *interface_name,
172                                    GType        type)
173 {
174   GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object);
175   g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
176   return iface->peek_with_typecheck (object, interface_name, type);
177 }
178
179 /**
180  * g_dbus_object_lookup_with_typecheck:
181  * @object: A #GDBusObject.
182  * @interface_name: A D-Bus interface name.
183  * @type: The #GType that the returned object must conform to.
184  *
185  * Like g_dbus_object_get_interface() but warns on stderr if the
186  * returned object, if any, does not conform to @type.
187  *
188  * <note><para>This function is intended to only be used in type
189  * implementations.</para></note>
190  *
191  * Returns: A #GDBusInterface implementing @type or %NULL if
192  * not found. Free with g_object_unref().
193  *
194  * Since: 2.30
195  */
196 gpointer
197 g_dbus_object_lookup_with_typecheck (GDBusObject *object,
198                                      const gchar *interface_name,
199                                      GType        type)
200 {
201   GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object);
202   g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
203   return iface->lookup_with_typecheck (object, interface_name, type);
204 }
205