Julian Hall | 2dcd69c | 2020-11-23 18:05:04 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef SERVICE_PROVIDER_H |
| 8 | #define SERVICE_PROVIDER_H |
| 9 | |
| 10 | #include <rpc/common/endpoint/call_ep.h> |
| 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; |
| 25 | rpc_status_t (*invoke)(void *context, struct call_req* req); |
| 26 | }; |
| 27 | |
| 28 | static inline int service_handler_invoke(const struct service_handler *handler, |
| 29 | void *context, struct call_req* req) |
| 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 |
| 42 | * requests and delegates them to the approprate handle provided by a concrete service |
| 43 | * provider. |
| 44 | */ |
| 45 | struct service_provider { |
| 46 | struct call_ep base; |
| 47 | const struct service_handler *handlers; |
| 48 | size_t num_handlers; |
| 49 | call_param_serializer_ptr default_serializer; |
| 50 | }; |
| 51 | |
| 52 | static inline struct call_ep *service_provider_get_call_ep(struct service_provider *sp) |
| 53 | { |
| 54 | return &sp->base; |
| 55 | } |
| 56 | |
| 57 | void service_provider_init(struct service_provider *sp, void *context, |
| 58 | const struct service_handler *handlers, |
| 59 | size_t num_handlers); |
| 60 | |
| 61 | static inline void service_set_default_serializer(struct service_provider *sp, |
| 62 | call_param_serializer_ptr serializer) |
| 63 | { |
| 64 | sp->default_serializer = serializer; |
| 65 | } |
| 66 | |
| 67 | #ifdef __cplusplus |
| 68 | } |
| 69 | #endif |
| 70 | |
| 71 | #endif /* SERVICE_PROVIDER_H */ |