]>
Commit | Line | Data |
---|---|---|
663996b3 MS |
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 | ||
db2df898 | 23 | #include "bus-util.h" |
14228c0d | 24 | #include "dbus-cgroup.h" |
db2df898 | 25 | #include "dbus-execute.h" |
14228c0d | 26 | #include "dbus-swap.h" |
db2df898 MP |
27 | #include "string-util.h" |
28 | #include "swap.h" | |
29 | #include "unit.h" | |
60f067b4 JS |
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); | |
663996b3 MS |
45 | assert(s); |
46 | ||
47 | if (s->from_proc_swaps) | |
60f067b4 | 48 | p = s->parameters_proc_swaps.priority; |
663996b3 | 49 | else if (s->from_fragment) |
60f067b4 | 50 | p = s->parameters_fragment.priority; |
663996b3 | 51 | else |
60f067b4 | 52 | p = -1; |
663996b3 | 53 | |
60f067b4 | 54 | return sd_bus_message_append(reply, "i", p); |
663996b3 MS |
55 | } |
56 | ||
5eef597e MP |
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 | ||
60f067b4 JS |
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), | |
5eef597e | 85 | SD_BUS_PROPERTY("Options", "s", property_get_options, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
60f067b4 JS |
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 | |
663996b3 MS |
92 | }; |
93 | ||
14228c0d MB |
94 | int bus_swap_set_property( |
95 | Unit *u, | |
96 | const char *name, | |
60f067b4 | 97 | sd_bus_message *message, |
14228c0d | 98 | UnitSetPropertiesMode mode, |
60f067b4 | 99 | sd_bus_error *error) { |
14228c0d MB |
100 | |
101 | Swap *s = SWAP(u); | |
14228c0d | 102 | |
60f067b4 | 103 | assert(s); |
14228c0d | 104 | assert(name); |
60f067b4 | 105 | assert(message); |
14228c0d | 106 | |
60f067b4 | 107 | return bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error); |
14228c0d MB |
108 | } |
109 | ||
110 | int bus_swap_commit_properties(Unit *u) { | |
111 | assert(u); | |
112 | ||
60f067b4 | 113 | unit_update_cgroup_members_masks(u); |
14228c0d | 114 | unit_realize_cgroup(u); |
60f067b4 | 115 | |
14228c0d MB |
116 | return 0; |
117 | } |