Service Locator
Service Locator is a small library that lets you:
- find out the value of an IPC handle based on the connection name;
- find out the value of the interface ID (RIID) based on the name of the interface implementation.
The values of the IPC handle and RIID are required for calling a specific interface of a specific server entity. These values are used when initializing a transport.
To use Service Locator, you need to include the sl_api.h
file in the entity code:
Main functions of Service Locator
Client-side functions:
ServiceLocatorConnect()
receives the connection name and returns the client IPC handle corresponding to this connection (channel).ServiceLocatorGetRiid()
receives the IPC handle and interface implementation name in the format<component instance name>.<interface implementation name>
. Returns a corresponding RIID (sequence number of the interface implementation).
The connection name is specified in the init.yaml
file, the component instance name is specified in the EDL file, and the interface implementation name is specified in the CDL file.
Server-side functions:
ServiceLocatorRegister()
receives the connection name and returns the server IPC handle corresponding to this connection (channel). If the channel is part of a group, the function returns the listener handle of this group.
Example use of Service Locator
Examine the next solution consisting of two entities: Client
and Server
.
The client entity does not implement any interface.
Client.edl
entity Client
The server entity contains an instance of the Ping
component. Instance name: ping_comp
.
Server.edl
entity Server
components {
ping_comp: Ping
}
The Ping
component contains a named implementation of the Ping
interface declared in the Ping.idl
file. Implementation name: ping_impl
.
Ping.cdl
component Ping
interfaces {
ping_impl: Ping
}
(For brevity, the Ping.idl
file is not provided.)
In the init description, we indicate that the Client
and Server
entities must be connected through a channel named server_connection
:
init.yaml
entities:
- name: Client
connections:
- target: Server
id: server_connection
- name: Server
Use of Service Locator on the client side:
client.c
…
/* Connect Service Locator */
…
/* Get client IPC handle "server_connection" channel */
Handle handle = ServiceLocatorConnect("server_connection");
…
/* Get ID (RIID) of ping_impl implementation contained in ping_comp instance */
nk_iid_t riid = ServiceLocatorGetRiid(handle, "ping_comp.ping_impl");
…
Use Service Locator on the server side:
server.c
…
/* Connect Service Locator */
…
nk_iid_t iid;
/* Get server IPC handle of "server_connection" channel */
Handle handle = ServiceLocatorRegister("server_connection", NULL, 0, &iid);
…