1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2011 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include "logind-seat.h"
26 #include "dbus-common.h"
29 #define BUS_SEAT_INTERFACE \
30 " <interface name=\"org.freedesktop.login1.Seat\">\n" \
31 " <method name=\"Terminate\"/>\n" \
32 " <property name=\"Id\" type=\"s\" access=\"read\"/>\n" \
33 " <property name=\"Active\" type=\"so\" access=\"read\"/>\n" \
34 " <property name=\"Sessions\" type=\"a(so)\" access=\"read\"/>\n" \
37 #define INTROSPECTION \
38 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
41 BUS_PROPERTIES_INTERFACE \
43 BUS_INTROSPECTABLE_INTERFACE \
46 #define INTERFACES_LIST \
47 BUS_GENERIC_INTERFACES_LIST \
48 "org.freedesktop.login1.Seat\0"
50 static int bus_seat_append_active(DBusMessageIter *i, const char *property, void *data) {
53 const char *id, *path;
60 if (!dbus_message_iter_open_container(i, DBUS_TYPE_STRUCT, NULL, &sub))
65 path = p = session_bus_path(s->active);
74 if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &id) ||
75 !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path)) {
82 if (!dbus_message_iter_close_container(i, &sub))
88 static int bus_seat_append_sessions(DBusMessageIter *i, const char *property, void *data) {
89 DBusMessageIter sub, sub2;
97 if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "so", &sub))
100 LIST_FOREACH(sessions_by_seat, session, s->sessions) {
103 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
106 p = session_bus_path(session);
110 if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &session->id) ||
111 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &p)) {
118 if (!dbus_message_iter_close_container(&sub, &sub2))
122 if (!dbus_message_iter_close_container(i, &sub))
128 static int get_seat_for_path(Manager *m, const char *path, Seat **_s) {
136 if (!startswith(path, "/org/freedesktop/login1/seat/"))
139 id = bus_path_unescape(path + 29);
143 s = hashmap_get(m->seats, id);
153 static DBusHandlerResult seat_message_dispatch(
155 DBusConnection *connection,
156 DBusMessage *message) {
158 const BusProperty properties[] = {
159 { "org.freedesktop.login1.Seat", "Id", bus_property_append_string, "s", s->id },
160 { "org.freedesktop.login1.Seat", "Active", bus_seat_append_active, "(so)", s },
161 { "org.freedesktop.login1.Seat", "Sessions", bus_seat_append_sessions, "a(so)", s },
162 { NULL, NULL, NULL, NULL, NULL }
169 return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, properties);
172 static DBusHandlerResult seat_message_handler(
173 DBusConnection *connection,
174 DBusMessage *message,
177 Manager *m = userdata;
181 r = get_seat_for_path(m, dbus_message_get_path(message), &s);
185 return DBUS_HANDLER_RESULT_NEED_MEMORY;
191 dbus_set_error_const(&e, DBUS_ERROR_UNKNOWN_OBJECT, "Unknown seat");
192 return bus_send_error_reply(connection, message, &e, r);
195 return bus_send_error_reply(connection, message, NULL, r);
198 return seat_message_dispatch(s, connection, message);
201 const DBusObjectPathVTable bus_seat_vtable = {
202 .message_function = seat_message_handler
205 char *seat_bus_path(Seat *s) {
210 t = bus_path_escape(s->id);
214 r = strappend("/org/freedesktop/login1/seat/", t);