HelenOS sources
This source file includes following definitions.
- ds_cfgclient_create
- ds_cfgclient_destroy
- ds_cfgclient_get_event
- ds_cfgclient_purge_events
- ds_cfgclient_post_seat_added_event
- ds_cfgclient_post_seat_removed_event
#include <adt/list.h>
#include <errno.h>
#include <io/log.h>
#include <stdlib.h>
#include "cfgclient.h"
#include "display.h"
#include "window.h"
errno_t ds_cfgclient_create(ds_display_t *display, ds_cfgclient_cb_t *cb,
void *cb_arg, ds_cfgclient_t **rcfgclient)
{
ds_cfgclient_t *cfgclient;
cfgclient = calloc(1, sizeof(ds_cfgclient_t));
if (cfgclient == NULL)
return ENOMEM;
list_initialize(&cfgclient->events);
cfgclient->cb = cb;
cfgclient->cb_arg = cb_arg;
ds_display_add_cfgclient(display, cfgclient);
*rcfgclient = cfgclient;
return EOK;
}
void ds_cfgclient_destroy(ds_cfgclient_t *cfgclient)
{
ds_cfgclient_purge_events(cfgclient);
ds_display_remove_cfgclient(cfgclient);
free(cfgclient);
}
errno_t ds_cfgclient_get_event(ds_cfgclient_t *cfgclient, dispcfg_ev_t *event)
{
link_t *link;
ds_cfgclient_ev_t *wevent;
link = list_first(&cfgclient->events);
if (link == NULL)
return ENOENT;
wevent = list_get_instance(link, ds_cfgclient_ev_t, levents);
list_remove(link);
*event = wevent->event;
free(wevent);
return EOK;
}
void ds_cfgclient_purge_events(ds_cfgclient_t *cfgclient)
{
link_t *cur;
link_t *next;
ds_cfgclient_ev_t *wevent;
cur = list_first(&cfgclient->events);
while (cur != NULL) {
next = list_next(cur, &cfgclient->events);
wevent = list_get_instance(cur, ds_cfgclient_ev_t, levents);
list_remove(cur);
free(wevent);
cur = next;
}
}
errno_t ds_cfgclient_post_seat_added_event(ds_cfgclient_t *cfgclient,
sysarg_t seat_id)
{
ds_cfgclient_ev_t *sevent;
log_msg(LOG_DEFAULT, LVL_DEBUG, "cfgclient_pos_seat_added_event "
"cfgclient=%p seat_id=%zu\n", (void *)cfgclient, seat_id);
sevent = calloc(1, sizeof(ds_cfgclient_ev_t));
if (sevent == NULL)
return ENOMEM;
sevent->cfgclient = cfgclient;
sevent->event.etype = dcev_seat_added;
sevent->event.seat_id = seat_id;
list_append(&sevent->levents, &cfgclient->events);
if (cfgclient->cb != NULL && cfgclient->cb->ev_pending != NULL)
cfgclient->cb->ev_pending(cfgclient->cb_arg);
return EOK;
}
errno_t ds_cfgclient_post_seat_removed_event(ds_cfgclient_t *cfgclient,
sysarg_t seat_id)
{
ds_cfgclient_ev_t *sevent;
log_msg(LOG_DEFAULT, LVL_DEBUG, "cfgclient_pos_seat_removed_event "
"cfgclient=%p seat_id=%zu\n", (void *)cfgclient, seat_id);
sevent = calloc(1, sizeof(ds_cfgclient_ev_t));
if (sevent == NULL)
return ENOMEM;
sevent->cfgclient = cfgclient;
sevent->event.etype = dcev_seat_removed;
sevent->event.seat_id = seat_id;
list_append(&sevent->levents, &cfgclient->events);
if (cfgclient->cb != NULL && cfgclient->cb->ev_pending != NULL)
cfgclient->cb->ev_pending(cfgclient->cb_arg);
return EOK;
}
HelenOS homepage, sources at GitHub