swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit 3ac3712ef45aee47da8b49c9f5e56490a6a42ae9
parent 6cc5eba3b6f014bee710ae4767bd1201657b1d57
Author: Michael Forney <mforney@mforney.org>
Date:   Fri, 21 Jun 2013 01:16:49 -0700

Add launch-related utility functions

Diffstat:
MMakefile.am | 2+-
Mutil.c | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Mutil.h | 4++++
3 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am @@ -27,7 +27,7 @@ libswc_la_SOURCES = \ libswc_la_LIBADD = $(wayland_server_LIBS) $(udev_LIBS) $(xkbcommon_LIBS) \ $(drm_LIBS) $(drm_intel_LIBS) $(gbm_LIBS) $(egl_LIBS) $(pixman_LIBS) \ - intel/libintel.la + intel/libintel.la launch/liblaunch-protocol.la SUBDIRS = launch intel diff --git a/util.c b/util.c @@ -1,10 +1,62 @@ #include "util.h" +#include "launch/protocol.h" #include <stdlib.h> #include <stdio.h> +#include <string.h> +#include <drm.h> +#include <sys/socket.h> void swc_remove_resource(struct wl_resource * resource) { wl_list_remove(wl_resource_get_link(resource)); } +bool swc_launch_drm_master(int socket, int fd, bool set) +{ + ssize_t size; + struct swc_launch_request request; + struct swc_launch_response response; + + request.type = SWC_LAUNCH_REQUEST_DRM_MASTER; + request.set = set; + + size = send_fd(socket, fd, &request, sizeof request); + + if (size == -1) + return false; + + size = recv(socket, &response, sizeof response, 0); + + if (size == -1) + return false; + + return true; +} + +int swc_launch_open_input_device(int socket, const char * path, int flags) +{ + size_t path_size = strlen(path); + char buffer[sizeof(struct swc_launch_request) + path_size + 1]; + struct swc_launch_request * request = (void *) buffer; + struct swc_launch_response response; + ssize_t size; + int fd; + + request->type = SWC_LAUNCH_REQUEST_OPEN_INPUT_DEVICE; + request->flags = flags; + strcpy(request->path, path); + + size = send(socket, buffer, sizeof buffer, 0); + + if (size == -1) + return -1; + + size = receive_fd(socket, &fd, &response, sizeof response); + + if (size == -1) + return -1; + + return fd; +} + diff --git a/util.h b/util.h @@ -1,9 +1,13 @@ #ifndef SWC_UTIL_H #define SWC_UTIL_H 1 +#include <stdbool.h> #include <wayland-server.h> void swc_remove_resource(struct wl_resource * resource); +int swc_launch_open_input_device(int socket, const char * path, int flags); +bool swc_launch_drm_master(int socket, int fd, bool set); + #endif