]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/dbus-swap.c
Merge pull request #57 from pwithnall/wip/pwithnall/udev-virtualbox-rules
[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 "unit.h"
24 #include "swap.h"
25 #include "dbus-execute.h"
26 #include "dbus-cgroup.h"
27 #include "dbus-swap.h"
28 #include "bus-util.h"
29
30 static int property_get_priority(
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 Swap *s = SWAP(userdata);
40 int p;
41
42 assert(bus);
43 assert(reply);
44 assert(s);
45
46 if (s->from_proc_swaps)
47 p = s->parameters_proc_swaps.priority;
48 else if (s->from_fragment)
49 p = s->parameters_fragment.priority;
50 else
51 p = -1;
52
53 return sd_bus_message_append(reply, "i", p);
54 }
55
56 static int property_get_options(
57 sd_bus *bus,
58 const char *path,
59 const char *interface,
60 const char *property,
61 sd_bus_message *reply,
62 void *userdata,
63 sd_bus_error *error) {
64
65 Swap *s = SWAP(userdata);
66 const char *options = NULL;
67
68 assert(bus);
69 assert(reply);
70 assert(s);
71
72 if (s->from_fragment)
73 options = s->parameters_fragment.options;
74
75 return sd_bus_message_append(reply, "s", options);
76 }
77
78 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, swap_result, SwapResult);
79
80 const sd_bus_vtable bus_swap_vtable[] = {
81 SD_BUS_VTABLE_START(0),
82 SD_BUS_PROPERTY("What", "s", NULL, offsetof(Swap, what), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
83 SD_BUS_PROPERTY("Priority", "i", property_get_priority, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
84 SD_BUS_PROPERTY("Options", "s", property_get_options, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
85 SD_BUS_PROPERTY("TimeoutUSec", "t", bus_property_get_usec, offsetof(Swap, timeout_usec), SD_BUS_VTABLE_PROPERTY_CONST),
86 SD_BUS_PROPERTY("ControlPID", "u", bus_property_get_pid, offsetof(Swap, control_pid), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
87 SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Swap, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
88 BUS_EXEC_COMMAND_VTABLE("ExecActivate", offsetof(Swap, exec_command[SWAP_EXEC_ACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
89 BUS_EXEC_COMMAND_VTABLE("ExecDeactivate", offsetof(Swap, exec_command[SWAP_EXEC_DEACTIVATE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
90 SD_BUS_VTABLE_END
91 };
92
93 int bus_swap_set_property(
94 Unit *u,
95 const char *name,
96 sd_bus_message *message,
97 UnitSetPropertiesMode mode,
98 sd_bus_error *error) {
99
100 Swap *s = SWAP(u);
101
102 assert(s);
103 assert(name);
104 assert(message);
105
106 return bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error);
107 }
108
109 int bus_swap_commit_properties(Unit *u) {
110 assert(u);
111
112 unit_update_cgroup_members_masks(u);
113 unit_realize_cgroup(u);
114
115 return 0;
116 }