8 #include<libtransistor/cpp/types.hpp>
15 #include<expected.hpp>
18 #include<forward_list>
41 static Result<IPCServer> Create(
Waiter *waiter, uint32_t max_ports=63, uint32_t max_sessions=63,
size_t pointer_buffer_size=0x500);
50 template<
typename T,
class... Args>
51 Result<T*> CreateObject(
Object *existing, Args &&... args) {
52 T *obj =
new T(
this, args...);
53 return ResultCode::ExpectOk(ipc_server_object_register(&existing->object, &obj->object)).map([obj](
auto const &ignored) {
58 template<
typename T,
class... Args>
59 Result<T*> AttachSession(
KObject &&
object, Args &&... args) {
60 T *obj =
new T(
this, args...);
61 return ResultCode::ExpectOk(ipc_server_create_session(server,
object.Claim(), 0, &obj->object)).map([obj](
auto const &ignored) {
67 Result<std::nullopt_t> CreateService(
const char *name) {
68 return CreateService(name, [](
IPCServer *server) {
72 Result<std::nullopt_t> CreateService(
const char *name, std::function<Result<Object*>(
IPCServer *server)> factory);
76 std::forward_list<std::function<Result<Object*>()>*> factories;
80 template<
typename... T>
86 std::vector<ipc_buffer_t*> buffers;
117 return ipc::OutRaw<T>(*(T*) (((uint8_t*) f.rs.raw_data) + offset));
181 template<
typename T, u
int32_t type,
size_t expected_size>
189 return {(T*) buffer->addr, buffer->
size};
237 fmt.rs.raw_data_size+= (
alignof(T) - 1);
238 fmt.rs.raw_data_size-= fmt.rs.raw_data_size %
alignof(T);
239 size_t offset = fmt.rs.raw_data_size;
240 fmt.rs.raw_data_size+=
sizeof(T);
273 template<
typename T, u
int32_t type,
size_t expected_size>
278 buffer->
size = expected_size;
279 fmt.buffers.push_back(buffer);
295 fmt.rs.send_pid =
true;
303 template<
typename Arg0,
typename... Args>
315 return std::make_tuple();
323 template<
typename T,
typename... Args,
ResultCode (T::*Func)(Args...)>
339 rs.result_code = r.code;
340 return ipc_server_object_reply(&object->object, &rs);
343 for(
size_t i = 0; i < fmt.rs.num_objects; i++) {
344 fmt.rs.objects[i] = &fmt.out_objects[i]->object;
347 return ipc_server_object_reply(&object->object, &fmt.rs);
350 template<std::size_t... I>
352 return std::invoke(Func,
object, (std::get<I>(accessors).Access(fmt))...);
356 template<
typename T,
typename... Args,
ResultCode (T::*Func)(std::function<void(ResultCode)>, Args...)>
359 std::shared_ptr<TransactionFormat> fmt = std::make_shared<TransactionFormat>();
369 RequestHandler<Func>::Helper(
object, fmt, accessors, std::index_sequence_for<Args...>());
372 template<std::size_t... I>
373 static ResultCode Helper(T *
object, std::shared_ptr<TransactionFormat> fmt,
const std::tuple<AccessorHelper<Args>...> &accessors, std::index_sequence<I...>) {
379 rs.result_code = r.code;
380 ipc_server_object_reply(&object->object, &rs);
384 for(
size_t i = 0; i < fmt->rs.num_objects; i++) {
385 fmt->rs.objects[i] = &fmt->out_objects[i]->object;
388 if(ipc_server_object_reply(&object->object, &fmt->rs) != RESULT_OK) {
389 ipc_server_session_close(object->object.owning_session);
391 }, (std::get<I>(accessors).Access(*fmt))...);
Represents the server side of an IPC object.
Definition: ipcserver.h:30
Definition: ipcserver.hpp:27
handle_t * copy_handles
Array to be populated with the expected amount of incoming copy handles.
Definition: ipc.h:110
bool send_pid
Whether to expect an incoming PID.
Definition: ipc.h:105
Definition: waiter.hpp:53
ipc_response_t ipc_default_response
An IPC response with default values set.
Represents an unmarshalled outgoing IPC response.
Definition: ipc.h:121
IPC Server data structures and functions.
Manager for waiting on synchronizable handles (C++ bindings)
size_t raw_data_size
Size in bytes of raw_data to expect.
Definition: ipc.h:104
Definition: ipcserver.hpp:95
ipc_request_fmt_t ipc_default_request_fmt
An IPC request format with default values set.
Describes format expectations for an incoming IPC request.
Definition: ipc.h:100
uint8_t num_move_handles
How many handles to expect to be moved.
Definition: ipc.h:108
Definition: ipcserver.hpp:194
handle_t * move_handles
Array to be populated with the expected amount of incoming move handles.
Definition: ipc.h:111
uint8_t num_copy_handles
How many handles to expect to be copied.
Definition: ipc.h:107
Buffer for transfer over IPC.
Definition: ipc.h:62
result_t ipc_unflatten_request(ipc_message_t *msg, ipc_request_fmt_t *rs, struct ipc_server_object_t *object)
Unflattens the IPC request described by rq from msg
Definition: ipcserver.hpp:321
void * raw_data
Buffer to copy raw request data into.
Definition: ipc.h:103
Definition: ipcserver.hpp:81
Interprocess Communication data structures and functions.
uint64_t size
Size in bytes.
Definition: ipc.h:64
Definition: ipcserver.hpp:39
Definition: ipcserver.h:107
Definition: ipcserver.hpp:204