logind-seat-dbus.c revision d200735e13c52dcfe36c0e066f9f6c2fbfb85a9c
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <string.h>
#include "logind.h"
#include "logind-seat.h"
#include "dbus-common.h"
#include "util.h"
#define BUS_SEAT_INTERFACE \
" <interface name=\"org.freedesktop.login1.Seat\">\n" \
" <method name=\"Terminate\"/>\n" \
" <method name=\"ActivateSession\">\n" \
" <arg name=\"id\" type=\"s\"/>\n" \
" </method>\n" \
" <property name=\"Id\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"ActiveSession\" type=\"so\" access=\"read\"/>\n" \
" <property name=\"CanMultiSession\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"Sessions\" type=\"a(so)\" access=\"read\"/>\n" \
" <property name=\"IdleHint\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"IdleSinceHint\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"IdleSinceHintMonotonic\" type=\"t\" access=\"read\"/>\n" \
" </interface>\n" \
#define INTROSPECTION \
"<node>\n" \
"</node>\n"
#define INTERFACES_LIST \
"org.freedesktop.login1.Seat\0"
char *p = NULL;
assert(i);
assert(s);
return -ENOMEM;
if (s->active) {
if (!p)
return -ENOMEM;
} else {
id = "";
path = "/";
}
free(p);
return -ENOMEM;
}
free(p);
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
assert(i);
assert(s);
return -ENOMEM;
char *p;
return -ENOMEM;
p = session_bus_path(session);
if (!p)
return -ENOMEM;
free(p);
return -ENOMEM;
}
free(p);
return -ENOMEM;
}
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
dbus_bool_t b;
assert(i);
assert(s);
b = seat_can_multi_session(s);
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
return -ENOMEM;
return 0;
}
dbus_bool_t b;
assert(i);
assert(s);
b = seat_get_idle_hint(s, NULL) > 0;
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
return -ENOMEM;
return 0;
}
uint64_t k;
assert(i);
assert(s);
seat_get_idle_hint(s, &t);
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &k))
return -ENOMEM;
return 0;
}
Seat *s;
char *id;
assert(m);
return -EINVAL;
if (!id)
return -ENOMEM;
if (!s)
return -ENOENT;
*_s = s;
return 0;
}
static const BusProperty bus_login_seat_properties[] = {
{ NULL, }
};
Seat *s,
DBusMessage *message) {
int r;
assert(s);
r = seat_stop_sessions(s);
if (r < 0)
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Seat", "ActivateSession")) {
const char *name;
if (!dbus_message_get_args(
&error,
r = session_activate(session);
if (r < 0)
if (!reply)
goto oom;
} else {
const BusBoundProperties bps[] = {
{ "org.freedesktop.login1.Seat", bus_login_seat_properties, s },
{ NULL, }
};
}
if (reply) {
goto oom;
}
return DBUS_HANDLER_RESULT_HANDLED;
oom:
if (reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
void *userdata) {
Seat *s;
int r;
if (r < 0) {
if (r == -ENOMEM)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if (r == -ENOENT) {
DBusError e;
dbus_error_init(&e);
}
}
}
const DBusObjectPathVTable bus_seat_vtable = {
};
char *seat_bus_path(Seat *s) {
char *t, *r;
assert(s);
t = bus_path_escape(s->id);
if (!t)
return NULL;
r = strappend("/org/freedesktop/login1/seat/", t);
free(t);
return r;
}
DBusMessage *m;
int r = -ENOMEM;
char *p = NULL;
assert(s);
m = dbus_message_new_signal("/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
if (!m)
return -ENOMEM;
p = seat_bus_path(s);
if (!p)
goto finish;
if (!dbus_message_append_args(
m,
DBUS_TYPE_STRING, &s->id,
goto finish;
goto finish;
r = 0;
free(p);
return r;
}
DBusMessage *m;
int r = -ENOMEM;
char *p = NULL;
assert(s);
if (!s->started)
return 0;
p = seat_bus_path(s);
if (!p)
return -ENOMEM;
if (!m)
goto finish;
goto finish;
r = 0;
if (m)
free(p);
return r;
}