diff options
| author | onelin <oscar@nelin.dk> | 2026-05-01 17:28:07 +0000 |
|---|---|---|
| committer | onelin <oscar@nelin.dk> | 2026-05-01 17:28:07 +0000 |
| commit | 4332b32f6007d3c50f043972f16a55af65caa998 (patch) | |
| tree | c04988d9f5be3690fbd71bc1289f1eb6769e4ad8 /status_update.c | |
| parent | 02f1cdaaf6660e70d3a609f0e0ec397287777303 (diff) | |
Add message queue and controller source program
Diffstat (limited to 'status_update.c')
| -rw-r--r-- | status_update.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/status_update.c b/status_update.c new file mode 100644 index 0000000..e4abda8 --- /dev/null +++ b/status_update.c @@ -0,0 +1,54 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <err.h> +#include <fcntl.h> +#include <mqueue.h> + +#include "config.h" + +int main (int argc, char* argv[]) { + struct message_t msg = {.action = nop, .element = ELEMENT_INVALID}; + char* queue_identifier; + + + if (argc != 3) { + errx(EXIT_FAILURE, "Invalid argument(s): %s ACTION ELEMENT\n", argv[0]); + } + + if (!strcmp(argv[1], "update")) { + msg.action = update; + } else { + errx(EXIT_FAILURE, "Invalid action\n"); + } + +#define ELEMENT(name, _arg, _minutes, _seconds) \ + else if (!strcmp(argv[2], #name)) { \ + msg.element = ELEMENT_##name; \ + } + + if (!strcmp(argv[2], "all")) { + msg.element = ELEMENT_MAX; \ + } +#include "config.def.h" +#undef ELEMENT + else { + errx(EXIT_FAILURE, "Invalid element\n"); + } + + queue_identifier = "/status"; + mqd_t msg_queue_id = mq_open(queue_identifier, O_WRONLY); + if (msg_queue_id == -1) { + errx(EXIT_FAILURE, "Failed to open mq\n"); + } + + + if (mq_send(msg_queue_id, (char*)&msg, sizeof(struct message_t), 0) == -1) { + err(EXIT_FAILURE, "Failed to send message\n"); + } + + mq_close(msg_queue_id); + + return 0; +} |
