HelenOS sources
This source file includes following definitions.
- ds_ievent_post_kbd
- ds_ievent_post_ptd
- ds_ievent_fibril
- ds_ievent_init
- ds_ievent_fini
#include <adt/list.h>
#include <errno.h>
#include <fibril_synch.h>
#include <io/kbd_event.h>
#include <stdlib.h>
#include "display.h"
#include "ievent.h"
errno_t ds_ievent_post_kbd(ds_display_t *disp, kbd_event_t *kbd)
{
ds_ievent_t *ievent;
ievent = calloc(1, sizeof(ds_ievent_t));
if (ievent == NULL)
return ENOMEM;
ievent->display = disp;
ievent->etype = det_kbd;
ievent->ev.kbd = *kbd;
list_append(&ievent->lievents, &disp->ievents);
fibril_condvar_signal(&disp->ievent_cv);
return EOK;
}
errno_t ds_ievent_post_ptd(ds_display_t *disp, ptd_event_t *ptd)
{
ds_ievent_t *ievent;
ds_ievent_t *prev;
link_t *link;
ievent = calloc(1, sizeof(ds_ievent_t));
if (ievent == NULL)
return ENOMEM;
link = list_last(&disp->ievents);
if (link != NULL) {
prev = list_get_instance(link, ds_ievent_t, lievents);
if (prev->etype == det_ptd && prev->ev.ptd.pos_id ==
ptd->pos_id) {
if (prev->ev.ptd.type == PTD_MOVE &&
ptd->type == PTD_MOVE) {
gfx_coord2_add(&ptd->dmove, &prev->ev.ptd.dmove,
&prev->ev.ptd.dmove);
return EOK;
} else if (prev->ev.ptd.type == PTD_ABS_MOVE &&
ptd->type == PTD_ABS_MOVE) {
prev->ev.ptd.apos = ptd->apos;
prev->ev.ptd.abounds = ptd->abounds;
return EOK;
}
}
}
ievent->display = disp;
ievent->etype = det_ptd;
ievent->ev.ptd = *ptd;
list_append(&ievent->lievents, &disp->ievents);
fibril_condvar_signal(&disp->ievent_cv);
return EOK;
}
static errno_t ds_ievent_fibril(void *arg)
{
ds_display_t *disp = (ds_display_t *)arg;
ds_ievent_t *ievent;
link_t *link;
fibril_mutex_lock(&disp->lock);
while (!disp->ievent_quit) {
while (list_empty(&disp->ievents))
fibril_condvar_wait(&disp->ievent_cv, &disp->lock);
link = list_first(&disp->ievents);
assert(link != NULL);
list_remove(link);
ievent = list_get_instance(link, ds_ievent_t, lievents);
switch (ievent->etype) {
case det_kbd:
(void)ds_display_post_kbd_event(disp, &ievent->ev.kbd);
break;
case det_ptd:
(void)ds_display_post_ptd_event(disp, &ievent->ev.ptd);
break;
}
}
disp->ievent_done = true;
fibril_condvar_signal(&disp->ievent_cv);
fibril_mutex_unlock(&disp->lock);
return EOK;
}
errno_t ds_ievent_init(ds_display_t *disp)
{
assert(disp->ievent_fid == 0);
disp->ievent_fid = fibril_create(ds_ievent_fibril, (void *)disp);
if (disp->ievent_fid == 0)
return ENOMEM;
fibril_add_ready(disp->ievent_fid);
return EOK;
}
void ds_ievent_fini(ds_display_t *disp)
{
ds_ievent_t *ievent;
link_t *link;
if (disp->ievent_fid == 0)
return;
fibril_mutex_lock(&disp->lock);
disp->ievent_quit = true;
fibril_condvar_signal(&disp->ievent_cv);
while (!disp->ievent_done)
fibril_condvar_wait(&disp->ievent_cv, &disp->lock);
while (!list_empty(&disp->ievents)) {
link = list_first(&disp->ievents);
assert(link != NULL);
list_remove(link);
ievent = list_get_instance(link, ds_ievent_t, lievents);
free(ievent);
}
fibril_mutex_unlock(&disp->lock);
fibril_detach(disp->ievent_fid);
disp->ievent_fid = 0;
}
HelenOS homepage, sources at GitHub