Golioth Firmware SDK
Loading...
Searching...
No Matches
golioth_rpc

Typedefs

typedef enum golioth_rpc_status(* golioth_rpc_cb_fn) (zcbor_state_t *request_params_array, zcbor_state_t *response_detail_map, void *callback_arg)
 

Enumerations

enum  golioth_rpc_status {
  GOLIOTH_RPC_OK = 0 , GOLIOTH_RPC_CANCELED = 1 , GOLIOTH_RPC_UNKNOWN = 2 , GOLIOTH_RPC_INVALID_ARGUMENT = 3 ,
  GOLIOTH_RPC_DEADLINE_EXCEEDED = 4 , GOLIOTH_RPC_NOT_FOUND = 5 , GOLIOTH_RPC_ALREADYEXISTS = 6 , GOLIOTH_RPC_PERMISSION_DENIED = 7 ,
  GOLIOTH_RPC_RESOURCE_EXHAUSTED = 8 , GOLIOTH_RPC_FAILED_PRECONDITION = 9 , GOLIOTH_RPC_ABORTED = 10 , GOLIOTH_RPC_OUT_OF_RANGE = 11 ,
  GOLIOTH_RPC_UNIMPLEMENTED = 12 , GOLIOTH_RPC_INTERNAL = 13 , GOLIOTH_RPC_UNAVAILABLE = 14 , GOLIOTH_RPC_DATA_LOSS = 15 ,
  GOLIOTH_RPC_UNAUTHENTICATED = 16
}
 Enumeration of RPC status codes, sent in the RPC response. More...
 

Functions

struct golioth_rpc * golioth_rpc_init (struct golioth_client *client)
 
enum golioth_status golioth_rpc_deinit (struct golioth_rpc *grpc)
 
enum golioth_status golioth_rpc_register (struct golioth_rpc *grpc, const char *method, golioth_rpc_cb_fn callback, void *callback_arg)
 

Detailed Description

Functions for interacting with the Golioth Remote Procedure Call service

Typedef Documentation

◆ golioth_rpc_cb_fn

typedef enum golioth_rpc_status(* golioth_rpc_cb_fn) (zcbor_state_t *request_params_array, zcbor_state_t *response_detail_map, void *callback_arg)

Callback function type for remote procedure call

Example of a callback function that implements the "multiply" method, which takes two float parameters, and multiplies them:

static enum golioth_rpc_status on_multiply(zcbor_state_t *request_params_array,
zcbor_state_t *response_detail_map,
void *callback_arg)
{
double a, b;
double value;
bool ok;
ok = zcbor_float_decode(request_params_array, &a) &&
zcbor_float_decode(request_params_array, &b);
if (!ok) {
GLTH_LOGE(TAG, "Failed to decode array items");
}
value = a * b;
ok = zcbor_tstr_put_lit(response_detail_map, "value") &&
zcbor_float64_put(response_detail_map, value);
if (!ok) {
GLTH_LOGE(TAG, "Failed to encode value");
}
}
#define GLTH_LOGE(TAG,...)
golioth_rpc_status
Enumeration of RPC status codes, sent in the RPC response.
Definition rpc.h:27
@ GOLIOTH_RPC_INVALID_ARGUMENT
Definition rpc.h:31
@ GOLIOTH_RPC_RESOURCE_EXHAUSTED
Definition rpc.h:36
@ GOLIOTH_RPC_OK
Definition rpc.h:28
Parameters
request_params_arrayzcbor decode state, inside of the RPC request params array
response_detail_mapzcbor encode state, inside of the RPC response detail map
callback_argcallback_arg, unchanged from callback_arg of golioth_rpc_register
Return values
GOLIOTH_RPC_OKmethod was called successfully
GOLIOTH_RPC_INVALID_ARGUMENTparams were invalid
Returns
otherwise - method failure

Definition at line 1 of file rpc.h.

Enumeration Type Documentation

◆ golioth_rpc_status

Enumeration of RPC status codes, sent in the RPC response.

Enumerator
GOLIOTH_RPC_OK 
GOLIOTH_RPC_CANCELED 
GOLIOTH_RPC_UNKNOWN 
GOLIOTH_RPC_INVALID_ARGUMENT 
GOLIOTH_RPC_DEADLINE_EXCEEDED 
GOLIOTH_RPC_NOT_FOUND 
GOLIOTH_RPC_ALREADYEXISTS 
GOLIOTH_RPC_PERMISSION_DENIED 
GOLIOTH_RPC_RESOURCE_EXHAUSTED 
GOLIOTH_RPC_FAILED_PRECONDITION 
GOLIOTH_RPC_ABORTED 
GOLIOTH_RPC_OUT_OF_RANGE 
GOLIOTH_RPC_UNIMPLEMENTED 
GOLIOTH_RPC_INTERNAL 
GOLIOTH_RPC_UNAVAILABLE 
GOLIOTH_RPC_DATA_LOSS 
GOLIOTH_RPC_UNAUTHENTICATED 

Definition at line 26 of file rpc.h.

Function Documentation

◆ golioth_rpc_deinit()

enum golioth_status golioth_rpc_deinit ( struct golioth_rpc * grpc)

Deinitialize the RPC service

Cancel all registered RPCs and free the Golioth RPC service handle.

Parameters
grpcGolioth RPC service handle.
Returns
GOLIOTH_OK - RPC service successfully deinitialized
otherwise - Error deinitializing the RPC service

◆ golioth_rpc_init()

struct golioth_rpc * golioth_rpc_init ( struct golioth_client * client)

Initialize the RPC service

Parameters
clientGolioth client handle
Returns
pointer to golioth rpc struct
NULL - Error initializing RPC service

◆ golioth_rpc_register()

enum golioth_status golioth_rpc_register ( struct golioth_rpc * grpc,
const char * method,
golioth_rpc_cb_fn callback,
void * callback_arg )

Register an RPC method

Parameters
grpcGolioth RPC service handle
methodThe name of the method to register
callbackThe callback to be invoked, when an RPC request with matching method name is received by the client.
callback_argUser data forwarded to callback when invoked. Optional, can be NULL.
Returns
GOLIOTH_OK - RPC method successfully registered
otherwise - Error registering RPC method