]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
01f78473 LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2010 Lennart Poettering | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
8 | under the terms of the GNU Lesser General Public License as published by |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
01f78473 LP |
10 | (at your option) any later version. |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 15 | Lesser General Public License for more details. |
01f78473 | 16 | |
5430f7f2 | 17 | You should have received a copy of the GNU Lesser General Public License |
01f78473 LP |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
19 | ***/ | |
20 | ||
07630cea | 21 | #include "bus-util.h" |
cf0fbc49 | 22 | #include "dbus-path.h" |
718db961 | 23 | #include "path.h" |
07630cea LP |
24 | #include "string-util.h" |
25 | #include "unit.h" | |
718db961 LP |
26 | |
27 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, path_result, PathResult); | |
28 | ||
29 | static int property_get_paths( | |
30 | sd_bus *bus, | |
31 | const char *path, | |
32 | const char *interface, | |
33 | const char *property, | |
34 | sd_bus_message *reply, | |
ebcf1f97 LP |
35 | void *userdata, |
36 | sd_bus_error *error) { | |
718db961 LP |
37 | |
38 | Path *p = userdata; | |
ebf57b80 | 39 | PathSpec *k; |
718db961 | 40 | int r; |
ebf57b80 | 41 | |
718db961 LP |
42 | assert(bus); |
43 | assert(reply); | |
ebf57b80 LP |
44 | assert(p); |
45 | ||
718db961 LP |
46 | r = sd_bus_message_open_container(reply, 'a', "(ss)"); |
47 | if (r < 0) | |
48 | return r; | |
ebf57b80 LP |
49 | |
50 | LIST_FOREACH(spec, k, p->specs) { | |
718db961 LP |
51 | r = sd_bus_message_append(reply, "(ss)", path_type_to_string(k->type), k->path); |
52 | if (r < 0) | |
53 | return r; | |
ebf57b80 LP |
54 | } |
55 | ||
718db961 | 56 | return sd_bus_message_close_container(reply); |
ebf57b80 LP |
57 | } |
58 | ||
718db961 LP |
59 | static int property_get_unit( |
60 | sd_bus *bus, | |
61 | const char *path, | |
62 | const char *interface, | |
63 | const char *property, | |
64 | sd_bus_message *reply, | |
ebcf1f97 LP |
65 | void *userdata, |
66 | sd_bus_error *error) { | |
b284eabd | 67 | |
718db961 | 68 | Unit *p = userdata, *trigger; |
b284eabd | 69 | |
718db961 LP |
70 | assert(bus); |
71 | assert(reply); | |
72 | assert(p); | |
b284eabd | 73 | |
718db961 | 74 | trigger = UNIT_TRIGGER(p); |
b284eabd | 75 | |
718db961 LP |
76 | return sd_bus_message_append(reply, "s", trigger ? trigger->id : ""); |
77 | } | |
cd43ca73 | 78 | |
718db961 LP |
79 | const sd_bus_vtable bus_path_vtable[] = { |
80 | SD_BUS_VTABLE_START(0), | |
556089dc LP |
81 | SD_BUS_PROPERTY("Unit", "s", property_get_unit, 0, SD_BUS_VTABLE_PROPERTY_CONST), |
82 | SD_BUS_PROPERTY("Paths", "a(ss)", property_get_paths, 0, SD_BUS_VTABLE_PROPERTY_CONST), | |
83 | SD_BUS_PROPERTY("MakeDirectory", "b", bus_property_get_bool, offsetof(Path, make_directory), SD_BUS_VTABLE_PROPERTY_CONST), | |
84 | SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode, offsetof(Path, directory_mode), SD_BUS_VTABLE_PROPERTY_CONST), | |
718db961 LP |
85 | SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Path, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
86 | SD_BUS_VTABLE_END | |
d200735e | 87 | }; |