aboutsummaryrefslogtreecommitdiff
path: root/components/rpc/dummy/dummy_caller.c
blob: f55b41898458263cc407f7904c2d0534feb476f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "dummy_caller.h"
#include <stdlib.h>

static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_len);
static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t opcode,
		     	int *opstatus, uint8_t **resp_buf, size_t *resp_len);
static void call_end(void *context, rpc_call_handle handle);


struct rpc_caller *dummy_caller_init(struct dummy_caller *s,
    rpc_status_t rpc_status, int opstatus)
{
    struct rpc_caller *base = &s->rpc_caller;

    rpc_caller_init(base, s);
    base->call_begin = call_begin;
    base->call_invoke = call_invoke;
    base->call_end = call_end;

    s->rpc_status = rpc_status;
    s->opstatus = opstatus;
    s->req_buf = NULL;

    return base;
}

void dummy_caller_deinit(struct dummy_caller *s)
{
    free(s->req_buf);
    s->req_buf = NULL;
}

static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_len)
{
    struct dummy_caller *this_context = (struct dummy_caller*)context;
    rpc_call_handle handle = this_context;

    free(this_context->req_buf);
    this_context->req_buf = malloc(req_len);
    *req_buf = this_context->req_buf;

    return handle;
}

static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t opcode,
		     	int *opstatus, uint8_t **resp_buf, size_t *resp_len)
{
    struct dummy_caller *this_context = (struct dummy_caller*)context;

    free(this_context->req_buf);
    this_context->req_buf = NULL;

    *resp_buf = NULL;
    *resp_len = 0;
    *opstatus = this_context->opstatus;

    return this_context->rpc_status;
}

static void call_end(void *context, rpc_call_handle handle)
{
    (void)context;
    (void)handle;
}