blob: 387489cdb1b2feb0e5364602b20fdfca63f501be [file] [log] [blame]
Julian Hall6c59e4e2020-11-23 17:50:47 +01001/*
julhal01c3f4e9a2020-12-15 13:39:01 +00002 * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
Julian Hall6c59e4e2020-11-23 17:50:47 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef RPC_CALLER_H
8#define RPC_CALLER_H
9
10#include <stddef.h>
11#include <stdint.h>
12#include "rpc_status.h"
13
14/*
15 * The rpc_caller puplic interface may be exported as a public interface to
16 * a shared library.
17 */
18#ifdef EXPORT_PUBLIC_INTERFACE_RPC_CALLER
19#define RPC_CALLER_EXPORTED __attribute__((__visibility__("default")))
20#else
21#define RPC_CALLER_EXPORTED
22#endif
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/*
29 * Defines an abstract interface for calling operations provided by an rpc endpoint.
30 * Concrete specializations will map the an RPC or direct calling mechanism to
31 * suite the deployment.
32 */
33
34typedef void *rpc_call_handle;
35
36struct rpc_caller
37{
38 void *context;
julhal01c3f4e9a2020-12-15 13:39:01 +000039 uint32_t encoding;
Julian Hall6c59e4e2020-11-23 17:50:47 +010040
41 /* A concrete rpc_caller implements these methods */
42 rpc_call_handle (*call_begin)(void *context, uint8_t **req_buf, size_t req_len);
43
44 rpc_status_t (*call_invoke)(void *context, rpc_call_handle handle, uint32_t opcode,
Julian Halld1dfda52021-11-25 18:46:45 +010045 rpc_opstatus_t *opstatus, uint8_t **resp_buf, size_t *resp_len);
Julian Hall6c59e4e2020-11-23 17:50:47 +010046
47 void (*call_end)(void *context, rpc_call_handle handle);
48};
49
50/*
julhal01c3f4e9a2020-12-15 13:39:01 +000051 * Called by a concrete rpc_caller to initialise the base rpc_caller.
52 */
53void rpc_caller_init(struct rpc_caller *s, void *context);
54
55/*
56 * Allows a client to specify the parameter encoding scheme that the client
57 * intends to use during an RPC session. It is the client's responsiblity
58 * to choose an encoding scheme that is supported by the remote interface.
59 */
60RPC_CALLER_EXPORTED void rpc_caller_set_encoding_scheme(struct rpc_caller *s,
61 uint32_t encoding);
62
63/*
Julian Hall6c59e4e2020-11-23 17:50:47 +010064 * Starts a call transaction. The returned handle is an identifier for the
65 * transaction and must be passed as a parameter to call_invoke() and
66 * call_end(). A concrete rpc_caller may perform resource allocation during
67 * this call. This will include a buffer for the request message parameters.
68 * Returns a NULL handle on failure.
69 */
70RPC_CALLER_EXPORTED rpc_call_handle rpc_caller_begin(struct rpc_caller *s,
71 uint8_t **req_buf, size_t req_len);
72
73/*
74 * Invokes the operation identified by the opcode. This method blocks
75 * until the operation completes. The status of the call is returned. An
76 * additional endpoint specific status value is also returned. If a response
77 * message was received, the concrete rpc_caller will have allocated a
78 * buffer for the reponse. This buffer will hold valid data until the point when
79 * call_end() is called for the transaction.
80 */
81RPC_CALLER_EXPORTED rpc_status_t rpc_caller_invoke(struct rpc_caller *s, rpc_call_handle handle,
Julian Halld1dfda52021-11-25 18:46:45 +010082 uint32_t opcode, rpc_opstatus_t *opstatus, uint8_t **resp_buf, size_t *resp_len);
Julian Hall6c59e4e2020-11-23 17:50:47 +010083
84/*
85 * Ends the call transaction, allowing any resource associated with the
86 * transaction to be freed.
87 */
88RPC_CALLER_EXPORTED void rpc_caller_end(struct rpc_caller *s, rpc_call_handle handle);
89
90#ifdef __cplusplus
91}
92#endif
93
94#endif /* RPC_CALLER_H */