From 762ac7f4c0168bf2ce536d94b3b44cb95939d769 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Wed, 3 May 2017 14:11:22 +1200 Subject: New session interface. --- include/session/interface.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 include/session/interface.h (limited to 'include/session') diff --git a/include/session/interface.h b/include/session/interface.h new file mode 100644 index 00000000..5dde89f0 --- /dev/null +++ b/include/session/interface.h @@ -0,0 +1,20 @@ +#ifndef WLR_SESSION_INTERFACE_H +#define WLR_SESSION_INTERFACE_H + +struct wlr_session; + +struct session_interface { + struct wlr_session *(*start)(void); + void (*finish)(struct wlr_session *session); + int (*open)(struct wlr_session *restrict session, + const char *restrict path); + void (*close)(struct wlr_session *session, int fd); +}; + +struct wlr_session { + struct session_interface iface; +}; + +extern const struct session_interface session_logind_iface; + +#endif -- cgit v1.2.3 From 0002b8dd08fdab7da12127ad2f43238f376b1a7a Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Wed, 3 May 2017 19:26:43 +1200 Subject: Added 'direct' session backend --- include/session/interface.h | 1 + session/CMakeLists.txt | 1 + session/direct.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ session/session.c | 1 + 4 files changed, 53 insertions(+) create mode 100644 session/direct.c (limited to 'include/session') diff --git a/include/session/interface.h b/include/session/interface.h index 5dde89f0..a815718f 100644 --- a/include/session/interface.h +++ b/include/session/interface.h @@ -16,5 +16,6 @@ struct wlr_session { }; extern const struct session_interface session_logind_iface; +extern const struct session_interface session_direct_iface; #endif diff --git a/session/CMakeLists.txt b/session/CMakeLists.txt index 304f3220..bd83068b 100644 --- a/session/CMakeLists.txt +++ b/session/CMakeLists.txt @@ -4,6 +4,7 @@ include_directories( set(sources session.c + direct.c ) set(libs diff --git a/session/direct.c b/session/direct.c new file mode 100644 index 00000000..08a9b617 --- /dev/null +++ b/session/direct.c @@ -0,0 +1,50 @@ +#define _POSIX_C_SOURCE 200809L + +#include +#include +#include +#include +#include +#include + +#include "session/interface.h" +#include "common/log.h" + +struct direct_session { + struct wlr_session base; +}; + +static int direct_session_open(struct wlr_session *restrict base, + const char *restrict path) { + return open(path, O_RDWR | O_CLOEXEC); +} + +static void direct_session_close(struct wlr_session *base, int fd) { + close(fd); +} + +static void direct_session_finish(struct wlr_session *base) { + struct direct_session *session = wl_container_of(base, session, base); + + free(session); +} + +static struct wlr_session *direct_session_start(void) { + struct direct_session *session = calloc(1, sizeof(*session)); + if (!session) { + wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno)); + return NULL; + } + + wlr_log(L_INFO, "Successfully loaded direct session"); + + session->base.iface = session_direct_iface; + return &session->base; +} + +const struct session_interface session_direct_iface = { + .start = direct_session_start, + .finish = direct_session_finish, + .open = direct_session_open, + .close = direct_session_close, +}; diff --git a/session/session.c b/session/session.c index 2f1b87be..0562dbf7 100644 --- a/session/session.c +++ b/session/session.c @@ -9,6 +9,7 @@ static const struct session_interface *ifaces[] = { #ifdef HAS_SYSTEMD &session_logind_iface, #endif + &session_direct_iface, NULL, }; -- cgit v1.2.3