1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3 #ifndef foodbuscommonhfoo
4 #define foodbuscommonhfoo
7 This file is part of systemd.
9 Copyright 2010 Lennart Poettering
11 systemd is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
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
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include <dbus/dbus.h>
27 #ifndef DBUS_ERROR_UNKNOWN_OBJECT
28 #define DBUS_ERROR_UNKNOWN_OBJECT "org.freedesktop.DBus.Error.UnknownObject"
31 #ifndef DBUS_ERROR_UNKNOWN_INTERFACE
32 #define DBUS_ERROR_UNKNOWN_INTERFACE "org.freedesktop.DBus.Error.UnknownInterface"
35 #ifndef DBUS_ERROR_UNKNOWN_PROPERTY
36 #define DBUS_ERROR_UNKNOWN_PROPERTY "org.freedesktop.DBus.Error.UnknownProperty"
39 #ifndef DBUS_ERROR_PROPERTY_READ_ONLY
40 #define DBUS_ERROR_PROPERTY_READ_ONLY "org.freedesktop.DBus.Error.PropertyReadOnly"
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" \
50 " <method name=\"GetAll\">\n" \
51 " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
52 " <arg name=\"properties\" direction=\"out\" type=\"a{sv}\"/>\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" \
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" \
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" \
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" \
81 #define BUS_GENERIC_INTERFACES_LIST \
82 "org.freedesktop.DBus.Properties\0" \
83 "org.freedesktop.DBus.Introspectable\0" \
84 "org.freedesktop.DBus.Peer\0"
86 int bus_check_peercred(DBusConnection *c);
88 int bus_connect(DBusBusType t, DBusConnection **_bus, bool *private_bus, DBusError *error);
90 int bus_connect_system_ssh(const char *user, const char *host, DBusConnection **_bus, DBusError *error);
91 int bus_connect_system_polkit(DBusConnection **_bus, DBusError *error);
93 const char *bus_error_message(const DBusError *error);
95 typedef int (*BusPropertyCallback)(DBusMessageIter *iter, const char *property, void *data);
96 typedef int (*BusPropertySetCallback)(DBusMessageIter *iter, const char *property);
98 typedef struct BusProperty {
99 const char *interface; /* interface of the property */
100 const char *property; /* name of the property */
101 BusPropertyCallback append; /* Function that is called to serialize this property */
102 const char *signature;
103 const void *data; /* The data of this property */
104 BusPropertySetCallback set; /* Optional: Function that is called to set this property */
107 DBusHandlerResult bus_send_error_reply(
109 DBusMessage *message,
110 DBusError *bus_error,
113 DBusHandlerResult bus_default_message_handler(
115 DBusMessage *message,
116 const char *introspection,
117 const char *interfaces,
118 const BusProperty *properties);
120 int bus_property_append_string(DBusMessageIter *i, const char *property, void *data);
121 int bus_property_append_strv(DBusMessageIter *i, const char *property, void *data);
122 int bus_property_append_bool(DBusMessageIter *i, const char *property, void *data);
123 int bus_property_append_int32(DBusMessageIter *i, const char *property, void *data);
124 int bus_property_append_uint32(DBusMessageIter *i, const char *property, void *data);
125 int bus_property_append_uint64(DBusMessageIter *i, const char *property, void *data);
126 int bus_property_append_size(DBusMessageIter *i, const char *property, void *data);
127 int bus_property_append_ul(DBusMessageIter *i, const char *property, void *data);
128 int bus_property_append_long(DBusMessageIter *i, const char *property, void *data);
130 #define bus_property_append_int bus_property_append_int32
131 #define bus_property_append_pid bus_property_append_uint32
132 #define bus_property_append_uid bus_property_append_uint32
133 #define bus_property_append_gid bus_property_append_uint32
134 #define bus_property_append_mode bus_property_append_uint32
135 #define bus_property_append_unsigned bus_property_append_uint32
136 #define bus_property_append_usec bus_property_append_uint64
138 #define DEFINE_BUS_PROPERTY_APPEND_ENUM(function,name,type) \
139 int function(DBusMessageIter *i, const char *property, void *data) { \
141 type *field = data; \
146 value = name##_to_string(*field); \
148 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &value)) \
154 const char *bus_errno_to_dbus(int error);
156 DBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties);
158 uint32_t bus_flags_to_events(DBusWatch *bus_watch);
159 unsigned bus_events_to_flags(uint32_t events);
161 int bus_parse_strv(DBusMessage *m, char ***_l);
162 int bus_parse_strv_iter(DBusMessageIter *iter, char ***_l);
164 int bus_append_strv_iter(DBusMessageIter *iter, char **l);
166 int bus_iter_get_basic_and_next(DBusMessageIter *iter, int type, void *data, bool next);
168 int generic_print_property(const char *name, DBusMessageIter *iter, bool all);
170 void bus_async_unregister_and_exit(DBusConnection *bus, const char *name);
172 DBusHandlerResult bus_exit_idle_filter(DBusConnection *bus, DBusMessage *m, void *userdata);