• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_disc_server.h"
17 
18 #include "disc_client_proxy.h"
19 #include "softbus_errcode.h"
20 #include "softbus_log.h"
21 #include "softbus_permission.h"
22 
23 static IServerDiscInnerCallback g_discInnerCb = {
24     .OnServerDeviceFound = ClientIpcOnDeviceFound,
25 };
26 
27 static bool g_isCallLnn = true;
28 
DiscServerInit(void)29 int32_t DiscServerInit(void)
30 {
31     int32_t ret = DiscMgrInit();
32     if (ret != SOFTBUS_OK) {
33         SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "DiscServerInit failed");
34         return ret;
35     }
36     return SOFTBUS_OK;
37 }
38 
DiscServerDeinit(void)39 void DiscServerDeinit(void)
40 {
41     DiscMgrDeinit();
42 }
43 
DiscServerDeathCallback(const char * pkgName)44 void DiscServerDeathCallback(const char *pkgName)
45 {
46     DiscMgrDeathCallback(pkgName);
47 }
48 
PublishErroCodeProcess(int32_t erroCode)49 static int32_t PublishErroCodeProcess(int32_t erroCode)
50 {
51     if (erroCode == SOFTBUS_DISCOVER_MANAGER_INVALID_MEDIUM) {
52         return PUBLISH_FAIL_REASON_NOT_SUPPORT_MEDIUM;
53     }
54     return PUBLISH_FAIL_REASON_INTERNAL;
55 }
56 
DiscoveryErroCodeProcess(int32_t erroCode)57 static int32_t DiscoveryErroCodeProcess(int32_t erroCode)
58 {
59     if (erroCode == SOFTBUS_DISCOVER_MANAGER_INVALID_MEDIUM) {
60         return DISCOVERY_FAIL_REASON_NOT_SUPPORT_MEDIUM;
61     }
62     return DISCOVERY_FAIL_REASON_INTERNAL;
63 }
64 
DiscIpcPublishService(const char * packageName,const PublishInfo * info)65 int32_t DiscIpcPublishService(const char *packageName, const PublishInfo *info)
66 {
67     int32_t ret = DiscPublishService(packageName, info);
68     if (ret != SOFTBUS_OK) {
69         SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "ServerPublishService failed");
70         (void)ClientIpcOnPublishFail(packageName, info->publishId, PublishErroCodeProcess(ret));
71         return ret;
72     }
73     SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "ServerPublishService success!");
74     (void)ClientIpcOnPublishSuccess(packageName, info->publishId);
75     return SOFTBUS_OK;
76 }
77 
DiscIpcUnPublishService(const char * packageName,int32_t publishId)78 int32_t DiscIpcUnPublishService(const char *packageName, int32_t publishId)
79 {
80     int32_t ret = DiscUnPublishService(packageName, publishId);
81     if (ret != SOFTBUS_OK) {
82         SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "ServerUnPublishService failed");
83         return ret;
84     }
85     SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "ServerUnPublishService success!");
86     return SOFTBUS_OK;
87 }
88 
DiscIpcStartDiscovery(const char * packageName,const SubscribeInfo * info)89 int32_t DiscIpcStartDiscovery(const char *packageName, const SubscribeInfo *info)
90 {
91     SetCallLnnStatus(false);
92     int32_t ret = DiscStartDiscovery(packageName, info, &g_discInnerCb);
93     if (ret != SOFTBUS_OK) {
94         SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "ServerStartDiscovery failed");
95         (void)ClientIpcOnDiscoverFailed(packageName, info->subscribeId, DiscoveryErroCodeProcess(ret));
96         return ret;
97     }
98     SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "ServerStartDiscovery success!");
99     (void)ClientIpcDiscoverySuccess(packageName, info->subscribeId);
100     return SOFTBUS_OK;
101 }
102 
DiscIpcStopDiscovery(const char * packageName,int32_t subscribeId)103 int32_t DiscIpcStopDiscovery(const char *packageName, int32_t subscribeId)
104 {
105     int32_t ret = DiscStopDiscovery(packageName, subscribeId);
106     if (ret != SOFTBUS_OK) {
107         SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "ServerStopDiscovery failed");
108         return ret;
109     }
110     SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "ServerStopDiscovery success!");
111     return SOFTBUS_OK;
112 }
113 
SetCallLnnStatus(bool flag)114 void SetCallLnnStatus(bool flag)
115 {
116     g_isCallLnn = flag;
117 }
118 
GetCallLnnStatus(void)119 bool GetCallLnnStatus(void)
120 {
121     return g_isCallLnn;
122 }
123