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 "instant_statistics.h"
22 #include "lnn_bus_center_ipc.h"
23 #include "softbus_adapter_bt_common.h"
24 #include "softbus_conn_ble_direct.h"
25 #include "softbus_disc_server.h"
26 #include "softbus_feature_config.h"
27 #include "softbus_hidumper_interface.h"
28 #include "softbus_hisysevt_common.h"
29 #include "softbus_utils.h"
30 #include "trans_session_service.h"
31 #include "wifi_direct_manager.h"
32
33 static bool g_isInit = false;
34
ServerStubInit(void)35 int __attribute__((weak)) ServerStubInit(void)
36 {
37 COMM_LOGW(COMM_SVC, "softbus server stub init(weak function).");
38 return SOFTBUS_OK;
39 }
40
ServerModuleDeinit(void)41 static void ServerModuleDeinit(void)
42 {
43 DiscEventManagerDeinit();
44 DiscServerDeinit();
45 ConnServerDeinit();
46 TransServerDeinit();
47 BusCenterServerDeinit();
48 AuthDeinit();
49 SoftBusTimerDeInit();
50 LooperDeinit();
51 SoftBusHiDumperDeinit();
52 DeinitSoftbusSysEvt();
53 }
54
GetServerIsInit(void)55 bool GetServerIsInit(void)
56 {
57 return g_isInit;
58 }
59
InitServicesAndModules(void)60 static int32_t InitServicesAndModules(void)
61 {
62 if (ConnServerInit() != SOFTBUS_OK) {
63 COMM_LOGE(COMM_SVC, "softbus conn server init failed.");
64 return SOFTBUS_CONN_SERVER_INIT_FAILED;
65 }
66
67 if (AuthInit() != SOFTBUS_OK) {
68 COMM_LOGE(COMM_SVC, "softbus auth init failed.");
69 return SOFTBUS_AUTH_INIT_FAIL;
70 }
71
72 if (DiscServerInit() != SOFTBUS_OK) {
73 COMM_LOGE(COMM_SVC, "softbus disc server init failed.");
74 return SOFTBUS_DISC_SERVER_INIT_FAILED;
75 }
76
77 if (BusCenterServerInit() != SOFTBUS_OK) {
78 COMM_LOGE(COMM_SVC, "softbus buscenter server init failed.");
79 return SOFTBUS_CENTER_SERVER_INIT_FAILED;
80 }
81
82 if (TransServerInit() != SOFTBUS_OK) {
83 COMM_LOGE(COMM_SVC, "softbus trans server init failed.");
84 return SOFTBUS_TRANS_SERVER_INIT_FAILED;
85 }
86
87 if (DiscEventManagerInit() != SOFTBUS_OK) {
88 COMM_LOGE(COMM_SVC, "softbus disc event manager init failed.");
89 return SOFTBUS_DISCOVER_MANAGER_INIT_FAIL;
90 }
91
92 if (GetWifiDirectManager()->init() != SOFTBUS_OK) {
93 COMM_LOGE(COMM_SVC, "softbus wifi direct init failed.");
94 return SOFTBUS_WIFI_DIRECT_INIT_FAILED;
95 }
96
97 if (ConnBleDirectInit() != SOFTBUS_OK) {
98 COMM_LOGE(COMM_SVC, "softbus ble direct init failed.");
99 return SOFTBUS_CONN_BLE_DIRECT_INIT_FAILED;
100 }
101
102 if (InitSoftbusSysEvt() != SOFTBUS_OK || SoftBusHiDumperInit() != SOFTBUS_OK) {
103 COMM_LOGE(COMM_SVC, "softbus dfx init failed.");
104 return SOFTBUS_DFX_INIT_FAILED;
105 }
106
107 InstRegister(NULL);
108 return SOFTBUS_OK;
109 }
110
InitSoftBusServer(void)111 void InitSoftBusServer(void)
112 {
113 SoftbusConfigInit();
114
115 if (ServerStubInit() != SOFTBUS_OK) {
116 COMM_LOGE(COMM_SVC, "server stub init failed.");
117 return;
118 }
119
120 if (SoftBusTimerInit() != SOFTBUS_OK) {
121 COMM_LOGE(COMM_SVC, "softbus timer init failed.");
122 return;
123 }
124
125 if (LooperInit() != SOFTBUS_OK) {
126 COMM_LOGE(COMM_SVC, "softbus looper init failed.");
127 return;
128 }
129
130 int32_t ret = InitServicesAndModules();
131 if (ret != SOFTBUS_OK) {
132 ServerModuleDeinit();
133 COMM_LOGE(COMM_SVC, "softbus framework init failed, err = %{public}d", ret);
134 return;
135 }
136
137 ret = SoftBusBtInit();
138 if (ret != SOFTBUS_OK) {
139 ServerModuleDeinit();
140 COMM_LOGE(COMM_SVC, "softbus bt init failed, err = %{public}d", ret);
141 return;
142 }
143 g_isInit = true;
144 COMM_LOGI(COMM_SVC, "softbus framework init success.");
145 }
146
ClientDeathCallback(const char * pkgName,int32_t pid)147 void ClientDeathCallback(const char *pkgName, int32_t pid)
148 {
149 DiscServerDeathCallback(pkgName);
150 TransServerDeathCallback(pkgName, pid);
151 BusCenterServerDeathCallback(pkgName);
152 AuthServerDeathCallback(pkgName, pid);
153 }
154