chiark / gitweb /
build-sys: move source files to subdirectory
[elogind.git] / src / dbus-swap.c
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
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
23 #include <errno.h>
24
25 #include "dbus-unit.h"
26 #include "dbus-swap.h"
27
28 static const char introspection[] =
29         DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
30         "<node>"
31         BUS_UNIT_INTERFACE
32         BUS_PROPERTIES_INTERFACE
33         " <interface name=\"org.freedesktop.systemd1.Swap\">"
34         "  <property name=\"What\" type=\"s\" access=\"read\"/>"
35         "  <property name=\"Priority\" type=\"i\" access=\"read\"/>"
36         " </interface>"
37         BUS_INTROSPECTABLE_INTERFACE
38         "</node>";
39
40 static int bus_swap_append_priority(Manager *m, DBusMessageIter *i, const char *property, void *data) {
41         Swap *s = data;
42         dbus_int32_t j;
43
44         assert(m);
45         assert(i);
46         assert(property);
47         assert(s);
48
49         if (s->from_proc_swaps)
50                 j = s->parameters_proc_swaps.priority;
51         else if (s->from_fragment)
52                 j = s->parameters_fragment.priority;
53         else if (s->from_etc_fstab)
54                 j = s->parameters_etc_fstab.priority;
55         else
56                 j = -1;
57
58         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, &j))
59                 return -ENOMEM;
60
61         return 0;
62 }
63
64 DBusHandlerResult bus_swap_message_handler(Unit *u, DBusMessage *message) {
65         const BusProperty properties[] = {
66                 BUS_UNIT_PROPERTIES,
67                 { "org.freedesktop.systemd1.Swap", "What",     bus_property_append_string, "s", u->swap.what },
68                 { "org.freedesktop.systemd1.Swap", "Priority", bus_swap_append_priority,   "i", u            },
69                 { NULL, NULL, NULL, NULL, NULL }
70         };
71
72         return bus_default_message_handler(u->meta.manager, message, introspection, properties);
73 }