1 /*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "softbus_server_frame.h"
17
18 #include "auth_interface.h"
19 #include "bus_center_manager.h"
20 #include "disc_event_manager.h"
21 #include "softbus_ddos.h"
22 #include "instant_statistics.h"
23 #include "lnn_bus_center_ipc.h"
24 #include "softbus_adapter_bt_common.h"
25 #include "softbus_conn_ble_direct.h"
26 #include "softbus_disc_server.h"
27 #include "softbus_feature_config.h"
28 #include "legacy/softbus_hidumper_interface.h"
29 #include "legacy/softbus_hisysevt_common.h"
30 #include "softbus_utils.h"
31 #include "trans_session_service.h"
32 #include "wifi_direct_manager.h"
33 #include "lnn_init_monitor.h"
34
35 static bool g_isInit = false;
36
ServerStubInit(void)37 int __attribute__((weak)) ServerStubInit(void)
38 {
39 COMM_LOGW(COMM_SVC, "softbus server stub init(weak function).");
40 return SOFTBUS_OK;
41 }
42
ServerModuleDeinit(void)43 static void ServerModuleDeinit(void)
44 {
45 DiscEventManagerDeinit();
46 DiscServerDeinit();
47 ConnServerDeinit();
48 TransServerDeinit();
49 BusCenterServerDeinit();
50 AuthDeinit();
51 SoftBusTimerDeInit();
52 LooperDeinit();
53 SoftBusHiDumperDeinit();
54 DeinitSoftbusSysEvt();
55 DeinitDdos();
56 }
57
GetServerIsInit(void)58 bool GetServerIsInit(void)
59 {
60 return g_isInit;
61 }
62
InitServicesAndModules(void)63 static int32_t InitServicesAndModules(void)
64 {
65 if (ConnServerInit() != SOFTBUS_OK) {
66 COMM_LOGE(COMM_SVC, "softbus conn server init failed.");
67 return SOFTBUS_CONN_SERVER_INIT_FAILED;
68 }
69
70 if (AuthInit() != SOFTBUS_OK) {
71 COMM_LOGE(COMM_SVC, "softbus auth init failed.");
72 return SOFTBUS_AUTH_INIT_FAIL;
73 }
74
75 if (DiscServerInit() != SOFTBUS_OK) {
76 COMM_LOGE(COMM_SVC, "softbus disc server init failed.");
77 return SOFTBUS_DISC_SERVER_INIT_FAILED;
78 }
79
80 if (BusCenterServerInit() != SOFTBUS_OK) {
81 COMM_LOGE(COMM_SVC, "softbus buscenter server init failed.");
82 return SOFTBUS_CENTER_SERVER_INIT_FAILED;
83 }
84
85 if (TransServerInit() != SOFTBUS_OK) {
86 COMM_LOGE(COMM_SVC, "softbus trans server init failed.");
87 return SOFTBUS_TRANS_SERVER_INIT_FAILED;
88 }
89
90 if (DiscEventManagerInit() != SOFTBUS_OK) {
91 COMM_LOGE(COMM_SVC, "softbus disc event manager init failed.");
92 return SOFTBUS_DISCOVER_MANAGER_INIT_FAIL;
93 }
94
95 if (GetWifiDirectManager()->init() != SOFTBUS_OK) {
96 COMM_LOGE(COMM_SVC, "softbus wifi direct init failed.");
97 return SOFTBUS_WIFI_DIRECT_INIT_FAILED;
98 }
99
100 if (ConnBleDirectInit() != SOFTBUS_OK) {
101 COMM_LOGE(COMM_SVC, "softbus ble direct init failed.");
102 return SOFTBUS_CONN_BLE_DIRECT_INIT_FAILED;
103 }
104
105 if (InitSoftbusSysEvt() != SOFTBUS_OK || SoftBusHiDumperInit() != SOFTBUS_OK) {
106 COMM_LOGE(COMM_SVC, "softbus dfx init failed.");
107 return SOFTBUS_DFX_INIT_FAILED;
108 }
109 InstRegister(NULL);
110 return SOFTBUS_OK;
111 }
112
InitSoftBusServer(void)113 void InitSoftBusServer(void)
114 {
115 SoftbusConfigInit();
116 LnnInitMonitorInit();
117 if (ServerStubInit() != SOFTBUS_OK) {
118 COMM_LOGE(COMM_SVC, "server stub init failed.");
119 return;
120 }
121
122 if (SoftBusTimerInit() != SOFTBUS_OK) {
123 COMM_LOGE(COMM_SVC, "softbus timer init failed.");
124 return;
125 }
126
127 if (LooperInit() != SOFTBUS_OK) {
128 COMM_LOGE(COMM_SVC, "softbus looper init failed.");
129 return;
130 }
131
132 if (InitDdos() != SOFTBUS_OK) {
133 COMM_LOGE(COMM_SVC, "softbus ddos init failed.");
134 }
135
136 int32_t ret = InitServicesAndModules();
137 if (ret != SOFTBUS_OK) {
138 ServerModuleDeinit();
139 COMM_LOGE(COMM_SVC, "softbus framework init failed, err = %{public}d", ret);
140 return;
141 }
142
143 ret = SoftBusBtInit();
144 if (ret != SOFTBUS_OK) {
145 LnnInitModuleReturnSet(INIT_DEPS_BLUETOOTH, ret);
146 LnnInitModuleStatusSet(INIT_DEPS_BLUETOOTH, DEPS_STATUS_FAILED);
147 ServerModuleDeinit();
148 COMM_LOGE(COMM_SVC, "softbus bt init failed, err = %{public}d", ret);
149 return;
150 }
151 LnnInitModuleStatusSet(INIT_DEPS_BLUETOOTH, DEPS_STATUS_SUCCESS);
152 LnnModuleInitMonitorCheckStart();
153 g_isInit = true;
154 COMM_LOGI(COMM_SVC, "softbus framework init success.");
155 }
156
ClientDeathCallback(const char * pkgName,int32_t pid)157 void ClientDeathCallback(const char *pkgName, int32_t pid)
158 {
159 DiscServerDeathCallback(pkgName, pid);
160 TransServerDeathCallback(pkgName, pid);
161 BusCenterServerDeathCallback(pkgName);
162 AuthServerDeathCallback(pkgName, pid);
163 }
164