1 /* GDBus - GLib D-Bus Library
3 * Copyright (C) 2008-2010 Red Hat, Inc.
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.
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.
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.
20 * Author: David Zeuthen <davidz@redhat.com>
25 #include "gdbusobject.h"
26 #include "gdbusinterface.h"
27 #include "gdbusutils.h"
28 #include "gio-marshal.h"
34 * @short_description: Base type for D-Bus objects
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
43 typedef GDBusObjectIface GDBusObjectInterface;
44 G_DEFINE_INTERFACE (GDBusObject, g_dbus_object, G_TYPE_OBJECT)
47 g_dbus_object_default_init (GDBusObjectIface *iface)
50 * GDBusObject::interface-added:
51 * @object: The #GDBusObject emitting the signal.
52 * @interface: The #GDBusInterface that was added.
54 * Emitted when @interface is added to @object.
58 g_signal_new ("interface-added",
59 G_TYPE_FROM_INTERFACE (iface),
61 G_STRUCT_OFFSET (GDBusObjectIface, interface_added),
64 g_cclosure_marshal_VOID__OBJECT,
67 G_TYPE_DBUS_INTERFACE);
70 * GDBusObject::interface-removed:
71 * @object: The #GDBusObject emitting the signal.
72 * @interface: The #GDBusInterface that was removed.
74 * Emitted when @interface is removed from @object.
78 g_signal_new ("interface-removed",
79 G_TYPE_FROM_INTERFACE (iface),
81 G_STRUCT_OFFSET (GDBusObjectIface, interface_removed),
84 g_cclosure_marshal_VOID__OBJECT,
87 G_TYPE_DBUS_INTERFACE);
90 /* ---------------------------------------------------------------------------------------------------- */
93 * g_dbus_object_get_object_path:
94 * @object: A #GDBusObject.
96 * Gets the object path for @object.
98 * Returns: A string owned by @object. Do not free.
103 g_dbus_object_get_object_path (GDBusObject *object)
105 GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object);
106 return iface->get_object_path (object);
110 * g_dbus_object_get_interfaces:
111 * @object: A #GDBusObject.
113 * Gets the D-Bus interfaces associated with @object.
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().
122 g_dbus_object_get_interfaces (GDBusObject *object)
124 GDBusObjectIface *iface = G_DBUS_OBJECT_GET_IFACE (object);
125 return iface->get_interfaces (object);
129 * g_dbus_object_get_interface:
130 * @object: A #GDBusObject.
131 * @interface_name: A D-Bus interface name.
133 * Gets the D-Bus interface with name @interface_name associated with
136 * Returns: %NULL if not found, otherwise a #GDBusInterface that must
137 * be freed with g_object_unref().
142 g_dbus_object_get_interface (GDBusObject *object,
143 const gchar *interface_name)
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);
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.
157 * Like g_dbus_object_lookup_with_typecheck() except that the caller
158 * does not own a reference to the returned object.
160 * <note><para>This function is intended to only be used in type
161 * implementations.</para></note>
163 * Returns: A #GDBusInterface implementing @type or %NULL if
164 * not found. Do not free the returned object, it is owned by
170 g_dbus_object_peek_with_typecheck (GDBusObject *object,
171 const gchar *interface_name,
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);
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.
185 * Like g_dbus_object_get_interface() but warns on stderr if the
186 * returned object, if any, does not conform to @type.
188 * <note><para>This function is intended to only be used in type
189 * implementations.</para></note>
191 * Returns: A #GDBusInterface implementing @type or %NULL if
192 * not found. Free with g_object_unref().
197 g_dbus_object_lookup_with_typecheck (GDBusObject *object,
198 const gchar *interface_name,
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);