HelenOS sources
This source file includes following definitions.
- ipc_test_create
- ipc_test_destroy
- ipc_test_ping
- ipc_test_get_ro_area_size
- ipc_test_get_rw_area_size
- ipc_test_share_in_ro
- ipc_test_share_in_rw
- ipc_test_set_rw_buf_size
- ipc_test_read
- ipc_test_write
#include <abi/ipc/interfaces.h>
#include <as.h>
#include <errno.h>
#include <ipc/services.h>
#include <ipc/ipc_test.h>
#include <loc.h>
#include <stdlib.h>
#include <ipc_test.h>
errno_t ipc_test_create(ipc_test_t **rtest)
{
ipc_test_t *test;
service_id_t test_svcid;
errno_t rc;
test = calloc(1, sizeof(ipc_test_t));
if (test == NULL) {
rc = ENOMEM;
goto error;
}
rc = loc_service_get_id(SERVICE_NAME_IPC_TEST, &test_svcid, 0);
if (rc != EOK) {
rc = ENOENT;
goto error;
}
test->sess = loc_service_connect(test_svcid, INTERFACE_IPC_TEST, 0);
if (test->sess == NULL) {
rc = EIO;
goto error;
}
*rtest = test;
return EOK;
error:
free(test);
return rc;
}
void ipc_test_destroy(ipc_test_t *test)
{
if (test == NULL)
return;
async_hangup(test->sess);
free(test);
}
errno_t ipc_test_ping(ipc_test_t *test)
{
async_exch_t *exch;
errno_t retval;
exch = async_exchange_begin(test->sess);
retval = async_req_0_0(exch, IPC_TEST_PING);
async_exchange_end(exch);
if (retval != EOK)
return retval;
return EOK;
}
errno_t ipc_test_get_ro_area_size(ipc_test_t *test, size_t *rsize)
{
async_exch_t *exch;
errno_t retval;
sysarg_t size;
exch = async_exchange_begin(test->sess);
retval = async_req_0_1(exch, IPC_TEST_GET_RO_AREA_SIZE, &size);
async_exchange_end(exch);
if (retval != EOK)
return retval;
*rsize = size;
return EOK;
}
errno_t ipc_test_get_rw_area_size(ipc_test_t *test, size_t *rsize)
{
async_exch_t *exch;
errno_t retval;
sysarg_t size;
exch = async_exchange_begin(test->sess);
retval = async_req_0_1(exch, IPC_TEST_GET_RW_AREA_SIZE, &size);
async_exchange_end(exch);
if (retval != EOK)
return retval;
*rsize = size;
return EOK;
}
errno_t ipc_test_share_in_ro(ipc_test_t *test, size_t size, const void **rptr)
{
async_exch_t *exch;
ipc_call_t answer;
aid_t req;
void *dst;
errno_t rc;
exch = async_exchange_begin(test->sess);
req = async_send_0(exch, IPC_TEST_SHARE_IN_RO, &answer);
dst = NULL;
rc = async_share_in_start_0_0(exch, size, &dst);
if (rc != EOK || dst == AS_MAP_FAILED) {
async_exchange_end(exch);
async_forget(req);
return ENOMEM;
}
async_exchange_end(exch);
async_wait_for(req, NULL);
*rptr = dst;
return EOK;
}
errno_t ipc_test_share_in_rw(ipc_test_t *test, size_t size, void **rptr)
{
async_exch_t *exch;
ipc_call_t answer;
aid_t req;
void *dst;
errno_t rc;
exch = async_exchange_begin(test->sess);
req = async_send_0(exch, IPC_TEST_SHARE_IN_RW, &answer);
rc = async_share_in_start_0_0(exch, size, &dst);
if (rc != EOK || dst == AS_MAP_FAILED) {
async_exchange_end(exch);
async_forget(req);
return ENOMEM;
}
async_exchange_end(exch);
async_wait_for(req, NULL);
*rptr = dst;
return EOK;
}
errno_t ipc_test_set_rw_buf_size(ipc_test_t *test, size_t size)
{
async_exch_t *exch;
errno_t retval;
exch = async_exchange_begin(test->sess);
retval = async_req_1_0(exch, IPC_TEST_SET_RW_BUF_SIZE, size);
async_exchange_end(exch);
if (retval != EOK)
return retval;
return EOK;
}
errno_t ipc_test_read(ipc_test_t *test, void *dest, size_t size)
{
async_exch_t *exch;
ipc_call_t answer;
aid_t req;
errno_t rc;
exch = async_exchange_begin(test->sess);
req = async_send_0(exch, IPC_TEST_READ, &answer);
rc = async_data_read_start(exch, dest, size);
if (rc != EOK) {
async_exchange_end(exch);
async_forget(req);
return rc;
}
async_exchange_end(exch);
async_wait_for(req, NULL);
return EOK;
}
errno_t ipc_test_write(ipc_test_t *test, const void *data, size_t size)
{
async_exch_t *exch;
ipc_call_t answer;
aid_t req;
errno_t rc;
exch = async_exchange_begin(test->sess);
req = async_send_0(exch, IPC_TEST_WRITE, &answer);
rc = async_data_write_start(exch, data, size);
if (rc != EOK) {
async_exchange_end(exch);
async_forget(req);
return rc;
}
async_exchange_end(exch);
async_wait_for(req, NULL);
return EOK;
}
HelenOS homepage, sources at GitHub