chiark / gitweb /
add org.freedesktop.DBus.Properies.Set method
[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 #include "manager.h"
28
29 typedef int (*BusPropertyCallback)(Manager *m, DBusMessageIter *iter, const char *property, void *data);
30 typedef int (*BusPropertySetCallback)(Manager *m, DBusMessageIter *iter, const char *property);
31
32 typedef struct BusProperty {
33         const char *interface;           /* interface of the property */
34         const char *property;            /* name of the property */
35         BusPropertyCallback append;      /* Function that is called to serialize this property */
36         const char *signature;
37         const void *data;                /* The data of this property */
38         BusPropertySetCallback set;      /* Function that is called to set this property */
39 } BusProperty;
40
41 #define BUS_PROPERTIES_INTERFACE                                        \
42         " <interface name=\"org.freedesktop.DBus.Properties\">\n"       \
43         "  <method name=\"Get\">\n"                                     \
44         "   <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n"    \
45         "   <arg name=\"property\" direction=\"in\" type=\"s\"/>\n"     \
46         "   <arg name=\"value\" direction=\"out\" type=\"v\"/>\n"       \
47         "  </method>\n"                                                 \
48         "  <method name=\"GetAll\">\n"                                  \
49         "   <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n"    \
50         "   <arg name=\"properties\" direction=\"out\" type=\"a{sv}\"/>\n" \
51         "  </method>\n"                                                 \
52         "  <method name=\"Set\">\n"                                     \
53         "   <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n"    \
54         "   <arg name=\"property\" direction=\"in\" type=\"s\"/>\n"     \
55         "   <arg name=\"value\" direction=\"in\" type=\"v\"/>\n"       \
56         "  </method>\n"                                                 \
57         "  <signal name=\"PropertiesChanged\">\n"                       \
58         "   <arg type=\"s\" name=\"interface\"/>\n"                     \
59         "   <arg type=\"a{sv}\" name=\"changed_properties\"/>\n"        \
60         "   <arg type=\"as\" name=\"invalidated_properties\"/>\n"       \
61         "  </signal>\n"                                                 \
62         " </interface>\n"
63
64 #define BUS_INTROSPECTABLE_INTERFACE                                    \
65         " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"   \
66         "  <method name=\"Introspect\">\n"                              \
67         "   <arg name=\"data\" type=\"s\" direction=\"out\"/>\n"        \
68         "  </method>\n"                                                 \
69         " </interface>\n"
70
71 #define BUS_PEER_INTERFACE                                              \
72         "<interface name=\"org.freedesktop.DBus.Peer\">\n"              \
73         " <method name=\"Ping\"/>\n"                                    \
74         " <method name=\"GetMachineId\">\n"                             \
75         "  <arg type=\"s\" name=\"machine_uuid\" direction=\"out\"/>\n" \
76         " </method>\n"                                                  \
77         "</interface>\n"
78
79 int bus_init(Manager *m, bool try_bus_connect);
80 void bus_done(Manager *m);
81
82 unsigned bus_dispatch(Manager *m);
83
84 void bus_watch_event(Manager *m, Watch *w, int events);
85 void bus_timeout_event(Manager *m, Watch *w, int events);
86
87 int bus_query_pid(Manager *m, const char *name);
88
89 DBusHandlerResult bus_default_message_handler(Manager *m, DBusConnection *c, DBusMessage *message, const char* introspection, const BusProperty *properties);
90 DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessage *message, DBusError *bus_error, int error);
91
92 int bus_broadcast(Manager *m, DBusMessage *message);
93
94 int bus_property_append_string(Manager *m, DBusMessageIter *i, const char *property, void *data);
95 int bus_property_append_strv(Manager *m, DBusMessageIter *i, const char *property, void *data);
96 int bus_property_append_bool(Manager *m, DBusMessageIter *i, const char *property, void *data);
97 int bus_property_append_int32(Manager *m, DBusMessageIter *i, const char *property, void *data);
98 int bus_property_append_uint32(Manager *m, DBusMessageIter *i, const char *property, void *data);
99 int bus_property_append_uint64(Manager *m, DBusMessageIter *i, const char *property, void *data);
100 int bus_property_append_size(Manager *m, DBusMessageIter *i, const char *property, void *data);
101 int bus_property_append_ul(Manager *m, DBusMessageIter *i, const char *property, void *data);
102
103 #define bus_property_append_int bus_property_append_int32
104 #define bus_property_append_pid bus_property_append_uint32
105 #define bus_property_append_mode bus_property_append_uint32
106 #define bus_property_append_unsigned bus_property_append_uint32
107 #define bus_property_append_usec bus_property_append_uint64
108
109 #define DEFINE_BUS_PROPERTY_APPEND_ENUM(function,name,type)             \
110         int function(Manager *m, DBusMessageIter *i, const char *property, void *data) { \
111                 const char *value;                                      \
112                 type *field = data;                                     \
113                                                                         \
114                 assert(m);                                              \
115                 assert(i);                                              \
116                 assert(property);                                       \
117                                                                         \
118                 value = name##_to_string(*field);                       \
119                                                                         \
120                 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &value)) \
121                         return -ENOMEM;                                 \
122                                                                         \
123                 return 0;                                               \
124         }
125
126 int bus_parse_strv(DBusMessage *m, char ***_l);
127
128 bool bus_has_subscriber(Manager *m);
129 bool bus_connection_has_subscriber(Manager *m, DBusConnection *c);
130
131 DBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties);
132
133 #define BUS_CONNECTION_SUBSCRIBED(m, c) dbus_connection_get_data((c), (m)->subscribed_data_slot)
134 #define BUS_PENDING_CALL_NAME(m, p) dbus_pending_call_get_data((p), (m)->name_data_slot)
135
136 extern const char * const bus_interface_table[];
137
138 #endif