]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/dbus-swap.c
Merge pull request #1654 from poettering/util-lib
[thirdparty/systemd.git] / src / core / dbus-swap.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 Copyright 2010 Maarten Lankhorst
8
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 #include "bus-util.h"
24 #include "dbus-cgroup.h"
25 #include "dbus-execute.h"
26 #include "string-util.h"
27 #include "swap.h"
28 #include "unit.h"
29 #include "dbus-swap.h"
30
31 static int property_get_priority(
32 sd_bus *bus,
33 const char *path,
34 const char *interface,
35 const char *property,
36 sd_bus_message *reply,
37 void *userdata,
38 sd_bus_error *error) {
39
40 Swap *s = SWAP(userdata);
41 int p;
42
43 assert(bus);
44 assert(reply);
45 assert(s);
46
47 if (s->from_proc_swaps)
48 p = s->parameters_proc_swaps.priority;
49 else if (s->from_fragment)
50 p = s->parameters_fragment.priority;
51 else
52 p = -1;
53
54 return sd_bus_message_append(reply, "i", p);
55 }
56
57 static int property_get_options(
58 sd_bus *bus,
59 const char *path,
60 const char *interface,
61 const char *property,
62 sd_bus_message *reply,
63 void *userdata,
64 sd_bus_error *error) {
65
66 Swap *s = SWAP(userdata);
67 const char *options = NULL;
68
69 assert(bus);
70 assert(reply);
71 assert(s);
72
73 if (s->from_fragment)
74 options = s->parameters_fragment.options;
75
76 return sd_bus_message_append(reply, "s", options);
77 }
78
79 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, swap_result, SwapResult);
80
81 const sd_bus_vtable bus_swap_vtable[] = {
82 SD_BUS_VTABLE_START(0),
83 SD_BUS_PROPERTY("What", "s", NULL, offsetof(Swap, what), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
84 SD_BUS_PROPERTY("Priority", "i", property_get_priority, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
85 SD_BUS_PROPERTY("Options", "s", property_get_options, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
86 SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Swap, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST),
87 SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Swap, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
88 SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Swap, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
89 BUS_EXEC_COMMAND_VTABLE("ExecActivate", offsetof(Swap, exec_command[SWAP_EXEC_ACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
90 BUS_EXEC_COMMAND_VTABLE("ExecDeactivate", offsetof(Swap, exec_command[SWAP_EXEC_DEACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
91 SD_BUS_VTABLE_END
92 };
93
94 int bus_swap_set_property(
95 Unit *u,
96 const char *name,
97 sd_bus_message *message,
98 UnitSetPropertiesMode mode,
99 sd_bus_error *error) {
100
101 Swap *s = SWAP(u);
102
103 assert(s);
104 assert(name);
105 assert(message);
106
107 return bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error);
108 }
109
110 int bus_swap_commit_properties(Unit *u) {
111 assert(u);
112
113 unit_update_cgroup_members_masks(u);
114 unit_realize_cgroup(u);
115
116 return 0;
117 }