MOS Source Code
Loading...
Searching...
No Matches
rpc_server.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2// RPC library server-side definitions
3
4#pragma once
5
6#include "librpc/rpc.h"
7
8#include <mos/types.h>
9
10#define RPC_MAX_ARGS 16
11
12typedef struct _rpc_server rpc_server_t;
13typedef struct _rpc_context rpc_context_t;
14
15typedef void (*rpc_server_on_connect_t)(rpc_context_t *context); // called when a client connects
16typedef void (*rpc_server_on_disconnect_t)(rpc_context_t *context); // called when a client disconnects
17typedef rpc_result_code_t (*rpc_function_t)(rpc_context_t *context); // called when a client calls a function
18
26
34MOSAPI rpc_server_t *rpc_server_create(const char *server_name, void *data);
35
43
51
58MOSAPI void rpc_server_set_data(rpc_server_t *server, void *data);
59
66
75
85MOSAPI bool rpc_server_register_functions(rpc_server_t *server, const rpc_function_info_t *functions, size_t count);
86
93
100
107MOSAPI void *rpc_context_get_data(const rpc_context_t *context);
108
116MOSAPI void *rpc_context_set_data(rpc_context_t *context, void *data);
117
124MOSAPI rpc_server_t *rpc_context_get_server(const rpc_context_t *context);
125
132MOSAPI int rpc_context_get_function_id(const rpc_context_t *context);
133
143MOSAPI const void *rpc_arg_next(rpc_context_t *args, size_t *size);
144
154MOSAPI const void *rpc_arg_sized_next(rpc_context_t *context, size_t expected_size);
155MOSAPI u8 rpc_arg_next_u8(rpc_context_t *args);
156MOSAPI u16 rpc_arg_next_u16(rpc_context_t *args);
157MOSAPI u32 rpc_arg_next_u32(rpc_context_t *args);
158MOSAPI u64 rpc_arg_next_u64(rpc_context_t *args);
159MOSAPI s8 rpc_arg_next_s8(rpc_context_t *args);
160MOSAPI s16 rpc_arg_next_s16(rpc_context_t *args);
161MOSAPI s32 rpc_arg_next_s32(rpc_context_t *args);
162MOSAPI s64 rpc_arg_next_s64(rpc_context_t *args);
163MOSAPI const char *rpc_arg_next_string(rpc_context_t *context);
164
165MOSAPI const void *rpc_arg(const rpc_context_t *context, size_t iarg, rpc_argtype_t type, size_t *argsize);
166MOSAPI u8 rpc_arg_u8(const rpc_context_t *context, size_t iarg);
167MOSAPI u16 rpc_arg_u16(const rpc_context_t *context, size_t iarg);
168MOSAPI u32 rpc_arg_u32(const rpc_context_t *context, size_t iarg);
169MOSAPI u64 rpc_arg_u64(const rpc_context_t *context, size_t iarg);
170MOSAPI s8 rpc_arg_s8(const rpc_context_t *context, size_t iarg);
171MOSAPI s16 rpc_arg_s16(const rpc_context_t *context, size_t iarg);
172MOSAPI s32 rpc_arg_s32(const rpc_context_t *context, size_t iarg);
173MOSAPI s64 rpc_arg_s64(const rpc_context_t *context, size_t iarg);
174MOSAPI const char *rpc_arg_string(const rpc_context_t *context, size_t iarg);
175
183MOSAPI void rpc_write_result(rpc_context_t *context, const void *data, size_t size);
184
185// so we can use protobuf (nanopb) with librpc
186typedef struct pb_msgdesc_s pb_msgdesc_t;
187
188MOSAPI bool rpc_arg_pb(rpc_context_t *context, const pb_msgdesc_t *type_fields, void *val, size_t argid);
189
190MOSAPI void rpc_write_result_pb(rpc_context_t *context, const pb_msgdesc_t *type_fields, const void *val);
char args[3][16]
Definition avr_io.c:16
MOSAPI void(1, 2) fatal_abort(const char *fmt
#define MOSAPI
Definition mos_global.h:102
rpc_argtype_t
Definition rpc.h:9
rpc_result_code_t
Definition rpc.h:25
MOSAPI u64 rpc_arg_u64(const rpc_context_t *context, size_t iarg)
Definition rpc_server.c:411
MOSAPI rpc_server_t * rpc_server_create(const char *server_name, void *data)
Create a new RPC server.
Definition rpc_server.c:213
MOSAPI void rpc_write_result_pb(rpc_context_t *context, const pb_msgdesc_t *type_fields, const void *val)
Definition rpc_server.c:443
MOSAPI s32 rpc_arg_next_s32(rpc_context_t *args)
Definition rpc_server.c:375
rpc_result_code_t(* rpc_function_t)(rpc_context_t *context)
Definition rpc_server.h:17
MOSAPI void rpc_write_result(rpc_context_t *context, const void *data, size_t size)
Write a result to the reply.
Definition rpc_server.c:422
MOSAPI void * rpc_context_set_data(rpc_context_t *context, void *data)
Set the context data for an RPC client.
Definition rpc_server.c:313
MOSAPI const void * rpc_arg(const rpc_context_t *context, size_t iarg, rpc_argtype_t type, size_t *argsize)
Definition rpc_server.c:383
MOSAPI s16 rpc_arg_s16(const rpc_context_t *context, size_t iarg)
Definition rpc_server.c:413
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.
Definition rpc_server.c:354
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.
Definition rpc_server.c:299
MOSAPI s8 rpc_arg_next_s8(rpc_context_t *args)
Definition rpc_server.c:373
void(* rpc_server_on_disconnect_t)(rpc_context_t *context)
Definition rpc_server.h:16
MOSAPI u16 rpc_arg_next_u16(rpc_context_t *args)
Definition rpc_server.c:370
MOSAPI bool rpc_arg_pb(rpc_context_t *context, const pb_msgdesc_t *type_fields, void *val, size_t argid)
Definition rpc_server.c:435
MOSAPI void rpc_server_close(rpc_server_t *server)
Close the RPC server.
Definition rpc_server.c:246
MOSAPI void * rpc_server_get_data(rpc_server_t *server)
Get the user data for the server.
Definition rpc_server.c:266
MOSAPI u8 rpc_arg_next_u8(rpc_context_t *args)
Definition rpc_server.c:369
MOSAPI u32 rpc_arg_u32(const rpc_context_t *context, size_t iarg)
Definition rpc_server.c:410
MOSAPI s64 rpc_arg_s64(const rpc_context_t *context, size_t iarg)
Definition rpc_server.c:415
void(* rpc_server_on_connect_t)(rpc_context_t *context)
Definition rpc_server.h:15
MOSAPI const char * rpc_arg_next_string(rpc_context_t *context)
Definition rpc_server.c:378
MOSAPI int rpc_context_get_function_id(const rpc_context_t *context)
Get the function ID for an RPC call context.
Definition rpc_server.c:325
MOSAPI void rpc_server_set_data(rpc_server_t *server, void *data)
Set the user data for the server.
Definition rpc_server.c:261
MOSAPI s16 rpc_arg_next_s16(rpc_context_t *args)
Definition rpc_server.c:374
MOSAPI void * rpc_context_get_data(const rpc_context_t *context)
Get the context data for an RPC context.
Definition rpc_server.c:308
#define RPC_MAX_ARGS
Definition rpc_server.h:10
MOSAPI s32 rpc_arg_s32(const rpc_context_t *context, size_t iarg)
Definition rpc_server.c:414
MOSAPI void rpc_server_exec(rpc_server_t *server)
Run the server, this function will not return until the server is destroyed.
Definition rpc_server.c:271
MOSAPI u16 rpc_arg_u16(const rpc_context_t *context, size_t iarg)
Definition rpc_server.c:409
MOSAPI void rpc_server_destroy(rpc_server_t *server)
Destroy the RPC server.
Definition rpc_server.c:252
MOSAPI u8 rpc_arg_u8(const rpc_context_t *context, size_t iarg)
Definition rpc_server.c:408
MOSAPI s8 rpc_arg_s8(const rpc_context_t *context, size_t iarg)
Definition rpc_server.c:412
MOSAPI u32 rpc_arg_next_u32(rpc_context_t *args)
Definition rpc_server.c:371
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.
Definition rpc_server.c:236
MOSAPI rpc_server_t * rpc_context_get_server(const rpc_context_t *context)
Get the RPC server instance for an RPC call context.
Definition rpc_server.c:320
MOSAPI u64 rpc_arg_next_u64(rpc_context_t *args)
Definition rpc_server.c:372
MOSAPI const char * rpc_arg_string(const rpc_context_t *context, size_t iarg)
Definition rpc_server.c:417
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.
Definition rpc_server.c:241
MOSAPI const void * rpc_arg_next(rpc_context_t *args, size_t *size)
Iterate to the next argument.
Definition rpc_server.c:332
MOSAPI s64 rpc_arg_next_s64(rpc_context_t *args)
Definition rpc_server.c:376
size_t size
Definition slab.c:30
rpc_function_t func
Definition rpc_server.h:22
signed int s32
Definition types.h:15
unsigned int u32
Definition types.h:21
signed char s8
Definition types.h:13
signed long long int s64
Definition types.h:17
signed short s16
Definition types.h:14
unsigned short u16
Definition types.h:20
unsigned long long u64
Definition types.h:23
unsigned char u8
Definition types.h:19