blob: 6d40b8009cf73fc90726f591097207f1048b61d6 [file] [log] [blame]
Julian Hallf7f84952020-11-23 17:55:51 +01001/*
2 * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
3 *
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,
12 int *opstatus, uint8_t **resp_buf, size_t *resp_len);
13static void call_end(void *context, rpc_call_handle handle);
14
15
16struct rpc_caller *dummy_caller_init(struct dummy_caller *s,
17 rpc_status_t rpc_status, int opstatus)
18{
19 struct rpc_caller *base = &s->rpc_caller;
20
21 base->context = s;
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
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,
52 int *opstatus, uint8_t **resp_buf, size_t *resp_len)
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
66static void call_end(void *context, rpc_call_handle handle)
67{
68 (void)context;
69 (void)handle;
70}