HelenOS sources
This source file includes following definitions.
- service_register
- service_register_broker
- service_connect
- service_connect_blocking
- ns_ping
- ns_intro
- ns_session_get
#include <ns.h>
#include <ipc/ns.h>
#include <async.h>
#include <macros.h>
#include <errno.h>
#include "private/ns.h"
static async_sess_t *sess_ns = NULL;
errno_t service_register(service_t service, iface_t iface,
async_port_handler_t handler, void *data)
{
errno_t rc;
async_sess_t *sess = ns_session_get(&rc);
if (sess == NULL)
return rc;
port_id_t port;
rc = async_create_port(iface, handler, data, &port);
if (rc != EOK)
return rc;
async_exch_t *exch = async_exchange_begin(sess);
ipc_call_t answer;
aid_t req = async_send_2(exch, NS_REGISTER, service, iface, &answer);
rc = async_connect_to_me(exch, iface, service, 0);
async_exchange_end(exch);
if (rc != EOK) {
async_forget(req);
return rc;
}
errno_t retval;
async_wait_for(req, &retval);
return rc;
}
errno_t service_register_broker(service_t service, async_port_handler_t handler,
void *data)
{
async_set_fallback_port_handler(handler, data);
errno_t rc;
async_sess_t *sess = ns_session_get(&rc);
if (sess == NULL)
return rc;
async_exch_t *exch = async_exchange_begin(sess);
ipc_call_t answer;
aid_t req = async_send_1(exch, NS_REGISTER_BROKER, service, &answer);
rc = async_connect_to_me(exch, INTERFACE_ANY, service, 0);
async_exchange_end(exch);
if (rc != EOK) {
async_forget(req);
return rc;
}
errno_t retval;
async_wait_for(req, &retval);
return rc;
}
async_sess_t *service_connect(service_t service, iface_t iface, sysarg_t arg3,
errno_t *rc)
{
async_sess_t *sess = ns_session_get(rc);
if (sess == NULL)
return NULL;
async_exch_t *exch = async_exchange_begin(sess);
if (exch == NULL)
return NULL;
async_sess_t *csess =
async_connect_me_to(exch, iface, service, arg3, rc);
async_exchange_end(exch);
if (csess == NULL)
return NULL;
async_sess_args_set(csess, iface, arg3, 0);
return csess;
}
async_sess_t *service_connect_blocking(service_t service, iface_t iface,
sysarg_t arg3, errno_t *rc)
{
async_sess_t *sess = ns_session_get(rc);
if (sess == NULL)
return NULL;
async_exch_t *exch = async_exchange_begin(sess);
async_sess_t *csess =
async_connect_me_to_blocking(exch, iface, service, arg3, rc);
async_exchange_end(exch);
if (csess == NULL)
return NULL;
async_sess_args_set(csess, iface, arg3, 0);
return csess;
}
errno_t ns_ping(void)
{
errno_t rc;
async_sess_t *sess = ns_session_get(&rc);
if (sess == NULL)
return rc;
async_exch_t *exch = async_exchange_begin(sess);
rc = async_req_0_0(exch, NS_PING);
async_exchange_end(exch);
return rc;
}
errno_t ns_intro(task_id_t id)
{
errno_t rc;
async_sess_t *sess = ns_session_get(&rc);
if (sess == NULL)
return EIO;
async_exch_t *exch = async_exchange_begin(sess);
rc = async_req_2_0(exch, NS_ID_INTRO, LOWER32(id), UPPER32(id));
async_exchange_end(exch);
return rc;
}
async_sess_t *ns_session_get(errno_t *rc)
{
async_exch_t *exch;
if (sess_ns == NULL) {
exch = async_exchange_begin(&session_ns);
sess_ns = async_connect_me_to(exch, 0, 0, 0, rc);
async_exchange_end(exch);
if (sess_ns == NULL)
return NULL;
}
return sess_ns;
}
HelenOS homepage, sources at GitHub