6 #include <ipc/capnp/init.capnp.h> 7 #include <ipc/capnp/init.capnp.proxy.h> 13 #include <mp/proxy-io.h> 14 #include <mp/proxy-types.h> 30 void IpcLogFn(
bool raise, std::string message)
36 class CapnpProtocol :
public Protocol 39 ~CapnpProtocol() noexcept(
true)
42 std::unique_lock<std::mutex> lock(
m_loop->m_mutex);
43 m_loop->removeClient(lock);
48 std::unique_ptr<interfaces::Init> connect(
int fd,
const char* exe_name)
override 51 return mp::ConnectStream<messages::Init>(*
m_loop, fd);
56 mp::g_thread_context.thread_name = mp::ThreadName(exe_name);
57 m_loop.emplace(exe_name, &IpcLogFn,
nullptr);
58 mp::ServeStream<messages::Init>(*
m_loop, fd,
init);
62 void addCleanup(std::type_index type,
void* iface, std::function<
void()> cleanup)
override 64 mp::ProxyTypeRegister::types().at(type)(iface).cleanup.emplace_back(std::move(cleanup));
66 void startLoop(
const char* exe_name)
69 std::promise<void> promise;
72 m_loop.emplace(exe_name, &IpcLogFn,
nullptr);
74 std::unique_lock<std::mutex> lock(
m_loop->m_mutex);
81 promise.get_future().wait();
#define LogPrint(category,...)
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name...
std::optional< mp::EventLoop > m_loop
std::thread m_loop_thread
std::unique_ptr< Protocol > MakeCapnpProtocol()
IPC protocol interface for calling IPC methods over sockets.
Initial interface created when a process is first started, and used to give and get access to other i...
Exception class thrown when a call to remote method fails due to an IPC error, like a socket getting ...