MOS Source Code
|
#include "librpc/rpc_server.h"
#include "librpc/internal.h"
#include "librpc/rpc.h"
#include <libipc/ipc.h>
#include <mos/types.h>
#include <pb.h>
#include <pb_decode.h>
#include <pb_encode.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mos/syscall/usermode.h>
#include <pthread.h>
Go to the source code of this file.
Classes | |
struct | rpc_server_t |
struct | rpc_args_iter_t |
struct | _rpc_reply_wrapper |
struct | rpc_context_t |
Macros | |
#define | MOS_LIB_ASSERT_X(cond, msg) |
#define | MOS_LIB_ASSERT(cond) |
#define | memzero(ptr, size) |
#define | mutex_acquire(mutex) |
#define | mutex_release(mutex) |
#define | mos_warn(fmt, ...) |
#define | MOS_LIB_UNREACHABLE() |
#define | RPC_SERVER_MAX_PENDING_CALLS 32 |
#define | RPC_ARG_NEXT_IMPL(type, TYPE) |
#define | RPC_GET_ARG_IMPL(type, TYPE) |
Functions | |
static void | start_thread (const char *name, thread_entry_t entry, void *arg) |
static rpc_function_info_t * | rpc_server_get_function (rpc_server_t *server, u32 function_id) |
static void | rpc_handle_client (void *arg) |
rpc_server_t * | rpc_server_create (const char *server_name, void *data) |
Create a new RPC server. | |
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. | |
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. | |
void | rpc_server_close (rpc_server_t *server) |
Close the RPC server. | |
void | rpc_server_destroy (rpc_server_t *server) |
Destroy the RPC server. | |
void | rpc_server_set_data (rpc_server_t *server, void *data) |
Set the user data for the server. | |
void * | rpc_server_get_data (rpc_server_t *server) |
Get the user data for the server. | |
void | rpc_server_exec (rpc_server_t *server) |
Run the server, this function will not return until the server is destroyed. | |
bool | rpc_server_register_functions (rpc_server_t *server, const rpc_function_info_t *functions, size_t count) |
Register multiple functions with the server. | |
void * | rpc_context_get_data (const rpc_context_t *context) |
Get the context data for an RPC context. | |
void * | rpc_context_set_data (rpc_context_t *context, void *data) |
Set the context data for an RPC client. | |
rpc_server_t * | rpc_context_get_server (const rpc_context_t *context) |
Get the RPC server instance for an RPC call context. | |
MOSAPI int | rpc_context_get_function_id (const rpc_context_t *context) |
Get the function ID for an RPC call context. | |
const void * | rpc_arg_next (rpc_context_t *context, size_t *size) |
Iterate to the next argument. | |
const void * | rpc_arg_sized_next (rpc_context_t *context, size_t expected_size) |
Iterate to the next argument, and check that the size is as expected. | |
u8 | rpc_arg_next_u8 (rpc_context_t *context) |
u16 | rpc_arg_next_u16 (rpc_context_t *context) |
u32 | rpc_arg_next_u32 (rpc_context_t *context) |
u64 | rpc_arg_next_u64 (rpc_context_t *context) |
s8 | rpc_arg_next_s8 (rpc_context_t *context) |
s16 | rpc_arg_next_s16 (rpc_context_t *context) |
s32 | rpc_arg_next_s32 (rpc_context_t *context) |
s64 | rpc_arg_next_s64 (rpc_context_t *context) |
const char * | rpc_arg_next_string (rpc_context_t *context) |
const void * | rpc_arg (const rpc_context_t *context, size_t iarg, rpc_argtype_t type, size_t *argsize) |
u8 | rpc_arg_u8 (const rpc_context_t *context, size_t iarg) |
u16 | rpc_arg_u16 (const rpc_context_t *context, size_t iarg) |
u32 | rpc_arg_u32 (const rpc_context_t *context, size_t iarg) |
u64 | rpc_arg_u64 (const rpc_context_t *context, size_t iarg) |
s8 | rpc_arg_s8 (const rpc_context_t *context, size_t iarg) |
s16 | rpc_arg_s16 (const rpc_context_t *context, size_t iarg) |
s32 | rpc_arg_s32 (const rpc_context_t *context, size_t iarg) |
s64 | rpc_arg_s64 (const rpc_context_t *context, size_t iarg) |
const char * | rpc_arg_string (const rpc_context_t *context, size_t iarg) |
void | rpc_write_result (rpc_context_t *context, const void *data, size_t size) |
Write a result to the reply. | |
bool | rpc_arg_pb (rpc_context_t *context, const pb_msgdesc_t *fields, void *val, size_t argid) |
void | rpc_write_result_pb (rpc_context_t *context, const pb_msgdesc_t *type_fields, const void *val) |
#define MOS_LIB_ASSERT_X | ( | cond, | |
msg ) |
Definition at line 25 of file rpc_server.c.
Referenced by hashmap_deinit(), hashmap_foreach(), hashmap_get(), hashmap_put(), hashmap_remove(), rpc_server_register_functions(), rpc_write_result(), and tree_add_child().
#define MOS_LIB_ASSERT | ( | cond | ) |
Definition at line 26 of file rpc_server.c.
Referenced by hashmap_init(), printf_cs(), printf_diouxX(), rpc_arg(), and tree_add_child().
#define memzero | ( | ptr, | |
size ) |
#define mutex_acquire | ( | mutex | ) |
Definition at line 49 of file rpc_server.c.
#define mutex_release | ( | mutex | ) |
Definition at line 50 of file rpc_server.c.
#define mos_warn | ( | fmt, | |
... ) |
#define MOS_LIB_UNREACHABLE | ( | ) |
Definition at line 52 of file rpc_server.c.
#define RPC_SERVER_MAX_PENDING_CALLS 32 |
Definition at line 66 of file rpc_server.c.
Referenced by rpc_server_create().
#define RPC_ARG_NEXT_IMPL | ( | type, | |
TYPE ) |
Definition at line 363 of file rpc_server.c.
#define RPC_GET_ARG_IMPL | ( | type, | |
TYPE ) |
Definition at line 402 of file rpc_server.c.
|
static |
Definition at line 53 of file rpc_server.c.
Referenced by rpc_server_exec().
|
inlinestatic |
Definition at line 100 of file rpc_server.c.
Referenced by rpc_handle_client().
Definition at line 108 of file rpc_server.c.
Referenced by rpc_server_exec().
rpc_server_t * rpc_server_create | ( | const char * | server_name, |
void * | data ) |
Create a new RPC server.
server_name | The name of the server |
data | A pointer to user data, which will be passed to the function |
Definition at line 213 of file rpc_server.c.
Referenced by RPCServer::RPCServer(), and userfs_manager_server_exec().
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.
server | The RPC server instance. |
on_connect | The callback function to be called when a client connects. |
Definition at line 236 of file rpc_server.c.
Referenced by RPCServer::RPCServer().
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.
server | The RPC server instance. |
on_disconnect | The callback function to be called when a client disconnects. |
Definition at line 241 of file rpc_server.c.
Referenced by RPCServer::RPCServer().
void rpc_server_close | ( | rpc_server_t * | server | ) |
Close the RPC server.
server | The server to close |
Definition at line 246 of file rpc_server.c.
Referenced by RPCServer::~RPCServer().
void rpc_server_destroy | ( | rpc_server_t * | server | ) |
Destroy the RPC server.
server | The server to destroy |
Definition at line 252 of file rpc_server.c.
void rpc_server_set_data | ( | rpc_server_t * | server, |
void * | data ) |
Set the user data for the server.
server | The server to set the data for |
data | The data to set |
Definition at line 261 of file rpc_server.c.
void * rpc_server_get_data | ( | rpc_server_t * | server | ) |
Get the user data for the server.
server | The server to get the data for |
Definition at line 266 of file rpc_server.c.
Referenced by RPCServer::RPCServer().
void rpc_server_exec | ( | rpc_server_t * | server | ) |
Run the server, this function will not return until the server is destroyed.
server | The server to run |
Definition at line 271 of file rpc_server.c.
Referenced by RPCServer::run(), and userfs_manager_server_exec().
bool rpc_server_register_functions | ( | rpc_server_t * | server, |
const rpc_function_info_t * | functions, | ||
size_t | count ) |
Register multiple functions with the server.
server | The server to register the functions with |
functions | An array of function info structures |
count | The number of functions to register |
Definition at line 299 of file rpc_server.c.
Referenced by RPCServer::RPCServer(), and userfs_manager_server_exec().
void * rpc_context_get_data | ( | const rpc_context_t * | context | ) |
Get the context data for an RPC context.
context | The context to get the data for |
Definition at line 308 of file rpc_server.c.
Referenced by RPCServer::get_data().
Set the context data for an RPC client.
context | The context to set the data for |
data | The data to set |
Definition at line 313 of file rpc_server.c.
Referenced by RPCServer::set_data().
rpc_server_t * rpc_context_get_server | ( | const rpc_context_t * | context | ) |
Get the RPC server instance for an RPC call context.
context | The context to get the server for |
Definition at line 320 of file rpc_server.c.
Referenced by RPCServer::RPCServer().
Get the function ID for an RPC call context.
context | The context to get the function ID for |
Definition at line 325 of file rpc_server.c.
Referenced by RPCServer::RPCServer().
Iterate to the next argument.
args | The argument iterator |
size | A pointer to the size of the argument |
Definition at line 332 of file rpc_server.c.
Referenced by rpc_arg_next_string(), and rpc_arg_sized_next().
Iterate to the next argument, and check that the size is as expected.
context | The RPC call context |
expected_size | The expected size of the argument |
Definition at line 354 of file rpc_server.c.
u8 rpc_arg_next_u8 | ( | rpc_context_t * | context | ) |
Definition at line 369 of file rpc_server.c.
u16 rpc_arg_next_u16 | ( | rpc_context_t * | context | ) |
Definition at line 370 of file rpc_server.c.
u32 rpc_arg_next_u32 | ( | rpc_context_t * | context | ) |
Definition at line 371 of file rpc_server.c.
u64 rpc_arg_next_u64 | ( | rpc_context_t * | context | ) |
Definition at line 372 of file rpc_server.c.
s8 rpc_arg_next_s8 | ( | rpc_context_t * | context | ) |
Definition at line 373 of file rpc_server.c.
s16 rpc_arg_next_s16 | ( | rpc_context_t * | context | ) |
Definition at line 374 of file rpc_server.c.
s32 rpc_arg_next_s32 | ( | rpc_context_t * | context | ) |
Definition at line 375 of file rpc_server.c.
s64 rpc_arg_next_s64 | ( | rpc_context_t * | context | ) |
Definition at line 376 of file rpc_server.c.
const char * rpc_arg_next_string | ( | rpc_context_t * | context | ) |
const void * rpc_arg | ( | const rpc_context_t * | context, |
size_t | iarg, | ||
rpc_argtype_t | type, | ||
size_t * | argsize ) |
Definition at line 383 of file rpc_server.c.
Referenced by rpc_arg_pb(), and rpc_arg_string().
Definition at line 408 of file rpc_server.c.
Definition at line 409 of file rpc_server.c.
Definition at line 410 of file rpc_server.c.
Definition at line 411 of file rpc_server.c.
Definition at line 412 of file rpc_server.c.
Definition at line 413 of file rpc_server.c.
Definition at line 414 of file rpc_server.c.
Definition at line 415 of file rpc_server.c.
const char * rpc_arg_string | ( | const rpc_context_t * | context, |
size_t | iarg ) |
Write a result to the reply.
context | The RPC call context |
data | The data to write |
size | The size of the data to write |
Definition at line 422 of file rpc_server.c.
Referenced by rpc_write_result_pb().