Julian Hall | 0446040 | 2021-07-08 17:40:57 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 11 | static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_len); |
| 12 | 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] | 13 | rpc_opstatus_t *opstatus, uint8_t **resp_buf, size_t *resp_len); |
Julian Hall | 0446040 | 2021-07-08 17:40:57 +0100 | [diff] [blame] | 14 | static void call_end(void *context, rpc_call_handle handle); |
| 15 | |
| 16 | |
| 17 | void 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 | |
| 33 | void logging_caller_deinit( |
| 34 | struct logging_caller *this_instance) |
| 35 | { |
| 36 | this_instance->attached_caller = NULL; |
| 37 | } |
| 38 | |
| 39 | struct 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 | |
| 47 | static 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 | |
| 71 | 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] | 72 | rpc_opstatus_t *opstatus, uint8_t **resp_buf, size_t *resp_len) |
Julian Hall | 0446040 | 2021-07-08 17:40:57 +0100 | [diff] [blame] | 73 | { |
| 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 Hall | 9eaaaa6 | 2021-12-20 09:18:51 +0000 | [diff] [blame] | 90 | fprintf(this_instance->log_file, "op_status: %ld\n", *opstatus); |
Julian Hall | 0446040 | 2021-07-08 17:40:57 +0100 | [diff] [blame] | 91 | 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 | |
| 99 | static 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 | } |