1 /*
2 * Copyright (c) 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 #include "module_manager.h"
10
11 #include "hdf_log.h"
12 #ifdef ENABLE_LWIP_MONITOR
13 #include "softbus_lwip_monitor.h"
14 #endif
15 #ifdef ENABLE_WLAN_PARAM_MONITOR
16 #include "wlan_param_monitor.h"
17 #endif
18
19 #define HDF_LOG_TAG "hdf_dsoftbus"
20
21 static SoftbusDriverModule g_modules[] = {
22 #ifdef ENABLE_LWIP_MONITOR
23 {
24 .init = SoftbusLwipMonitorInit,
25 .deinit = NULL,
26 .process = NULL,
27 },
28 #endif
29 #ifdef ENABLE_WLAN_PARAM_MONITOR
30 {
31 .init = SoftbusWlanParamMonitorInit,
32 .deinit = NULL,
33 .process = SoftbusWlanParamMonitorProcess,
34 },
35 #endif
36 };
37
SoftbusDispatchModuleCommand(int32_t moduleId,const struct HdfSBuf * reqData,struct HdfSBuf * rspData)38 void SoftbusDispatchModuleCommand(int32_t moduleId, const struct HdfSBuf *reqData, struct HdfSBuf *rspData)
39 {
40 int32_t i;
41
42 for (i = 0; i < HDF_ARRAY_SIZE(g_modules); ++i) {
43 if (g_modules[i].moduleId != moduleId) {
44 continue;
45 }
46 if (g_modules[i].process == NULL) {
47 HDF_LOGE("module(%d) no process function", moduleId);
48 break;
49 }
50 g_modules[i].process(reqData, rspData);
51 return;
52 }
53 HDF_LOGE("no moduleId: %d process command", moduleId);
54 }
55
SoftbusModuleManagerInit(struct HdfDeviceObject * device)56 int32_t SoftbusModuleManagerInit(struct HdfDeviceObject *device)
57 {
58 int32_t i;
59
60 for (i = 0; i < HDF_ARRAY_SIZE(g_modules); ++i) {
61 if (g_modules[i].init == NULL) {
62 HDF_LOGE("module(%d) is no init function", g_modules[i].moduleId);
63 break;
64 }
65 if (g_modules[i].init(device) != HDF_SUCCESS) {
66 HDF_LOGE("init module(%d) fail", g_modules[i].moduleId);
67 break;
68 }
69 }
70 if (i < HDF_ARRAY_SIZE(g_modules)) {
71 for (i = i - 1; i >= 0; --i) {
72 if (g_modules[i].deinit == NULL) {
73 continue;
74 }
75 g_modules[i].deinit();
76 }
77 return HDF_FAILURE;
78 }
79 HDF_LOGE("init softbus module manager success");
80 return HDF_SUCCESS;
81 }
82
SoftbusModuleManagerDeinit(void)83 void SoftbusModuleManagerDeinit(void)
84 {
85 int32_t i;
86
87 for (i = 0; i < HDF_ARRAY_SIZE(g_modules); ++i) {
88 if (g_modules[i].deinit == NULL) {
89 continue;
90 }
91 g_modules[i].deinit();
92 }
93 HDF_LOGE("deinit softbus module manager");
94 }