aboutsummaryrefslogtreecommitdiff
path: root/src/lib/include
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2015-03-11 11:51:01 +0100
committerAlex Auvolat <alex@adnab.me>2015-03-11 11:51:01 +0100
commitbde334e6393b142d9953328e9ea2881ce88a1a7b (patch)
treef3ed7bbc6c8a534fccbd2cf653e7ecb1f24b9fd4 /src/lib/include
parentaa5e2760711c092e1235105ebf097ac594512370 (diff)
downloadkogata-bde334e6393b142d9953328e9ea2881ce88a1a7b.tar.gz
kogata-bde334e6393b142d9953328e9ea2881ce88a1a7b.zip
Begin work on GIP (Graphics Initiation Protocol)
Diffstat (limited to 'src/lib/include')
-rw-r--r--src/lib/include/gip.h55
-rw-r--r--src/lib/include/mainloop.h47
-rw-r--r--src/lib/include/proto/gip.h118
3 files changed, 220 insertions, 0 deletions
diff --git a/src/lib/include/gip.h b/src/lib/include/gip.h
new file mode 100644
index 0000000..98b4655
--- /dev/null
+++ b/src/lib/include/gip.h
@@ -0,0 +1,55 @@
+#pragma once
+
+// Not thread safe
+
+#include <hashtbl.h>
+
+#include <proto/gip.h>
+#include <mainloop.h>
+
+typedef struct gip_handler gip_handler_t;
+
+typedef void (*noarg_gip_callback_t)(gip_handler_t *s, gip_msg_header *m);
+typedef void (*gip_reply_callback_t)(gip_handler_t *s, gip_msg_header *m, void* data);
+
+typedef struct {
+ noarg_gip_callback_t
+ reset, initiate, ok, failure,
+ enable_features, disable_features,
+ query_mode, set_mode, switch_buffer;
+ void (*buffer_info)(gip_handler_t *s, gip_msg_header *m, gip_buffer_info_msg *i);
+ void (*mode_info)(gip_handler_t *s, gip_msg_header *m, gip_mode_info_msg *i);
+ void (*buffer_damage)(gip_handler_t *s, gip_msg_header *m, gip_buffer_damage_msg *i);
+ void (*unknown_msg)(gip_handler_t *s, gip_msg_header *m);
+ void (*fd_error)(gip_handler_t *s);
+} gip_handler_callbacks_t;
+
+typedef struct gip_handler {
+ gip_handler_callbacks_t* cb;
+ void* data;
+
+ gip_msg_header msg_buf;
+ gip_buffer_info_msg buffer_info_msg_buf;
+ gip_mode_info_msg mode_info_msg_buf;
+ gip_buffer_damage_msg buffer_damage_msg_buf;
+
+ hashtbl_t *requests_in_progress;
+ uint32_t next_req_id;
+
+ mainloop_fd_t mainloop_item;
+} gip_handler_t;
+
+gip_handler_t *new_gip_handler(gip_handler_callbacks_t *cb, void* data);
+void delete_gip_handler(gip_handler_t *h);
+
+// GIP send messages
+
+bool gip_cmd(gip_handler_t *h, gip_msg_header *msg, void* msg_data, gip_reply_callback_t cb, void* cb_data);
+
+bool gip_reply(gip_handler_t *h, gip_msg_header *orig_request, gip_msg_header *msg, void* msg_data);
+bool gip_reply_fail(gip_handler_t *h, gip_msg_header *o);
+bool gip_reply_ok(gip_handler_t *h, gip_msg_header *o);
+
+bool gip_notify(gip_handler_t *h, gip_msg_header *msg, void* msg_data);
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/include/mainloop.h b/src/lib/include/mainloop.h
new file mode 100644
index 0000000..1e71ffb
--- /dev/null
+++ b/src/lib/include/mainloop.h
@@ -0,0 +1,47 @@
+#pragma once
+
+// These functions are not thread safe, their purpose
+// is to multiplex several IO operations on a
+// single thread.
+
+#include <syscall.h>
+
+#define MAINLOOP_MAX_WR_BUFS 4
+
+typedef struct mainloop_fd mainloop_fd_t;
+
+typedef void (*buf_full_callback_t)(mainloop_fd_t *fd);
+typedef void (*fd_error_callback_t)(mainloop_fd_t *fd);
+
+typedef struct {
+ size_t size, written;
+ void* buf;
+ bool must_free;
+} mainloop_wr_buf_t;
+
+typedef struct mainloop_fd {
+ fd_t fd;
+
+ size_t rd_buf_expect_size, rd_buf_filled;
+ void* rd_buf;
+
+ mainloop_wr_buf_t wr_bufs[MAINLOOP_MAX_WR_BUFS];
+
+ void* data;
+
+ buf_full_callback_t rd_on_full;
+ fd_error_callback_t on_error;
+
+ mainloop_fd_t *next;
+} mainloop_fd_t;
+
+void mainloop_add_fd(mainloop_fd_t* fd);
+void mainloop_rm_fd(mainloop_fd_t* fd);
+
+void mainloop_expect(mainloop_fd_t *fd, void* buf, size_t size, buf_full_callback_t cb);
+bool mainloop_nonblocking_write(mainloop_fd_t *fd, void* buf, size_t size, bool must_free_buf);
+
+void mainloop_run();
+void mainloop_exit();
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/include/proto/gip.h b/src/lib/include/proto/gip.h
new file mode 100644
index 0000000..f79e29f
--- /dev/null
+++ b/src/lib/include/proto/gip.h
@@ -0,0 +1,118 @@
+#pragma once
+
+#include <proto/fb.h>
+
+#include <syscall.h>
+
+/*
+ Definition of the GIP protocol (Graphics Initiation Protocol).
+ This is a protocol meant for communication on a local machine between
+ a process providing a graphics window (screen & input) and a client
+ process that does user interaction.
+
+ Examples :
+ - giosrv makes the hardware available as a GIP server
+ - the login manager is a GIP client of giosrv
+ - the user window manager is a GIP client of the login manager
+ (when a user session is active, the login manager is mostly a GIP proxy,
+ but it intercepts the Ctrl+Alt+Del keyboard shortcut to terminate/lock
+ the active user session)
+ - each window managed by the WM acts as a GIP server.
+ - the GUI library basically knows how to be a GIP client that does actually
+ usefull stuff (displaying a gui)
+
+ Features of the GIP protocol for OUTPUT :
+ - as an option, mode setting (for when the buffer is a display)
+ - as an option, buffer resizing (for when the buffer is a window)
+ TODO: interacts somehow with WMP (window managing protocol)
+ - server-side allocation of a framebuffer
+ - as an option, double buffering (server allocates two buffers,
+ client tells server to switch buffers)
+ - "buffer damage" notification from clients on active buffer,
+ (not necessary, and disabled, when the buffer is actually the
+ display output itself)
+ (a buffer switch request implies a global buffer damage notification)
+
+ Features of the GIP protocol for KEYBOARD INPUT :
+ - raw keycode notification from server on keypress/keyrelease
+
+ Features of the GIP protocol for MOUSE INPUT :
+ - as an option, raw mouse data input
+ - as an option, mouse data parsing & notification in terms
+ of (mouse_x, mouse_y)
+ - as an option, cursor display handling (server mouse data
+ parsing must be enabled)
+
+ The active/inactive features are defined on a per-GIP-channel basis.
+
+ Typical GIP session :
+ - C: RESET
+ - S: INTIATE (available features)
+ - S: BUFFER_INFO (base buffer)
+ - C: ENABLE_FEATURES (desired features)
+ - S: OK
+ - S: BUFFER_INFO (double buffering is enabled! new buffers needed)
+ - C: draws on buffer 1
+ - C: SWITCH_BUFFER 1
+ - S does not answer to SWITCH_BUFFER messages (they happen too often!)
+ - C: draws on buffer 0
+ - C: SWITCH_BUFFER 0
+ - ...
+ */
+
+// GIP features
+#define GIPF_DOUBLE_BUFFER 0x01
+#define GIPF_DAMAGE_NOTIF 0x02
+#define GIPF_MODESET 0x04
+// #define GIP_F_RESIZING 0x08 // TODO semantics for this shit
+#define GIPF_MOUSE_XY 0x10
+#define GIPF_MOUSE_CURSOR 0x20
+
+// GIP message IDs
+// ---- GIPC : commands, expect a reply
+// ---- GIPR : reply to a command
+// ---- GIPN : notification, no reply expected
+#define GIPC_RESET 0 // client: plz open new session
+#define GIPR_INITIATE 1 // server: ok, here is supported feature list
+#define GIPR_OK 2
+#define GIPR_FAILURE 3
+#define GIPC_ENABLE_FEATURES 4
+#define GIPC_DISABLE_FEATURES 5
+
+#define GIPN_BUFFER_INFO 10 // server: buffer #i is at #token and has #geom
+#define GIPC_QUERY_MODE 11 // client: what about mode #i?
+#define GIPR_MODE_INFO 12 // server: mode #i is xxyy
+#define GIPC_SET_MODE 13 // client: please switch to mode #i
+#define GIPN_BUFFER_DAMAGE 14 // client: please update region
+#define GIPC_SWITCH_BUFFER 15 // client: please switch to buffer b (0 or 1)
+
+#define GIPN_KEY_DOWN 20 // server: key k down
+#define GIPN_KEY_UP 21 // server: key k up
+
+#define GIPN_MOUSE_DATA 30 // server: raw mouse data
+#define GIPN_MOUSE_XY 31 // server: mouse moved at xy ; client: put mouse at xy
+#define GIPN_MOUSE_PRESSED 32 // server: button b pressed
+#define GIPN_MOUSE_RELEASED 33 // server: button b released
+#define GIPC_LOAD_CURSOR 34 // client: this is graphics for cursor #i
+#define GIPC_SET_CURSOR 35 // client: please use cursor #i (0 = hide cursor)
+
+typedef struct {
+ uint32_t code; // message type
+ uint32_t req_id; // for reply messages, code of the reply
+ uint32_t arg;
+} gip_msg_header;
+
+typedef struct {
+ token_t tok;
+ framebuffer_info_t geom;
+} gip_buffer_info_msg;
+
+typedef struct {
+ framebuffer_info_t geom;
+} gip_mode_info_msg;
+
+typedef struct {
+ uint32_t x, y, w, h;
+} gip_buffer_damage_msg;
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/