]>
Commit | Line | Data |
---|---|---|
40ca29a1 LP |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | #pragma once | |
4 | ||
5 | /*** | |
6 | This file is part of systemd. | |
7 | ||
8 | Copyright 2013 Lennart Poettering | |
9 | ||
10 | systemd is free software; you can redistribute it and/or modify it | |
11 | under the terms of the GNU Lesser General Public License as published by | |
12 | the Free Software Foundation; either version 2.1 of the License, or | |
13 | (at your option) any later version. | |
14 | ||
15 | systemd is distributed in the hope that it will be useful, but | |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | Lesser General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU Lesser General Public License | |
21 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
22 | ***/ | |
23 | ||
24 | #include "sd-event.h" | |
25 | #include "sd-bus.h" | |
26 | #include "hashmap.h" | |
27 | #include "time-util.h" | |
28 | #include "util.h" | |
29 | ||
d21ed1ea LP |
30 | typedef enum BusTransport { |
31 | BUS_TRANSPORT_LOCAL, | |
32 | BUS_TRANSPORT_REMOTE, | |
33 | BUS_TRANSPORT_CONTAINER, | |
34 | _BUS_TRANSPORT_MAX, | |
35 | _BUS_TRANSPORT_INVALID = -1 | |
36 | } BusTransport; | |
37 | ||
9f6eb1cd KS |
38 | typedef int (*bus_property_set_t) (sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata); |
39 | ||
ffc06c35 | 40 | struct bus_properties_map { |
9f6eb1cd KS |
41 | const char *member; |
42 | const char *signature; | |
43 | bus_property_set_t set; | |
44 | size_t offset; | |
ffc06c35 KS |
45 | }; |
46 | ||
9f6eb1cd KS |
47 | int bus_map_id128(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata); |
48 | ||
ffc06c35 KS |
49 | int bus_map_all_properties(sd_bus *bus, |
50 | const char *destination, | |
51 | const char *path, | |
9f6eb1cd KS |
52 | const struct bus_properties_map *map, |
53 | void *userdata); | |
ffc06c35 | 54 | |
40ca29a1 LP |
55 | int bus_async_unregister_and_quit(sd_event *e, sd_bus *bus, const char *name); |
56 | ||
57 | int bus_event_loop_with_idle(sd_event *e, sd_bus *bus, const char *name, usec_t timeout); | |
58 | int bus_property_get_tristate(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata); | |
59 | ||
60 | int bus_verify_polkit(sd_bus *bus, sd_bus_message *m, const char *action, bool interactive, bool *_challenge, sd_bus_error *e); | |
61 | ||
62 | int bus_verify_polkit_async(sd_bus *bus, Hashmap **registry, sd_bus_message *m, const char *action, bool interactive, sd_bus_error *error, sd_bus_message_handler_t callback, void *userdata); | |
63 | void bus_verify_polkit_async_registry_free(sd_bus *bus, Hashmap *registry); | |
64 | ||
0f8bd8de | 65 | int bus_open_system_systemd(sd_bus **_bus); |
a1da8583 | 66 | |
d21ed1ea LP |
67 | int bus_open_transport(BusTransport transport, const char *host, bool user, sd_bus **bus); |
68 | ||
9f6eb1cd | 69 | int bus_print_property(const char *name, sd_bus_message *property, bool all); |
27e72d6b | 70 | int bus_print_all_properties(sd_bus *bus, const char *dest, const char *path, char **filter, bool all); |
0c842e0a | 71 | |
e6504030 LP |
72 | int bus_property_get_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata); |
73 | int bus_property_get_uid(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, sd_bus_error *error, void *userdata); | |
74 | ||
75 | #define bus_property_get_gid bus_property_get_uid | |
76 | #define bus_property_get_pid bus_property_get_uid | |
77 | ||
40ca29a1 LP |
78 | DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus*, sd_bus_unref); |
79 | DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_message*, sd_bus_message_unref); | |
80 | ||
81 | #define _cleanup_bus_unref_ _cleanup_(sd_bus_unrefp) | |
40ca29a1 | 82 | #define _cleanup_bus_message_unref_ _cleanup_(sd_bus_message_unrefp) |
c3350683 LP |
83 | #define _cleanup_bus_error_free_ _cleanup_(sd_bus_error_free) |
84 | ||
85 | #define BUS_DEFINE_PROPERTY_GET_ENUM(function, name, type) \ | |
86 | int function(sd_bus *bus, \ | |
87 | const char *path, \ | |
88 | const char *interface, \ | |
89 | const char *property, \ | |
90 | sd_bus_message *reply, \ | |
91 | sd_bus_error *error, \ | |
92 | void *userdata) { \ | |
93 | \ | |
94 | const char *value; \ | |
95 | type *field = userdata; \ | |
96 | int r; \ | |
97 | \ | |
98 | assert(bus); \ | |
99 | assert(reply); \ | |
100 | assert(field); \ | |
101 | \ | |
102 | value = strempty(name##_to_string(*field)); \ | |
103 | \ | |
104 | r = sd_bus_message_append_basic(reply, 's', value); \ | |
105 | if (r < 0) \ | |
106 | return r; \ | |
107 | \ | |
108 | return 1; \ | |
109 | } \ | |
110 | struct __useless_struct_to_allow_trailing_semicolon__ | |
111 | ||
112 | #define BUS_ERROR_NO_SUCH_UNIT "org.freedesktop.systemd1.NoSuchUnit" | |
113 | #define BUS_ERROR_LOAD_FAILED "org.freedesktop.systemd1.LoadFailed" | |
114 | #define BUS_ERROR_JOB_FAILED "org.freedesktop.systemd1.JobFailed" | |
115 | ||
116 | #define BUS_ERROR_NO_SUCH_MACHINE "org.freedesktop.machine1.NoSuchMachine" | |
117 | #define BUS_ERROR_NO_MACHINE_FOR_PID "org.freedesktop.machine1.NoMachineForPID" | |
118 | #define BUS_ERROR_MACHINE_EXISTS "org.freedesktop.machine1.MachineExists" | |
cc377381 LP |
119 | |
120 | #define BUS_ERROR_NO_SUCH_SESSION "org.freedesktop.login1.NoSuchSession" | |
121 | #define BUS_ERROR_NO_SESSION_FOR_PID "org.freedesktop.login1.NoSessionForPID" | |
122 | #define BUS_ERROR_NO_SUCH_USER "org.freedesktop.login1.NoSuchUser" | |
123 | #define BUS_ERROR_NO_USER_FOR_PID "org.freedesktop.login1.NoUserForPID" | |
124 | #define BUS_ERROR_NO_SUCH_SEAT "org.freedesktop.login1.NoSuchSeat" | |
125 | #define BUS_ERROR_SESSION_NOT_ON_SEAT "org.freedesktop.login1.SessionNotOnSeat" | |
126 | #define BUS_ERROR_NOT_IN_CONTROL "org.freedesktop.login1.NotInControl" | |
127 | #define BUS_ERROR_DEVICE_IS_TAKEN "org.freedesktop.login1.DeviceIsTaken" | |
128 | #define BUS_ERROR_DEVICE_NOT_TAKEN "org.freedesktop.login1.DeviceNotTaken" | |
129 | #define BUS_ERROR_OPERATION_IN_PROGRESS "org.freedesktop.login1.OperationInProgress" | |
130 | #define BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED "org.freedesktop.login1.SleepVerbNotSupported" |