diff options
author | Marvin Borner | 2021-02-11 23:03:49 +0100 |
---|---|---|
committer | Marvin Borner | 2021-02-11 23:03:49 +0100 |
commit | 9a601884193dda4fd259d715392889402e477419 (patch) | |
tree | 16841762b3b22be6cedd01212cdb64013d0154f6 | |
parent | 802dbd9134b0902e1072ef35b443e150e11facc3 (diff) |
Added msging
-rw-r--r-- | libgui/inc/msg.h | 34 | ||||
-rw-r--r-- | libgui/msg.c | 25 |
2 files changed, 59 insertions, 0 deletions
diff --git a/libgui/inc/msg.h b/libgui/inc/msg.h new file mode 100644 index 0000000..e120b70 --- /dev/null +++ b/libgui/inc/msg.h @@ -0,0 +1,34 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef MSG_H +#define MSG_H + +#include <def.h> + +#define MSG_MAGIC 0x42042069 + +struct message { + u32 magic; + int src; + int type; + void *data; +}; + +enum message_type { + // GFX + GFX_NEW_CONTEXT, + GFX_REDRAW, + GFX_REDRAW_FOCUSED, + + // GUI + GUI_KILL, + GUI_KEYBOARD, + GUI_MOUSE, + GUI_RESIZE, + GUI_MAX +}; + +int msg_send(u32 pid, enum message_type, void *data); +int msg_receive(struct message *msg); + +#endif diff --git a/libgui/msg.c b/libgui/msg.c new file mode 100644 index 0000000..6898121 --- /dev/null +++ b/libgui/msg.c @@ -0,0 +1,25 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#include <assert.h> +#include <msg.h> +#include <print.h> +#include <sys.h> + +int msg_send(u32 pid, enum message_type type, void *data) +{ + assert((signed)pid != -1); + char path[32] = { 0 }; + sprintf(path, "/proc/%d/msg", pid); + struct message msg = { .magic = MSG_MAGIC, .src = getpid(), .type = type, .data = data }; + return write(path, &msg, 0, sizeof(msg)); +} + +int msg_receive(struct message *msg) +{ + int ret = read("/proc/self/msg", msg, 0, sizeof(*msg)); + assert(msg->magic == MSG_MAGIC); + if (msg->magic == MSG_MAGIC && ret == sizeof(*msg)) + return ret; + else + return -1; +} |