Julian Hall | a6b3e1c | 2021-06-25 10:15:01 +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 <assert.h> |
| 8 | #include <stddef.h> |
| 9 | #include <protocols/rpc/common/packed-c/status.h> |
| 10 | #include "rpc_demux.h" |
| 11 | |
| 12 | static rpc_status_t receive(struct rpc_interface *rpc_iface, struct call_req *req) |
| 13 | { |
| 14 | rpc_status_t rpc_status = TS_RPC_ERROR_INTERFACE_DOES_NOT_EXIST; |
| 15 | struct rpc_demux *context = (struct rpc_demux*)rpc_iface->context; |
| 16 | |
| 17 | unsigned int iface_id = call_req_get_interface_id(req); |
| 18 | |
| 19 | if ((iface_id < RPC_DEMUX_MAX_OUTPUTS) && context->outputs[iface_id]) { |
| 20 | |
| 21 | rpc_status = rpc_interface_receive(context->outputs[iface_id], req); |
| 22 | } |
| 23 | |
| 24 | return rpc_status; |
| 25 | } |
| 26 | |
| 27 | struct rpc_interface *rpc_demux_init(struct rpc_demux *context) |
| 28 | { |
| 29 | context->input.receive = receive; |
| 30 | context->input.context = context; |
| 31 | |
| 32 | for (unsigned int i = 0; i < RPC_DEMUX_MAX_OUTPUTS; ++i) { |
| 33 | |
| 34 | context->outputs[i] = NULL; |
| 35 | } |
| 36 | |
| 37 | return &context->input; |
| 38 | } |
| 39 | |
| 40 | void rpc_demux_deinit(struct rpc_demux *context) |
| 41 | { |
| 42 | (void)context; |
| 43 | } |
| 44 | |
| 45 | void rpc_demux_attach(struct rpc_demux *context, |
| 46 | unsigned int iface_id, struct rpc_interface *output) |
| 47 | { |
| 48 | assert(iface_id < RPC_DEMUX_MAX_OUTPUTS); |
| 49 | context->outputs[iface_id] = output; |
| 50 | } |
| 51 | |
| 52 | void rpc_demux_dettach(struct rpc_demux *context, |
| 53 | unsigned int iface_id) |
| 54 | { |
| 55 | assert(iface_id < RPC_DEMUX_MAX_OUTPUTS); |
| 56 | context->outputs[iface_id] = NULL; |
| 57 | } |