blob: da0f491d089506efd0ee5d31263b4b64a58d6a21 [file] [log] [blame]
Julian Hallf7f84952020-11-23 17:55:51 +01001/*
julhal01c3f4e9a2020-12-15 13:39:01 +00002 * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
Julian Hallf7f84952020-11-23 17:55:51 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include "dummy_caller.h"
8#include <stdlib.h>
9
10static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_len);
11static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t opcode,
Julian Halld1dfda52021-11-25 18:46:45 +010012 rpc_opstatus_t *opstatus, uint8_t **resp_buf, size_t *resp_len);
Julian Hallf7f84952020-11-23 17:55:51 +010013static void call_end(void *context, rpc_call_handle handle);
14
15
16struct rpc_caller *dummy_caller_init(struct dummy_caller *s,
Julian Halld1dfda52021-11-25 18:46:45 +010017 rpc_status_t rpc_status, rpc_opstatus_t opstatus)
Julian Hallf7f84952020-11-23 17:55:51 +010018{
19 struct rpc_caller *base = &s->rpc_caller;
20
julhal01c3f4e9a2020-12-15 13:39:01 +000021 rpc_caller_init(base, s);
Julian Hallf7f84952020-11-23 17:55:51 +010022 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
33void dummy_caller_deinit(struct dummy_caller *s)
34{
35 free(s->req_buf);
36 s->req_buf = NULL;
37}
38
39static 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
51static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t opcode,
Julian Halld1dfda52021-11-25 18:46:45 +010052 rpc_opstatus_t *opstatus, uint8_t **resp_buf, size_t *resp_len)
Julian Hallf7f84952020-11-23 17:55:51 +010053{
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
66static void call_end(void *context, rpc_call_handle handle)
67{
68 (void)context;
69 (void)handle;
70}