From 12fab7029a0092dc53570e7b15f0479d3d7bbdcd Mon Sep 17 00:00:00 2001 From: Milo Turner Date: Thu, 20 Feb 2020 12:05:51 -0500 Subject: [PATCH] [core] stub for events api --- src/ax.h | 19 +++++++++++++++++++ src/concurrent/msgq.c | 8 ++++++++ src/concurrent/msgq.h | 1 + src/ctxt/ctxt.c | 16 ++++++++++++++++ test/main.c | 7 ++++++- 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/ax.h b/src/ax.h index 78223b7..44eb4d1 100644 --- a/src/ax.h +++ b/src/ax.h @@ -40,6 +40,25 @@ int ax_select_theme(struct ax_ctxt* ax, struct ax_theme* thm); #define AX_ERR_THEME_LOADING 1 #define AX_ERR_THEME_INVALID 2 +/* ----------------------------------------------------------------------------- + * Events + * -------------------------------------------------------------------------- */ + +enum ax_evt_type { + AX_EVT_THEME_LOADED = 0, + AX_EVT__COUNT, +}; + +struct ax_evt { + enum ax_evt_type ty; + union { + struct ax_theme* theme; + } arg; +}; + +void ax_wait_evt_avail(struct ax_ctxt* ax); +bool ax_poll_evt(struct ax_ctxt* ax, struct ax_evt* out_evt); + /* ----------------------------------------------------------------------------- * Windows * -------------------------------------------------------------------------- */ diff --git a/src/concurrent/msgq.c b/src/concurrent/msgq.c index 55de30f..e314921 100644 --- a/src/concurrent/msgq.c +++ b/src/concurrent/msgq.c @@ -51,6 +51,14 @@ void msgq_begin_recv(struct msgq* mq) pthread_mutex_lock(&mq->mx); } +void msgq_begin_recv_and_wait(struct msgq* mq) +{ + pthread_mutex_lock(&mq->mx); + if (mq->head == NULL) { + pthread_cond_wait(&mq->cv, &mq->mx); + } +} + void* msgq_recv1(struct msgq* mq, int* out_type) { if (mq->head == NULL) { diff --git a/src/concurrent/msgq.h b/src/concurrent/msgq.h index 6cc4ea0..f406c00 100644 --- a/src/concurrent/msgq.h +++ b/src/concurrent/msgq.h @@ -25,6 +25,7 @@ void* msgq_begin_send(struct msgq* mq, int type, size_t payload_size); void msgq_end_send(struct msgq* mq); void msgq_begin_recv(struct msgq* mq); +void msgq_begin_recv_and_wait(struct msgq* mq); void* msgq_recv1(struct msgq* mq, int* out_type); void msgq_end_recv(struct msgq* mq); diff --git a/src/ctxt/ctxt.c b/src/ctxt/ctxt.c index cea28ed..15ddcb6 100644 --- a/src/ctxt/ctxt.c +++ b/src/ctxt/ctxt.c @@ -5,6 +5,7 @@ #include "../ctxt.h" #include "../util.h" #include "theme.h" +#include /* ----------------------------------------------------------------------------- * API functions :: init / cleanup @@ -167,6 +168,21 @@ int ax_select_theme(struct ax_ctxt* ax, struct ax_theme* thm) return 0; } +/* ----------------------------------------------------------------------------- + * API functions :: events + * -------------------------------------------------------------------------- */ + +void ax_wait_evt_avail(struct ax_ctxt* ax) +{ + usleep(1000 * 1000); +} + +bool ax_poll_evt(struct ax_ctxt* ax, struct ax_evt* out_evt) +{ + ax_log(ax, "nuffin."); + return false; +} + /* ----------------------------------------------------------------------------- * Backend worker thread * -------------------------------------------------------------------------- */ diff --git a/test/main.c b/test/main.c index e8abce9..c348b67 100644 --- a/test/main.c +++ b/test/main.c @@ -41,7 +41,12 @@ int main(void) (void) make_example_theme(); - usleep(5 * 1000 * 1000); + for (;;) { + ax_wait_evt_avail(ax); + while (ax_poll_evt(ax, NULL)) { + printf("Got an event, assuredly.\n"); + } + } cleanup(); return 0;