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