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