6#if defined(__MOS_KERNEL__) || !defined(__cplusplus)
7#error "This file is only for use in C++ userspace code"
20 const auto redirector = [](rpc_context_t *context)
24 return ((
RPCServer *) userdata)->dispatcher(context, fid);
27 const auto redirector_on_connect = [](rpc_context_t *context)
30 ((
RPCServer *) userdata)->on_connect(context);
33 const auto redirector_on_disconnect = [](rpc_context_t *context)
36 ((
RPCServer *) userdata)->on_disconnect(context);
40 for (
size_t i = 0; i < count; i++)
42 redirect_functions[i] = functions[i];
43 redirect_functions[i].
func = redirector;
49 throw std::runtime_error(
"Failed to create RPC server: " +
server_name +
" (" + strerror(errno) +
")");
std::string get_name() const
virtual void on_disconnect(rpc_context_t *)
void set_data(rpc_context_t *context, T *data)
RPCServer(const std::string &server_name, const rpc_function_info_t *functions, size_t count)
T * get_data(rpc_context_t *context)
virtual rpc_result_code_t dispatcher(rpc_context_t *context, u32 funcid)=0
virtual void on_connect(rpc_context_t *)
MOSAPI rpc_server_t * rpc_server_create(const char *server_name, void *data)
Create a new RPC server.
MOSAPI void * rpc_context_set_data(rpc_context_t *context, void *data)
Set the context data for an RPC client.
MOSAPI bool rpc_server_register_functions(rpc_server_t *server, const rpc_function_info_t *functions, size_t count)
Register multiple functions with the server.
MOSAPI void rpc_server_close(rpc_server_t *server)
Close the RPC server.
MOSAPI void * rpc_server_get_data(rpc_server_t *server)
Get the user data for the server.
MOSAPI int rpc_context_get_function_id(const rpc_context_t *context)
Get the function ID for an RPC call context.
MOSAPI void * rpc_context_get_data(const rpc_context_t *context)
Get the context data for an RPC context.
MOSAPI void rpc_server_exec(rpc_server_t *server)
Run the server, this function will not return until the server is destroyed.
MOSAPI void rpc_server_set_on_connect(rpc_server_t *server, rpc_server_on_connect_t on_connect)
Sets the callback function to be called when a client connects to the RPC server.
MOSAPI rpc_server_t * rpc_context_get_server(const rpc_context_t *context)
Get the RPC server instance for an RPC call context.
MOSAPI void rpc_server_set_on_disconnect(rpc_server_t *server, rpc_server_on_disconnect_t on_disconnect)
Sets the callback function to be called when a client disconnects from the RPC server.