1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
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>
29 typedef int (*BusPropertyCallback)(Manager *m, DBusMessageIter *iter, const char *property, void *data);
31 typedef struct BusProperty {
32 const char *interface; /* interface of the property */
33 const char *property; /* name of the property */
34 BusPropertyCallback append; /* Function that is called to serialize this property */
35 const char *signature;
36 const void *data; /* The data of this property */
39 #define BUS_PROPERTIES_INTERFACE \
40 " <interface name=\"org.freedesktop.DBus.Properties\">\n" \
41 " <method name=\"Get\">\n" \
42 " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
43 " <arg name=\"property\" direction=\"in\" type=\"s\"/>\n" \
44 " <arg name=\"value\" direction=\"out\" type=\"v\"/>\n" \
46 " <method name=\"GetAll\">\n" \
47 " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
48 " <arg name=\"properties\" direction=\"out\" type=\"a{sv}\"/>\n" \
50 " <signal name=\"PropertiesChanged\">\n" \
51 " <arg type=\"s\" name=\"interface\"/>\n" \
52 " <arg type=\"a{sv}\" name=\"changed_properties\"/>\n" \
53 " <arg type=\"as\" name=\"invalidated_properties\"/>\n" \
57 #define BUS_INTROSPECTABLE_INTERFACE \
58 " <interface name=\"org.freedesktop.DBus.Introspectable\">\n" \
59 " <method name=\"Introspect\">\n" \
60 " <arg name=\"data\" type=\"s\" direction=\"out\"/>\n" \
64 #define BUS_PEER_INTERFACE \
65 "<interface name=\"org.freedesktop.DBus.Peer\">\n" \
66 " <method name=\"Ping\"/>\n" \
67 " <method name=\"GetMachineId\">\n" \
68 " <arg type=\"s\" name=\"machine_uuid\" direction=\"out\"/>\n" \
72 int bus_init(Manager *m, bool try_bus_connect);
73 void bus_done(Manager *m);
75 unsigned bus_dispatch(Manager *m);
77 void bus_watch_event(Manager *m, Watch *w, int events);
78 void bus_timeout_event(Manager *m, Watch *w, int events);
80 int bus_query_pid(Manager *m, const char *name);
82 DBusHandlerResult bus_default_message_handler(Manager *m, DBusConnection *c, DBusMessage *message, const char* introspection, const BusProperty *properties);
83 DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessage *message, DBusError *bus_error, int error);
85 int bus_broadcast(Manager *m, DBusMessage *message);
87 int bus_property_append_string(Manager *m, DBusMessageIter *i, const char *property, void *data);
88 int bus_property_append_strv(Manager *m, DBusMessageIter *i, const char *property, void *data);
89 int bus_property_append_bool(Manager *m, DBusMessageIter *i, const char *property, void *data);
90 int bus_property_append_int32(Manager *m, DBusMessageIter *i, const char *property, void *data);
91 int bus_property_append_uint32(Manager *m, DBusMessageIter *i, const char *property, void *data);
92 int bus_property_append_uint64(Manager *m, DBusMessageIter *i, const char *property, void *data);
93 int bus_property_append_size(Manager *m, DBusMessageIter *i, const char *property, void *data);
94 int bus_property_append_ul(Manager *m, DBusMessageIter *i, const char *property, void *data);
96 #define bus_property_append_int bus_property_append_int32
97 #define bus_property_append_pid bus_property_append_uint32
98 #define bus_property_append_mode bus_property_append_uint32
99 #define bus_property_append_unsigned bus_property_append_uint32
100 #define bus_property_append_usec bus_property_append_uint64
102 #define DEFINE_BUS_PROPERTY_APPEND_ENUM(function,name,type) \
103 int function(Manager *m, DBusMessageIter *i, const char *property, void *data) { \
105 type *field = data; \
111 value = name##_to_string(*field); \
113 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &value)) \
119 int bus_parse_strv(DBusMessage *m, char ***_l);
121 bool bus_has_subscriber(Manager *m);
122 bool bus_connection_has_subscriber(Manager *m, DBusConnection *c);
124 DBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties);
126 #define BUS_CONNECTION_SUBSCRIBED(m, c) dbus_connection_get_data((c), (m)->subscribed_data_slot)
127 #define BUS_PENDING_CALL_NAME(m, p) dbus_pending_call_get_data((p), (m)->name_data_slot)
129 extern const char * const bus_interface_table[];