1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 
10 #ifndef MESSAGE_ROUTER_INNER_H
11 #define MESSAGE_ROUTER_INNER_H
12 #include "message_types.h"
13 #include "message_router.h"
14 #include "message_dispatcher.h"
15 #include "shared_obj.h"
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 struct MessageNode;
22 struct RemoteService;
23 
24 #define INHERT_MESSAGE_NODE                                                                              \
25     SHARED_OBJ(MessageNode);                                                                            \
26     OSAL_DECLARE_MUTEX(mutex);                                                                           \
27     ErrorCode (*Init)(struct MessageNode *);                                                            \
28     struct RemoteService *(*CreateRemoteService)(struct MessageNode *, MessageDispatcher * dispatcher, \
29         struct ServiceDef * mapper);                                                                     \
30     ErrorCode (*SyncService)(struct MessageNode *);                                                     \
31     ErrorCode (*NotifyServiceAdd)(const struct MessageNode *, const struct ServiceDef *mapper);         \
32     ErrorCode (*NotifyServiceDel)(const struct MessageNode *, const ServiceId serviceId)
33 
34 DECLEAR_SHARED_OBJ_FUNC(MessageNode);
35 
36 typedef struct MessageNode {
37     INHERT_MESSAGE_NODE;
38 } MessageNode;
39 
40 #define INHERT_REMOTE_SERVICE SHARED_OBJ(RemoteService);                                                              \
41     void (*ExecRequestMsg)(const struct RemoteService *service, MessageContext *context);   \
42     void (*ExecResponseMsg)(const struct RemoteService *service, MessageContext *context);  \
43     ErrorCode (*SendMessage)(const struct RemoteService *service, MessageContext *context); \
44     void (*Shutdown)(struct RemoteService * service);                                       \
45     ServiceId serviceId
46 
47 DECLEAR_SHARED_OBJ_FUNC(RemoteService);
48 
49 typedef struct RemoteService {
50     INHERT_REMOTE_SERVICE;
51 } RemoteService;
52 
53 RemoteService *RefRemoteService(ServiceId serviceId);
54 
55 ErrorCode SendMessage(MessageContext *context);
56 
57 ErrorCode CreateLocalNode(MessageNode **node);
58 
59 ErrorCode AddDispatcherInner(const NodeId nodeId, DispatcherConfig *config);
60 
61 void DestroyDispatcherInner(const NodeId nodeId, const DispatcherId dispatcherId);
62 
63 ErrorCode RegistRemoteService(NodeId nodeId, RemoteService *service);
64 
65 ErrorCode UnregistRemoteService(NodeId nodeId, ServiceId serviceId);
66 
67 MessageNode *RefMessageNode(const NodeId nodeId, bool isRequireLock);
68 
69 #ifdef __cplusplus
70 }
71 #endif
72 
73 #endif
74