KasperskyOS Community Edition 1.2
Statically creating IPC channels for C++ development
To implement a client program that calls a method of an endpoint provided by a server program:
- Include the generated header file (
*.edl.cpp.h
) of the client program description. - Include the generated header files of the descriptions of the utilized interfaces (
*.idl.cpp.h
). - Include the header files:
/opt/KasperskyOS-Community-Edition-<version>/sysroot-*-kos/include/kosipc/application.h
/opt/KasperskyOS-Community-Edition-<version>/sysroot-*-kos/include/kosipc/api.h
/opt/KasperskyOS-Community-Edition-<version>/sysroot-*-kos/include/kosipc/connect_static_channel.h
- Initialize the application object by calling the
kosipc::MakeApplicationAutodetect()
function. (You can also use thekosipc::MakeApplication()
andkosipc::MakeApplicationPureClient()
functions.) - Get the client IPC handle of the channel and the endpoint ID (
riid
) by calling thekosipc::ConnectStaticChannel()
function.This function gets the name of the IPC channel (from the init.yaml file) and the qualified name of the endpoint (from the CDL and EDL descriptions of the solution component).
- Initialize the proxy object for the utilized endpoint by calling the
MakeProxy()
function.
Example
// Create and initialize the application object
kosipc::Application app = kosipc::MakeApplicationAutodetect();
// Create and initialize the proxy object
auto proxy = app.MakeProxy<IDLInterface>(
kosipc::ConnectStaticChannel(channelName, endpointName))
// Call the method of the required endpoint
proxy->DoSomeWork();
To implement a server program that provides endpoints to other programs:
- Include the generated header file
*.edl.cpp.h
containing a description of the component structure of the program, including all provided endpoints. - Include the header files:
/opt/KasperskyOS-Community-Edition-<version>/sysroot-*-kos/include/kosipc/event_loop.h
/opt/KasperskyOS-Community-Edition-<version>/sysroot-*-kos/include/kosipc/api.h
/opt/KasperskyOS-Community-Edition-<version>/sysroot-*-kos/include/kosipc/serve_static_channel.h
- Create classes containing the implementations of interfaces that this program and its components provide as endpoints.
- Initialize the application object by calling the
kosipc::MakeApplicationAutodetect()
function. - Initialize the
kosipc::components::Root
structure, which describes the component structure of the program and describes the interfaces of all endpoints provided by the program. - Bind fields of the
kosipc::components::Root
structure to the objects that implement the corresponding endpoints.Fields of the
Root
structure replicate the hierarchy of components and endpoints that are collectively defined by the CDL and EDL files. - Get the server IPC handle of the channel by calling the
ServeStaticChannel()
function.This function gets the name of the IPC channel (from the init.yaml file) and the structure created at step 5.
- Create the
kosipc::EventLoop
object by calling theMakeEventLoop()
function. - Start the loop for dispatching incoming IPC messages by calling the
Run()
method of thekosipc::EventLoop
object.
Example
// Create class objects that implement interfaces
// provided by the server as endpoints
MyIDLInterfaceImp_1 impl_1;
MyIDLInterfaceImp_2 impl_2;
// Create and initialize the application object
kosipc::Application app = kosipc::MakeApplicationAutodetect();
// Create and initialize the root object that describes
// the components and endpoints of the server
kosipc::components::Root root;
// Bind the root object to the class objects that implement the server endpoints
root.component1.endpoint1 = &impl_1;
root.component2.endpoint2 = &impl_2;
// Create and initialize the object that implements the
// loop for dispatching incoming IPC messages
kosipc::EventLoop loop = app.MakeEventLoop(ServeStaticChannel(channelName, root));
// Start the loop in the current thread
loop.Run();
Article ID: static_IPC_kosipc, Last review: May 21, 2024