Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 1 | /* |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 2 | * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved. |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 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 |
| 25 | extern "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 | |
| 34 | typedef void *rpc_call_handle; |
| 35 | |
| 36 | struct rpc_caller |
| 37 | { |
| 38 | void *context; |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 39 | uint32_t encoding; |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 40 | |
| 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 Hall | d1dfda5 | 2021-11-25 18:46:45 +0100 | [diff] [blame] | 45 | rpc_opstatus_t *opstatus, uint8_t **resp_buf, size_t *resp_len); |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 46 | |
| 47 | void (*call_end)(void *context, rpc_call_handle handle); |
| 48 | }; |
| 49 | |
| 50 | /* |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 51 | * Called by a concrete rpc_caller to initialise the base rpc_caller. |
| 52 | */ |
| 53 | void 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 | */ |
| 60 | RPC_CALLER_EXPORTED void rpc_caller_set_encoding_scheme(struct rpc_caller *s, |
| 61 | uint32_t encoding); |
| 62 | |
| 63 | /* |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 64 | * 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 | */ |
| 70 | RPC_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 | */ |
| 81 | RPC_CALLER_EXPORTED rpc_status_t rpc_caller_invoke(struct rpc_caller *s, rpc_call_handle handle, |
Julian Hall | d1dfda5 | 2021-11-25 18:46:45 +0100 | [diff] [blame] | 82 | uint32_t opcode, rpc_opstatus_t *opstatus, uint8_t **resp_buf, size_t *resp_len); |
Julian Hall | 6c59e4e | 2020-11-23 17:50:47 +0100 | [diff] [blame] | 83 | |
| 84 | /* |
| 85 | * Ends the call transaction, allowing any resource associated with the |
| 86 | * transaction to be freed. |
| 87 | */ |
| 88 | RPC_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 */ |