diff options
| author | dec05eba <dec05eba@protonmail.com> | 2026-08-02 01:11:33 +0200 |
|---|---|---|
| committer | dec05eba <dec05eba@protonmail.com> | 2026-08-02 01:11:53 +0200 |
| commit | d72113be395891f4289f0d86a32a37a99a4d5b38 (patch) | |
| tree | c2dd74d24fe62d1020be64980b8a321e999bcc29 /include/cli | |
| parent | b38d324c8fcb61b699a16c39fc0dcdb31ad9934b (diff) | |
Add -ipc option to control gpu-screen-recorder over a unix domain socket
The socket accepts the same commands as the signal handlers, except that
saving a replay takes an arbitrary number of seconds instead of only the
fixed times that the signals provide. Requests and replies are newline
terminated json objects and every request is replied to, parsed with the
sj.h json library that was added to external.
Requests are handled on a thread that only runs while the recorder
exists, so the recorder control fields are now atomics, which they have
to be now that another thread writes them.
Diffstat (limited to 'include/cli')
| -rw-r--r-- | include/cli/ipc.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/include/cli/ipc.h b/include/cli/ipc.h new file mode 100644 index 0000000..0862c71 --- /dev/null +++ b/include/cli/ipc.h @@ -0,0 +1,56 @@ +#ifndef GSR_CLI_IPC_H +#define GSR_CLI_IPC_H + +#include <stdbool.h> +#include <stddef.h> +#include <limits.h> +#include <pthread.h> + +#define GSR_IPC_MAX_CLIENTS 8 +#define GSR_IPC_MAX_REQUEST_SIZE 4096 +#define GSR_IPC_MAX_ERROR_MESSAGE_SIZE 256 + +/* + These are called from the ipc thread while the recording is running. + Return false and write a message to |error_message| to reply to the request with an error. +*/ +typedef struct { + bool (*stop)(char *error_message, size_t error_message_size, void *userdata); + bool (*toggle_pause)(char *error_message, size_t error_message_size, void *userdata); + bool (*toggle_replay_recording)(char *error_message, size_t error_message_size, void *userdata); + /* |seconds| is GSR_SAVE_REPLAY_SECONDS_FULL when the whole replay buffer should be saved */ + bool (*save_replay)(int seconds, char *error_message, size_t error_message_size, void *userdata); + void *userdata; +} gsr_ipc_handlers; + +typedef struct { + int fd; + char request[GSR_IPC_MAX_REQUEST_SIZE]; + size_t request_size; + bool request_too_large; +} gsr_ipc_client; + +/* Receives newline terminated json requests on a unix domain socket and replies to every request */ +typedef struct { + bool initialized; + int socket_fd; + bool socket_bound; + char socket_filepath[PATH_MAX]; + int wakeup_pipe[2]; + gsr_ipc_client clients[GSR_IPC_MAX_CLIENTS]; + int num_clients; + gsr_ipc_handlers handlers; + pthread_t thread; + bool thread_running; +} gsr_ipc; + +/* Returns a |gsr_error| value. Creates the socket, requests are not handled until gsr_ipc_start is called */ +int gsr_ipc_init(gsr_ipc *self, const char *socket_filepath); +void gsr_ipc_deinit(gsr_ipc *self); + +/* Returns a |gsr_error| value. Starts handling requests. Does nothing if |self| hasn't been initialized */ +int gsr_ipc_start(gsr_ipc *self, const gsr_ipc_handlers *handlers); +/* Stops handling requests. Does nothing if the ipc hasn't been started */ +void gsr_ipc_stop(gsr_ipc *self); + +#endif /* GSR_CLI_IPC_H */ |
