commit 3ac3712

Michael Forney  ·  2013-06-21 08:16:49 +0000 UTC
parent 6cc5eba
Add launch-related utility functions
3 files changed,  +57, -1
M util.c
M util.h
+1, -1
1@@ -27,7 +27,7 @@ libswc_la_SOURCES = \
2 
3 libswc_la_LIBADD = $(wayland_server_LIBS) $(udev_LIBS) $(xkbcommon_LIBS) \
4 	$(drm_LIBS) $(drm_intel_LIBS) $(gbm_LIBS) $(egl_LIBS) $(pixman_LIBS) \
5-	intel/libintel.la
6+	intel/libintel.la launch/liblaunch-protocol.la
7 
8 SUBDIRS = launch intel
9 
M util.c
+52, -0
 1@@ -1,10 +1,62 @@
 2 #include "util.h"
 3+#include "launch/protocol.h"
 4 
 5 #include <stdlib.h>
 6 #include <stdio.h>
 7+#include <string.h>
 8+#include <drm.h>
 9+#include <sys/socket.h>
10 
11 void swc_remove_resource(struct wl_resource * resource)
12 {
13     wl_list_remove(wl_resource_get_link(resource));
14 }
15 
16+bool swc_launch_drm_master(int socket, int fd, bool set)
17+{
18+    ssize_t size;
19+    struct swc_launch_request request;
20+    struct swc_launch_response response;
21+
22+    request.type = SWC_LAUNCH_REQUEST_DRM_MASTER;
23+    request.set = set;
24+
25+    size = send_fd(socket, fd, &request, sizeof request);
26+
27+    if (size == -1)
28+        return false;
29+
30+    size = recv(socket, &response, sizeof response, 0);
31+
32+    if (size == -1)
33+        return false;
34+
35+    return true;
36+}
37+
38+int swc_launch_open_input_device(int socket, const char * path, int flags)
39+{
40+    size_t path_size = strlen(path);
41+    char buffer[sizeof(struct swc_launch_request) + path_size + 1];
42+    struct swc_launch_request * request = (void *) buffer;
43+    struct swc_launch_response response;
44+    ssize_t size;
45+    int fd;
46+
47+    request->type = SWC_LAUNCH_REQUEST_OPEN_INPUT_DEVICE;
48+    request->flags = flags;
49+    strcpy(request->path, path);
50+
51+    size = send(socket, buffer, sizeof buffer, 0);
52+
53+    if (size == -1)
54+        return -1;
55+
56+    size = receive_fd(socket, &fd, &response, sizeof response);
57+
58+    if (size == -1)
59+        return -1;
60+
61+    return fd;
62+}
63+
M util.h
+4, -0
 1@@ -1,9 +1,13 @@
 2 #ifndef SWC_UTIL_H
 3 #define SWC_UTIL_H 1
 4 
 5+#include <stdbool.h>
 6 #include <wayland-server.h>
 7 
 8 void swc_remove_resource(struct wl_resource * resource);
 9 
10+int swc_launch_open_input_device(int socket, const char * path, int flags);
11+bool swc_launch_drm_master(int socket, int fd, bool set);
12+
13 #endif
14