[core] completely nuke the event api

This commit is contained in:
Milo Turner 2020-02-21 14:37:32 -05:00
parent fe4b533f72
commit 6b939e44ee
6 changed files with 19 additions and 112 deletions

View File

@ -40,25 +40,6 @@ 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
* -------------------------------------------------------------------------- */

View File

@ -21,11 +21,6 @@ struct ax_ctxt {
struct rgn err_rgn;
const char* err;
// events
struct rgn evts_rgn;
struct ax_evt_list* evts;
struct msgq* inbox;
// backend
pthread_t bac_thid;
struct ax_backend* bac;

View File

@ -58,11 +58,6 @@ void ax__ctxt_init(struct ax_ctxt* ax, struct rgn* init_rgn)
rgn_pin(init_rgn, &ax->err_rgn, (void*) rgn_cleanup);
ax->err = "";
rgn_init(&ax->evts_rgn, SMALL);
rgn_pin(init_rgn, &ax->evts_rgn, (void*) rgn_cleanup);
ax->evts = NULL;
ax->inbox = msgq_new(init_rgn);
rgn_init(&ax->thmb_rgn, THEME_BUILDER_DESIRED_REGION_SIZE);
rgn_pin(init_rgn, &ax->thmb_rgn, (void*) rgn_cleanup);
ax->thmb = NULL;
@ -117,15 +112,20 @@ void ax_begin_theme(struct ax_ctxt* ax)
void ax_end_theme(struct ax_ctxt* ax, struct ax_theme** out_thm)
{
ASSERT(ax->thmb != NULL, "`ax_end_theme' called while not building a theme");
struct ax_theme* thm;
ax__theme_builder_finish(ax->thmb, ax->init_rgn, &thm);
ax__theme_request_load(thm,
ax__backend_msgq(ax->bac),
ax->inbox);
struct ax_theme* thm = ax__theme_builder_finish(ax->thmb, ax->init_rgn);
rgn_clear(&ax->thmb_rgn);
if (out_thm != NULL) {
*out_thm = thm;
}
struct msgq* callback;
UNIMPLEMENTED();
ax__theme_request_load(thm,
ax__backend_msgq(ax->bac),
callback);
}
void ax_set_theme_color(
@ -177,69 +177,6 @@ int ax_select_theme(struct ax_ctxt* ax, struct ax_theme* thm)
return 0;
}
/* -----------------------------------------------------------------------------
* API functions :: events
* -------------------------------------------------------------------------- */
struct ax_evt_list {
struct ax_evt_list* next;
struct ax_evt e;
};
static struct ax_evt* push_evt(struct ax_ctxt* ax)
{
struct ax_evt_list* l =
ralloc_typed(&ax->evts_rgn, struct ax_evt_list, 1);
l->next = ax->evts;
ax->evts = l;
return &l->e;
}
static struct ax_evt* pop_evt(struct ax_ctxt* ax)
{
struct ax_evt_list* l = ax->evts;
if (l == NULL) {
rgn_clear(&ax->evts_rgn);
return NULL;
} else {
ax->evts = l->next;
return &l->e;
}
}
void ax_wait_evt_avail(struct ax_ctxt* ax)
{
msgq_begin_recv_and_wait(ax->inbox);
MSGQ_RECV_ALL(ax->inbox) {
ON(ax_msg_theme_loaded,
{
struct ax_evt* e = push_evt(ax);
e->ty = AX_EVT_THEME_LOADED;
e->arg.theme = m.theme;
break;
});
default:
ax_log(ax, "Got some weird message");
break;
}
msgq_end_recv(ax->inbox);
}
bool ax_poll_evt(struct ax_ctxt* ax, struct ax_evt* out_evt)
{
struct ax_evt* e = pop_evt(ax);
if (e == NULL) {
ax_log(ax, "event queue now empty");
return false;
}
if (out_evt != NULL) {
*out_evt = *e;
}
return true;
}
/* -----------------------------------------------------------------------------
* Backend worker thread
* -------------------------------------------------------------------------- */

View File

@ -73,26 +73,17 @@ void ax__theme_set_font(
}
}
void ax__theme_builder_finish(
struct ax_theme* ax__theme_builder_finish(
struct ax_theme_builder* thmb,
struct rgn* dst_rgn,
struct ax_theme** out_thm)
struct rgn* dst_rgn)
{
if (out_thm == NULL) {
return;
}
struct ax_theme* thm = ralloc_typed(dst_rgn, struct ax_theme, 1);
*out_thm = thm;
if (thmb->err != NULL) {
thm->err = rstrdup(dst_rgn, thmb->err);
}
const char* dflt_font_path = (thmb->dflt_font_path == NULL) ?
default_font_path(dst_rgn) :
rstrdup(dst_rgn, thmb->dflt_font_path);
for (size_t i = 0; i < AX_FONT__COUNT; i++) {
thm->color[i] = thmb->color[i];
thm->font_size[i] = thmb->font_size[i];
@ -100,9 +91,9 @@ void ax__theme_builder_finish(
dflt_font_path :
rstrdup(dst_rgn, thm->font_path[i]);
}
pthread_mutex_init(&thm->handles_mx, NULL);
rgn_pin(dst_rgn, thm, (void*) pthread_mutex_destroy);
return thm;
}
/* -----------------------------------------------------------------------------

View File

@ -71,10 +71,9 @@ void ax__theme_set_font(
enum ax_font_cat cat,
const char* path, size_t size);
void ax__theme_builder_finish(
struct ax_theme* ax__theme_builder_finish(
struct ax_theme_builder* thmb,
struct rgn* dst_rgn,
struct ax_theme** out_thm);
struct rgn* dst_rgn);
static inline int64_t ax__theme_color(
struct ax_theme* thm,

View File

@ -40,6 +40,9 @@ int main(void)
ax_set_logger(ax, 0, false);
struct ax_theme* thm = make_example_theme();
(void) thm;
/*
struct ax_evt evt;
for (;;) {
@ -50,6 +53,7 @@ int main(void)
}
}
}
*/
cleanup();
return 0;