]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/dbus-common.h
relicense to LGPLv2.1 (with exceptions)
[thirdparty/systemd.git] / src / dbus-common.h
CommitLineData
03467c88 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
9a1ac7b9
LP
2
3#ifndef foodbuscommonhfoo
4#define foodbuscommonhfoo
5
6/***
7 This file is part of systemd.
8
9 Copyright 2010 Lennart Poettering
10
11 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
12 under the terms of the GNU Lesser General Public License as published by
13 the Free Software Foundation; either version 2.1 of the License, or
9a1ac7b9
LP
14 (at your option) any later version.
15
16 systemd is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 19 Lesser General Public License for more details.
9a1ac7b9 20
5430f7f2 21 You should have received a copy of the GNU Lesser General Public License
9a1ac7b9
LP
22 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23***/
24
25#include <dbus/dbus.h>
26
bfebab7f
LP
27#ifndef DBUS_ERROR_UNKNOWN_OBJECT
28#define DBUS_ERROR_UNKNOWN_OBJECT "org.freedesktop.DBus.Error.UnknownObject"
29#endif
30
31#ifndef DBUS_ERROR_UNKNOWN_INTERFACE
32#define DBUS_ERROR_UNKNOWN_INTERFACE "org.freedesktop.DBus.Error.UnknownInterface"
33#endif
34
35#ifndef DBUS_ERROR_UNKNOWN_PROPERTY
36#define DBUS_ERROR_UNKNOWN_PROPERTY "org.freedesktop.DBus.Error.UnknownProperty"
37#endif
38
39#ifndef DBUS_ERROR_PROPERTY_READ_ONLY
40#define DBUS_ERROR_PROPERTY_READ_ONLY "org.freedesktop.DBus.Error.PropertyReadOnly"
41#endif
42
43#define BUS_PROPERTIES_INTERFACE \
44 " <interface name=\"org.freedesktop.DBus.Properties\">\n" \
45 " <method name=\"Get\">\n" \
46 " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
47 " <arg name=\"property\" direction=\"in\" type=\"s\"/>\n" \
48 " <arg name=\"value\" direction=\"out\" type=\"v\"/>\n" \
49 " </method>\n" \
50 " <method name=\"GetAll\">\n" \
51 " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
52 " <arg name=\"properties\" direction=\"out\" type=\"a{sv}\"/>\n" \
53 " </method>\n" \
54 " <method name=\"Set\">\n" \
55 " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
56 " <arg name=\"property\" direction=\"in\" type=\"s\"/>\n" \
57 " <arg name=\"value\" direction=\"in\" type=\"v\"/>\n" \
58 " </method>\n" \
59 " <signal name=\"PropertiesChanged\">\n" \
60 " <arg type=\"s\" name=\"interface\"/>\n" \
61 " <arg type=\"a{sv}\" name=\"changed_properties\"/>\n" \
62 " <arg type=\"as\" name=\"invalidated_properties\"/>\n" \
63 " </signal>\n" \
64 " </interface>\n"
65
66#define BUS_INTROSPECTABLE_INTERFACE \
67 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n" \
68 " <method name=\"Introspect\">\n" \
69 " <arg name=\"data\" type=\"s\" direction=\"out\"/>\n" \
70 " </method>\n" \
71 " </interface>\n"
72
73#define BUS_PEER_INTERFACE \
74 "<interface name=\"org.freedesktop.DBus.Peer\">\n" \
75 " <method name=\"Ping\"/>\n" \
76 " <method name=\"GetMachineId\">\n" \
77 " <arg type=\"s\" name=\"machine_uuid\" direction=\"out\"/>\n" \
78 " </method>\n" \
79 "</interface>\n"
80
81#define BUS_GENERIC_INTERFACES_LIST \
82 "org.freedesktop.DBus.Properties\0" \
83 "org.freedesktop.DBus.Introspectable\0" \
84 "org.freedesktop.DBus.Peer\0"
85
9a1ac7b9
LP
86int bus_check_peercred(DBusConnection *c);
87
f4579ce7 88int bus_connect(DBusBusType t, DBusConnection **_bus, bool *private_bus, DBusError *error);
9a1ac7b9 89
a8f11321
LP
90int bus_connect_system_ssh(const char *user, const char *host, DBusConnection **_bus, DBusError *error);
91int bus_connect_system_polkit(DBusConnection **_bus, DBusError *error);
92
4cf5d675
LP
93const char *bus_error_message(const DBusError *error);
94
bfebab7f 95typedef int (*BusPropertyCallback)(DBusMessageIter *iter, const char *property, void *data);
9612f07c 96typedef int (*BusPropertySetCallback)(DBusMessageIter *iter, const char *property, void *data);
bfebab7f
LP
97
98typedef struct BusProperty {
bfebab7f
LP
99 const char *property; /* name of the property */
100 BusPropertyCallback append; /* Function that is called to serialize this property */
101 const char *signature;
d200735e
MS
102 const uint16_t offset; /* Offset from BusBoundProperties::base address to the property data.
103 * uint16_t is sufficient, because we have no structs too big.
104 * -Werror=overflow will catch it if this does not hold. */
105 bool indirect; /* data is indirect, ie. not base+offset, but *(base+offset) */
bfebab7f
LP
106 BusPropertySetCallback set; /* Optional: Function that is called to set this property */
107} BusProperty;
108
d200735e
MS
109typedef struct BusBoundProperties {
110 const char *interface; /* interface of the properties */
111 const BusProperty *properties; /* array of properties, ended by a NULL-filled element */
112 const void *const base; /* base pointer to which the offset must be added to reach data */
113} BusBoundProperties;
114
bfebab7f
LP
115DBusHandlerResult bus_send_error_reply(
116 DBusConnection *c,
117 DBusMessage *message,
118 DBusError *bus_error,
119 int error);
120
121DBusHandlerResult bus_default_message_handler(
122 DBusConnection *c,
123 DBusMessage *message,
124 const char *introspection,
125 const char *interfaces,
d200735e 126 const BusBoundProperties *bound_properties);
bfebab7f
LP
127
128int bus_property_append_string(DBusMessageIter *i, const char *property, void *data);
129int bus_property_append_strv(DBusMessageIter *i, const char *property, void *data);
130int bus_property_append_bool(DBusMessageIter *i, const char *property, void *data);
aa001cd6 131int bus_property_append_tristate_false(DBusMessageIter *i, const char *property, void *data);
bfebab7f
LP
132int bus_property_append_int32(DBusMessageIter *i, const char *property, void *data);
133int bus_property_append_uint32(DBusMessageIter *i, const char *property, void *data);
134int bus_property_append_uint64(DBusMessageIter *i, const char *property, void *data);
135int bus_property_append_size(DBusMessageIter *i, const char *property, void *data);
136int bus_property_append_ul(DBusMessageIter *i, const char *property, void *data);
916abb21 137int bus_property_append_long(DBusMessageIter *i, const char *property, void *data);
bfebab7f
LP
138
139#define bus_property_append_int bus_property_append_int32
140#define bus_property_append_pid bus_property_append_uint32
bd253d1b
LP
141#define bus_property_append_uid bus_property_append_uint32
142#define bus_property_append_gid bus_property_append_uint32
bfebab7f
LP
143#define bus_property_append_mode bus_property_append_uint32
144#define bus_property_append_unsigned bus_property_append_uint32
145#define bus_property_append_usec bus_property_append_uint64
146
147#define DEFINE_BUS_PROPERTY_APPEND_ENUM(function,name,type) \
148 int function(DBusMessageIter *i, const char *property, void *data) { \
149 const char *value; \
150 type *field = data; \
151 \
152 assert(i); \
153 assert(property); \
154 \
155 value = name##_to_string(*field); \
156 \
157 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &value)) \
158 return -ENOMEM; \
159 \
160 return 0; \
161 }
162
c57c09ee
MO
163#define DEFINE_BUS_PROPERTY_SET_ENUM(function,name,type) \
164 int function(DBusMessageIter *i, const char *property, void *data) { \
165 const char *value; \
166 type *field = data; \
167 \
168 assert(i); \
169 assert(property); \
170 \
171 dbus_message_iter_get_basic(i, &value); \
172 \
173 *field = name##_from_string(value); \
174 \
175 return 0; \
176 }
177
bfebab7f
LP
178const char *bus_errno_to_dbus(int error);
179
180DBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties);
181
3df5bf61
LP
182uint32_t bus_flags_to_events(DBusWatch *bus_watch);
183unsigned bus_events_to_flags(uint32_t events);
184
8d0e38a2
LP
185int bus_parse_strv(DBusMessage *m, char ***_l);
186int bus_parse_strv_iter(DBusMessageIter *iter, char ***_l);
187
98a28fef
LP
188int bus_append_strv_iter(DBusMessageIter *iter, char **l);
189
abca4822
LP
190int bus_iter_get_basic_and_next(DBusMessageIter *iter, int type, void *data, bool next);
191
a4c279f8
LP
192int generic_print_property(const char *name, DBusMessageIter *iter, bool all);
193
ad740100
LP
194void bus_async_unregister_and_exit(DBusConnection *bus, const char *name);
195
196DBusHandlerResult bus_exit_idle_filter(DBusConnection *bus, DBusMessage *m, void *userdata);
197
9a1ac7b9 198#endif