Merge remote-tracking branch 'gvdb/master'
[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
29 #include "glibintl.h"
30
31 /**
32  * SECTION:gdbusobject
33  * @short_description: Base type for D-Bus objects
34  * @include: gio/gio.h
35  *
36  * The #GDBusObject type is the base type for D-Bus objects on both
37  * the service side (see #GDBusObjectSkeleton) and the client side
38  * (see #GDBusObjectProxy). It is essentially just a container of
39  * interfaces.
40  */
41
42 typedef GDBusObjectIface GDBusObjectInterface;
43 G_DEFINE_INTERFACE (GDBusObject, g_dbus_object, G_TYPE_OBJECT)
44
45 static void
46 g_dbus_object_default_init (GDBusObjectIface *iface)
47 {
48   /**
49    * GDBusObject::interface-added:
50    * @object: The #GDBusObject emitting the signal.
51    * @interface: The #GDBusInterface that was added.
52    *
53    * Emitted when @interface is added to @object.
54    *
55    * Since: 2.30
56    */
57   g_signal_new ("interface-added",
58                 G_TYPE_FROM_INTERFACE (iface),
59                 G_SIGNAL_RUN_LAST,
60                 G_STRUCT_OFFSET (GDBusObjectIface, interface_added),
61                 NULL,
62                 NULL,
63                 g_cclosure_marshal_VOID__OBJECT,
64                 G_TYPE_NONE,
65                 1,
66                 G_TYPE_DBUS_INTERFACE);
67
68   /**
69    * GDBusObject::interface-removed:
70    * @object: The #GDBusObject emitting the signal.
71    * @interface: The #GDBusInterface that was removed.
72    *
73    * Emitted when @interface is removed from @object.
74    *
75    * Since: 2.30
76    */
77   g_signal_new ("interface-removed",
78                 G_TYPE_FROM_INTERFACE (iface),
79                 G_SIGNAL_RUN_LAST,
80                 G_STRUCT_OFFSET (GDBusObjectIface, interface_removed),
81                 NULL,
82                 NULL,
83                 g_cclosure_marshal_VOID__OBJECT,
84                 G_TYPE_NONE,
85                 1,
86                 G_TYPE_DBUS_INTERFACE);
87 }
88
89 /* ---------------------------------------------------------------------------------------------------- */
90
91 /**
92  * g_dbus_object_get_object_path:
93  * @object: A #GDBusObject.
94  *
95  * Gets the object path for @object.
96  *
97  * Returns: A string owned by @object. Do not free.
98  *
99  * Since: 2.30
100  */
101 const gchar *
102 g_dbus_object_get_object_path (GDBusObject *object)
103 {
104   GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object);
105   return iface->get_object_path (object);
106 }
107
108 /**
109  * g_dbus_object_get_interfaces:
110  * @object: A #GDBusObject.
111  *
112  * Gets the D-Bus interfaces associated with @object.
113  *
114  * Returns: (element-type GDBusInterface) (transfer full) : A list of #GDBusInterface instances.
115  *   The returned list must be freed by g_list_free() after each element has been freed
116  *   with g_object_unref().
117  *
118  * Since: 2.30
119  */
120 GList *
121 g_dbus_object_get_interfaces (GDBusObject *object)
122 {
123   GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object);
124   return iface->get_interfaces (object);
125 }
126
127 /**
128  * g_dbus_object_get_interface:
129  * @object: A #GDBusObject.
130  * @interface_name: A D-Bus interface name.
131  *
132  * Gets the D-Bus interface with name @interface_name associated with
133  * @object, if any.
134  *
135  * Returns: (transfer full): %NULL if not found, otherwise a
136  *   #GDBusInterface that must be freed with g_object_unref().
137  *
138  * Since: 2.30
139  */
140 GDBusInterface *
141 g_dbus_object_get_interface (GDBusObject *object,
142                              const gchar *interface_name)
143 {
144   GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object);
145   g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL);
146   return iface->get_interface (object, interface_name);
147 }