]>
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 | |
10 | under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2 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 | General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
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" | |
27 | ||
4288f619 LP |
28 | #define BUS_SWAP_INTERFACE \ |
29 | " <interface name=\"org.freedesktop.systemd1.Swap\">\n" \ | |
30 | " <property name=\"What\" type=\"s\" access=\"read\"/>\n" \ | |
31 | " <property name=\"Priority\" type=\"i\" access=\"read\"/>\n" \ | |
32 | " </interface>\n" | |
33 | ||
34 | #define INTROSPECTION \ | |
35 | DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \ | |
36 | "<node>\n" \ | |
37 | BUS_UNIT_INTERFACE \ | |
38 | BUS_SWAP_INTERFACE \ | |
39 | BUS_PROPERTIES_INTERFACE \ | |
40 | BUS_INTROSPECTABLE_INTERFACE \ | |
41 | "</node>\n" | |
42 | ||
43 | const char bus_swap_interface[] = BUS_SWAP_INTERFACE; | |
07b0b134 | 44 | |
4e85aff4 LP |
45 | static int bus_swap_append_priority(Manager *m, DBusMessageIter *i, const char *property, void *data) { |
46 | Swap *s = data; | |
47 | dbus_int32_t j; | |
48 | ||
49 | assert(m); | |
50 | assert(i); | |
51 | assert(property); | |
52 | assert(s); | |
53 | ||
54 | if (s->from_proc_swaps) | |
55 | j = s->parameters_proc_swaps.priority; | |
56 | else if (s->from_fragment) | |
57 | j = s->parameters_fragment.priority; | |
58 | else if (s->from_etc_fstab) | |
59 | j = s->parameters_etc_fstab.priority; | |
60 | else | |
61 | j = -1; | |
62 | ||
63 | if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &j)) | |
64 | return -ENOMEM; | |
65 | ||
66 | return 0; | |
67 | } | |
68 | ||
5e8d1c9a | 69 | DBusHandlerResult bus_swap_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) { |
07b0b134 ML |
70 | const BusProperty properties[] = { |
71 | BUS_UNIT_PROPERTIES, | |
4e85aff4 LP |
72 | { "org.freedesktop.systemd1.Swap", "What", bus_property_append_string, "s", u->swap.what }, |
73 | { "org.freedesktop.systemd1.Swap", "Priority", bus_swap_append_priority, "i", u }, | |
07b0b134 ML |
74 | { NULL, NULL, NULL, NULL, NULL } |
75 | }; | |
76 | ||
5e8d1c9a | 77 | return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties); |
07b0b134 | 78 | } |