MOS Source Code
Loading...
Searching...
No Matches
rpc_client.c File Reference
#include "librpc/rpc_client.h"
#include "librpc/internal.h"
#include "librpc/rpc.h"
#include <libipc/ipc.h>
#include <mos/types.h>
#include <pb_decode.h>
#include <pb_encode.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mos/syscall/usermode.h>
#include <pthread.h>
+ Include dependency graph for rpc_client.c:

Go to the source code of this file.

Classes

struct  rpc_server_stub_t
 
struct  rpc_call_t
 

Macros

#define memzero(ptr, size)
 
#define mutex_acquire(mutex)
 
#define mutex_release(mutex)
 
#define mos_warn(...)
 
#define MOS_LIB_UNREACHABLE()
 
#define RPC_CLIENT_SMH_SIZE   MOS_PAGE_SIZE
 
#define RPC_CALL_ARG_IMPL(type, TYPE)
 

Typedefs

typedef pthread_mutex_t mutex_t
 

Functions

rpc_server_stub_trpc_client_create (const char *server_name)
 Create a new RPC client stub for the given server.
 
void rpc_client_destroy (rpc_server_stub_t *server)
 Destroy a server stub.
 
rpc_call_trpc_call_create (rpc_server_stub_t *server, u32 function_id)
 Manually create a new RPC call.
 
void rpc_call_destroy (rpc_call_t *call)
 Destroy a call.
 
void rpc_call_arg (rpc_call_t *call, rpc_argtype_t argtype, const void *data, size_t size)
 Add an argument to a call.
 
void rpc_call_arg_u8 (rpc_call_t *call, u8 arg)
 
void rpc_call_arg_u32 (rpc_call_t *call, u32 arg)
 
void rpc_call_arg_u64 (rpc_call_t *call, u64 arg)
 
void rpc_call_arg_s8 (rpc_call_t *call, s8 arg)
 
void rpc_call_arg_s32 (rpc_call_t *call, s32 arg)
 
void rpc_call_arg_s64 (rpc_call_t *call, s64 arg)
 
void rpc_call_arg_string (rpc_call_t *call, const char *arg)
 
rpc_result_code_t rpc_call_exec (rpc_call_t *call, void **result_data, size_t *data_size)
 Execute a call.
 
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.
 
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_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)
 

Macro Definition Documentation

◆ memzero

◆ mutex_acquire

#define mutex_acquire ( mutex)

◆ mutex_release

#define mutex_release ( mutex)
Value:
pthread_mutex_unlock(mutex)

Definition at line 42 of file rpc_client.c.

Referenced by do_pagecache_flush(), inode_try_drop(), rpc_call_arg(), rpc_call_exec(), vfs_fault_handler(), vfs_read_pagecache(), and vfs_write_pagecache().

◆ mos_warn

#define mos_warn ( ...)
Value:
fprintf(stderr, __VA_ARGS__)
#define stderr
Definition mos_stdio.h:32

Definition at line 43 of file rpc_client.c.

Referenced by rpc_simple_callv().

◆ MOS_LIB_UNREACHABLE

#define MOS_LIB_UNREACHABLE ( )
Value:
__builtin_unreachable()

Definition at line 44 of file rpc_client.c.

Referenced by printf_diouxX(), rpc_simple_callv(), and vsnprintf().

◆ RPC_CLIENT_SMH_SIZE

#define RPC_CLIENT_SMH_SIZE   MOS_PAGE_SIZE

Definition at line 47 of file rpc_client.c.

Referenced by rpc_client_create().

◆ RPC_CALL_ARG_IMPL

#define RPC_CALL_ARG_IMPL ( type,
TYPE )
Value:
void rpc_call_arg_##type(rpc_call_t *call, type arg) \
{ \
rpc_call_arg(call, RPC_ARGTYPE_##TYPE, &arg, sizeof(arg)); \
}

Definition at line 126 of file rpc_client.c.

Typedef Documentation

◆ mutex_t

typedef pthread_mutex_t mutex_t

Definition at line 39 of file rpc_client.c.

Function Documentation

◆ rpc_client_create()

rpc_server_stub_t * rpc_client_create ( const char * server_name)

Create a new RPC client stub for the given server.

Parameters
server_nameThe name of the server to connect to
Returns
rpc_server_stub_t* A pointer to the new server stub, or NULL on error

Definition at line 65 of file rpc_client.c.

Referenced by userfs_ensure_connected().

+ Here is the call graph for this function:

◆ rpc_client_destroy()

void rpc_client_destroy ( rpc_server_stub_t * server)

Destroy a server stub.

Parameters
serverThe server stub to destroy

Definition at line 81 of file rpc_client.c.

+ Here is the call graph for this function:

◆ rpc_call_create()

rpc_call_t * rpc_call_create ( rpc_server_stub_t * server,
u32 function_id )

Manually create a new RPC call.

Parameters
serverThe server stub to call
function_idThe function ID to call
Returns
rpc_call_t* A pointer to the new call.

Definition at line 88 of file rpc_client.c.

Referenced by rpc_do_pb_call(), and rpc_simple_callv().

◆ rpc_call_destroy()

void rpc_call_destroy ( rpc_call_t * call)

Destroy a call.

Parameters
callThe call to destroy

Definition at line 103 of file rpc_client.c.

Referenced by rpc_do_pb_call(), and rpc_simple_callv().

◆ rpc_call_arg()

void rpc_call_arg ( rpc_call_t * call,
rpc_argtype_t argtype,
const void * data,
size_t size )

Add an argument to a call.

Parameters
callThe call to add the argument to
argtypeThe type of the argument
dataA pointer to the argument data
sizeThe size of the argument data

Definition at line 110 of file rpc_client.c.

Referenced by rpc_call_arg_string(), rpc_do_pb_call(), and rpc_simple_callv().

+ Here is the call graph for this function:

◆ rpc_call_arg_u8()

void rpc_call_arg_u8 ( rpc_call_t * call,
u8 arg )

Definition at line 132 of file rpc_client.c.

◆ rpc_call_arg_u32()

void rpc_call_arg_u32 ( rpc_call_t * call,
u32 arg )

Definition at line 133 of file rpc_client.c.

◆ rpc_call_arg_u64()

void rpc_call_arg_u64 ( rpc_call_t * call,
u64 arg )

Definition at line 134 of file rpc_client.c.

◆ rpc_call_arg_s8()

void rpc_call_arg_s8 ( rpc_call_t * call,
s8 arg )

Definition at line 135 of file rpc_client.c.

◆ rpc_call_arg_s32()

void rpc_call_arg_s32 ( rpc_call_t * call,
s32 arg )

Definition at line 136 of file rpc_client.c.

◆ rpc_call_arg_s64()

void rpc_call_arg_s64 ( rpc_call_t * call,
s64 arg )

Definition at line 137 of file rpc_client.c.

◆ rpc_call_arg_string()

void rpc_call_arg_string ( rpc_call_t * call,
const char * arg )

Definition at line 139 of file rpc_client.c.

+ Here is the call graph for this function:

◆ rpc_call_exec()

rpc_result_code_t rpc_call_exec ( rpc_call_t * call,
void ** result_data,
size_t * result_size )

Execute a call.

Parameters
callThe call to execute
result_dataA pointer to a pointer to the result data, or NULL if no result is expected
result_sizeA pointer to the size of the result data, or NULL if no result is expected
Returns
rpc_result_code_t The result code of the call
Note
The result data will be malloc'd and must be freed by the caller.

Definition at line 144 of file rpc_client.c.

Referenced by rpc_do_pb_call(), and rpc_simple_callv().

+ Here is the call graph for this function:

◆ rpc_simple_call()

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.

Parameters
stubThe server stub to call
funcidThe function ID to call
resultA pointer to a result structure, or NULL if no result is expected
argspecAn argument specification string, see spec.md for details
...The arguments to the function
Returns
rpc_result_code_t The result code of the call
Note
The result data will be malloc'd and must be freed by the caller.
This function is a simple wrapper around rpc_call_create, rpc_call_arg, rpc_call_exec and rpc_call_destroy.

Definition at line 222 of file rpc_client.c.

+ Here is the call graph for this function:

◆ rpc_simple_callv()

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.

Parameters
stubThe server stub to call
funcidThe function ID to call
resultA pointer to a result structure, or NULL if no result is expected
argspecAn argument specification string, see spec.md for details
argsThe arguments to the function
Returns
rpc_result_code_t The result code of the call

Definition at line 231 of file rpc_client.c.

Referenced by rpc_simple_call().

+ Here is the call graph for this function:

◆ rpc_do_pb_call()

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)

Parameters
stubThe server stub to call
funcidThe function ID to call
reqmThe protobuf message descriptor for the request
reqThe request message
respmThe protobuf message descriptor for the response
respThe response message
Returns
rpc_result_code_t

Definition at line 298 of file rpc_client.c.

+ Here is the call graph for this function: