HelenOS sources
This source file includes following definitions.
- dispcfg_callback_create_srv
- dispcfg_get_seat_list_srv
- dispcfg_get_seat_info_srv
- dispcfg_seat_create_srv
- dispcfg_seat_delete_srv
- dispcfg_dev_assign_srv
- dispcfg_dev_unassign_srv
- dispcfg_get_asgn_dev_list_srv
- dispcfg_get_event_srv
- dispcfg_conn
- dispcfg_srv_initialize
- dispcfg_srv_ev_pending
#include <dispcfg.h>
#include <dispcfg_srv.h>
#include <errno.h>
#include <ipc/dispcfg.h>
#include <mem.h>
#include <stdlib.h>
#include <stddef.h>
#include <str.h>
#include "../private/dispcfg.h"
static void dispcfg_callback_create_srv(dispcfg_srv_t *srv, ipc_call_t *call)
{
async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE);
if (sess == NULL) {
async_answer_0(call, ENOMEM);
return;
}
srv->client_sess = sess;
async_answer_0(call, EOK);
}
static void dispcfg_get_seat_list_srv(dispcfg_srv_t *srv, ipc_call_t *icall)
{
ipc_call_t call;
dispcfg_seat_list_t *list = NULL;
size_t size;
errno_t rc;
if (srv->ops->get_seat_list == NULL) {
async_answer_0(icall, ENOTSUP);
return;
}
rc = srv->ops->get_seat_list(srv->arg, &list);
if (rc != EOK) {
async_answer_0(icall, rc);
return;
}
if (!async_data_read_receive(&call, &size)) {
dispcfg_free_seat_list(list);
async_answer_0(&call, EREFUSED);
async_answer_0(icall, EREFUSED);
return;
}
if (size != sizeof(list->nseats)) {
dispcfg_free_seat_list(list);
async_answer_0(&call, EINVAL);
async_answer_0(icall, EINVAL);
return;
}
rc = async_data_read_finalize(&call, &list->nseats, size);
if (rc != EOK) {
dispcfg_free_seat_list(list);
async_answer_0(&call, rc);
async_answer_0(icall, rc);
return;
}
if (!async_data_read_receive(&call, &size)) {
dispcfg_free_seat_list(list);
async_answer_0(&call, EREFUSED);
async_answer_0(icall, EREFUSED);
return;
}
if (size != list->nseats * sizeof(sysarg_t)) {
dispcfg_free_seat_list(list);
async_answer_0(&call, EINVAL);
async_answer_0(icall, EINVAL);
return;
}
rc = async_data_read_finalize(&call, list->seats, size);
if (rc != EOK) {
dispcfg_free_seat_list(list);
async_answer_0(&call, rc);
async_answer_0(icall, rc);
return;
}
async_answer_0(icall, EOK);
dispcfg_free_seat_list(list);
}
static void dispcfg_get_seat_info_srv(dispcfg_srv_t *srv, ipc_call_t *icall)
{
sysarg_t seat_id;
ipc_call_t call;
dispcfg_seat_info_t *info = NULL;
size_t namesize;
size_t size;
errno_t rc;
seat_id = ipc_get_arg1(icall);
if (srv->ops->get_seat_info == NULL) {
async_answer_0(icall, ENOTSUP);
return;
}
rc = srv->ops->get_seat_info(srv->arg, seat_id, &info);
if (rc != EOK) {
async_answer_0(icall, rc);
return;
}
if (!async_data_read_receive(&call, &size)) {
dispcfg_free_seat_info(info);
async_answer_0(&call, EREFUSED);
async_answer_0(icall, EREFUSED);
return;
}
if (size != sizeof(size_t)) {
dispcfg_free_seat_info(info);
async_answer_0(&call, EINVAL);
async_answer_0(icall, EINVAL);
return;
}
namesize = str_size(info->name);
rc = async_data_read_finalize(&call, &namesize, size);
if (rc != EOK) {
dispcfg_free_seat_info(info);
async_answer_0(&call, rc);
async_answer_0(icall, rc);
return;
}
if (!async_data_read_receive(&call, &size)) {
dispcfg_free_seat_info(info);
async_answer_0(&call, EREFUSED);
async_answer_0(icall, EREFUSED);
return;
}
if (size != namesize) {
dispcfg_free_seat_info(info);
async_answer_0(&call, EINVAL);
async_answer_0(icall, EINVAL);
return;
}
rc = async_data_read_finalize(&call, info->name, size);
if (rc != EOK) {
dispcfg_free_seat_info(info);
async_answer_0(&call, rc);
async_answer_0(icall, rc);
return;
}
async_answer_0(icall, EOK);
dispcfg_free_seat_info(info);
}
static void dispcfg_seat_create_srv(dispcfg_srv_t *srv, ipc_call_t *icall)
{
sysarg_t seat_id;
ipc_call_t call;
char *name;
size_t size;
errno_t rc;
if (!async_data_write_receive(&call, &size)) {
async_answer_0(&call, EREFUSED);
async_answer_0(icall, EREFUSED);
return;
}
name = calloc(size + 1, 1);
if (name == NULL) {
async_answer_0(&call, ENOMEM);
async_answer_0(icall, ENOMEM);
return;
}
rc = async_data_write_finalize(&call, name, size);
if (rc != EOK) {
free(name);
async_answer_0(&call, rc);
async_answer_0(icall, rc);
return;
}
if (srv->ops->seat_create == NULL) {
free(name);
async_answer_0(icall, ENOTSUP);
return;
}
rc = srv->ops->seat_create(srv->arg, name, &seat_id);
async_answer_1(icall, rc, seat_id);
free(name);
}
static void dispcfg_seat_delete_srv(dispcfg_srv_t *srv, ipc_call_t *icall)
{
sysarg_t seat_id;
errno_t rc;
seat_id = ipc_get_arg1(icall);
if (srv->ops->seat_delete == NULL) {
async_answer_0(icall, ENOTSUP);
return;
}
rc = srv->ops->seat_delete(srv->arg, seat_id);
async_answer_0(icall, rc);
}
static void dispcfg_dev_assign_srv(dispcfg_srv_t *srv, ipc_call_t *icall)
{
sysarg_t svc_id;
sysarg_t seat_id;
errno_t rc;
svc_id = ipc_get_arg1(icall);
seat_id = ipc_get_arg2(icall);
if (srv->ops->dev_assign == NULL) {
async_answer_0(icall, ENOTSUP);
return;
}
rc = srv->ops->dev_assign(srv->arg, svc_id, seat_id);
async_answer_0(icall, rc);
}
static void dispcfg_dev_unassign_srv(dispcfg_srv_t *srv, ipc_call_t *icall)
{
sysarg_t svc_id;
errno_t rc;
svc_id = ipc_get_arg1(icall);
if (srv->ops->dev_unassign == NULL) {
async_answer_0(icall, ENOTSUP);
return;
}
rc = srv->ops->dev_unassign(srv->arg, svc_id);
async_answer_0(icall, rc);
}
static void dispcfg_get_asgn_dev_list_srv(dispcfg_srv_t *srv, ipc_call_t *icall)
{
sysarg_t seat_id;
ipc_call_t call;
dispcfg_dev_list_t *list = NULL;
size_t size;
errno_t rc;
seat_id = ipc_get_arg1(icall);
if (srv->ops->get_asgn_dev_list == NULL) {
async_answer_0(icall, ENOTSUP);
return;
}
rc = srv->ops->get_asgn_dev_list(srv->arg, seat_id, &list);
if (rc != EOK) {
async_answer_0(icall, rc);
return;
}
if (!async_data_read_receive(&call, &size)) {
dispcfg_free_dev_list(list);
async_answer_0(&call, EREFUSED);
async_answer_0(icall, EREFUSED);
return;
}
if (size != sizeof(list->ndevs)) {
dispcfg_free_dev_list(list);
async_answer_0(&call, EINVAL);
async_answer_0(icall, EINVAL);
return;
}
rc = async_data_read_finalize(&call, &list->ndevs, size);
if (rc != EOK) {
dispcfg_free_dev_list(list);
async_answer_0(&call, rc);
async_answer_0(icall, rc);
return;
}
if (!async_data_read_receive(&call, &size)) {
dispcfg_free_dev_list(list);
async_answer_0(&call, EREFUSED);
async_answer_0(icall, EREFUSED);
return;
}
if (size != list->ndevs * sizeof(sysarg_t)) {
dispcfg_free_dev_list(list);
async_answer_0(&call, EINVAL);
async_answer_0(icall, EINVAL);
return;
}
rc = async_data_read_finalize(&call, list->devs, size);
if (rc != EOK) {
dispcfg_free_dev_list(list);
async_answer_0(&call, rc);
async_answer_0(icall, rc);
return;
}
async_answer_0(icall, EOK);
dispcfg_free_dev_list(list);
}
static void dispcfg_get_event_srv(dispcfg_srv_t *srv, ipc_call_t *icall)
{
dispcfg_ev_t event;
ipc_call_t call;
size_t size;
errno_t rc;
if (srv->ops->get_event == NULL) {
async_answer_0(icall, ENOTSUP);
return;
}
rc = srv->ops->get_event(srv->arg, &event);
if (rc != EOK) {
async_answer_0(icall, rc);
return;
}
if (!async_data_read_receive(&call, &size)) {
async_answer_0(&call, EREFUSED);
async_answer_0(icall, EREFUSED);
return;
}
if (size != sizeof(event)) {
async_answer_0(&call, EREFUSED);
async_answer_0(icall, EREFUSED);
return;
}
rc = async_data_read_finalize(&call, &event, sizeof(event));
if (rc != EOK) {
async_answer_0(&call, rc);
async_answer_0(icall, rc);
return;
}
async_answer_0(icall, EOK);
}
void dispcfg_conn(ipc_call_t *icall, dispcfg_srv_t *srv)
{
async_accept_0(icall);
while (true) {
ipc_call_t call;
async_get_call(&call);
sysarg_t method = ipc_get_imethod(&call);
if (!method) {
async_answer_0(&call, EOK);
break;
}
switch (method) {
case DISPCFG_CALLBACK_CREATE:
dispcfg_callback_create_srv(srv, &call);
break;
case DISPCFG_GET_SEAT_LIST:
dispcfg_get_seat_list_srv(srv, &call);
break;
case DISPCFG_GET_SEAT_INFO:
dispcfg_get_seat_info_srv(srv, &call);
break;
case DISPCFG_SEAT_CREATE:
dispcfg_seat_create_srv(srv, &call);
break;
case DISPCFG_SEAT_DELETE:
dispcfg_seat_delete_srv(srv, &call);
break;
case DISPCFG_DEV_ASSIGN:
dispcfg_dev_assign_srv(srv, &call);
break;
case DISPCFG_DEV_UNASSIGN:
dispcfg_dev_unassign_srv(srv, &call);
break;
case DISPCFG_GET_ASGN_DEV_LIST:
dispcfg_get_asgn_dev_list_srv(srv, &call);
break;
case DISPCFG_GET_EVENT:
dispcfg_get_event_srv(srv, &call);
break;
default:
async_answer_0(&call, ENOTSUP);
}
}
if (srv->client_sess != NULL) {
async_hangup(srv->client_sess);
srv->client_sess = NULL;
}
}
void dispcfg_srv_initialize(dispcfg_srv_t *srv)
{
memset(srv, 0, sizeof(*srv));
}
void dispcfg_srv_ev_pending(dispcfg_srv_t *srv)
{
async_exch_t *exch;
exch = async_exchange_begin(srv->client_sess);
async_msg_0(exch, DISPCFG_EV_PENDING);
async_exchange_end(exch);
}
HelenOS homepage, sources at GitHub