MOS Source Code
Loading...
Searching...
No Matches
rpc_server.h File Reference
#include "librpc/rpc.h"
#include <mos/types.h>
+ Include dependency graph for rpc_server.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  rpc_function_info_t
 

Macros

#define RPC_MAX_ARGS   16
 

Typedefs

typedef struct _rpc_server rpc_server_t
 
typedef void(* rpc_server_on_connect_t) (rpc_context_t *context)
 
typedef void(* rpc_server_on_disconnect_t) (rpc_context_t *context)
 
typedef rpc_result_code_t(* rpc_function_t) (rpc_context_t *context)
 

Functions

MOSAPI rpc_server_trpc_server_create (const char *server_name, void *data)
 Create a new RPC server.
 
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 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.
 
MOSAPI void rpc_server_set_data (rpc_server_t *server, void *data)
 Set the user data for the server.
 
MOSAPI voidrpc_server_get_data (rpc_server_t *server)
 Get the user data for the server.
 
MOSAPI void rpc_server_exec (rpc_server_t *server)
 Run the server, this function will not return until the server is destroyed.
 
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_destroy (rpc_server_t *server)
 Destroy the RPC server.
 
MOSAPI voidrpc_context_get_data (const rpc_context_t *context)
 Get the context data for an RPC context.
 
MOSAPI voidrpc_context_set_data (rpc_context_t *context, void *data)
 Set the context data for an RPC client.
 
MOSAPI rpc_server_trpc_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.
 
MOSAPI const voidrpc_arg_next (rpc_context_t *args, size_t *size)
 Iterate to the next argument.
 
MOSAPI const voidrpc_arg_sized_next (rpc_context_t *context, size_t expected_size)
 Iterate to the next argument, and check that the size is as expected.
 
MOSAPI u8 rpc_arg_next_u8 (rpc_context_t *args)
 
MOSAPI u16 rpc_arg_next_u16 (rpc_context_t *args)
 
MOSAPI u32 rpc_arg_next_u32 (rpc_context_t *args)
 
MOSAPI u64 rpc_arg_next_u64 (rpc_context_t *args)
 
MOSAPI s8 rpc_arg_next_s8 (rpc_context_t *args)
 
MOSAPI s16 rpc_arg_next_s16 (rpc_context_t *args)
 
MOSAPI s32 rpc_arg_next_s32 (rpc_context_t *args)
 
MOSAPI s64 rpc_arg_next_s64 (rpc_context_t *args)
 
MOSAPI const char * rpc_arg_next_string (rpc_context_t *context)
 
MOSAPI const voidrpc_arg (const rpc_context_t *context, size_t iarg, rpc_argtype_t type, size_t *argsize)
 
MOSAPI u8 rpc_arg_u8 (const rpc_context_t *context, size_t iarg)
 
MOSAPI u16 rpc_arg_u16 (const rpc_context_t *context, size_t iarg)
 
MOSAPI u32 rpc_arg_u32 (const rpc_context_t *context, size_t iarg)
 
MOSAPI u64 rpc_arg_u64 (const rpc_context_t *context, size_t iarg)
 
MOSAPI s8 rpc_arg_s8 (const rpc_context_t *context, size_t iarg)
 
MOSAPI s16 rpc_arg_s16 (const rpc_context_t *context, size_t iarg)
 
MOSAPI s32 rpc_arg_s32 (const rpc_context_t *context, size_t iarg)
 
MOSAPI s64 rpc_arg_s64 (const rpc_context_t *context, size_t iarg)
 
MOSAPI const char * rpc_arg_string (const rpc_context_t *context, size_t iarg)
 
MOSAPI void rpc_write_result (rpc_context_t *context, const void *data, size_t size)
 Write a result to the reply.
 
MOSAPI bool rpc_arg_pb (rpc_context_t *context, const pb_msgdesc_t *type_fields, void *val, size_t argid)
 
MOSAPI void rpc_write_result_pb (rpc_context_t *context, const pb_msgdesc_t *type_fields, const void *val)
 

Macro Definition Documentation

◆ RPC_MAX_ARGS

#define RPC_MAX_ARGS   16

Definition at line 10 of file rpc_server.h.

Referenced by rpc_handle_client().

Typedef Documentation

◆ rpc_server_t

typedef struct _rpc_server rpc_server_t

Definition at line 12 of file rpc_server.h.

◆ rpc_server_on_connect_t

typedef void(* rpc_server_on_connect_t) (rpc_context_t *context)

Definition at line 15 of file rpc_server.h.

◆ rpc_server_on_disconnect_t

typedef void(* rpc_server_on_disconnect_t) (rpc_context_t *context)

Definition at line 16 of file rpc_server.h.

◆ rpc_function_t

typedef rpc_result_code_t(* rpc_function_t) (rpc_context_t *context)

Definition at line 17 of file rpc_server.h.

Function Documentation

◆ rpc_server_create()

MOSAPI rpc_server_t * rpc_server_create ( const char * server_name,
void * data )

Create a new RPC server.

Parameters
server_nameThe name of the server
dataA pointer to user data, which will be passed to the function
Returns
rpc_server_t* A pointer to the new server

Definition at line 213 of file rpc_server.c.

Referenced by RPCServer::RPCServer(), and userfs_manager_server_exec().

+ Here is the call graph for this function:

◆ rpc_server_set_on_connect()

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.

Parameters
serverThe RPC server instance.
on_connectThe callback function to be called when a client connects.

Definition at line 236 of file rpc_server.c.

Referenced by RPCServer::RPCServer().

◆ rpc_server_set_on_disconnect()

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.

Parameters
serverThe RPC server instance.
on_disconnectThe callback function to be called when a client disconnects.

Definition at line 241 of file rpc_server.c.

Referenced by RPCServer::RPCServer().

◆ rpc_server_set_data()

MOSAPI void rpc_server_set_data ( rpc_server_t * server,
void * data )

Set the user data for the server.

Parameters
serverThe server to set the data for
dataThe data to set

Definition at line 261 of file rpc_server.c.

◆ rpc_server_get_data()

MOSAPI void * rpc_server_get_data ( rpc_server_t * server)

Get the user data for the server.

Parameters
serverThe server to get the data for

Definition at line 266 of file rpc_server.c.

Referenced by RPCServer::RPCServer().

◆ rpc_server_exec()

MOSAPI void rpc_server_exec ( rpc_server_t * server)

Run the server, this function will not return until the server is destroyed.

Parameters
serverThe server to run
Note
The incoming RPC calls will be handled in a separate thread.

Definition at line 271 of file rpc_server.c.

Referenced by RPCServer::run(), and userfs_manager_server_exec().

+ Here is the call graph for this function:

◆ rpc_server_register_functions()

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.

Parameters
serverThe server to register the functions with
functionsAn array of function info structures
countThe number of functions to register
Returns
true The functions were registered successfully
false The functions could not be registered

Definition at line 299 of file rpc_server.c.

Referenced by RPCServer::RPCServer(), and userfs_manager_server_exec().

+ Here is the call graph for this function:

◆ rpc_server_close()

MOSAPI void rpc_server_close ( rpc_server_t * server)

Close the RPC server.

Parameters
serverThe server to close

Definition at line 246 of file rpc_server.c.

Referenced by RPCServer::~RPCServer().

+ Here is the call graph for this function:

◆ rpc_server_destroy()

MOSAPI void rpc_server_destroy ( rpc_server_t * server)

Destroy the RPC server.

Parameters
serverThe server to destroy

Definition at line 252 of file rpc_server.c.

+ Here is the call graph for this function:

◆ rpc_context_get_data()

MOSAPI void * rpc_context_get_data ( const rpc_context_t * context)

Get the context data for an RPC context.

Parameters
contextThe context to get the data for
Returns
MOSAPI*

Definition at line 308 of file rpc_server.c.

Referenced by RPCServer::get_data().

◆ rpc_context_set_data()

MOSAPI void * rpc_context_set_data ( rpc_context_t * context,
void * data )

Set the context data for an RPC client.

Parameters
contextThe context to set the data for
dataThe data to set
Returns
void* The previous data, or NULL if there was no previous data

Definition at line 313 of file rpc_server.c.

Referenced by RPCServer::set_data().

◆ rpc_context_get_server()

MOSAPI rpc_server_t * rpc_context_get_server ( const rpc_context_t * context)

Get the RPC server instance for an RPC call context.

Parameters
contextThe context to get the server for
Returns
rpc_server_t* The server

Definition at line 320 of file rpc_server.c.

Referenced by RPCServer::RPCServer().

◆ rpc_context_get_function_id()

MOSAPI int rpc_context_get_function_id ( const rpc_context_t * context)

Get the function ID for an RPC call context.

Parameters
contextThe context to get the function ID for
Returns
int The function ID

Definition at line 325 of file rpc_server.c.

Referenced by RPCServer::RPCServer().

◆ rpc_arg_next()

MOSAPI const void * rpc_arg_next ( rpc_context_t * args,
size_t * size )

Iterate to the next argument.

Parameters
argsThe argument iterator
sizeA pointer to the size of the argument
Returns
const void* A pointer to the next argument
Note
Do not modify any of the data in the returned pointer.

Definition at line 332 of file rpc_server.c.

Referenced by rpc_arg_next_string(), and rpc_arg_sized_next().

◆ rpc_arg_sized_next()

MOSAPI 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.

Parameters
contextThe RPC call context
expected_sizeThe expected size of the argument
Returns
const void* A pointer to the next argument, or NULL if the size is incorrect.
Note
Do not modify any of the data in the returned pointer.

Definition at line 354 of file rpc_server.c.

+ Here is the call graph for this function:

◆ rpc_arg_next_u8()

MOSAPI u8 rpc_arg_next_u8 ( rpc_context_t * args)

Definition at line 369 of file rpc_server.c.

◆ rpc_arg_next_u16()

MOSAPI u16 rpc_arg_next_u16 ( rpc_context_t * args)

Definition at line 370 of file rpc_server.c.

◆ rpc_arg_next_u32()

MOSAPI u32 rpc_arg_next_u32 ( rpc_context_t * args)

Definition at line 371 of file rpc_server.c.

◆ rpc_arg_next_u64()

MOSAPI u64 rpc_arg_next_u64 ( rpc_context_t * args)

Definition at line 372 of file rpc_server.c.

◆ rpc_arg_next_s8()

MOSAPI s8 rpc_arg_next_s8 ( rpc_context_t * args)

Definition at line 373 of file rpc_server.c.

◆ rpc_arg_next_s16()

MOSAPI s16 rpc_arg_next_s16 ( rpc_context_t * args)

Definition at line 374 of file rpc_server.c.

◆ rpc_arg_next_s32()

MOSAPI s32 rpc_arg_next_s32 ( rpc_context_t * args)

Definition at line 375 of file rpc_server.c.

◆ rpc_arg_next_s64()

MOSAPI s64 rpc_arg_next_s64 ( rpc_context_t * args)

Definition at line 376 of file rpc_server.c.

◆ rpc_arg_next_string()

MOSAPI const char * rpc_arg_next_string ( rpc_context_t * context)

Definition at line 378 of file rpc_server.c.

+ Here is the call graph for this function:

◆ rpc_arg()

MOSAPI 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().

◆ rpc_arg_u8()

MOSAPI u8 rpc_arg_u8 ( const rpc_context_t * context,
size_t iarg )

Definition at line 408 of file rpc_server.c.

◆ rpc_arg_u16()

MOSAPI u16 rpc_arg_u16 ( const rpc_context_t * context,
size_t iarg )

Definition at line 409 of file rpc_server.c.

◆ rpc_arg_u32()

MOSAPI u32 rpc_arg_u32 ( const rpc_context_t * context,
size_t iarg )

Definition at line 410 of file rpc_server.c.

◆ rpc_arg_u64()

MOSAPI u64 rpc_arg_u64 ( const rpc_context_t * context,
size_t iarg )

Definition at line 411 of file rpc_server.c.

◆ rpc_arg_s8()

MOSAPI s8 rpc_arg_s8 ( const rpc_context_t * context,
size_t iarg )

Definition at line 412 of file rpc_server.c.

◆ rpc_arg_s16()

MOSAPI s16 rpc_arg_s16 ( const rpc_context_t * context,
size_t iarg )

Definition at line 413 of file rpc_server.c.

◆ rpc_arg_s32()

MOSAPI s32 rpc_arg_s32 ( const rpc_context_t * context,
size_t iarg )

Definition at line 414 of file rpc_server.c.

◆ rpc_arg_s64()

MOSAPI s64 rpc_arg_s64 ( const rpc_context_t * context,
size_t iarg )

Definition at line 415 of file rpc_server.c.

◆ rpc_arg_string()

MOSAPI const char * rpc_arg_string ( const rpc_context_t * context,
size_t iarg )

Definition at line 417 of file rpc_server.c.

+ Here is the call graph for this function:

◆ rpc_write_result()

MOSAPI void rpc_write_result ( rpc_context_t * context,
const void * data,
size_t size )

Write a result to the reply.

Parameters
contextThe RPC call context
dataThe data to write
sizeThe size of the data to write

Definition at line 422 of file rpc_server.c.

Referenced by rpc_write_result_pb().

+ Here is the call graph for this function:

◆ rpc_arg_pb()

MOSAPI bool rpc_arg_pb ( rpc_context_t * context,
const pb_msgdesc_t * type_fields,
void * val,
size_t argid )

Definition at line 435 of file rpc_server.c.

+ Here is the call graph for this function:

◆ rpc_write_result_pb()

MOSAPI void rpc_write_result_pb ( rpc_context_t * context,
const pb_msgdesc_t * type_fields,
const void * val )

Definition at line 443 of file rpc_server.c.

+ Here is the call graph for this function: