8000 GitHub - rcoscali/libmultiprocess: C++ library and code generator making it easy to call functions and reference objects in different processes
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

C++ library and code generator making it easy to call functions and reference objects in different processes

License

Notifications You must be signed in to change notification settings

rcoscali/libmultiprocess

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libmultiprocess

Summary

C++ library and code generator making it easy to call functions and reference objects in different processes.

Description

Given an interface description of an object with one or more methods, libmultiprocess generates:

  • A C++ ProxyClient class with an implementation of each interface method that sends a request over a socket, waits for a response, and returns the result.
  • A C++ ProxyServer class that listens for requests over a socket and calls a wrapped C++ object implementating the same interface to actually execute the requests.

The function call ⇆ request translation supports input and output arguments, standard types like unique_ptr, vector, map, and optional, and bidirectional calls between processes through interface pointer and std::function arguments.

If the wrapped C++ object inherits from an abstract base class declaring virtual methods, the generated ProxyClient objects can inherit from the same class, allowing interprocess calls to replace local calls without changes to existing code.

There is also optional support for thread mapping, so each thread making interprocess calls can have a dedicated thread processing requests from it, and callbacks from processing threads are executed on corresponding request threads (so recursive mutexes and thread names function as expected in callbacks).

What is kj?

KJ is a concurrency framework bundled with capnproto; it is used as a basis in this library to construct the event-loop necessary to service IPC requests.

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

Future directions

libmultiprocess uses the Cap'n Proto interface description language and protocol, but it could be extended or changed to use a different IDL/protocol like gRPC. The nice thing about Cap'n Proto compared to gRPC and most other lower level protocols is that it allows interface pointers (Services in gRPC parlance) to be passed as method arguments and return values, so object references and bidirectional requests work out of the box. Supporting a lower-level protocol would require writing adding maps and tracking code to proxy objects.

libmultiprocess is currently compatible with sandboxing but could add platform-specific sandboxing support or integration with a sandboxing library like SAPI.

Installation

Installation currently requires Cap'n Proto:

apt install libcapnp-dev capnproto
brew install capnp
dnf install capnproto

Installation steps are:

mkdir build
cd build
cmake ..
make
make check # Optionally build and run tests
make install

About

C++ library and code generator making it easy to call functions and reference objects in different processes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 88.7%
  • CMake 7.6%
  • Cap'n Proto 3.6%
  • Makefile 0.1%
0