chiark / gitweb /
unit: don't override timestamps due to state changes when deserializing
[elogind.git] / src / dbus.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #ifndef foodbushfoo
4 #define foodbushfoo
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
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.
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
19   General Public License for more details.
20
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/>.
23 ***/
24
25 #include <dbus/dbus.h>
26
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 #include "manager.h"
44
45 typedef int (*BusPropertyCallback)(Manager *m, DBusMessageIter *iter, const char *property, void *data);
46 typedef int (*BusPropertySetCallback)(Manager *m, DBusMessageIter *iter, const char *property);
47
48 typedef struct BusProperty {
49         const char *interface;           /* interface of the property */
50         const char *property;            /* name of the property */
51         BusPropertyCallback append;      /* Function that is called to serialize this property */
52         const char *signature;
53         const void *data;                /* The data of this property */
54         BusPropertySetCallback set;      /* Function that is called to set this property */
55 } BusProperty;
56
57 #define BUS_PROPERTIES_INTERFACE                                        \
58         " <interface name=\"org.freedesktop.DBus.Properties\">\n"       \
59         "  <method name=\"Get\">\n"                                     \
60         "   <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n"    \
61         "   <arg name=\"property\" direction=\"in\" type=\"s\"/>\n"     \
62         "   <arg name=\"value\" direction=\"out\" type=\"v\"/>\n"       \
63         "  </method>\n"                                                 \
64         "  <method name=\"GetAll\">\n"                                  \
65         "   <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n"    \
66         "   <arg name=\"properties\" direction=\"out\" type=\"a{sv}\"/>\n" \
67         "  </method>\n"                                                 \
68         "  <method name=\"Set\">\n"                                     \
69         "   <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n"    \
70         "   <arg name=\"property\" direction=\"in\" type=\"s\"/>\n"     \
71         "   <arg name=\"value\" direction=\"in\" type=\"v\"/>\n"       \
72         "  </method>\n"                                                 \
73         "  <signal name=\"PropertiesChanged\">\n"                       \
74         "   <arg type=\"s\" name=\"interface\"/>\n"                     \
75         "   <arg type=\"a{sv}\" name=\"changed_properties\"/>\n"        \
76         "   <arg type=\"as\" name=\"invalidated_properties\"/>\n"       \
77         "  </signal>\n"                                                 \
78         " </interface>\n"
79
80 #define BUS_INTROSPECTABLE_INTERFACE                                    \
81         " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"   \
82         "  <method name=\"Introspect\">\n"                              \
83         "   <arg name=\"data\" type=\"s\" direction=\"out\"/>\n"        \
84         "  </method>\n"                                                 \
85         " </interface>\n"
86
87 #define BUS_PEER_INTERFACE                                              \
88         "<interface name=\"org.freedesktop.DBus.Peer\">\n"              \
89         " <method name=\"Ping\"/>\n"                                    \
90         " <method name=\"GetMachineId\">\n"                             \
91         "  <arg type=\"s\" name=\"machine_uuid\" direction=\"out\"/>\n" \
92         " </method>\n"                                                  \
93         "</interface>\n"
94
95 #define BUS_GENERIC_INTERFACES_LIST             \
96         "org.freedesktop.DBus.Properties\0"     \
97         "org.freedesktop.DBus.Introspectable\0" \
98         "org.freedesktop.DBus.Peer\0"
99
100 int bus_init(Manager *m, bool try_bus_connect);
101 void bus_done(Manager *m);
102
103 unsigned bus_dispatch(Manager *m);
104
105 void bus_watch_event(Manager *m, Watch *w, int events);
106 void bus_timeout_event(Manager *m, Watch *w, int events);
107
108 int bus_query_pid(Manager *m, const char *name);
109
110 DBusHandlerResult bus_default_message_handler(Manager *m, DBusConnection *c, DBusMessage *message, const char* introspection, const char *interfaces, const BusProperty *properties);
111 DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessage *message, DBusError *bus_error, int error);
112
113 int bus_broadcast(Manager *m, DBusMessage *message);
114
115 int bus_property_append_string(Manager *m, DBusMessageIter *i, const char *property, void *data);
116 int bus_property_append_strv(Manager *m, DBusMessageIter *i, const char *property, void *data);
117 int bus_property_append_bool(Manager *m, DBusMessageIter *i, const char *property, void *data);
118 int bus_property_append_int32(Manager *m, DBusMessageIter *i, const char *property, void *data);
119 int bus_property_append_uint32(Manager *m, DBusMessageIter *i, const char *property, void *data);
120 int bus_property_append_uint64(Manager *m, DBusMessageIter *i, const char *property, void *data);
121 int bus_property_append_size(Manager *m, DBusMessageIter *i, const char *property, void *data);
122 int bus_property_append_ul(Manager *m, DBusMessageIter *i, const char *property, void *data);
123
124 #define bus_property_append_int bus_property_append_int32
125 #define bus_property_append_pid bus_property_append_uint32
126 #define bus_property_append_mode bus_property_append_uint32
127 #define bus_property_append_unsigned bus_property_append_uint32
128 #define bus_property_append_usec bus_property_append_uint64
129
130 #define DEFINE_BUS_PROPERTY_APPEND_ENUM(function,name,type)             \
131         int function(Manager *m, DBusMessageIter *i, const char *property, void *data) { \
132                 const char *value;                                      \
133                 type *field = data;                                     \
134                                                                         \
135                 assert(m);                                              \
136                 assert(i);                                              \
137                 assert(property);                                       \
138                                                                         \
139                 value = name##_to_string(*field);                       \
140                                                                         \
141                 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &value)) \
142                         return -ENOMEM;                                 \
143                                                                         \
144                 return 0;                                               \
145         }
146
147 int bus_parse_strv(DBusMessage *m, char ***_l);
148
149 bool bus_has_subscriber(Manager *m);
150 bool bus_connection_has_subscriber(Manager *m, DBusConnection *c);
151
152 DBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties);
153
154 #define BUS_CONNECTION_SUBSCRIBED(m, c) dbus_connection_get_data((c), (m)->subscribed_data_slot)
155 #define BUS_PENDING_CALL_NAME(m, p) dbus_pending_call_get_data((p), (m)->name_data_slot)
156
157 extern const char * const bus_interface_table[];
158
159 #endif