HelenOS sources
This source file includes following definitions.
- system_callback_create_srv
- system_shutdown_srv
- system_conn
- system_srv_initialize
- system_srv_shutdown_complete
- system_srv_shutdown_failed
#include <errno.h>
#include <io/log.h>
#include <ipc/system.h>
#include <mem.h>
#include <stdlib.h>
#include <stddef.h>
#include <system_srv.h>
static void system_callback_create_srv(system_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 system_shutdown_srv(system_srv_t *srv, ipc_call_t *icall)
{
errno_t rc;
if (srv->ops->shutdown == NULL) {
async_answer_0(icall, ENOTSUP);
return;
}
rc = srv->ops->shutdown(srv->arg);
async_answer_0(icall, rc);
}
void system_conn(ipc_call_t *icall, system_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 SYSTEM_CALLBACK_CREATE:
system_callback_create_srv(srv, &call);
break;
case SYSTEM_SHUTDOWN:
system_shutdown_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 system_srv_initialize(system_srv_t *srv)
{
memset(srv, 0, sizeof(*srv));
}
void system_srv_shutdown_complete(system_srv_t *srv)
{
async_exch_t *exch;
exch = async_exchange_begin(srv->client_sess);
async_msg_0(exch, SYSTEM_SHUTDOWN_COMPLETE);
async_exchange_end(exch);
}
void system_srv_shutdown_failed(system_srv_t *srv)
{
async_exch_t *exch;
exch = async_exchange_begin(srv->client_sess);
async_msg_0(exch, SYSTEM_SHUTDOWN_FAILED);
async_exchange_end(exch);
}
HelenOS homepage, sources at GitHub