1 /*
2 * Copyright (c) 2021 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 "lnn_bus_center_ipc.h"
21 #include "message_handler.h"
22 #include "wifi_direct_initiator.h"
23 #include "softbus_conn_interface.h"
24 #include "softbus_conn_ble_direct.h"
25 #include "softbus_disc_server.h"
26 #include "softbus_errcode.h"
27 #include "softbus_feature_config.h"
28 #include "softbus_log.h"
29 #include "softbus_utils.h"
30 #include "trans_session_manager.h"
31 #include "trans_session_service.h"
32 #include "softbus_hidumper_interface.h"
33 #include "softbus_hisysevt_common.h"
34
35 static bool g_isInit = false;
36
ServerStubInit(void)37 int __attribute__((weak)) ServerStubInit(void)
38 {
39 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_WARN, "softbus server stub init(weak function).");
40 return SOFTBUS_OK;
41 }
42
ServerModuleDeinit(void)43 static void ServerModuleDeinit(void)
44 {
45 DiscServerDeinit();
46 ConnServerDeinit();
47 TransServerDeinit();
48 BusCenterServerDeinit();
49 AuthDeinit();
50 SoftBusTimerDeInit();
51 LooperDeinit();
52 SoftBusHiDumperDeinit();
53 DeinitSoftbusSysEvt();
54 }
55
GetServerIsInit(void)56 NO_SANITIZE("cfi") bool GetServerIsInit(void)
57 {
58 return g_isInit;
59 }
60
InitSoftBusServer(void)61 NO_SANITIZE("cfi") void InitSoftBusServer(void)
62 {
63 SoftbusConfigInit();
64
65 if (ServerStubInit() != SOFTBUS_OK) {
66 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "server stub init failed.");
67 return;
68 }
69
70 if (SoftBusTimerInit() == SOFTBUS_ERR) {
71 return;
72 }
73
74 if (LooperInit() == -1) {
75 return;
76 }
77 if (ConnServerInit() == SOFTBUS_ERR) {
78 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "softbus conn server init failed.");
79 goto ERR_EXIT;
80 }
81
82 if (AuthInit() == SOFTBUS_ERR) {
83 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "softbus auth init failed.");
84 goto ERR_EXIT;
85 }
86
87 if (DiscServerInit() == SOFTBUS_ERR) {
88 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "softbus disc server init failed.");
89 goto ERR_EXIT;
90 }
91
92 if (BusCenterServerInit() == SOFTBUS_ERR) {
93 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "softbus buscenter server init failed.");
94 goto ERR_EXIT;
95 }
96 if (ConnBleDirectInit() == SOFTBUS_ERR) {
97 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "softbus ble direct init failed.");
98 goto ERR_EXIT;
99 }
100 if (TransServerInit() == SOFTBUS_ERR) {
101 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "softbus trans server init failed.");
102 goto ERR_EXIT;
103 }
104
105 if (WifiDirectInit() != SOFTBUS_OK) {
106 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "softbus wifi direct init failed.");
107 goto ERR_EXIT;
108 }
109
110 if (InitSoftbusSysEvt() != SOFTBUS_OK || SoftBusHiDumperInit() != SOFTBUS_OK) {
111 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "softbus dfx init failed.");
112 goto ERR_EXIT;
113 }
114
115 g_isInit = true;
116 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "softbus framework init success.");
117 return;
118 ERR_EXIT:
119 ServerModuleDeinit();
120 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "softbus framework init failed.");
121 return;
122 }
123
ClientDeathCallback(const char * pkgName,int32_t pid)124 NO_SANITIZE("cfi") void ClientDeathCallback(const char *pkgName, int32_t pid)
125 {
126 DiscServerDeathCallback(pkgName);
127 TransServerDeathCallback(pkgName, pid);
128 BusCenterServerDeathCallback(pkgName);
129 AuthServerDeathCallback(pkgName, pid);
130 }
131