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