14#if defined(__MOS_KERNEL__)
30#define syscall_ipc_connect(n, s) ipc_connect(n, s)
31#define syscall_io_close(fd) io_unref(fd)
36#if !defined(__MOS_KERNEL__)
40#define memzero(ptr, size) memset(ptr, 0, size)
41#define mutex_acquire(mutex) pthread_mutex_lock(mutex)
42#define mutex_release(mutex) pthread_mutex_unlock(mutex)
43#define mos_warn(...) fprintf(stderr, __VA_ARGS__)
44#define MOS_LIB_UNREACHABLE() __builtin_unreachable()
47#define RPC_CLIENT_SMH_SIZE MOS_PAGE_SIZE
49typedef struct rpc_server_stub
57typedef struct rpc_call
126#define RPC_CALL_ARG_IMPL(type, TYPE) \
127 void rpc_call_arg_##type(rpc_call_t *call, type arg) \
129 rpc_call_arg(call, RPC_ARGTYPE_##TYPE, &arg, sizeof(arg)); \
146 if (result_data && data_size)
208 if (result_data && data_size && response->
data_size)
211 *result_data = malloc(response->
data_size);
225 va_start(
args, argspec);
243 if (*++argspec !=
'\0')
245 mos_warn(
"argspec is not empty after 'v' (void) (argspec='%s')", argspec);
252 for (
const char *c = argspec; *c !=
'\0'; c++)
258 u8 arg = va_arg(
args,
int);
270 u64 arg = va_arg(
args,
long long);
283 const char *arg = va_arg(
args,
const char *);
311 size_t result_size = 0;
#define RPC_RESPONSE_MAGIC
#define RPC_REQUEST_MAGIC
ipc_msg_t * ipc_read_msg(ipcfd_t fd)
Read an IPC message.
bool ipc_write_as_msg(ipcfd_t fd, const char *data, size_t size)
void ipc_msg_destroy(ipc_msg_t *buffer)
Destroy an IPC message.
bool pb_decode(pb_istream_t *stream, const pb_msgdesc_t *fields, void *dest_struct)
pb_istream_t pb_istream_from_buffer(const pb_byte_t *buf, size_t msglen)
bool pb_get_encoded_size(size_t *size, const pb_msgdesc_t *fields, const void *src_struct)
pb_ostream_t pb_ostream_from_buffer(pb_byte_t *buf, size_t bufsize)
bool pb_encode(pb_ostream_t *stream, const pb_msgdesc_t *fields, const void *src_struct)
static void * memcpy(void *s1, const void *s2, size_t n)
static size_t strlen(const char *s)
@ RPC_RESULT_CLIENT_INVALID_ARGSPEC
@ RPC_RESULT_CALLID_MISMATCH
@ RPC_RESULT_CLIENT_WRITE_FAILED
@ RPC_RESULT_CLIENT_READ_FAILED
rpc_result_code_t rpc_do_pb_call(rpc_server_stub_t *stub, u32 funcid, const pb_msgdesc_t *reqm, const void *req, const pb_msgdesc_t *respm, void *resp)
Call a function on the server using protobuf (nanopb)
#define RPC_CALL_ARG_IMPL(type, TYPE)
#define RPC_CLIENT_SMH_SIZE
void rpc_call_arg(rpc_call_t *call, rpc_argtype_t argtype, const void *data, size_t size)
Add an argument to a call.
#define MOS_LIB_UNREACHABLE()
rpc_result_code_t rpc_call_exec(rpc_call_t *call, void **result_data, size_t *data_size)
Execute a call.
#define mutex_acquire(mutex)
rpc_call_t * rpc_call_create(rpc_server_stub_t *server, u32 function_id)
Manually create a new RPC call.
#define memzero(ptr, size)
void rpc_call_destroy(rpc_call_t *call)
Destroy a call.
void rpc_call_arg_string(rpc_call_t *call, const char *arg)
void rpc_client_destroy(rpc_server_stub_t *server)
Destroy a server stub.
rpc_result_code_t rpc_simple_callv(rpc_server_stub_t *stub, u32 funcid, rpc_result_t *result, const char *argspec, va_list args)
Call a function on the server.
rpc_server_stub_t * rpc_client_create(const char *server_name)
Create a new RPC client stub for the given server.
#define mutex_release(mutex)
rpc_result_code_t rpc_simple_call(rpc_server_stub_t *stub, u32 funcid, rpc_result_t *result, const char *argspec,...)
Call a function on the server.
struct rpc_server_stub rpc_server_stub_t
struct rpc_call rpc_call_t
rpc_server_stub_t * server
rpc_result_code_t result_code
should_inline fd_t syscall_ipc_connect(const char *name, size_t buffer_size)
should_inline bool syscall_io_close(fd_t fd)