]>
Commit | Line | Data |
---|---|---|
d6c9574f | 1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
07b0b134 ML |
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 | |
5430f7f2 LP |
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 | |
07b0b134 ML |
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 | |
5430f7f2 | 17 | Lesser General Public License for more details. |
07b0b134 | 18 | |
5430f7f2 | 19 | You should have received a copy of the GNU Lesser General Public License |
07b0b134 ML |
20 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
21 | ***/ | |
22 | ||
4e85aff4 LP |
23 | #include <errno.h> |
24 | ||
07b0b134 ML |
25 | #include "dbus-unit.h" |
26 | #include "dbus-swap.h" | |
15412f29 | 27 | #include "dbus-execute.h" |
4819ff03 | 28 | #include "dbus-kill.h" |
bfebab7f | 29 | #include "dbus-common.h" |
07b0b134 | 30 | |
4288f619 LP |
31 | #define BUS_SWAP_INTERFACE \ |
32 | " <interface name=\"org.freedesktop.systemd1.Swap\">\n" \ | |
33 | " <property name=\"What\" type=\"s\" access=\"read\"/>\n" \ | |
34 | " <property name=\"Priority\" type=\"i\" access=\"read\"/>\n" \ | |
15412f29 LP |
35 | " <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \ |
36 | BUS_EXEC_COMMAND_INTERFACE("ExecActivate") \ | |
37 | BUS_EXEC_COMMAND_INTERFACE("ExecDeactivate") \ | |
38 | BUS_EXEC_CONTEXT_INTERFACE \ | |
4819ff03 | 39 | BUS_KILL_CONTEXT_INTERFACE \ |
15412f29 | 40 | " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \ |
e1770af8 | 41 | " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \ |
4288f619 LP |
42 | " </interface>\n" |
43 | ||
44 | #define INTROSPECTION \ | |
45 | DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \ | |
46 | "<node>\n" \ | |
47 | BUS_UNIT_INTERFACE \ | |
48 | BUS_SWAP_INTERFACE \ | |
49 | BUS_PROPERTIES_INTERFACE \ | |
c4e2ceae | 50 | BUS_PEER_INTERFACE \ |
4288f619 LP |
51 | BUS_INTROSPECTABLE_INTERFACE \ |
52 | "</node>\n" | |
53 | ||
05feefe0 LP |
54 | #define INTERFACES_LIST \ |
55 | BUS_UNIT_INTERFACES_LIST \ | |
56 | "org.freedesktop.systemd1.Swap\0" | |
57 | ||
9a60da28 | 58 | const char bus_swap_interface[] _introspect_("Swap") = BUS_SWAP_INTERFACE; |
07b0b134 | 59 | |
c4e2ceae LP |
60 | const char bus_swap_invalidating_properties[] = |
61 | "What\0" | |
62 | "Priority\0" | |
15412f29 LP |
63 | "ExecActivate\0" |
64 | "ExecDeactivate\0" | |
e1770af8 LP |
65 | "ControlPID\0" |
66 | "Result\0"; | |
c4e2ceae | 67 | |
bfebab7f | 68 | static int bus_swap_append_priority(DBusMessageIter *i, const char *property, void *data) { |
4e85aff4 LP |
69 | Swap *s = data; |
70 | dbus_int32_t j; | |
71 | ||
4e85aff4 LP |
72 | assert(i); |
73 | assert(property); | |
74 | assert(s); | |
75 | ||
76 | if (s->from_proc_swaps) | |
77 | j = s->parameters_proc_swaps.priority; | |
78 | else if (s->from_fragment) | |
79 | j = s->parameters_fragment.priority; | |
4e85aff4 LP |
80 | else |
81 | j = -1; | |
82 | ||
83 | if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &j)) | |
84 | return -ENOMEM; | |
85 | ||
86 | return 0; | |
87 | } | |
88 | ||
e1770af8 LP |
89 | static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_swap_append_swap_result, swap_result, SwapResult); |
90 | ||
d200735e MS |
91 | static const BusProperty bus_swap_properties[] = { |
92 | { "What", bus_property_append_string, "s", offsetof(Swap, what), true }, | |
93 | { "Priority", bus_swap_append_priority, "i", 0 }, | |
94 | BUS_EXEC_COMMAND_PROPERTY("ExecActivate", offsetof(Swap, exec_command[SWAP_EXEC_ACTIVATE]), false), | |
95 | BUS_EXEC_COMMAND_PROPERTY("ExecDeactivate", offsetof(Swap, exec_command[SWAP_EXEC_DEACTIVATE]), false), | |
96 | { "ControlPID", bus_property_append_pid, "u", offsetof(Swap, control_pid) }, | |
e1770af8 | 97 | { "Result", bus_swap_append_swap_result,"s", offsetof(Swap, result) }, |
d200735e MS |
98 | { NULL, } |
99 | }; | |
100 | ||
5e8d1c9a | 101 | DBusHandlerResult bus_swap_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) { |
ac155bb8 | 102 | Swap *s = SWAP(u); |
d200735e MS |
103 | const BusBoundProperties bps[] = { |
104 | { "org.freedesktop.systemd1.Unit", bus_unit_properties, u }, | |
105 | { "org.freedesktop.systemd1.Swap", bus_swap_properties, s }, | |
106 | { "org.freedesktop.systemd1.Swap", bus_exec_context_properties, &s->exec_context }, | |
4819ff03 | 107 | { "org.freedesktop.systemd1.Swap", bus_kill_context_properties, &s->kill_context }, |
d200735e | 108 | { NULL, } |
07b0b134 ML |
109 | }; |
110 | ||
d200735e | 111 | return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps); |
07b0b134 | 112 | } |