blob: 1b5d03dc413112096b3d3b00ab44bd89ba99c458 [file] [log] [blame]
Julian Hall6c59e4e2020-11-23 17:50:47 +01001/*
2 * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef CALL_EP_H
8#define CALL_EP_H
9
10#include <stddef.h>
11#include <stdint.h>
12#include <rpc_status.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18/* Definitions related to an rpc call endpoint */
19
20/** \brief Call parameter buffer
21 *
22 * Describes a buffer for holding call request and response parameters.
23 */
24struct call_param_buf {
25 size_t size;
26 size_t data_len;
27 void *data;
28};
29
30static inline struct call_param_buf call_param_buf_init_empty(void *data, size_t size)
31{
32 struct call_param_buf v;
33
34 v.size = size;
35 v.data_len = 0;
36 v.data = data;
37
38 return v;
39}
40
41static inline struct call_param_buf call_param_buf_init_full(void *data,
42 size_t size,
43 size_t data_len)
44{
45 struct call_param_buf v;
46
47 v.size = size;
48 v.data_len = data_len;
49 v.data = data;
50
51 return v;
52}
53
54/** \brief Serializer for handling call parameters
55 *
56 * An abstract serializer pointer, used for attaching a concrete
57 * serializer to a call request for serializing/deserializing call
58 * parameters. The strategy for selecting an appropriate serializer
59 * could be hard-coded or dynamic, based on a content type identifier
60 * carried by a concrete rpc.
61 */
62typedef const void* call_param_serializer_ptr;
63
64/** \brief Call request
65 *
66 * A call request object represents a request from a client that will
67 * be handled by a call endpoint.
68 */
69struct call_req {
70 uint32_t caller_id;
71 uint32_t opcode;
72 int opstatus;
73 call_param_serializer_ptr serializer;
74 struct call_param_buf req_buf;
75 struct call_param_buf resp_buf;
76};
77
78static inline uint32_t call_req_get_caller_id(const struct call_req *req)
79{
80 return req->caller_id;
81}
82
83static inline uint32_t call_req_get_opcode(const struct call_req *req)
84{
85 return req->opcode;
86}
87
88static inline int call_req_get_opstatus(const struct call_req *req)
89{
90 return req->opstatus;
91}
92
93static inline void call_req_set_opstatus(struct call_req *req, int opstatus)
94{
95 req->opstatus = opstatus;
96}
97
98static inline call_param_serializer_ptr call_req_get_serializer(const struct call_req *req)
99{
100 return req->serializer;
101}
102
103static inline struct call_param_buf *call_req_get_req_buf(struct call_req *req)
104{
105 return &req->req_buf;
106}
107
108static inline struct call_param_buf *call_req_get_resp_buf(struct call_req *req)
109{
110 return &req->resp_buf;
111}
112
113/** \brief Call endpoint
114 *
115 * A generalized call endpoint. Provides a standard interface for a
116 * call endpoint that handles incoming call requests.
117 */
118struct call_ep
119{
120 void *context;
121 rpc_status_t (*receive)(struct call_ep *ep, struct call_req *req);
122};
123
124static inline rpc_status_t call_ep_receive(struct call_ep *ep,
125 struct call_req *req)
126{
127 return ep->receive(ep, req);
128}
129
130#ifdef __cplusplus
131}
132#endif
133
134#endif /* CALL_EP_H */