blob: f246ebfc16aa4980ac9cca2981d801751d08e67a [file] [log] [blame]
Julian Hall04460402021-07-08 17:40:57 +01001/*
2 * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <stddef.h>
8#include <protocols/rpc/common/packed-c/status.h>
9#include "logging_caller.h"
10
11static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_len);
12static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t opcode,
Julian Halld1dfda52021-11-25 18:46:45 +010013 rpc_opstatus_t *opstatus, uint8_t **resp_buf, size_t *resp_len);
Julian Hall04460402021-07-08 17:40:57 +010014static void call_end(void *context, rpc_call_handle handle);
15
16
17void logging_caller_init(
18 struct logging_caller *this_instance,
19 FILE *log_file)
20{
21 struct rpc_caller *base = &this_instance->rpc_caller;
22
23 rpc_caller_init(base, this_instance);
24 base->call_begin = call_begin;
25 base->call_invoke = call_invoke;
26 base->call_end = call_end;
27
28 this_instance->attached_caller = NULL;
29 this_instance->log_file = log_file;
30 this_instance->call_index = 0;
31}
32
33void logging_caller_deinit(
34 struct logging_caller *this_instance)
35{
36 this_instance->attached_caller = NULL;
37}
38
39struct rpc_caller *logging_caller_attach(
40 struct logging_caller *this_instance,
41 struct rpc_caller *attached_caller)
42{
43 this_instance->attached_caller = attached_caller;
44 return &this_instance->rpc_caller;
45}
46
47static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_len)
48{
49 struct logging_caller *this_instance = (struct logging_caller*)context;
50 rpc_call_handle handle = NULL;
51
52 if (this_instance->attached_caller) {
53
54 handle = rpc_caller_begin(this_instance->attached_caller, req_buf, req_len);
55 }
56
57 fprintf(this_instance->log_file, "========================\n");
58 fprintf(this_instance->log_file, "index: %d\n", this_instance->call_index);
59 fprintf(this_instance->log_file, "req_len: %ld\n", req_len);
60
61 if (!handle) {
62
63 fprintf(this_instance->log_file, "ERROR: call_begin failed\n");
64 }
65
66 ++this_instance->call_index;
67
68 return handle;
69}
70
71static rpc_status_t call_invoke(void *context, rpc_call_handle handle, uint32_t opcode,
Julian Halld1dfda52021-11-25 18:46:45 +010072 rpc_opstatus_t *opstatus, uint8_t **resp_buf, size_t *resp_len)
Julian Hall04460402021-07-08 17:40:57 +010073{
74 struct logging_caller *this_instance = (struct logging_caller*)context;
75 rpc_status_t status = TS_RPC_ERROR_INVALID_TRANSACTION;
76
77 if (this_instance->attached_caller) {
78
79
80 status = rpc_caller_invoke(this_instance->attached_caller,
81 handle, opcode, opstatus,
82 resp_buf, resp_len);
83 }
84
85 fprintf(this_instance->log_file, "opcode: %d\n", opcode);
86 fprintf(this_instance->log_file, "rpc_status: %d\n", status);
87
88 if (status == TS_RPC_CALL_ACCEPTED) {
89
Julian Hall9eaaaa62021-12-20 09:18:51 +000090 fprintf(this_instance->log_file, "op_status: %ld\n", *opstatus);
Julian Hall04460402021-07-08 17:40:57 +010091 fprintf(this_instance->log_file, "resp_len: %ld\n", *resp_len);
92 }
93
94 fprintf(this_instance->log_file, "------------------------\n");
95
96 return status;
97}
98
99static void call_end(void *context, rpc_call_handle handle)
100{
101 struct logging_caller *this_instance = (struct logging_caller*)context;
102
103 if (this_instance->attached_caller) {
104
105 rpc_caller_end(this_instance->attached_caller, handle);
106 }
107}