blob: a75bdd9abe1afd44759fc1d504e8a940128db57b [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 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;
39
40 /* A concrete rpc_caller implements these methods */
41 rpc_call_handle (*call_begin)(void *context, uint8_t **req_buf, size_t req_len);
42
43 rpc_status_t (*call_invoke)(void *context, rpc_call_handle handle, uint32_t opcode,
44 int *opstatus, uint8_t **resp_buf, size_t *resp_len);
45
46 void (*call_end)(void *context, rpc_call_handle handle);
47};
48
49/*
50 * Starts a call transaction. The returned handle is an identifier for the
51 * transaction and must be passed as a parameter to call_invoke() and
52 * call_end(). A concrete rpc_caller may perform resource allocation during
53 * this call. This will include a buffer for the request message parameters.
54 * Returns a NULL handle on failure.
55 */
56RPC_CALLER_EXPORTED rpc_call_handle rpc_caller_begin(struct rpc_caller *s,
57 uint8_t **req_buf, size_t req_len);
58
59/*
60 * Invokes the operation identified by the opcode. This method blocks
61 * until the operation completes. The status of the call is returned. An
62 * additional endpoint specific status value is also returned. If a response
63 * message was received, the concrete rpc_caller will have allocated a
64 * buffer for the reponse. This buffer will hold valid data until the point when
65 * call_end() is called for the transaction.
66 */
67RPC_CALLER_EXPORTED rpc_status_t rpc_caller_invoke(struct rpc_caller *s, rpc_call_handle handle,
68 uint32_t opcode, int *opstatus, uint8_t **resp_buf, size_t *resp_len);
69
70/*
71 * Ends the call transaction, allowing any resource associated with the
72 * transaction to be freed.
73 */
74RPC_CALLER_EXPORTED void rpc_caller_end(struct rpc_caller *s, rpc_call_handle handle);
75
76#ifdef __cplusplus
77}
78#endif
79
80#endif /* RPC_CALLER_H */