7 #include <ipc/capnp/init.capnp.h>
8 #include <ipc/capnp/init.capnp.proxy.h>
14 #include <mp/proxy-io.h>
15 #include <mp/proxy-types.h>
31 void IpcLogFn(
bool raise, std::string message)
34 if (
raise)
throw Exception(message);
37 class CapnpProtocol :
public Protocol
40 ~CapnpProtocol() noexcept(true)
43 std::unique_lock<std::mutex> lock(
m_loop->m_mutex);
44 m_loop->removeClient(lock);
49 std::unique_ptr<interfaces::Init> connect(
int fd,
const char* exe_name)
override
52 return mp::ConnectStream<messages::Init>(*
m_loop, fd);
57 mp::g_thread_context.thread_name = mp::ThreadName(exe_name);
59 mp::ServeStream<messages::Init>(*
m_loop, fd,
init);
63 void addCleanup(std::type_index type,
void* iface, std::function<
void()> cleanup)
override
65 mp::ProxyTypeRegister::types().at(type)(iface).cleanup.emplace_back(std::move(cleanup));
67 Context& context()
override {
return m_context; }
68 void startLoop(
const char* exe_name)
71 std::promise<void> promise;
76 std::unique_lock<std::mutex> lock(
m_loop->m_mutex);
83 promise.get_future().wait();
Initial interface created when a process is first started, and used to give and get access to other i...
std::thread m_loop_thread
std::optional< mp::EventLoop > m_loop
#define LogPrint(category,...)
std::unique_ptr< Protocol > MakeCapnpProtocol()
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name.