Julian Hall | f7f8495 | 2020-11-23 17:55:51 +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 | f7f8495 | 2020-11-23 17:55:51 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include "dummy_caller.h" |
| 8 | #include <stdlib.h> |
| 9 | |
| 10 | static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_len); |
| 11 | static 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] | 12 | rpc_opstatus_t *opstatus, uint8_t **resp_buf, size_t *resp_len); |
Julian Hall | f7f8495 | 2020-11-23 17:55:51 +0100 | [diff] [blame] | 13 | static void call_end(void *context, rpc_call_handle handle); |
| 14 | |
| 15 | |
| 16 | struct rpc_caller *dummy_caller_init(struct dummy_caller *s, |
Julian Hall | d1dfda5 | 2021-11-25 18:46:45 +0100 | [diff] [blame] | 17 | rpc_status_t rpc_status, rpc_opstatus_t opstatus) |
Julian Hall | f7f8495 | 2020-11-23 17:55:51 +0100 | [diff] [blame] | 18 | { |
| 19 | struct rpc_caller *base = &s->rpc_caller; |
| 20 | |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 21 | rpc_caller_init(base, s); |
Julian Hall | f7f8495 | 2020-11-23 17:55:51 +0100 | [diff] [blame] | 22 | base->call_begin = call_begin; |
| 23 | base->call_invoke = call_invoke; |
| 24 | base->call_end = call_end; |
| 25 | |
| 26 | s->rpc_status = rpc_status; |
| 27 | s->opstatus = opstatus; |
| 28 | s->req_buf = NULL; |
| 29 | |
| 30 | return base; |
| 31 | } |
| 32 | |
| 33 | void dummy_caller_deinit(struct dummy_caller *s) |
| 34 | { |
| 35 | free(s->req_buf); |
| 36 | s->req_buf = NULL; |
| 37 | } |
| 38 | |
| 39 | static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_len) |
| 40 | { |
| 41 | struct dummy_caller *this_context = (struct dummy_caller*)context; |
| 42 | rpc_call_handle handle = this_context; |
| 43 | |
| 44 | free(this_context->req_buf); |
| 45 | this_context->req_buf = malloc(req_len); |
| 46 | *req_buf = this_context->req_buf; |
| 47 | |
| 48 | return handle; |
| 49 | } |
| 50 | |
| 51 | static 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] | 52 | rpc_opstatus_t *opstatus, uint8_t **resp_buf, size_t *resp_len) |
Julian Hall | f7f8495 | 2020-11-23 17:55:51 +0100 | [diff] [blame] | 53 | { |
| 54 | struct dummy_caller *this_context = (struct dummy_caller*)context; |
| 55 | |
| 56 | free(this_context->req_buf); |
| 57 | this_context->req_buf = NULL; |
| 58 | |
| 59 | *resp_buf = NULL; |
| 60 | *resp_len = 0; |
| 61 | *opstatus = this_context->opstatus; |
| 62 | |
| 63 | return this_context->rpc_status; |
| 64 | } |
| 65 | |
| 66 | static void call_end(void *context, rpc_call_handle handle) |
| 67 | { |
| 68 | (void)context; |
| 69 | (void)handle; |
| 70 | } |