[core] stub for events api

This commit is contained in:
Milo Turner 2020-02-20 12:05:51 -05:00
parent 4b069080f9
commit 12fab7029a
5 changed files with 50 additions and 1 deletions

View File

@ -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_LOADING 1
#define AX_ERR_THEME_INVALID 2 #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 * Windows
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */

View File

@ -51,6 +51,14 @@ void msgq_begin_recv(struct msgq* mq)
pthread_mutex_lock(&mq->mx); 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) void* msgq_recv1(struct msgq* mq, int* out_type)
{ {
if (mq->head == NULL) { if (mq->head == NULL) {

View File

@ -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_end_send(struct msgq* mq);
void msgq_begin_recv(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_recv1(struct msgq* mq, int* out_type);
void msgq_end_recv(struct msgq* mq); void msgq_end_recv(struct msgq* mq);

View File

@ -5,6 +5,7 @@
#include "../ctxt.h" #include "../ctxt.h"
#include "../util.h" #include "../util.h"
#include "theme.h" #include "theme.h"
#include <unistd.h>
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* API functions :: init / cleanup * API functions :: init / cleanup
@ -167,6 +168,21 @@ int ax_select_theme(struct ax_ctxt* ax, struct ax_theme* thm)
return 0; 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 * Backend worker thread
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */

View File

@ -41,7 +41,12 @@ int main(void)
(void) make_example_theme(); (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(); cleanup();
return 0; return 0;