]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/dbus-path.c
core: convert PID 1 to libsystemd-bus
[thirdparty/systemd.git] / src / core / dbus-path.c
CommitLineData
d6c9574f 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
01f78473
LP
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
5430f7f2
LP
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
01f78473
LP
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
5430f7f2 16 Lesser General Public License for more details.
01f78473 17
5430f7f2 18 You should have received a copy of the GNU Lesser General Public License
01f78473
LP
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
718db961
LP
22#include "unit.h"
23#include "path.h"
01f78473
LP
24#include "dbus-unit.h"
25#include "dbus-path.h"
718db961
LP
26#include "bus-util.h"
27
28static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, path_result, PathResult);
29
30static 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 sd_bus_error *error,
37 void *userdata) {
38
39 Path *p = userdata;
ebf57b80 40 PathSpec *k;
718db961 41 int r;
ebf57b80 42
718db961
LP
43 assert(bus);
44 assert(reply);
ebf57b80
LP
45 assert(p);
46
718db961
LP
47 r = sd_bus_message_open_container(reply, 'a', "(ss)");
48 if (r < 0)
49 return r;
ebf57b80
LP
50
51 LIST_FOREACH(spec, k, p->specs) {
718db961
LP
52 r = sd_bus_message_append(reply, "(ss)", path_type_to_string(k->type), k->path);
53 if (r < 0)
54 return r;
ebf57b80
LP
55 }
56
718db961 57 return sd_bus_message_close_container(reply);
ebf57b80
LP
58}
59
718db961
LP
60static 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 sd_bus_error *error,
67 void *userdata) {
b284eabd 68
718db961 69 Unit *p = userdata, *trigger;
b284eabd 70
718db961
LP
71 assert(bus);
72 assert(reply);
73 assert(p);
b284eabd 74
718db961 75 trigger = UNIT_TRIGGER(p);
b284eabd 76
718db961
LP
77 return sd_bus_message_append(reply, "s", trigger ? trigger->id : "");
78}
cd43ca73 79
718db961
LP
80const 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
d200735e
MS
88};
89
718db961
LP
90const char* const bus_path_changing_properties[] = {
91 "Result",
92 NULL
93};