Skip to content

Latest commit

 

History

History
24 lines (14 loc) · 3.45 KB

usage.md

File metadata and controls

24 lines (14 loc) · 3.45 KB

libmultiprocess Usage

Overview

libmultiprocess is a library and code generator that allows calling C++ class interfaces across different processes. For an interface to be available from other processes, it needs two definitions:

The *.capnp data definition files are consumed by the libmultiprocess code generator and each X.capnp file generates X.capnp.c++, X.capnp.h, X.capnp.proxy-client.c++, X.capnp.proxy-server.c++, X.capnp.proxy-types.c++, X.capnp.proxy-types.h, and X.capnp.proxy.h output files. The generated files include mp::ProxyClient<Interface> and mp::ProxyServer<Interface> class specializations for all the interfaces in the .capnp files. These allow methods on C++ objects in one process to be called from other processes over IPC sockets.

The ProxyServer objects help translate IPC requests from a socket to method calls on a local object. The ProxyServer objects are just used internally by the mp::ServeStream(loop, socket, wrapped_object) and mp::ListenConnections(loop, socket, wrapped_object) functions, and aren't exposed externally. The ProxyClient classes are exposed, and returned from the mp::ConnectStream(loop, socket) function and meant to be used directly. The classes implement methods described in .capnp definitions, and whenever any method is called, a request with the method arguments is sent over the associated IPC connection, and the corresponding wrapped_object method on the other end of the connection is called, with the ProxyClient method blocking until it returns and forwarding back any return value to the ProxyClient method caller.

Example

A simple interface description can be found at test/mp/test/foo.capnp, implementation in test/mp/test/foo.h, and usage in test/mp/test/test.cpp.

A more complete example can be found in example and run with:

make -C build example
build/example/mpexample