aboutsummaryrefslogtreecommitdiff
path: root/components/rpc/common/endpoint/rpc_interface.h
blob: 44e5783548b6353c672a926809845f63cdba49b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#ifndef RPC_INTERFACE_H
#define RPC_INTERFACE_H

#include <stddef.h>
#include <stdint.h>
#include <rpc_status.h>

#ifdef __cplusplus
extern "C" {
#endif

/* Definitions related to an rpc call endpoint */

/** \brief Call parameter buffer
 *
 * Describes a buffer for holding call request and response parameters.
 */
struct call_param_buf {
	size_t size;
	size_t data_len;
	void *data;
};

static inline struct call_param_buf call_param_buf_init_empty(void *data, size_t size)
{
	struct call_param_buf v;

	v.size = size;
	v.data_len = 0;
	v.data = data;

	return v;
}

static inline struct call_param_buf call_param_buf_init_full(void *data,
							       size_t size,
							       size_t data_len)
{
	struct call_param_buf v;

	v.size = size;
	v.data_len = data_len;
	v.data = data;

	return v;
}

/** \brief Call request
 *
 * A call request object represents a request from a client that will
 * be handled by a call endpoint.
 */
struct call_req {
	uint32_t caller_id;
	uint32_t interface_id;
	uint32_t opcode;
	uint32_t encoding;
	int opstatus;
	struct call_param_buf req_buf;
	struct call_param_buf resp_buf;
};

static inline uint32_t call_req_get_caller_id(const struct call_req *req)
{
	return req->caller_id;
}

static inline uint32_t call_req_get_interface_id(const struct call_req *req)
{
	return req->interface_id;
}

static inline uint32_t call_req_get_opcode(const struct call_req *req)
{
	return req->opcode;
}

static inline uint32_t call_req_get_encoding(const struct call_req *req)
{
	return req->encoding;
}

static inline int call_req_get_opstatus(const struct call_req *req)
{
	return req->opstatus;
}

static inline void call_req_set_opstatus(struct call_req *req, int opstatus)
{
	req->opstatus = opstatus;
}

static inline struct call_param_buf *call_req_get_req_buf(struct call_req *req)
{
	return &req->req_buf;
}

static inline struct call_param_buf *call_req_get_resp_buf(struct call_req *req)
{
	return &req->resp_buf;
}

/** \brief RPC interface
 *
 * A generalized RPC interface.  Provides a standard interface for a
 * call endpoint that handles incoming call requests.
 */
struct rpc_interface
{
	void *context;
	rpc_status_t (*receive)(struct rpc_interface *iface, struct call_req *req);
};

static inline rpc_status_t rpc_interface_receive(struct rpc_interface *iface,
					  struct call_req *req)
{
	return iface->receive(iface, req);
}

#ifdef __cplusplus
}
#endif

#endif /* RPC_INTERFACE_H */