Julian Hall | 2dcd69c | 2020-11-23 18:05:04 +0100 | [diff] [blame] | 1 | /* |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 2 | * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved. |
Julian Hall | 2dcd69c | 2020-11-23 18:05:04 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef SERVICE_PROVIDER_H |
| 8 | #define SERVICE_PROVIDER_H |
| 9 | |
Imre Kis | 82ba61b | 2023-07-04 13:53:39 +0200 | [diff] [blame] | 10 | #include "rpc/common/endpoint/rpc_service_interface.h" |
Julian Hall | 2dcd69c | 2020-11-23 18:05:04 +0100 | [diff] [blame] | 11 | #include <stddef.h> |
| 12 | #include <stdint.h> |
| 13 | |
| 14 | #ifdef __cplusplus |
| 15 | extern "C" { |
| 16 | #endif |
| 17 | |
| 18 | /** \brief Service handler |
| 19 | * |
| 20 | * Defines a mapping between an opcode and a handler function. A complete |
| 21 | * service interface is defined by an array of service request handlers. |
| 22 | */ |
| 23 | struct service_handler { |
| 24 | uint32_t opcode; |
Imre Kis | 82ba61b | 2023-07-04 13:53:39 +0200 | [diff] [blame] | 25 | rpc_status_t (*invoke)(void *context, struct rpc_request *req); |
Julian Hall | 2dcd69c | 2020-11-23 18:05:04 +0100 | [diff] [blame] | 26 | }; |
| 27 | |
Imre Kis | 82ba61b | 2023-07-04 13:53:39 +0200 | [diff] [blame] | 28 | static inline int service_handler_invoke(const struct service_handler *handler, void *context, |
| 29 | struct rpc_request *req) |
Julian Hall | 2dcd69c | 2020-11-23 18:05:04 +0100 | [diff] [blame] | 30 | { |
| 31 | return handler->invoke(context, req); |
| 32 | } |
| 33 | |
| 34 | static inline uint32_t service_handler_get_opcode(const struct service_handler *handler) |
| 35 | { |
| 36 | return handler->opcode; |
| 37 | } |
| 38 | |
| 39 | /** \brief Service provider |
| 40 | * |
| 41 | * A generalised service provider that acts as an rpc call endpoint. It receives call |
Imre Kis | 82ba61b | 2023-07-04 13:53:39 +0200 | [diff] [blame] | 42 | * requests and delegates them to the appropriate handle provided by a concrete service |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 43 | * provider. To support service specialization and proxying, unhandled requests may |
| 44 | * optionally be passed to a delegate rpc_interface to form a chain of responsibility. |
Julian Hall | 2dcd69c | 2020-11-23 18:05:04 +0100 | [diff] [blame] | 45 | */ |
| 46 | struct service_provider { |
Imre Kis | 82ba61b | 2023-07-04 13:53:39 +0200 | [diff] [blame] | 47 | struct rpc_service_interface iface; |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 48 | const struct service_handler *handlers; |
| 49 | size_t num_handlers; |
Julian Hall | 65ff905 | 2021-07-27 09:08:32 +0100 | [diff] [blame] | 50 | uint32_t opcode_range_lo; |
| 51 | uint32_t opcode_range_hi; |
Imre Kis | 82ba61b | 2023-07-04 13:53:39 +0200 | [diff] [blame] | 52 | struct rpc_service_interface *successor; |
Julian Hall | 2dcd69c | 2020-11-23 18:05:04 +0100 | [diff] [blame] | 53 | }; |
| 54 | |
Imre Kis | 82ba61b | 2023-07-04 13:53:39 +0200 | [diff] [blame] | 55 | static inline struct rpc_service_interface *service_provider_get_rpc_interface(struct service_provider *sp) |
Julian Hall | 2dcd69c | 2020-11-23 18:05:04 +0100 | [diff] [blame] | 56 | { |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 57 | return &sp->iface; |
Julian Hall | 2dcd69c | 2020-11-23 18:05:04 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void service_provider_init(struct service_provider *sp, void *context, |
Imre Kis | 82ba61b | 2023-07-04 13:53:39 +0200 | [diff] [blame] | 61 | const struct rpc_uuid *service_uuid, |
| 62 | const struct service_handler *handlers, size_t num_handlers); |
Julian Hall | 2dcd69c | 2020-11-23 18:05:04 +0100 | [diff] [blame] | 63 | |
Julian Hall | 13e7695 | 2021-07-13 12:17:09 +0100 | [diff] [blame] | 64 | /* |
| 65 | * Extend the core set of operations provided by a service provider by |
| 66 | * adding a sub provider that will add a capability. This facility |
| 67 | * allows a deployment to customize the set of operations |
| 68 | * supported to meet requirements by only extending the core service |
| 69 | * provider if needed. |
| 70 | */ |
| 71 | void service_provider_extend(struct service_provider *context, |
Imre Kis | 82ba61b | 2023-07-04 13:53:39 +0200 | [diff] [blame] | 72 | struct service_provider *sub_provider); |
Julian Hall | 13e7695 | 2021-07-13 12:17:09 +0100 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * Link a successor to this service provider to extend the chain of responsibility |
| 76 | * to allow call handling to be delegated to different components. Used to support |
| 77 | * modular configuration of service capabilities. |
| 78 | */ |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 79 | static inline void service_provider_link_successor(struct service_provider *sp, |
Imre Kis | 82ba61b | 2023-07-04 13:53:39 +0200 | [diff] [blame] | 80 | struct rpc_service_interface *successor) |
Julian Hall | 2dcd69c | 2020-11-23 18:05:04 +0100 | [diff] [blame] | 81 | { |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 82 | sp->successor = successor; |
Julian Hall | 2dcd69c | 2020-11-23 18:05:04 +0100 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | #ifdef __cplusplus |
| 86 | } |
| 87 | #endif |
| 88 | |
| 89 | #endif /* SERVICE_PROVIDER_H */ |