Golioth Zephyr SDK
rpc.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-2023 Golioth, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef GOLIOTH_INCLUDE_NET_GOLIOTH_RPC_H_
8 #define GOLIOTH_INCLUDE_NET_GOLIOTH_RPC_H_
9 
10 #include <stdint.h>
11 #include <zephyr/net/coap.h>
12 #include <zephyr/kernel.h>
13 
14 #ifdef CONFIG_ZCBOR
15 #include <zcbor_decode.h>
16 #include <zcbor_encode.h>
17 #else
18 typedef struct {} zcbor_state_t;
19 #endif
20 
28 struct golioth_client;
29 
51 };
52 
102 typedef enum golioth_rpc_status (*golioth_rpc_cb_fn)(zcbor_state_t *request_params_array,
103  zcbor_state_t *response_detail_map,
104  void *callback_arg);
105 
110  const char *name;
113 };
114 
118 struct golioth_rpc {
119 #if defined(CONFIG_GOLIOTH_RPC)
120  struct golioth_rpc_method methods[CONFIG_GOLIOTH_RPC_MAX_NUM_METHODS];
121  int num_methods;
122  struct k_mutex mutex;
123 #endif
124 };
125 
134 int golioth_rpc_init(struct golioth_client *client);
135 
149  const char *method_name,
150  golioth_rpc_cb_fn callback,
151  void *callback_arg);
152 
170 
173 #endif /* GOLIOTH_INCLUDE_NET_GOLIOTH_RPC_H_ */
int golioth_rpc_register(struct golioth_client *client, const char *method_name, golioth_rpc_cb_fn callback, void *callback_arg)
Register an RPC method.
int golioth_rpc_init(struct golioth_client *client)
Initialize RPC.
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.
Definition: rpc.h:102
golioth_rpc_status
Enumeration of RPC status codes, sent in the RPC response.
Definition: rpc.h:33
int golioth_rpc_observe(struct golioth_client *client)
Observe for RPC method invocations.
@ GOLIOTH_RPC_ABORTED
Definition: rpc.h:44
@ GOLIOTH_RPC_UNAVAILABLE
Definition: rpc.h:48
@ GOLIOTH_RPC_UNKNOWN
Definition: rpc.h:36
@ GOLIOTH_RPC_OUT_OF_RANGE
Definition: rpc.h:45
@ GOLIOTH_RPC_ALREADYEXISTS
Definition: rpc.h:40
@ GOLIOTH_RPC_INVALID_ARGUMENT
Definition: rpc.h:37
@ GOLIOTH_RPC_PERMISSION_DENIED
Definition: rpc.h:41
@ GOLIOTH_RPC_DATA_LOSS
Definition: rpc.h:49
@ GOLIOTH_RPC_INTERNAL
Definition: rpc.h:47
@ GOLIOTH_RPC_RESOURCE_EXHAUSTED
Definition: rpc.h:42
@ GOLIOTH_RPC_OK
Definition: rpc.h:34
@ GOLIOTH_RPC_NOT_FOUND
Definition: rpc.h:39
@ GOLIOTH_RPC_UNAUTHENTICATED
Definition: rpc.h:50
@ GOLIOTH_RPC_DEADLINE_EXCEEDED
Definition: rpc.h:38
@ GOLIOTH_RPC_FAILED_PRECONDITION
Definition: rpc.h:43
@ GOLIOTH_RPC_UNIMPLEMENTED
Definition: rpc.h:46
@ GOLIOTH_RPC_CANCELED
Definition: rpc.h:35
Represents a Golioth client instance.
Definition: net/golioth.h:50
Data for each registered RPC method.
Definition: rpc.h:109
golioth_rpc_cb_fn callback
Definition: rpc.h:111
const char * name
Definition: rpc.h:110
void * callback_arg
Definition: rpc.h:112
Global/shared RPC state data, placed in struct golioth_client.
Definition: rpc.h:118