!7423 【OpenHarmony5.0】删除发现模块冗余代码

Merge pull request !7423 from JanierVan/master
This commit is contained in:
openharmony_ci 2024-08-28 09:34:55 +00:00 committed by Gitee
commit 54cfd38702
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
115 changed files with 16 additions and 8533 deletions

View File

@ -45,11 +45,9 @@ tests/core/connection/wifi_direct_cpp/ wuchunbo1@huawei.com
[Disc]
adapter/common/range/ fanjingya1@huawei.com
core/discovery/ fanjingya1@huawei.com
sdk/discovery/ fanjingya1@huawei.com
tests/adapter/fuzztest/softbusadapterrange_fuzzer/ fanjingya1@huawei.com
tests/adapter/unittest/softbus_adapter_range_test.cpp fanjingya1@huawei.com
tests/core/discovery/ fanjingya1@huawei.com
tests/sdk/discovery/ fanjingya1@huawei.com
[DiscInterface]
interfaces/kits/discovery/ fanjingya1@huawei.com

View File

@ -116,7 +116,6 @@
"bus_center/softbus_bus_center.h",
"common/softbus_common.h",
"common/softbus_error_code.h",
"discovery/discovery_service.h",
"transport/session.h"
],
"header_base": "//foundation/communication/dsoftbus/interfaces/kits"

View File

@ -25,11 +25,6 @@ public:
: IRemoteProxy<ISoftBusClient>(impl) {}
virtual ~BusCenterClientProxy() = default;
void OnDeviceFound(const DeviceInfo *device) override;
void OnDiscoverFailed(int subscribeId, int failReason) override;
void OnDiscoverySuccess(int subscribeId) override;
void OnPublishSuccess(int publishId) override;
void OnPublishFail(int publishId, int reason) override;
int32_t OnChannelOpened(const char *sessionName, const ChannelInfo *channel) override;
int32_t OnChannelOpenFailed(int32_t channelId, int32_t channelType, int32_t errCode) override;
int32_t OnChannelLinkDown(const char *NetworkId, int32_t routeType) override;

View File

@ -53,26 +53,6 @@ int32_t BusCenterClientProxy::OnChannelQosEvent(int32_t channelId, int32_t chann
return SOFTBUS_OK;
}
void BusCenterClientProxy::OnDeviceFound(const DeviceInfo *deviceInfo)
{
}
void BusCenterClientProxy::OnDiscoverFailed(int subscribeId, int failReason)
{
}
void BusCenterClientProxy::OnDiscoverySuccess(int subscribeId)
{
}
void BusCenterClientProxy::OnPublishSuccess(int publishId)
{
}
void BusCenterClientProxy::OnPublishFail(int publishId, int reason)
{
}
int32_t BusCenterClientProxy::OnJoinLNNResult(void *addr, uint32_t addrTypeLen, const char *networkId, int retCode)
{
sptr<IRemoteObject> remote = Remote();

View File

@ -17,7 +17,6 @@
#include <string.h>
#include "discovery_service.h"
#include "lnn_coap_discovery_impl.h"
#include "lnn_log.h"
#include "lnn_net_builder.h"

View File

@ -82,10 +82,6 @@ typedef struct {
char *apiName;
}ApiNameIdMap;
static ApiNameIdMap g_apiNameIdMapTbl[] = {
{SERVER_START_DISCOVERY, "StartDiscovery"},
{SERVER_STOP_DISCOVERY, "StopDiscovery"},
{SERVER_PUBLISH_SERVICE, "PublishService"},
{SERVER_UNPUBLISH_SERVICE, "UnPublishService"},
{MANAGE_REGISTER_SERVICE, "SoftbusRegisterService"},
{SERVER_CREATE_SESSION_SERVER, "CreateSessionServer"},
{SERVER_REMOVE_SESSION_SERVER, "RemoveSessionServer"},

View File

@ -40,10 +40,7 @@ struct CommonScvId {
enum SoftBusFuncId {
MANAGE_REGISTER_SERVICE = 0,
SERVER_PUBLISH_SERVICE = 128,
SERVER_UNPUBLISH_SERVICE,
SERVER_CREATE_SESSION_SERVER,
SERVER_CREATE_SESSION_SERVER = 128,
SERVER_REMOVE_SESSION_SERVER,
SERVER_OPEN_SESSION,
SERVER_OPEN_AUTH_SESSION,
@ -57,9 +54,6 @@ enum SoftBusFuncId {
SERVER_STREAM_STATS,
SERVER_GET_SOFTBUS_SPEC_OBJECT,
SERVER_START_DISCOVERY,
SERVER_STOP_DISCOVERY,
SERVER_JOIN_LNN,
SERVER_JOIN_METANODE,
SERVER_LEAVE_LNN,
@ -93,12 +87,6 @@ enum SoftBusFuncId {
CLIENT_ON_CHANNEL_MSGRECEIVED,
CLIENT_ON_CHANNEL_QOSEVENT,
CLIENT_DISCOVERY_SUCC,
CLIENT_DISCOVERY_FAIL,
CLIENT_DISCOVERY_DEVICE_FOUND,
CLIENT_PUBLISH_SUCC,
CLIENT_PUBLISH_FAIL,
CLIENT_ON_JOIN_RESULT,
CLIENT_ON_JOIN_METANODE_RESULT,
CLIENT_ON_LEAVE_RESULT,

View File

@ -19,7 +19,7 @@
#include <stdbool.h>
#include <stdint.h>
#include "discovery_service.h"
#include "softbus_common.h"
#ifdef __cplusplus
#if __cplusplus

View File

@ -26,7 +26,6 @@
#include "disc_event.h"
#include "disc_log.h"
#include "disc_manager.h"
#include "discovery_service.h"
#include "lnn_device_info.h"
#include "lnn_ohos_account.h"
#include "message_handler.h"

View File

@ -26,8 +26,6 @@ disc_server_src += [
"$dsoftbus_root_path/core/discovery/manager/src/softbus_disc_server.c",
]
disc_server_inc += [
"$dsoftbus_root_path/core/discovery/ipc/include",
"$dsoftbus_root_path/core/discovery/ipc/include",
"$dsoftbus_root_path/core/discovery/manager/include",
"$dsoftbus_root_path/core/discovery/interface",
"$dsoftbus_root_path/core/common/dfx/hisysevent_adapter/include",
@ -37,22 +35,11 @@ if (!dsoftbus_feature_ex_kits) {
}
if (defined(ohos_lite)) {
if (ohos_kernel_type == "liteos_m") {
disc_server_src +=
[ "$dsoftbus_root_path/core/discovery/ipc/mini/disc_client_proxy.c" ]
disc_server_inc += [ "$dsoftbus_root_path/sdk/discovery/manager/include" ]
} else {
disc_server_src +=
[ "$dsoftbus_root_path/core/discovery/ipc/small/disc_client_proxy.c" ]
disc_server_deps += [
"//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single",
]
}
} else {
disc_server_src += [
"$dsoftbus_root_path/core/discovery/ipc/$os_type/src/disc_client_proxy.cpp",
"$dsoftbus_root_path/core/discovery/ipc/$os_type/src/disc_client_proxy_standard.cpp",
]
disc_server_inc +=
[ "$dsoftbus_root_path/core/discovery/ipc/$os_type/include" ]
disc_server_external_deps += [ "c_utils:utils" ]
}

View File

@ -16,7 +16,7 @@
#ifndef DISC_MANAGER_INTERFACE_H
#define DISC_MANAGER_INTERFACE_H
#include "discovery_service.h"
#include "softbus_common.h"
#include "stdint.h"
#ifdef __cplusplus

View File

@ -16,8 +16,6 @@
#ifndef DISC_SERIALIZER_H
#define DISC_SERIALIZER_H
#include "discovery_service.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {

View File

@ -1,85 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DISC_CLIENT_PROXY_H
#include <stdint.h>
#include "softbus_common.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
/**
* @brief Discovery device callback function.
* @see {@link ClientIpcOnDiscoverFailed} or {@link ClientIpcDiscoverySuccess}
* @param[in] pkgName Indicates the pointer to package name, which can contain a maximum of 64 bytes.
* @param[in] device Indicates a pointer to device information. For details, see {@link DeviceInfo}.
* @param[in] addtions Indicates a pointer to device additional information.
* @return <b>SOFTBUS_OK</b> Client IPC found on device.
*/
int32_t ClientIpcOnDeviceFound(const char *pkgName, const DeviceInfo *device, const InnerDeviceInfoAddtions *addtions);
/**
* @brief The discovery failure callback notifies the local end of failure to discover other devices.
* This callback is only called when discovering other devices fails.
* @see {@link ClientIpcOnDeviceFound} or {@link ClientIpcDiscoverySuccess}
* @param[in] pkgName Indicates the pointer to package name, which can contain a maximum of 64 bytes.
* @param[in] subscribeId Indicates the service ID.
* @param[in] failReason Fail reason.
* @return <b>SOFTBUS_OK</b> Failed to find Client IPC found on device.
*/
int32_t ClientIpcOnDiscoverFailed(const char *pkgName, int subscribeId, int failReason);
/**
* @brief The discovery success callback notifies the local end of successfully discovering other devices.
* This callback is only called when other devices are successfully discovered.
* @see {@link ClientIpcOnDeviceFound} or {@link ClientIpcOnDiscoverFailed}
* @param[in] pkgName Indicates the pointer to package name, which can contain a maximum of 64 bytes.
* @param[in] subscribeId Indicates the service ID.
* @return <b>SOFTBUS_OK</b> Client IPC found on device successfully.
*/
int32_t ClientIpcDiscoverySuccess(const char *pkgName, int subscribeId);
/**
* @brief Publishing success callback, notifying the local end of publishing its own information successfully.
* This callback is only called when the ability to publish itself is successful.
* @see {@link ClientIpcOnPublishFail}
* @param[in] pkgName Indicates the pointer to package name, which can contain a maximum of 64 bytes.
* @param[in] publishId Publish ID.
* @return <b>SOFTBUS_OK</b> Client IPC published successfully.
*/
int32_t ClientIpcOnPublishSuccess(const char *pkgName, int publishId);
/**
* @brief Publishing failure callback, notifying the local end of the failure to publish its own information.
* This callback is only called when the ability to publish itself fails.
* @see {@link ClientIpcOnPublishSuccess}
* @param[in] pkgName Indicates the pointer to package name, which can contain a maximum of 64 bytes.
* @param[in] publishId Publish ID.
* @param[in] reason Fail reason.
* @return <b>SOFTBUS_OK</b> Client IPC published failed.
*/
int32_t ClientIpcOnPublishFail(const char *pkgName, int publishId, int reason);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif // !DISC_CLIENT_PROXY_H

View File

@ -1,62 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "disc_client_proxy.h"
#include "client_disc_manager.h"
#include "disc_log.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
int32_t ClientIpcOnDeviceFound(const char *pkgName, const DeviceInfo *device, const InnerDeviceInfoAddtions *additions)
{
(void)pkgName;
(void)additions;
DISC_LOGI(DISC_CONTROL, "ondevice found ipc server push.");
DiscClientOnDeviceFound(device);
return SOFTBUS_OK;
}
int32_t ClientIpcOnDiscoverFailed(const char *pkgName, int subscribeId, int failReason)
{
(void)pkgName;
DISC_LOGI(DISC_CONTROL, "on discovery failed callback ipc server push.");
DiscClientOnDiscoverFailed(subscribeId, (DiscoveryFailReason)failReason);
return SOFTBUS_OK;
}
int32_t ClientIpcDiscoverySuccess(const char *pkgName, int subscribeId)
{
(void)pkgName;
DISC_LOGI(DISC_CONTROL, "on discovery success callback ipc server push.");
DiscClientOnDiscoverySuccess(subscribeId);
return SOFTBUS_OK;
}
int32_t ClientIpcOnPublishSuccess(const char *pkgName, int publishId)
{
(void)pkgName;
DISC_LOGI(DISC_CONTROL, "on publish success callback ipc server push.");
DiscClientOnPublishSuccess(publishId);
return SOFTBUS_OK;
}
int32_t ClientIpcOnPublishFail(const char *pkgName, int publishId, int reason)
{
(void)pkgName;
DISC_LOGI(DISC_CONTROL, "on publish failed ipc server push.");
DiscClientOnPublishFail(publishId, (PublishFailReason)reason);
return SOFTBUS_OK;
}

View File

@ -1,189 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "disc_client_proxy.h"
#include "disc_log.h"
#include "ipc_skeleton.h"
#include "serializer.h"
#include "softbus_client_info_manager.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_server_ipc_interface_code.h"
static int32_t GetSvcIdentityByPkgName(const char *pkgName, SvcIdentity *svc)
{
struct CommonScvId svcId = {0};
int ret = SERVER_GetIdentityByPkgName(pkgName, &svcId);
if (ret != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "ondevice found callback failed.");
return ret;
}
svc->handle = svcId.handle;
svc->token = svcId.token;
svc->cookie = svcId.cookie;
return SOFTBUS_OK;
}
int32_t ClientIpcOnDeviceFound(const char *pkgName, const DeviceInfo *device, const InnerDeviceInfoAddtions *additions)
{
(void)additions;
DISC_LOGI(DISC_CONTROL, "ondevice found ipc server push.");
IpcIo io;
uint8_t tmpData[MAX_SOFT_BUS_IPC_LEN_EX] = {0};
IpcIoInit(&io, tmpData, MAX_SOFT_BUS_IPC_LEN_EX, 0);
bool ret = WriteRawData(&io, (const void*)device, sizeof(DeviceInfo));
if (!ret) {
DISC_LOGE(DISC_CONTROL, "Write DeviceInfo failed.");
return SOFTBUS_IPC_ERR;
}
SvcIdentity svc = {0};
int status = GetSvcIdentityByPkgName(pkgName, &svc);
if (status != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "ondevice found callback get svc failed.");
return status;
}
MessageOption option;
MessageOptionInit(&option);
option.flags = TF_OP_ASYNC;
int32_t ans = SendRequest(svc, CLIENT_DISCOVERY_DEVICE_FOUND, &io, NULL, option, NULL);
if (ans != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "ondevice found callback SendRequest failed.");
return ans;
}
return SOFTBUS_OK;
}
int32_t ClientIpcOnDiscoverFailed(const char *pkgName, int subscribeId, int failReason)
{
DISC_LOGI(DISC_CONTROL, "on discovery failed callback ipc server push.");
IpcIo io;
uint8_t tmpData[MAX_SOFT_BUS_IPC_LEN] = {0};
IpcIoInit(&io, tmpData, MAX_SOFT_BUS_IPC_LEN, 0);
bool ret = WriteInt32(&io, subscribeId);
if (!ret) {
DISC_LOGE(DISC_CONTROL, "Write subscribeId failed.");
return SOFTBUS_IPC_ERR;
}
ret = WriteInt32(&io, failReason);
if (!ret) {
DISC_LOGE(DISC_CONTROL, "Write failReason failed.");
return SOFTBUS_IPC_ERR;
}
SvcIdentity svc = {0};
int status = GetSvcIdentityByPkgName(pkgName, &svc);
if (status != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "on discovery failed callback get svc failed.");
return status;
}
MessageOption option;
MessageOptionInit(&option);
option.flags = TF_OP_ASYNC;
int32_t ans = SendRequest(svc, CLIENT_DISCOVERY_FAIL, &io, NULL, option, NULL);
if (ans != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "on discovery failed callback SendRequest failed.");
return ans;
}
return SOFTBUS_OK;
}
int32_t ClientIpcDiscoverySuccess(const char *pkgName, int subscribeId)
{
DISC_LOGI(DISC_CONTROL, "on discovery success callback ipc server push.");
IpcIo io;
uint8_t tmpData[MAX_SOFT_BUS_IPC_LEN] = {0};
IpcIoInit(&io, tmpData, MAX_SOFT_BUS_IPC_LEN, 0);
bool ret = WriteInt32(&io, subscribeId);
if (!ret) {
DISC_LOGE(DISC_CONTROL, "Write subscribeId failed.");
return SOFTBUS_IPC_ERR;
}
SvcIdentity svc = {0};
int status = GetSvcIdentityByPkgName(pkgName, &svc);
if (status != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "on discovery success callback get svc failed.");
return status;
}
MessageOption option;
MessageOptionInit(&option);
option.flags = TF_OP_ASYNC;
int32_t ans = SendRequest(svc, CLIENT_DISCOVERY_SUCC, &io, NULL, option, NULL);
if (ans != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "on discovery success callback SendRequest failed.");
return ans;
}
return SOFTBUS_OK;
}
int32_t ClientIpcOnPublishSuccess(const char *pkgName, int publishId)
{
DISC_LOGI(DISC_CONTROL, "on publish success callback ipc server push.");
IpcIo io;
uint8_t tmpData[MAX_SOFT_BUS_IPC_LEN] = {0};
IpcIoInit(&io, tmpData, MAX_SOFT_BUS_IPC_LEN, 0);
bool ret = WriteInt32(&io, publishId);
if (!ret) {
DISC_LOGE(DISC_CONTROL, "Write publishId failed.");
return SOFTBUS_IPC_ERR;
}
SvcIdentity svc = {0};
int status = GetSvcIdentityByPkgName(pkgName, &svc);
if (status != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "on publish success callback get svc failed.");
return status;
}
MessageOption option;
MessageOptionInit(&option);
option.flags = TF_OP_ASYNC;
int32_t ans = SendRequest(svc, CLIENT_PUBLISH_SUCC, &io, NULL, option, NULL);
if (ans != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "on publish success callback SendRequest failed.");
return ans;
}
return SOFTBUS_OK;
}
int32_t ClientIpcOnPublishFail(const char *pkgName, int publishId, int reason)
{
DISC_LOGI(DISC_CONTROL, "on publish failed ipc server push.");
IpcIo io;
uint8_t tmpData[MAX_SOFT_BUS_IPC_LEN] = {0};
IpcIoInit(&io, tmpData, MAX_SOFT_BUS_IPC_LEN, 0);
bool ret = WriteInt32(&io, publishId);
if (!ret) {
DISC_LOGE(DISC_CONTROL, "Write publishId failed.");
return SOFTBUS_IPC_ERR;
}
ret = WriteInt32(&io, reason);
if (!ret) {
DISC_LOGE(DISC_CONTROL, "Write reason failed.");
return SOFTBUS_IPC_ERR;
}
SvcIdentity svc = {0};
int status = GetSvcIdentityByPkgName(pkgName, &svc);
if (status != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "on publish failed callback get svc failed.");
return status;
}
MessageOption option;
MessageOptionInit(&option);
option.flags = TF_OP_ASYNC;
int32_t ans = SendRequest(svc, CLIENT_PUBLISH_FAIL, &io, NULL, option, NULL);
if (ans != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "on publish failed callback SendRequest failed.");
return ans;
}
return SOFTBUS_OK;
}

View File

@ -1,38 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef INTERFACES_INNERKITS_DISC_CLIENT_PROXY_STANDARD_H_
#define INTERFACES_INNERKITS_DISC_CLIENT_PROXY_STANDARD_H_
#include "if_softbus_client.h"
#include "softbus_error_code.h"
namespace OHOS {
class DiscClientProxy : public IRemoteProxy<ISoftBusClient> {
public:
explicit DiscClientProxy(const sptr<IRemoteObject> &impl);
~DiscClientProxy() override;
void OnDeviceFound(const DeviceInfo *device) override;
void OnDiscoverFailed(int subscribeId, int failReason) override;
void OnDiscoverySuccess(int subscribeId) override;
void OnPublishSuccess(int publishId) override;
void OnPublishFail(int publishId, int reason) override;
private:
static inline BrokerDelegator<DiscClientProxy> delegator_;
};
}
#endif

View File

@ -1,82 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "disc_client_proxy.h"
#include "disc_client_proxy_standard.h"
#include "disc_log.h"
#include "softbus_client_info_manager.h"
#include "softbus_def.h"
#include "softbus_error_code.h"
using namespace OHOS;
static sptr<DiscClientProxy> GetClientProxy(const char *pkgName)
{
sptr<IRemoteObject> clientObject = SoftbusClientInfoManager::GetInstance().GetSoftbusClientProxy(pkgName);
sptr<DiscClientProxy> clientProxy = new (std::nothrow) DiscClientProxy(clientObject);
return clientProxy;
}
int32_t ClientIpcOnDeviceFound(const char *pkgName, const DeviceInfo *device,
const InnerDeviceInfoAddtions *additions)
{
sptr<DiscClientProxy> clientProxy = GetClientProxy(pkgName);
DISC_CHECK_AND_RETURN_RET_LOGE(clientProxy != nullptr, SOFTBUS_DISCOVER_GET_CLIENT_PROXY_FAILED,
DISC_CONTROL, "client proxy is nullptr");
clientProxy->OnDeviceFound(device);
return SOFTBUS_OK;
}
int32_t ClientIpcOnDiscoverFailed(const char *pkgName, int subscribeId, int failReason)
{
sptr<DiscClientProxy> clientProxy = GetClientProxy(pkgName);
DISC_CHECK_AND_RETURN_RET_LOGE(clientProxy != nullptr, SOFTBUS_DISCOVER_GET_CLIENT_PROXY_FAILED,
DISC_CONTROL, "client proxy is nullptr");
clientProxy->OnDiscoverFailed(subscribeId, failReason);
return SOFTBUS_OK;
}
int32_t ClientIpcDiscoverySuccess(const char *pkgName, int subscribeId)
{
sptr<DiscClientProxy> clientProxy = GetClientProxy(pkgName);
DISC_CHECK_AND_RETURN_RET_LOGE(clientProxy != nullptr, SOFTBUS_DISCOVER_GET_CLIENT_PROXY_FAILED,
DISC_CONTROL, "client proxy is nullptr");
clientProxy->OnDiscoverySuccess(subscribeId);
return SOFTBUS_OK;
}
int32_t ClientIpcOnPublishSuccess(const char *pkgName, int publishId)
{
sptr<DiscClientProxy> clientProxy = GetClientProxy(pkgName);
DISC_CHECK_AND_RETURN_RET_LOGE(clientProxy != nullptr, SOFTBUS_DISCOVER_GET_CLIENT_PROXY_FAILED,
DISC_CONTROL, "client proxy is nullptr");
clientProxy->OnPublishSuccess(publishId);
return SOFTBUS_OK;
}
int32_t ClientIpcOnPublishFail(const char *pkgName, int publishId, int reason)
{
sptr<DiscClientProxy> clientProxy = GetClientProxy(pkgName);
DISC_CHECK_AND_RETURN_RET_LOGE(clientProxy != nullptr, SOFTBUS_DISCOVER_GET_CLIENT_PROXY_FAILED,
DISC_CONTROL, "client proxy is nullptr");
clientProxy->OnPublishFail(publishId, reason);
return SOFTBUS_OK;
}

View File

@ -1,119 +0,0 @@
/*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "disc_client_proxy_standard.h"
#include "disc_log.h"
#include "softbus_server_ipc_interface_code.h"
namespace OHOS {
DiscClientProxy::DiscClientProxy(const sptr<IRemoteObject> &impl)
: IRemoteProxy<ISoftBusClient>(impl)
{
DISC_LOGI(DISC_CONTROL, "construct");
}
DiscClientProxy::~DiscClientProxy()
{
DISC_LOGI(DISC_CONTROL, "destroy");
}
void DiscClientProxy::OnDeviceFound(const DeviceInfo *deviceInfo)
{
MessageParcel data;
DISC_CHECK_AND_RETURN_LOGE(data.WriteInterfaceToken(GetDescriptor()), DISC_CONTROL, "write InterfaceToken failed");
DISC_CHECK_AND_RETURN_LOGE(data.WriteBuffer(deviceInfo, sizeof(DeviceInfo)), DISC_CONTROL,
"write device info failed");
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
DISC_LOGE(DISC_CONTROL, "remote is nullptr");
return;
}
MessageParcel reply;
MessageOption option { MessageOption::TF_ASYNC };
DISC_CHECK_AND_RETURN_LOGE(remote->SendRequest(CLIENT_DISCOVERY_DEVICE_FOUND, data, reply, option) == SOFTBUS_OK,
DISC_CONTROL, "send request failed");
}
void DiscClientProxy::OnDiscoverFailed(int subscribeId, int reason)
{
MessageParcel data;
DISC_CHECK_AND_RETURN_LOGE(data.WriteInterfaceToken(GetDescriptor()), DISC_CONTROL, "write InterfaceToken failed");
DISC_CHECK_AND_RETURN_LOGE(data.WriteInt32(subscribeId), DISC_CONTROL, "write subscribe id failed");
DISC_CHECK_AND_RETURN_LOGE(data.WriteInt32(reason), DISC_CONTROL, "write reason failed");
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
DISC_LOGE(DISC_LNN, "remote is nullptr");
return;
}
MessageParcel reply;
MessageOption option { MessageOption::TF_ASYNC };
DISC_CHECK_AND_RETURN_LOGE(remote->SendRequest(CLIENT_DISCOVERY_FAIL, data, reply, option) == SOFTBUS_OK,
DISC_CONTROL, "send request failed");
}
void DiscClientProxy::OnDiscoverySuccess(int subscribeId)
{
MessageParcel data;
DISC_CHECK_AND_RETURN_LOGE(data.WriteInterfaceToken(GetDescriptor()), DISC_CONTROL, "write InterfaceToken failed");
DISC_CHECK_AND_RETURN_LOGE(data.WriteInt32(subscribeId), DISC_CONTROL, "write subscribe id failed");
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
DISC_LOGE(DISC_LNN, "remote is nullptr");
return;
}
MessageParcel reply;
MessageOption option { MessageOption::TF_ASYNC };
DISC_CHECK_AND_RETURN_LOGE(remote->SendRequest(CLIENT_DISCOVERY_SUCC, data, reply, option) == SOFTBUS_OK,
DISC_CONTROL, "send request failed");
}
void DiscClientProxy::OnPublishSuccess(int publishId)
{
MessageParcel data;
DISC_CHECK_AND_RETURN_LOGE(data.WriteInterfaceToken(GetDescriptor()), DISC_CONTROL, "write InterfaceToken failed");
DISC_CHECK_AND_RETURN_LOGE(data.WriteInt32(publishId), DISC_CONTROL, "write publish id failed");
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
DISC_LOGE(DISC_LNN, "remote is nullptr");
return;
}
MessageParcel reply;
MessageOption option { MessageOption::TF_ASYNC };
DISC_CHECK_AND_RETURN_LOGE(remote->SendRequest(CLIENT_PUBLISH_SUCC, data, reply, option) == SOFTBUS_OK,
DISC_CONTROL, "send request failed");
}
void DiscClientProxy::OnPublishFail(int publishId, int reason)
{
MessageParcel data;
DISC_CHECK_AND_RETURN_LOGE(data.WriteInterfaceToken(GetDescriptor()), DISC_CONTROL, "write InterfaceToken failed");
DISC_CHECK_AND_RETURN_LOGE(data.WriteInt32(publishId), DISC_CONTROL, "write publish id failed");
DISC_CHECK_AND_RETURN_LOGE(data.WriteInt32(reason), DISC_CONTROL, "write reason failed");
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
DISC_LOGE(DISC_LNN, "remote is nullptr");
return;
}
MessageParcel reply;
MessageOption option{MessageOption::TF_ASYNC};
DISC_CHECK_AND_RETURN_LOGE(remote->SendRequest(CLIENT_PUBLISH_FAIL, data, reply, option) == SOFTBUS_OK,
DISC_CONTROL, "send request failed");
}
}

View File

@ -26,11 +26,6 @@ int32_t DiscServerInit(void);
void DiscServerDeinit(void);
void DiscServerDeathCallback(const char *pkgName);
int32_t DiscIpcPublishService(const char *packageName, const PublishInfo *info);
int32_t DiscIpcUnPublishService(const char *packageName, int32_t publishId);
int32_t DiscIpcStartDiscovery(const char *packageName, const SubscribeInfo *info);
int32_t DiscIpcStopDiscovery(const char *packageName, int32_t subscribeId);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -15,15 +15,10 @@
#include "softbus_disc_server.h"
#include "disc_client_proxy.h"
#include "disc_log.h"
#include "softbus_error_code.h"
#include "softbus_hisysevt_discreporter.h"
static IServerDiscInnerCallback g_discInnerCb = {
.OnServerDeviceFound = ClientIpcOnDeviceFound,
};
int32_t DiscServerInit(void)
{
int32_t ret = DiscMgrInit();
@ -43,85 +38,3 @@ void DiscServerDeathCallback(const char *pkgName)
{
DiscMgrDeathCallback(pkgName);
}
static SoftBusDiscMedium ConvertDiscType(const ExchangeMedium *discType)
{
switch (*discType) {
case BLE:
return SOFTBUS_HISYSEVT_DISC_MEDIUM_BLE;
case COAP:
return SOFTBUS_HISYSEVT_DISC_MEDIUM_COAP;
default:
return SOFTBUS_HISYSEVT_DISC_MEDIUM_BUTT;
}
}
static int32_t PublishErroCodeProcess(int32_t erroCode)
{
if (erroCode == SOFTBUS_DISCOVER_MANAGER_INVALID_MEDIUM) {
return PUBLISH_FAIL_REASON_NOT_SUPPORT_MEDIUM;
}
return PUBLISH_FAIL_REASON_INTERNAL;
}
static int32_t DiscoveryErroCodeProcess(int32_t erroCode)
{
if (erroCode == SOFTBUS_DISCOVER_MANAGER_INVALID_MEDIUM) {
return DISCOVERY_FAIL_REASON_NOT_SUPPORT_MEDIUM;
}
return DISCOVERY_FAIL_REASON_INTERNAL;
}
int32_t DiscIpcPublishService(const char *packageName, const PublishInfo *info)
{
DISC_CHECK_AND_RETURN_RET_LOGW(packageName != NULL && info != NULL, SOFTBUS_INVALID_PARAM, DISC_CONTROL,
"invalid parameters");
int32_t ret = DiscPublishService(packageName, info);
if (ret != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "ServerPublishService failed");
SoftbusReportDiscFault(ConvertDiscType(&info->medium), ret);
(void)ClientIpcOnPublishFail(packageName, info->publishId, PublishErroCodeProcess(ret));
return ret;
}
DISC_LOGI(DISC_CONTROL, "ServerPublishService success!");
(void)ClientIpcOnPublishSuccess(packageName, info->publishId);
return SOFTBUS_OK;
}
int32_t DiscIpcUnPublishService(const char *packageName, int32_t publishId)
{
int32_t ret = DiscUnPublishService(packageName, publishId);
if (ret != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "ServerUnPublishService failed");
return ret;
}
DISC_LOGI(DISC_CONTROL, "ServerUnPublishService success!");
return SOFTBUS_OK;
}
int32_t DiscIpcStartDiscovery(const char *packageName, const SubscribeInfo *info)
{
DISC_CHECK_AND_RETURN_RET_LOGW(packageName != NULL && info != NULL, SOFTBUS_INVALID_PARAM, DISC_CONTROL,
"invalid parameters");
int32_t ret = DiscStartDiscovery(packageName, info, &g_discInnerCb);
if (ret != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "ServerStartDiscovery failed");
SoftbusReportDiscFault(ConvertDiscType(&info->medium), ret);
(void)ClientIpcOnDiscoverFailed(packageName, info->subscribeId, DiscoveryErroCodeProcess(ret));
return ret;
}
DISC_LOGI(DISC_CONTROL, "ServerStartDiscovery success!");
(void)ClientIpcDiscoverySuccess(packageName, info->subscribeId);
return SOFTBUS_OK;
}
int32_t DiscIpcStopDiscovery(const char *packageName, int32_t subscribeId)
{
int32_t ret = DiscStopDiscovery(packageName, subscribeId);
if (ret != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "ServerStopDiscovery failed");
return ret;
}
DISC_LOGI(DISC_CONTROL, "ServerStopDiscovery success!");
return SOFTBUS_OK;
}

View File

@ -144,7 +144,6 @@ if (defined(ohos_lite)) {
"common/src/softbus_server_frame.c",
"small/client_manager/src/softbus_client_info_manager.c",
"small/init/src/bus_center_server_stub.c",
"small/init/src/disc_server_stub.c",
"small/init/src/softbus_server_stub.c",
"small/init/src/trans_server_stub.c",
]

View File

@ -1,38 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DISC_SERVER_STUB_H
#include <stdint.h>
#include "serializer.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
int32_t ServerPublishService(IpcIo *req, IpcIo *reply);
int32_t ServerUnPublishService(IpcIo *req, IpcIo *reply);
int32_t ServerStartDiscovery(IpcIo *req, IpcIo *reply);
int32_t ServerStopDiscovery(IpcIo *req, IpcIo *reply);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif // !DISC_SERVER_STUB_H

View File

@ -1,153 +0,0 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "disc_server_stub.h"
#include "comm_log.h"
#include "disc_serializer.h"
#include "discovery_service.h"
#include "ipc_skeleton.h"
#include "softbus_def.h"
#include "softbus_disc_server.h"
#include "softbus_errcode.h"
#include "softbus_permission.h"
int32_t ServerPublishService(IpcIo *req, IpcIo *reply)
{
COMM_LOGI(COMM_SVC, "publish service ipc server pop.");
if (req == NULL || reply == NULL) {
COMM_LOGE(COMM_SVC, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
size_t len;
unsigned char *capabilityData = NULL;
const char *pkgName = (const char*)ReadString(req, &len);
if (pkgName == NULL) {
COMM_LOGE(COMM_SVC, "ServerPublishService pkgName is null");
return SOFTBUS_ERR;
}
PublishSerializer *info = (PublishSerializer*)ReadRawData(req, sizeof(PublishSerializer));
if (info == NULL) {
COMM_LOGE(COMM_SVC, "ipc pop is null.");
return SOFTBUS_ERR;
}
char *capability = (char*)ReadString(req, &len);
if (info->commonSerializer.dataLen != 0) {
capabilityData = (unsigned char*)ReadString(req, &len);
}
PublishInfo publishInfo = {
.capability = capability,
.capabilityData = capabilityData,
.dataLen = info->commonSerializer.dataLen,
.freq = info->commonSerializer.freq,
.medium = info->commonSerializer.medium,
.mode = info->commonSerializer.mode,
.publishId = info->commonSerializer.id.publishId,
};
int32_t callingUid = GetCallingUid();
if (!CheckDiscPermission(callingUid, pkgName)) {
COMM_LOGE(COMM_SVC, "publish service no permission.");
return SOFTBUS_PERMISSION_DENIED;
}
int32_t ret = DiscIpcPublishService(pkgName, &publishInfo);
if (ret != SOFTBUS_OK) {
COMM_LOGE(COMM_SVC, "publish service failed.");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
int32_t ServerUnPublishService(IpcIo *req, IpcIo *reply)
{
COMM_LOGI(COMM_SVC, "unpublish service ipc server pop.");
size_t len;
const char *pkgName = (const char*)ReadString(req, &len);
if (pkgName == NULL) {
COMM_LOGE(COMM_SVC, "ServerUnPublishService read pkgName failed!");
return SOFTBUS_IPC_ERR;
}
int32_t publishId;
ReadInt32(req, &publishId);
int32_t callingUid = GetCallingUid();
if (!CheckDiscPermission(callingUid, pkgName)) {
COMM_LOGE(COMM_SVC, "unpublish service no permission.");
return SOFTBUS_PERMISSION_DENIED;
}
int32_t ret = DiscIpcUnPublishService(pkgName, publishId);
if (ret != SOFTBUS_OK) {
COMM_LOGE(COMM_SVC, "unpublish service failed.");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
int32_t ServerStartDiscovery(IpcIo *req, IpcIo *reply)
{
COMM_LOGD(COMM_SVC, "start discovery ipc server pop.");
size_t len;
unsigned char *capabilityData = NULL;
const char *pkgName = (const char *)ReadString(req, &len);
SubscribeSerializer *info = (SubscribeSerializer *)ReadRawData(req, sizeof(SubscribeSerializer));
if (info == NULL) {
COMM_LOGE(COMM_SVC, "ipc pop is null.");
return SOFTBUS_ERR;
}
char *capability = (char *)ReadString(req, &len);
if (info->commonSerializer.dataLen != 0) {
capabilityData = (unsigned char *)ReadString(req, &len);
}
SubscribeInfo subscribeInfo = {
.capability = capability,
.capabilityData = capabilityData,
.dataLen = info->commonSerializer.dataLen,
.freq = info->commonSerializer.freq,
.medium = info->commonSerializer.medium,
.mode = info->commonSerializer.mode,
.subscribeId = info->commonSerializer.id.subscribeId,
.isSameAccount = info->isSameAccount,
.isWakeRemote = info->isWakeRemote,
};
int32_t callingUid = GetCallingUid();
if (!CheckDiscPermission(callingUid, pkgName)) {
COMM_LOGE(COMM_SVC, "start discovery no permission.");
return SOFTBUS_PERMISSION_DENIED;
}
int32_t ret = DiscIpcStartDiscovery(pkgName, &subscribeInfo);
if (ret != SOFTBUS_OK) {
COMM_LOGE(COMM_SVC, "start discovery failed.");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
int32_t ServerStopDiscovery(IpcIo *req, IpcIo *reply)
{
COMM_LOGI(COMM_SVC, "stop discovery ipc server pop.");
size_t len;
const char *pkgName = (const char *)ReadString(req, &len);
int32_t subscribeId;
ReadInt32(req, &subscribeId);
int32_t callingUid = GetCallingUid();
if (!CheckDiscPermission(callingUid, pkgName)) {
COMM_LOGE(COMM_SVC, "stop discovery no permission.");
return SOFTBUS_PERMISSION_DENIED;
}
int32_t ret = DiscIpcStopDiscovery(pkgName, subscribeId);
if (ret != SOFTBUS_OK) {
COMM_LOGE(COMM_SVC, "stop discovery failed.");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}

View File

@ -17,7 +17,6 @@
#include "bus_center_server_stub.h"
#include "comm_log.h"
#include "disc_server_stub.h"
#include "ipc_skeleton.h"
#include "iproxy_server.h"
#include "lnn_bus_center_ipc.h"
@ -178,10 +177,6 @@ typedef struct {
const ServerInvokeCmd g_serverInvokeCmdTbl[] = {
{ MANAGE_REGISTER_SERVICE, ServerRegisterService },
{ SERVER_PUBLISH_SERVICE, ServerPublishService },
{ SERVER_UNPUBLISH_SERVICE, ServerUnPublishService },
{ SERVER_START_DISCOVERY, ServerStartDiscovery },
{ SERVER_STOP_DISCOVERY, ServerStopDiscovery },
{ SERVER_JOIN_LNN, ServerJoinLNN },
{ SERVER_JOIN_METANODE, ServerJoinMetaNode },
{ SERVER_LEAVE_LNN, ServerLeaveLNN },

View File

@ -17,7 +17,6 @@
#define INTERFACES_INNERKITS_SOFTBUS_SERVER_H_
#include "data_level.h"
#include "discovery_service.h"
#include "iremote_broker.h"
#include "iremote_object.h"
#include "iremote_proxy.h"
@ -30,10 +29,6 @@ class ISoftBusServer : public IRemoteBroker {
public:
virtual ~ISoftBusServer() = default;
virtual int32_t StartDiscovery(const char *pkgName, const SubscribeInfo *info) = 0;
virtual int32_t StopDiscovery(const char *pkgName, int subscribeId) = 0;
virtual int32_t PublishService(const char *pkgName, const PublishInfo *info) = 0;
virtual int32_t UnPublishService(const char *pkgName, int publishId) = 0;
virtual int32_t SoftbusRegisterService(const char *clientPkgName, const sptr<IRemoteObject> &object) = 0;
virtual int32_t CreateSessionServer(const char *pkgName, const char *sessionName) = 0;

View File

@ -28,10 +28,6 @@ public:
SoftBusServer(int32_t saId, bool runOnCreate);
~SoftBusServer() = default;
int32_t StartDiscovery(const char *pkgName, const SubscribeInfo *info) override;
int32_t StopDiscovery(const char *pkgName, int subscribeId) override;
int32_t PublishService(const char *pkgName, const PublishInfo *info) override;
int32_t UnPublishService(const char *pkgName, int publishId) override;
int32_t SoftbusRegisterService(const char *clientPkgName, const sptr<IRemoteObject> &object) override;
int32_t CreateSessionServer(const char *pkgName, const char *sessionName) override;

View File

@ -31,10 +31,6 @@ public:
private:
int32_t GetNodeKeyInfoLen(int32_t key);
int32_t StartDiscoveryInner(MessageParcel &data, MessageParcel &reply);
int32_t StopDiscoveryInner(MessageParcel &data, MessageParcel &reply);
int32_t PublishServiceInner(MessageParcel &data, MessageParcel &reply);
int32_t UnpublishServiceInner(MessageParcel &data, MessageParcel &reply);
int32_t SoftbusRegisterServiceInner(MessageParcel &data, MessageParcel &reply);
int32_t CreateSessionServerInner(MessageParcel &data, MessageParcel &reply);

View File

@ -58,26 +58,6 @@ SoftBusServer::SoftBusServer(int32_t saId, bool runOnCreate) : SystemAbility(saI
{
}
int32_t SoftBusServer::StartDiscovery(const char *pkgName, const SubscribeInfo *info)
{
return DiscIpcStartDiscovery(pkgName, info);
}
int32_t SoftBusServer::StopDiscovery(const char *pkgName, int subscribeId)
{
return DiscIpcStopDiscovery(pkgName, subscribeId);
}
int32_t SoftBusServer::PublishService(const char *pkgName, const PublishInfo *info)
{
return DiscIpcPublishService(pkgName, (PublishInfo *)(info));
}
int32_t SoftBusServer::UnPublishService(const char *pkgName, int publishId)
{
return DiscIpcUnPublishService(pkgName, publishId);
}
int32_t SoftBusServer::SoftbusRegisterService(const char *clientPkgName, const sptr<IRemoteObject> &object)
{
if (clientPkgName == nullptr || object == nullptr) {

View File

@ -149,10 +149,6 @@ SoftBusServerStub::SoftBusServerStub()
void SoftBusServerStub::InitMemberFuncMap()
{
memberFuncMap_[SERVER_START_DISCOVERY] = &SoftBusServerStub::StartDiscoveryInner;
memberFuncMap_[SERVER_STOP_DISCOVERY] = &SoftBusServerStub::StopDiscoveryInner;
memberFuncMap_[SERVER_PUBLISH_SERVICE] = &SoftBusServerStub::PublishServiceInner;
memberFuncMap_[SERVER_UNPUBLISH_SERVICE] = &SoftBusServerStub::UnpublishServiceInner;
memberFuncMap_[MANAGE_REGISTER_SERVICE] = &SoftBusServerStub::SoftbusRegisterServiceInner;
memberFuncMap_[SERVER_CREATE_SESSION_SERVER] = &SoftBusServerStub::CreateSessionServerInner;
memberFuncMap_[SERVER_REMOVE_SESSION_SERVER] = &SoftBusServerStub::RemoveSessionServerInner;
@ -194,10 +190,6 @@ void SoftBusServerStub::InitMemberFuncMap()
void SoftBusServerStub::InitMemberPermissionMap()
{
memberPermissionMap_[SERVER_START_DISCOVERY] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
memberPermissionMap_[SERVER_STOP_DISCOVERY] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
memberPermissionMap_[SERVER_PUBLISH_SERVICE] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
memberPermissionMap_[SERVER_UNPUBLISH_SERVICE] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
memberPermissionMap_[MANAGE_REGISTER_SERVICE] = nullptr;
memberPermissionMap_[SERVER_CREATE_SESSION_SERVER] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
memberPermissionMap_[SERVER_REMOVE_SESSION_SERVER] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
@ -287,128 +279,6 @@ int32_t SoftBusServerStub::OnRemoteRequest(
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
int32_t SoftBusServerStub::StartDiscoveryInner(MessageParcel &data, MessageParcel &reply)
{
const char *pkgName = data.ReadCString();
COMM_CHECK_AND_RETURN_RET_LOGE(pkgName != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read pkgName failed");
COMM_CHECK_AND_RETURN_RET_LOGE(strnlen(pkgName, PKG_NAME_SIZE_MAX) < PKG_NAME_SIZE_MAX, SOFTBUS_INVALID_PKGNAME,
COMM_SVC, "pkgName invalid");
SoftbusRecordCalledApiInfo(pkgName, SERVER_START_DISCOVERY);
SubscribeInfo info = {0};
int32_t value = 0;
COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(info.subscribeId), SOFTBUS_IPC_ERR, COMM_SVC,
"read subscribeId failed");
COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read mode failed");
COMM_CHECK_AND_RETURN_RET_LOGE(value == DISCOVER_MODE_PASSIVE || value == DISCOVER_MODE_ACTIVE,
SOFTBUS_INVALID_PARAM, COMM_SVC, "mode invalid");
info.mode = static_cast<DiscoverMode>(value);
COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read medium failed");
COMM_CHECK_AND_RETURN_RET_LOGE(0 <= value && value < MEDIUM_BUTT, SOFTBUS_INVALID_PARAM, COMM_SVC,
"medium invalid");
info.medium = static_cast<ExchangeMedium>(value);
COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read freq failed");
COMM_CHECK_AND_RETURN_RET_LOGE(0 <= value && value < FREQ_BUTT, SOFTBUS_INVALID_PARAM, COMM_SVC, "freq invalid");
info.freq = static_cast<ExchangeFreq>(value);
COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadBool(info.isSameAccount), SOFTBUS_IPC_ERR, COMM_SVC,
"read isSameAccount failed");
COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadBool(info.isWakeRemote), SOFTBUS_IPC_ERR, COMM_SVC,
"read isWakeRemote failed");
info.capability = data.ReadCString();
COMM_CHECK_AND_RETURN_RET_LOGE(info.capability != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read capability failed");
COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadUint32(info.dataLen), SOFTBUS_IPC_ERR, COMM_SVC, "read dataLen failed");
if (info.dataLen > 0 && info.dataLen < MAX_CAPABILITYDATA_LEN) {
const char *capabilityData = data.ReadCString();
COMM_CHECK_AND_RETURN_RET_LOGE(capabilityData != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read capaData failed");
COMM_CHECK_AND_RETURN_RET_LOGE(strlen(capabilityData) == info.dataLen, SOFTBUS_INVALID_PARAM, COMM_SVC,
"capabilityData invalid");
info.capabilityData = const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(capabilityData));
} else {
info.capabilityData = nullptr;
info.dataLen = 0;
}
int32_t retReply = StartDiscovery(pkgName, &info);
COMM_CHECK_AND_RETURN_RET_LOGE(reply.WriteInt32(retReply), SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
return SOFTBUS_OK;
}
int32_t SoftBusServerStub::StopDiscoveryInner(MessageParcel &data, MessageParcel &reply)
{
const char *pkgName = data.ReadCString();
COMM_CHECK_AND_RETURN_RET_LOGE(pkgName != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read pkgName failed");
COMM_CHECK_AND_RETURN_RET_LOGE(strnlen(pkgName, PKG_NAME_SIZE_MAX) < PKG_NAME_SIZE_MAX, SOFTBUS_INVALID_PKGNAME,
COMM_SVC, "pkgName invalid");
SoftbusRecordCalledApiInfo(pkgName, SERVER_STOP_DISCOVERY);
int32_t subscribeId = 0;
COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(subscribeId), SOFTBUS_IPC_ERR, COMM_SVC, "read subscribeId failed");
int32_t retReply = StopDiscovery(pkgName, subscribeId);
COMM_CHECK_AND_RETURN_RET_LOGE(reply.WriteInt32(retReply), SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
return SOFTBUS_OK;
}
int32_t SoftBusServerStub::PublishServiceInner(MessageParcel &data, MessageParcel &reply)
{
const char *pkgName = data.ReadCString();
COMM_CHECK_AND_RETURN_RET_LOGE(pkgName != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read pkgName failed");
COMM_CHECK_AND_RETURN_RET_LOGE(strnlen(pkgName, PKG_NAME_SIZE_MAX) < PKG_NAME_SIZE_MAX, SOFTBUS_INVALID_PKGNAME,
COMM_SVC, "pkgName invalid");
SoftbusRecordCalledApiInfo(pkgName, SERVER_PUBLISH_SERVICE);
PublishInfo info = {0};
int32_t value = 0;
COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(info.publishId), SOFTBUS_IPC_ERR, COMM_SVC,
"read publishId failed");
COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read mode failed");
COMM_CHECK_AND_RETURN_RET_LOGE(value == DISCOVER_MODE_PASSIVE || value == DISCOVER_MODE_ACTIVE,
SOFTBUS_INVALID_PARAM, COMM_SVC, "mode invalid");
info.mode = static_cast<DiscoverMode>(value);
COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read medium failed");
COMM_CHECK_AND_RETURN_RET_LOGE(0 <= value && value < MEDIUM_BUTT, SOFTBUS_INVALID_PARAM, COMM_SVC,
"medium invalid");
info.medium = static_cast<ExchangeMedium>(value);
COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read freq failed");
COMM_CHECK_AND_RETURN_RET_LOGE(0 <= value && value < FREQ_BUTT, SOFTBUS_INVALID_PARAM, COMM_SVC, "freq invalid");
info.freq = static_cast<ExchangeFreq>(value);
info.capability = data.ReadCString();
COMM_CHECK_AND_RETURN_RET_LOGE(info.capability != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read capability failed");
COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadUint32(info.dataLen), SOFTBUS_IPC_ERR, COMM_SVC, "read dataLen failed");
if (info.dataLen > 0 && info.dataLen < MAX_CAPABILITYDATA_LEN) {
const char *capabilityData = data.ReadCString();
COMM_CHECK_AND_RETURN_RET_LOGE(capabilityData != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read capaData failed");
COMM_CHECK_AND_RETURN_RET_LOGE(strlen(capabilityData) == info.dataLen, SOFTBUS_INVALID_PARAM, COMM_SVC,
"capabilityData invalid");
info.capabilityData = const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(capabilityData));
} else {
info.capabilityData = nullptr;
info.dataLen = 0;
}
int32_t retReply = PublishService(pkgName, &info);
COMM_CHECK_AND_RETURN_RET_LOGE(reply.WriteInt32(retReply), SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
return SOFTBUS_OK;
}
int32_t SoftBusServerStub::UnpublishServiceInner(MessageParcel &data, MessageParcel &reply)
{
const char *pkgName = data.ReadCString();
COMM_CHECK_AND_RETURN_RET_LOGE(pkgName != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read pkgName failed");
COMM_CHECK_AND_RETURN_RET_LOGE(strnlen(pkgName, PKG_NAME_SIZE_MAX) < PKG_NAME_SIZE_MAX, SOFTBUS_INVALID_PKGNAME,
COMM_SVC, "pkgName invalid");
SoftbusRecordCalledApiInfo(pkgName, SERVER_UNPUBLISH_SERVICE);
int32_t publishId = 0;
COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(publishId), SOFTBUS_IPC_ERR, COMM_SVC, "read publishId failed");
int32_t retReply = UnPublishService(pkgName, publishId);
COMM_CHECK_AND_RETURN_RET_LOGE(reply.WriteInt32(retReply), SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
return SOFTBUS_OK;
}
int32_t SoftBusServerStub::SoftbusRegisterServiceInner(MessageParcel &data, MessageParcel &reply)
{
COMM_LOGD(COMM_SVC, "enter");

View File

@ -25,11 +25,6 @@ public:
: IRemoteProxy<ISoftBusClient>(impl) {}
virtual ~TransClientProxy() = default;
void OnDeviceFound(const DeviceInfo *device) override;
void OnDiscoverFailed(int subscribeId, int failReason) override;
void OnDiscoverySuccess(int subscribeId) override;
void OnPublishSuccess(int publishId) override;
void OnPublishFail(int publishId, int reason) override;
int32_t OnChannelOpened(const char *sessionName, const ChannelInfo *channel) override;
int32_t OnChannelBind(int32_t channelId, int32_t channelType) override;
int32_t OnChannelOpenFailed(int32_t channelId, int32_t channelType, int32_t errCode) override;

View File

@ -376,33 +376,6 @@ int32_t TransClientProxy::SetChannelInfo(
return serverRet;
}
void TransClientProxy::OnDeviceFound(const DeviceInfo *device)
{
(void)device;
}
void TransClientProxy::OnDiscoverFailed(int subscribeId, int failReason)
{
(void)subscribeId;
(void)failReason;
}
void TransClientProxy::OnDiscoverySuccess(int subscribeId)
{
(void)subscribeId;
}
void TransClientProxy::OnPublishSuccess(int publishId)
{
(void)publishId;
}
void TransClientProxy::OnPublishFail(int publishId, int reason)
{
(void)publishId;
(void)reason;
}
int32_t TransClientProxy::OnJoinLNNResult(void *addr, uint32_t addrTypeLen, const char *networkId, int retCode)
{
(void)addr;

View File

@ -1,186 +0,0 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @addtogroup SoftBus
* @{
*
* @brief Provides high-speed, secure communication between devices.
*
* This module implements unified distributed communication capability management between nearby devices, and provides
* link-independent device discovery and transmission interfaces to support service publishing and data transmission.
*
* @since 1.0
* @version 1.0
*/
/** @} */
/**
* @file discovery_service.h
*
* @brief Declares functions and constants for the discovery service of the Intelligent Soft Bus.
*
* The functions are used to perform
* the following operations: \n
* <ul>
* <li>Publishing service and stop publishing service functions</li>
* <li>Start the discovery function and stop the discover function</li>
*
* @since 1.0
* @version 1.0
*/
#ifndef DISCOVERY_SERVICE_H
#define DISCOVERY_SERVICE_H
#include "softbus_common.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
/**
* @brief Indicates the maximum length of the device address in <b>IDiscoveryCallback</b>.
*
*/
#define CONNECT_ADDR_LEN 46
/**
* @brief Enumerates error codes for service publishing failures.
*
* The error codes are returned to the caller through <b>IPublishCallback</b>.
*
*/
typedef enum {
/* Unsupported medium */
PUBLISH_FAIL_REASON_NOT_SUPPORT_MEDIUM = 1,
/* internal error */
PUBLISH_FAIL_REASON_INTERNAL = 2,
/* Unknown reason */
PUBLISH_FAIL_REASON_UNKNOWN = 0xFF
} PublishFailReason;
/**
* @brief Defines the callbacks for successful and failed service publishing.
*
*/
typedef struct {
/** Callback for successful publishing */
void (*OnPublishSuccess)(int publishId);
/** Callback for failed publishing */
void (*OnPublishFail)(int publishId, PublishFailReason reason);
} IPublishCallback;
/**
* @brief Enumerates error codes for service subscription failures.
*
* The error codes are returned to the caller through <b>IDiscoveryCallback</b>.
*
*/
typedef enum {
/* Unsupported medium */
DISCOVERY_FAIL_REASON_NOT_SUPPORT_MEDIUM = 1,
/* internal error */
DISCOVERY_FAIL_REASON_INTERNAL = 2,
/* Unknown error */
DISCOVERY_FAIL_REASON_UNKNOWN = 0xFF
} DiscoveryFailReason;
/**
* @brief Defines a callback for service subscription.
*
* Three types of callbacks are available.
*
*/
typedef struct {
/** Callback that is invoked when a device is found */
void (*OnDeviceFound)(const DeviceInfo *device);
/** Callback for a subscription failure */
void (*OnDiscoverFailed)(int subscribeId, DiscoveryFailReason failReason);
/** Callback for a subscription success */
void (*OnDiscoverySuccess)(int subscribeId);
} IDiscoveryCallback;
/**
* @brief Publishing service, the discovered end publishes its own information,
* which can be discovered by other devices.
* Peer devices in the same LAN as the device that publishes this service can discover this service as needed.
* The service is identified by <b>publicId</b> and <b>pkgName</b>.
* @see {@link UnPublishService}
* @param[in] pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes.
* @param[in] info Indicates the pointer to the service publishing information.
* For details, see {@link PublishInfo}.
* @param[in] cb Indicates the pointer to the service publishing callback.
* For details, see {@link IPublishCallback}.
* @return <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null or invalid.
* @return <b>SOFTBUS_DISCOVER_NOT_INIT</b> if the Intelligent SoftBus client fails to be initialized.
* @return <b>SOFTBUS_LOCK_ERR</b> if the mutex fails to be locked.
* @return <b>SOFTBUS_OK</b> if the service is successfully published.
* @deprecated Please use PublishLNN instead, for details, see {@link PublishLNN}.
*/
int PublishService(const char *pkgName, const PublishInfo *info, const IPublishCallback *cb);
/**
* @brief Stop publishing service functions, stop publishing its own capability information,
* and other devices cannot find it.
* @see {@link PublishService}
* @param[in] pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes.
* @param[in] publishId Indicates the service ID.
* @return <b>SOFTBUS_INVALID_PARAM</b> if <b>pkgName</b> is invalid.
* @return <b>SOFTBUS_DISCOVER_NOT_INIT</b> if the Intelligent SoftBus client fails to be initialized.
* @return <b>SOFTBUS_OK</b> if the service is successfully unpublished.
* @deprecated Please use StopPublishLNN instead, for details, see {@link StopPublishLNN}.
*/
int UnPublishService(const char *pkgName, int publishId);
/**
* @brief Start the discovery function, the discovered end begins to discover other devices
* and obtains the information of the remote device.
* Information about the device that publishes the service will be reported to the device that subscribes to
* the service. The service is identified by <b>subscribeId</b> and <b>pkgName</b>.
* @see {@link StopDiscovery}
* @param[in] pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes.
* @param[in] info Indicates the pointer to the service subscription information.
* For details, see {@link SubscribeInfo}.
* @param[in] cb Indicates the service subscription callback. For details, see {@link IDiscoveryCallback}.
* @return <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null or invalid.
* @return <b>SOFTBUS_DISCOVER_NOT_INIT</b> if the Intelligent SoftBus client fails to be initialized.
* @return <b>SOFTBUS_LOCK_ERR</b> if the mutex fails to be locked.
* @return <b>SOFTBUS_OK</b> if the service subscription is successful.
* @deprecated Please use RefreshLNN instead, for details, see {@link RefreshLNN}.
*/
int StartDiscovery(const char *pkgName, const SubscribeInfo *info, const IDiscoveryCallback *cb);
/**
* @brief Stop the discovery function, at this time no longer capture device information of other devices at this time.
* @see {@link StartDiscovery}
* @param[in] pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes.
* @param[in] subscribeId Indicates the service ID.
* @return <b>SOFTBUS_INVALID_PARAM</b> if <b>pkgName</b> is invalid.
* @return <b>SOFTBUS_DISCOVER_NOT_INIT</b> if the Intelligent SoftBus client fails to be initialized.
* @return <b>SOFTBUS_OK</b> if the service unsubscription is successful.
* @deprecated Please use StopRefreshLNN instead, for details, see {@link StopRefreshLNN}.
*/
int StopDiscovery(const char *pkgName, int subscribeId);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* DISCOVERY_SERVICE_H */

View File

@ -14,16 +14,15 @@
import("../core/common/dfx/dsoftbus_dfx.gni")
import("../dsoftbus.gni")
import("bus_center/bus_center_sdk.gni")
import("discovery/disc_sdk.gni")
import("frame/frame_sdk.gni")
import("transmission/trans_sdk.gni")
dsoftbus_root_path = ".."
common_client_src = bus_center_sdk_src + disc_sdk_src +
softbus_client_frame_src + trans_session_manager_sdk_src
common_client_inc = bus_center_sdk_inc + disc_sdk_inc +
softbus_client_frame_inc + trans_session_manager_sdk_inc
common_client_src = bus_center_sdk_src + softbus_client_frame_src +
trans_session_manager_sdk_src
common_client_inc = bus_center_sdk_inc + softbus_client_frame_inc +
trans_session_manager_sdk_inc
common_client_deps = bus_center_sdk_deps + trans_session_manager_sdk_deps
common_client_ext_deps = []

View File

@ -58,4 +58,4 @@ int32_t ServerIpcShiftLNNGear(const char *pkgName, const char *callerId, const c
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif // !DISC_SERVER_PROXY_H
#endif // BUS_CENTER_SERVER_PROXY_H

View File

@ -26,10 +26,6 @@ public:
: IRemoteProxy<ISoftBusServer>(impl) {}
virtual ~BusCenterServerProxy() = default;
int32_t StartDiscovery(const char *pkgName, const SubscribeInfo *info) override;
int32_t StopDiscovery(const char *pkgName, int subscribeId) override;
int32_t PublishService(const char *pkgName, const PublishInfo *info) override;
int32_t UnPublishService(const char *pkgName, int publishId) override;
int32_t SoftbusRegisterService(const char *clientPkgName, const sptr<IRemoteObject> &object) override;
int32_t CreateSessionServer(const char *pkgName, const char *sessionName) override;

View File

@ -17,7 +17,6 @@
#include <securec.h>
#include "bus_center_server_proxy.h"
#include "discovery_service.h"
#include "ipc_skeleton.h"
#include "iremote_broker.h"
#include "iremote_object.h"
@ -82,34 +81,6 @@ void BusCenterServerProxy::BusCenterServerProxyStandardDeInit(void)
g_remoteProxy.clear();
}
int32_t BusCenterServerProxy::StartDiscovery(const char *pkgName, const SubscribeInfo *subInfo)
{
(void)pkgName;
(void)subInfo;
return SOFTBUS_OK;
}
int32_t BusCenterServerProxy::StopDiscovery(const char *pkgName, int32_t subscribeId)
{
(void)pkgName;
(void)subscribeId;
return SOFTBUS_OK;
}
int32_t BusCenterServerProxy::PublishService(const char *pkgName, const PublishInfo *pubInfo)
{
(void)pkgName;
(void)pubInfo;
return SOFTBUS_OK;
}
int32_t BusCenterServerProxy::UnPublishService(const char *pkgName, int32_t publishId)
{
(void)pkgName;
(void)publishId;
return SOFTBUS_OK;
}
int32_t BusCenterServerProxy::SoftbusRegisterService(const char *clientPkgName, const sptr<IRemoteObject>& object)
{
(void)clientPkgName;

View File

@ -1,51 +0,0 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("../../dsoftbus.gni")
disc_sdk_src =
[ "$dsoftbus_root_path/sdk/discovery/service/src/client_disc_service.c" ]
disc_sdk_inc = [
"$dsoftbus_root_path/sdk/discovery/ipc/include",
"$dsoftbus_root_path/sdk/discovery/manager/include",
"$dsoftbus_root_path/sdk/discovery/service/include",
]
if (defined(ohos_lite)) {
disc_sdk_inc += [ "$dsoftbus_root_path/core/discovery/interface" ]
if (ohos_kernel_type == "liteos_m") {
import("../../core/discovery/disc.gni")
disc_sdk_src += [
"$dsoftbus_root_path/sdk/discovery/ipc/mini/disc_server_proxy.c",
"$dsoftbus_root_path/sdk/discovery/manager/src/client_disc_manager.c",
]
disc_sdk_inc += disc_server_inc
} else {
disc_sdk_src += [
"$dsoftbus_root_path/sdk/discovery/ipc/small/disc_server_proxy.c",
"$dsoftbus_root_path/sdk/discovery/manager/src/client_disc_manager.c",
]
}
} else {
disc_sdk_inc += [
"$dsoftbus_root_path/sdk/discovery/ipc/$os_type/include",
"$dsoftbus_root_path/core/frame/$os_type/init/include",
"$dsoftbus_root_path/core/transmission/common/include",
"$dsoftbus_root_path/interfaces/inner_kits/lnn",
"$dsoftbus_root_path/interfaces/kits/transport",
]
disc_sdk_src += [
"$dsoftbus_root_path/sdk/discovery/ipc/$os_type/src/disc_server_proxy.cpp",
"$dsoftbus_root_path/sdk/discovery/ipc/$os_type/src/disc_server_proxy_standard.cpp",
"$dsoftbus_root_path/sdk/discovery/manager/src/client_disc_manager.c",
]
}

View File

@ -1,78 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DISC_SERVER_PROXY_H
#include <stdint.h>
#include "discovery_service.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
int32_t DiscServerProxyInit(void);
void DiscServerProxyDeInit(void);
/**
* @brief The publishing service is started in the IPC communication,
* and the agent is called to start the publishing service.
* @see {@link ServerIpcUnPublishService}
* @param[in] pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes.
* @param[in] info Indicates the pointer to the service publishing information.
* For details, see {@link PublishInfo}.
* @return <b>SOFTBUS_OK</b> if the service ipc is successfully published.
*/
int32_t ServerIpcPublishService(const char *pkgName, const PublishInfo *info);
/**
* @brief Unpublish the service in the IPC communication, call the proxy to stop publishing the service.
* @see {@link ServerIpcPublishService}
* @param[in] pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes.
* @param[in] publishId Indicates the service ID.
* @return <b>SOFTBUS_OK</b> if the service ipc is successfully unpublished.
*/
int32_t ServerIpcUnPublishService(const char *pkgName, int32_t publishId);
/**
* @brief The active discovery service is started in the IPC communication,
* and the agent is called to start the active discovery service.
* @see {@link ServerIpcStopDiscovery}
* @param[in] pkgName Indicates the pointer to the subscribe package name,
* which can contain a maximum of 64 bytes.
* @param[in] info Indicates the pointer to the service publishing information.
* For details, see {@link SubscribeInfo}.
* @return <b>SOFTBUS_OK</b> if the service ipc is successfully start discovery.
*/
int32_t ServerIpcStartDiscovery(const char *pkgName, const SubscribeInfo *info);
/**
* @brief Stop the discovery service in IPC communication and call the agent to stop the discovery service.
* @see {@link ServerIpcStartDiscovery}
* @param[in] pkgName Indicates the pointer to the subscribe package name,
* which can contain a maximum of 64 bytes.
* @param[in] subscribeId Indicates the subscribe ID.
* @return <b>SOFTBUS_OK</b> if the service ipc is successfully stop discovery.
*/
int32_t ServerIpcStopDiscovery(const char *pkgName, int32_t subscribeId);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif // !DISC_SERVER_PROXY_H

View File

@ -1,50 +0,0 @@
/*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "disc_server_proxy.h"
#include "softbus_disc_server.h"
#include "softbus_errcode.h"
int32_t DiscServerProxyInit(void)
{
return SOFTBUS_OK;
}
void DiscServerProxyDeInit(void)
{
return;
}
int32_t ServerIpcPublishService(const char *pkgName, const PublishInfo *info)
{
return DiscIpcPublishService(pkgName, info);
}
int32_t ServerIpcUnPublishService(const char *pkgName, int32_t publishId)
{
return DiscIpcUnPublishService(pkgName, publishId);
}
int32_t ServerIpcStartDiscovery(const char *pkgName, const SubscribeInfo *info)
{
return DiscIpcStartDiscovery(pkgName, info);
}
int32_t ServerIpcStopDiscovery(const char *pkgName, int32_t subscribeId)
{
return DiscIpcStopDiscovery(pkgName, subscribeId);
}

View File

@ -1,235 +0,0 @@
/*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "disc_server_proxy.h"
#include "disc_log.h"
#include "disc_serializer.h"
#include "iproxy_client.h"
#include "samgr_lite.h"
#include "serializer.h"
#include "softbus_adapter_file.h"
#include "softbus_adapter_timer.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_server_ipc_interface_code.h"
#define WAIT_SERVER_READY_INTERVAL_COUNT 50
static IClientProxy *g_serverProxy = NULL;
int32_t DiscServerProxyInit(void)
{
if (g_serverProxy != NULL) {
DISC_LOGI(DISC_INIT, "server proxy has initialized.");
return SOFTBUS_OK;
}
DISC_LOGI(DISC_INIT, "disc start get server proxy");
int32_t proxyInitCount = 0;
while (g_serverProxy == NULL) {
proxyInitCount++;
if (proxyInitCount == WAIT_SERVER_READY_INTERVAL_COUNT) {
DISC_LOGE(DISC_INIT, "disc get server proxy error");
return SOFTBUS_DISC_SERVER_INIT_FAILED;
}
IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(SOFTBUS_SERVICE);
if (iUnknown == NULL) {
SoftBusSleepMs(WAIT_SERVER_READY_INTERVAL);
continue;
}
int32_t ret = iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&g_serverProxy);
if (ret != EC_SUCCESS || g_serverProxy == NULL) {
DISC_LOGE(DISC_INIT, "QueryInterface failed. ret=%{public}d", ret);
SoftBusSleepMs(WAIT_SERVER_READY_INTERVAL);
continue;
}
}
DISC_LOGI(DISC_INIT, "disc get server proxy ok");
return SOFTBUS_OK;
}
void DiscServerProxyDeInit(void)
{
g_serverProxy = NULL;
}
int ServerIpcPublishService(const char *pkgName, const PublishInfo *info)
{
DISC_LOGI(DISC_CONTROL, "publish service ipc client push.");
DISC_CHECK_AND_RETURN_RET_LOGE(pkgName != NULL && info != NULL, SOFTBUS_INVALID_PARAM, DISC_CONTROL,
"Invalid param");
DISC_CHECK_AND_RETURN_RET_LOGE(g_serverProxy != NULL, SOFTBUS_NO_INIT, DISC_CONTROL, "g_serverProxy is null");
uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
IpcIo request = {0};
IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
bool ret = WriteString(&request, pkgName);
if (!ret) {
DISC_LOGE(DISC_SDK, "Write pkgName failed");
return SOFTBUS_IPC_ERR;
}
DiscSerializer serializer = {
.dataLen = info->dataLen,
.freq = info->freq,
.medium = info->medium,
.mode = info->mode,
.id.publishId = info->publishId
};
PublishSerializer publishSerializer = {
.commonSerializer = serializer
};
ret = WriteRawData(&request, (void*)&publishSerializer, sizeof(PublishSerializer));
if (!ret) {
DISC_LOGE(DISC_SDK, "Write publish serializer failed");
return SOFTBUS_IPC_ERR;
}
ret = WriteString(&request, info->capability);
if (!ret) {
DISC_LOGE(DISC_SDK, "Write capability failed");
return SOFTBUS_IPC_ERR;
}
if (info->dataLen != 0) {
ret = WriteString(&request, (const char *)(info->capabilityData));
if (!ret) {
DISC_LOGE(DISC_SDK, "Write capability Data failed");
return SOFTBUS_IPC_ERR;
}
}
/* asynchronous invocation */
int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_PUBLISH_SERVICE, &request, NULL, NULL);
if (ans != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "publish service invoke failed. ans=%{public}d", ans);
return ans;
}
return SOFTBUS_OK;
}
int ServerIpcUnPublishService(const char *pkgName, int publishId)
{
DISC_LOGI(DISC_CONTROL, "unpublish service ipc client push.");
DISC_CHECK_AND_RETURN_RET_LOGE(pkgName != NULL, SOFTBUS_INVALID_PARAM, DISC_CONTROL,
"Invalid param");
DISC_CHECK_AND_RETURN_RET_LOGE(g_serverProxy != NULL, SOFTBUS_NO_INIT, DISC_CONTROL, "g_serverProxy is null");
uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
IpcIo request = {0};
IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
bool ret = WriteString(&request, pkgName);
if (!ret) {
DISC_LOGE(DISC_SDK, "Write pkgName failed");
return SOFTBUS_IPC_ERR;
}
ret = WriteInt32(&request, publishId);
if (!ret) {
DISC_LOGE(DISC_SDK, "Write publishId failed");
return SOFTBUS_IPC_ERR;
}
/* asynchronous invocation */
int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_UNPUBLISH_SERVICE, &request, NULL, NULL);
if (ans != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "unpublish service invoke failed. ans=%{public}d", ans);
return ans;
}
return SOFTBUS_OK;
}
int ServerIpcStartDiscovery(const char *pkgName, const SubscribeInfo *info)
{
DISC_LOGI(DISC_CONTROL, "start discovery ipc client push.");
DISC_CHECK_AND_RETURN_RET_LOGE(pkgName != NULL && info != NULL, SOFTBUS_INVALID_PARAM, DISC_CONTROL,
"Invalid param");
DISC_CHECK_AND_RETURN_RET_LOGE(g_serverProxy != NULL, SOFTBUS_NO_INIT, DISC_CONTROL, "g_serverProxy is null");
uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
IpcIo request = {0};
IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
bool ret = WriteString(&request, pkgName);
if (!ret) {
DISC_LOGE(DISC_SDK, "Write pkgName failed");
return SOFTBUS_IPC_ERR;
}
DiscSerializer serializer = {
.dataLen = info->dataLen,
.freq = info->freq,
.medium = info->medium,
.mode = info->mode,
.id.subscribeId = info->subscribeId
};
SubscribeSerializer subscribeSerializer = {
.commonSerializer = serializer,
.isSameAccount = info->isSameAccount,
.isWakeRemote = info->isWakeRemote
};
ret = WriteRawData(&request, (void*)&subscribeSerializer, sizeof(SubscribeSerializer));
if (!ret) {
DISC_LOGE(DISC_SDK, "Write SubscribeSerializer failed");
return SOFTBUS_IPC_ERR;
}
ret = WriteString(&request, info->capability);
if (!ret) {
DISC_LOGE(DISC_SDK, "Write capability failed");
return SOFTBUS_IPC_ERR;
}
if (info->dataLen != 0) {
ret = WriteString(&request, (const char *)(info->capabilityData));
if (!ret) {
DISC_LOGE(DISC_SDK, "Write capabilityData failed");
return SOFTBUS_IPC_ERR;
}
}
/* asynchronous invocation */
int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_START_DISCOVERY, &request, NULL, NULL);
if (ans != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "start discovery invoke failed. ans=%{public}d", ans);
return ans;
}
return SOFTBUS_OK;
}
int ServerIpcStopDiscovery(const char *pkgName, int subscribeId)
{
DISC_LOGI(DISC_SDK, "stop discovery ipc client push.");
DISC_CHECK_AND_RETURN_RET_LOGE(pkgName != NULL, SOFTBUS_INVALID_PARAM, DISC_CONTROL,
"Invalid param");
DISC_CHECK_AND_RETURN_RET_LOGE(g_serverProxy != NULL, SOFTBUS_NO_INIT, DISC_CONTROL, "g_serverProxy is null");
uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
IpcIo request = {0};
IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
bool ret = WriteString(&request, pkgName);
if (!ret) {
DISC_LOGE(DISC_SDK, "Write pkgName failed");
return SOFTBUS_IPC_ERR;
}
ret = WriteInt32(&request, subscribeId);
if (!ret) {
DISC_LOGE(DISC_SDK, "Write subscribeId failed");
return SOFTBUS_IPC_ERR;
}
/* asynchronous invocation */
int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_STOP_DISCOVERY, &request, NULL, NULL);
if (ans != SOFTBUS_OK) {
DISC_LOGE(DISC_CONTROL, "stop discovery invoke failed. ans=%{public}d", ans);
return ans;
}
return SOFTBUS_OK;
}

View File

@ -1,71 +0,0 @@
/*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef INTERFACES_INNERKITS_DISC_SERVER_PROXY_STANDARD_H_
#define INTERFACES_INNERKITS_DISC_SERVER_PROXY_STANDARD_H_
#include "if_softbus_server.h"
#include "softbus_common.h"
namespace OHOS {
class DiscServerProxy : public IRemoteProxy<ISoftBusServer> {
public:
explicit DiscServerProxy(const sptr<IRemoteObject> &impl)
: IRemoteProxy<ISoftBusServer>(impl) {}
virtual ~DiscServerProxy() = default;
int32_t StartDiscovery(const char *pkgName, const SubscribeInfo *info) override;
int32_t StopDiscovery(const char *pkgName, int subscribeId) override;
int32_t PublishService(const char *pkgName, const PublishInfo *info) override;
int32_t UnPublishService(const char *pkgName, int publishId) override;
int32_t SoftbusRegisterService(const char *clientPkgName, const sptr<IRemoteObject> &object) override;
int32_t CreateSessionServer(const char *pkgName, const char *sessionName) override;
int32_t RemoveSessionServer(const char *pkgName, const char *sessionName) override;
int32_t OpenSession(const SessionParam *param, TransInfo *info) override;
int32_t NotifyAuthSuccess(int32_t channelId, int32_t channelType) override;
int32_t OpenAuthSession(const char *sessionName, const ConnectionAddr *addrInfo) override;
int32_t ReleaseResources(int32_t channelId) override;
int32_t CloseChannel(const char *sessionName, int32_t channelId, int32_t channelType) override;
int32_t CloseChannelWithStatistics(int32_t channelId, uint64_t laneId, const void *dataInfo,
uint32_t len) override;
int32_t SendMessage(int32_t channelId, int32_t channelType, const void *data,
uint32_t len, int32_t msgType) override;
int32_t JoinLNN(const char *pkgName, void *addr, uint32_t addrTypeLen) override;
int32_t LeaveLNN(const char *pkgName, const char *networkId) override;
int32_t GetAllOnlineNodeInfo(const char *pkgName, void **info, uint32_t infoTypeLen, int *infoNum) override;
int32_t GetLocalDeviceInfo(const char *pkgName, void *info, uint32_t infoTypeLen) override;
int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, int key, unsigned char *buf,
uint32_t len) override;
int32_t SetNodeDataChangeFlag(const char *pkgName, const char *networkId, uint16_t dataChangeFlag) override;
int32_t RegDataLevelChangeCb(const char *pkgName) override;
int32_t UnregDataLevelChangeCb(const char *pkgName) override;
int32_t SetDataLevel(const DataLevel *dataLevel) override;
int32_t StartTimeSync(const char *pkgName, const char *targetNetworkId, int32_t accuracy,
int32_t period) override;
int32_t StopTimeSync(const char *pkgName, const char *targetNetworkId) override;
int32_t QosReport(int32_t channelId, int32_t chanType, int32_t appType, int32_t quality) override;
int32_t StreamStats(int32_t channelId, int32_t channelType, const StreamSendStats *data) override;
int32_t RippleStats(int32_t channelId, int32_t channelType, const TrafficStats *data) override;
int32_t EvaluateQos(const char *peerNetworkId, TransDataType dataType, const QosTV *qos,
uint32_t qosCount) override;
private:
static inline BrokerDelegator<DiscServerProxy> delegator_;
};
} // namespace OHOS
#endif // !defined(INTERFACES_INNERKITS_DISC_SERVER_PROXY_STANDARD_H_)

View File

@ -1,126 +0,0 @@
/*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "disc_server_proxy.h"
#include "disc_server_proxy_standard.h"
#include <mutex>
#include "disc_log.h"
#include "ipc_skeleton.h"
#include "iremote_broker.h"
#include "iremote_object.h"
#include "iremote_proxy.h"
#include "softbus_errcode.h"
#include "softbus_server_ipc_interface_code.h"
using namespace OHOS;
namespace {
sptr<DiscServerProxy> g_serverProxy = nullptr;
const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken";
uint32_t g_getSystemAbilityId = 2;
std::mutex g_mutex;
}
static sptr<IRemoteObject> GetSystemAbility()
{
MessageParcel data;
if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) {
DISC_LOGE(DISC_SDK, "Write INTERFACE_TOKEN failed!");
return nullptr;
}
if (!data.WriteInt32(SOFTBUS_SERVER_SA_ID_INNER)) {
DISC_LOGE(DISC_SDK, "Write SERVER_SA_ID_INNER failed!");
return nullptr;
}
MessageParcel reply;
MessageOption option;
sptr<IRemoteObject> samgr = IPCSkeleton::GetContextObject();
if (samgr == nullptr) {
DISC_LOGE(DISC_SDK, "Get samgr failed!");
return nullptr;
}
int32_t err = samgr->SendRequest(g_getSystemAbilityId, data, reply, option);
if (err != 0) {
DISC_LOGE(DISC_SDK, "Get GetSystemAbility failed!");
return nullptr;
}
return reply.ReadRemoteObject();
}
int32_t DiscServerProxyInit(void)
{
std::lock_guard<std::mutex> lock(g_mutex);
if (g_serverProxy != nullptr) {
DISC_LOGI(DISC_INIT, "Init success");
return SOFTBUS_OK;
}
sptr<IRemoteObject> object = GetSystemAbility();
if (object == nullptr) {
DISC_LOGE(DISC_INIT, "Get remote softbus object failed!");
return SOFTBUS_DISCOVER_GET_REMOTE_FAILED;
}
g_serverProxy = new (std::nothrow) DiscServerProxy(object);
if (g_serverProxy == nullptr) {
DISC_LOGE(DISC_INIT, "Create disc server proxy failed!");
return SOFTBUS_NO_INIT;
}
return SOFTBUS_OK;
}
void DiscServerProxyDeInit(void)
{
DISC_LOGI(DISC_INIT, "enter");
g_serverProxy.clear();
}
int32_t ServerIpcPublishService(const char *pkgName, const PublishInfo *info)
{
if (g_serverProxy == nullptr) {
DISC_LOGE(DISC_SDK, "softbus server g_serverProxy is nullptr!");
return SOFTBUS_NO_INIT;
}
return g_serverProxy->PublishService(pkgName, info);
}
int32_t ServerIpcUnPublishService(const char *pkgName, int32_t publishId)
{
if (g_serverProxy == nullptr) {
DISC_LOGE(DISC_SDK, "softbus server g_serverProxy is nullptr!");
return SOFTBUS_NO_INIT;
}
int ret = g_serverProxy->UnPublishService(pkgName, publishId);
return ret;
}
int32_t ServerIpcStartDiscovery(const char *pkgName, const SubscribeInfo *info)
{
if (g_serverProxy == nullptr) {
DISC_LOGE(DISC_SDK, "softbus server g_serverProxy is nullptr!");
return SOFTBUS_NO_INIT;
}
return g_serverProxy->StartDiscovery(pkgName, info);
}
int32_t ServerIpcStopDiscovery(const char *pkgName, int32_t subscribeId)
{
if (g_serverProxy == nullptr) {
DISC_LOGE(DISC_SDK, "softbus server g_serverProxy is nullptr!");
return SOFTBUS_NO_INIT;
}
return g_serverProxy->StopDiscovery(pkgName, subscribeId);
}

View File

@ -1,406 +0,0 @@
/*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "disc_server_proxy_standard.h"
#include "ipc_skeleton.h"
#include "disc_log.h"
#include "discovery_service.h"
#include "message_parcel.h"
#include "softbus_errcode.h"
#include "softbus_server_ipc_interface_code.h"
namespace OHOS {
static uint32_t g_getSystemAbilityId = 2;
const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken";
static sptr<IRemoteObject> GetSystemAbility()
{
MessageParcel data;
if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) {
DISC_LOGE(DISC_SDK, "Write Interface token failed!");
return nullptr;
}
if (!data.WriteInt32(SOFTBUS_SERVER_SA_ID_INNER)) {
DISC_LOGE(DISC_SDK, "Write inner failed!");
return nullptr;
}
MessageParcel reply;
MessageOption option;
sptr<IRemoteObject> samgr = IPCSkeleton::GetContextObject();
if (samgr == nullptr) {
DISC_LOGE(DISC_SDK, "Get samgr failed!");
return nullptr;
}
int32_t err = samgr->SendRequest(g_getSystemAbilityId, data, reply, option);
if (err != 0) {
DISC_LOGE(DISC_SDK, "Get SystemAbility failed!");
return nullptr;
}
return reply.ReadRemoteObject();
}
int32_t DiscServerProxy::StartDiscovery(const char *pkgName, const SubscribeInfo *subInfo)
{
sptr<IRemoteObject> remote = GetSystemAbility();
DISC_CHECK_AND_RETURN_RET_LOGE(remote != nullptr, SOFTBUS_DISCOVER_GET_REMOTE_FAILED, DISC_ABILITY,
"remote is nullptr!");
MessageParcel data;
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteInterfaceToken(GetDescriptor()), SOFTBUS_IPC_ERR, DISC_SDK,
"StartDiscovery faceToken failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteCString(pkgName), SOFTBUS_IPC_ERR, DISC_SDK,
"StartDiscovery pkgName failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteInt32(subInfo->subscribeId), SOFTBUS_IPC_ERR, DISC_SDK,
"StartDiscovery subInfo subscribeId failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteInt32(subInfo->mode), SOFTBUS_IPC_ERR, DISC_SDK,
"StartDiscovery subInfo mode failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteInt32(subInfo->medium), SOFTBUS_IPC_ERR, DISC_SDK,
"StartDiscovery subInfo medium failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteInt32(subInfo->freq), SOFTBUS_IPC_ERR, DISC_SDK,
"StartDiscovery subInfo freq failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteBool(subInfo->isSameAccount), SOFTBUS_IPC_ERR, DISC_SDK,
"StartDiscovery subInfo isSameAccount failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteBool(subInfo->isWakeRemote), SOFTBUS_IPC_ERR, DISC_SDK,
"StartDiscovery subInfo isWakeRemote failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteCString(subInfo->capability), SOFTBUS_IPC_ERR, DISC_SDK,
"StartDiscovery subInfo capability failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteUint32(subInfo->dataLen), SOFTBUS_IPC_ERR, DISC_SDK,
"StartDiscovery subInfo dataLen failed!");
if (subInfo->dataLen != 0) {
data.WriteCString((char *)subInfo->capabilityData);
}
MessageParcel reply;
MessageOption option;
int32_t err = remote->SendRequest(SERVER_START_DISCOVERY, data, reply, option);
if (err != 0) {
DISC_LOGE(DISC_SDK, "StartDiscovery send request failed!");
return err;
}
int32_t serverRet = 0;
int32_t ret = reply.ReadInt32(serverRet);
if (!ret) {
DISC_LOGE(DISC_SDK, "StartDiscovery read serverRet failed!");
return SOFTBUS_IPC_ERR;
}
return serverRet;
}
int32_t DiscServerProxy::StopDiscovery(const char *pkgName, int subscribeId)
{
sptr<IRemoteObject> remote = GetSystemAbility();
DISC_CHECK_AND_RETURN_RET_LOGE(remote != nullptr, SOFTBUS_DISCOVER_GET_REMOTE_FAILED, DISC_ABILITY,
"remote is nullptr!");
MessageParcel data;
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteInterfaceToken(GetDescriptor()), SOFTBUS_IPC_ERR, DISC_SDK,
"StopDiscovery failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteCString(pkgName), SOFTBUS_IPC_ERR, DISC_SDK,
"StopDiscovery pkgName failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteInt32(subscribeId), SOFTBUS_IPC_ERR, DISC_SDK,
"StopDiscovery subscribeId failed!");
MessageParcel reply;
MessageOption option;
int32_t err = remote->SendRequest(SERVER_STOP_DISCOVERY, data, reply, option);
DISC_LOGI(DISC_ABILITY, "StopDiscovery send request ret=%{public}d!", err);
if (err != 0) {
DISC_LOGE(DISC_SDK, "StopDiscovery send request failed!");
return err;
}
int32_t serverRet = 0;
int32_t ret = reply.ReadInt32(serverRet);
if (!ret) {
DISC_LOGE(DISC_SDK, "StopDiscovery read serverRet failed!");
return SOFTBUS_IPC_ERR;
}
return serverRet;
}
int32_t DiscServerProxy::PublishService(const char *pkgName, const PublishInfo *pubInfo)
{
sptr<IRemoteObject> remote = GetSystemAbility();
DISC_CHECK_AND_RETURN_RET_LOGE(remote != nullptr, SOFTBUS_DISCOVER_GET_REMOTE_FAILED, DISC_ABILITY,
"remote is nullptr!");
MessageParcel data;
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteInterfaceToken(GetDescriptor()), SOFTBUS_IPC_ERR, DISC_SDK,
"PublishService write InterfaceToken failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteCString(pkgName), SOFTBUS_IPC_ERR, DISC_SDK,
"PublishService write pkgName failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteInt32(pubInfo->publishId), SOFTBUS_IPC_ERR, DISC_SDK,
"PublishService write publishId failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteInt32(pubInfo->mode), SOFTBUS_IPC_ERR, DISC_SDK,
"PublishService write mode failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteInt32(pubInfo->medium), SOFTBUS_IPC_ERR, DISC_SDK,
"PublishService write medium failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteInt32(pubInfo->freq), SOFTBUS_IPC_ERR, DISC_SDK,
"PublishService write freq failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteCString(pubInfo->capability), SOFTBUS_IPC_ERR, DISC_SDK,
"PublishService write capability failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteUint32(pubInfo->dataLen), SOFTBUS_IPC_ERR, DISC_SDK,
"PublishService write dataLen failed!");
if (pubInfo->dataLen != 0) {
data.WriteCString((char *)pubInfo->capabilityData);
}
MessageParcel reply;
MessageOption option;
int32_t err = remote->SendRequest(SERVER_PUBLISH_SERVICE, data, reply, option);
DISC_LOGI(DISC_ABILITY, "PublishService send request ret=%{public}d!", err);
if (err != 0) {
DISC_LOGE(DISC_SDK, "PublishService send request failed!");
return err;
}
int32_t serverRet = 0;
int32_t ret = reply.ReadInt32(serverRet);
if (!ret) {
DISC_LOGE(DISC_SDK, "PublishService read serverRet failed!");
return SOFTBUS_IPC_ERR;
}
return serverRet;
}
int32_t DiscServerProxy::UnPublishService(const char *pkgName, int publishId)
{
sptr<IRemoteObject> remote = GetSystemAbility();
DISC_CHECK_AND_RETURN_RET_LOGE(remote != nullptr, SOFTBUS_DISCOVER_GET_REMOTE_FAILED, DISC_ABILITY,
"remote is nullptr!");
MessageParcel data;
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteInterfaceToken(GetDescriptor()), SOFTBUS_IPC_ERR, DISC_SDK,
"UnPublishService failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteCString(pkgName), SOFTBUS_IPC_ERR, DISC_SDK,
"UnPublishService pkgName failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(data.WriteInt32(publishId), SOFTBUS_IPC_ERR, DISC_SDK,
"UnPublishService publishId failed!");
MessageParcel reply;
MessageOption option;
int32_t err = remote->SendRequest(SERVER_UNPUBLISH_SERVICE, data, reply, option);
DISC_LOGI(DISC_ABILITY, "UnPublishService send request ret=%{public}d!", err);
if (err != 0) {
DISC_LOGE(DISC_SDK, "UnPublishService send request failed!");
return err;
}
int32_t serverRet = 0;
int32_t ret = reply.ReadInt32(serverRet);
if (!ret) {
DISC_LOGE(DISC_SDK, "UnPublishService read serverRet failed!");
return SOFTBUS_IPC_ERR;
}
return serverRet;
}
int32_t DiscServerProxy::SoftbusRegisterService(const char *clientPkgName, const sptr<IRemoteObject>& object)
{
(void)clientPkgName;
(void)object;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::CreateSessionServer(const char *pkgName, const char *sessionName)
{
(void)pkgName;
(void)sessionName;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::RemoveSessionServer(const char *pkgName, const char *sessionName)
{
(void)pkgName;
(void)sessionName;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::OpenSession(const SessionParam *param, TransInfo *info)
{
(void)param;
(void)info;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::OpenAuthSession(const char *sessionName, const ConnectionAddr *addrInfo)
{
(void)sessionName;
(void)addrInfo;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::NotifyAuthSuccess(int32_t channelId, int32_t channelType)
{
(void)channelId;
(void)channelType;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::ReleaseResources(int32_t channelId)
{
(void)channelId;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::CloseChannel(const char *sessionName, int32_t channelId, int32_t channelType)
{
(void)sessionName;
(void)channelId;
(void)channelType;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::CloseChannelWithStatistics(int32_t channelId, uint64_t laneId, const void *dataInfo,
uint32_t len)
{
(void)channelId;
(void)laneId;
(void)dataInfo;
(void)len;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::SendMessage(int32_t channelId, int32_t channelType, const void *data,
uint32_t len, int32_t msgType)
{
(void)channelId;
(void)channelType;
(void)data;
(void)len;
(void)msgType;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::JoinLNN(const char *pkgName, void *addr, uint32_t addrTypeLen)
{
(void)pkgName;
(void)addr;
(void)addrTypeLen;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::LeaveLNN(const char *pkgName, const char *networkId)
{
(void)pkgName;
(void)networkId;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::GetAllOnlineNodeInfo(const char *pkgName, void **info, uint32_t infoTypeLen, int *infoNum)
{
(void)pkgName;
(void)info;
(void)infoTypeLen;
(void)infoNum;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::GetLocalDeviceInfo(const char *pkgName, void *info, uint32_t infoTypeLen)
{
(void)pkgName;
(void)info;
(void)infoTypeLen;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::GetNodeKeyInfo(const char *pkgName, const char *networkId, int key, unsigned char *buf,
uint32_t len)
{
(void)pkgName;
(void)networkId;
(void)key;
(void)buf;
(void)len;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::SetNodeDataChangeFlag(const char *pkgName, const char *networkId, uint16_t dataChangeFlag)
{
(void)pkgName;
(void)networkId;
(void)dataChangeFlag;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::RegDataLevelChangeCb(const char *pkgName)
{
(void)pkgName;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::UnregDataLevelChangeCb(const char *pkgName)
{
(void)pkgName;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::SetDataLevel(const DataLevel *dataLevel)
{
(void)dataLevel;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::StartTimeSync(const char *pkgName, const char *targetNetworkId, int32_t accuracy,
int32_t period)
{
(void)pkgName;
(void)targetNetworkId;
(void)accuracy;
(void)period;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::StopTimeSync(const char *pkgName, const char *targetNetworkId)
{
(void)pkgName;
(void)targetNetworkId;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::QosReport(int32_t channelId, int32_t chanType, int32_t appType, int32_t quality)
{
(void)channelId;
(void)chanType;
(void)appType;
(void)quality;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::StreamStats(int32_t channelId, int32_t channelType, const StreamSendStats *data)
{
(void)channelId;
(void)channelType;
(void)data;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::RippleStats(int32_t channelId, int32_t channelType, const TrafficStats *data)
{
(void)channelId;
(void)channelType;
(void)data;
return SOFTBUS_OK;
}
int32_t DiscServerProxy::EvaluateQos(const char *peerNetworkId, TransDataType dataType, const QosTV *qos,
uint32_t qosCount)
{
(void)peerNetworkId;
(void)dataType;
(void)qos;
(void)qosCount;
return SOFTBUS_OK;
}
} // namespace OHOS

View File

@ -1,145 +0,0 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOFTBUS_CLIENT_DISC_MANAGER_H
#define SOFTBUS_CLIENT_DISC_MANAGER_H
#include "discovery_service.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Client initialization. Configure the storage information environment,
* this interface is only called once when the softbus service is created.
* @see {@link DiscClientDeinit}
* @return <b>SOFTBUS_MALLOC_ERR</b> Failed to allocate space for global variable of discovery information.
* @return <b>SOFTBUS_DISC_SERVER_INIT_FAILED</b> Failed to initialize the server agent on the discovery side.
* @return <b>SOFTBUS_OK</b> The discoverer client was initialized successfully.
*/
int32_t DiscClientInit(void);
/**
* @brief The client deinitializes, releasing the stored information.
* This interface is only called once when the softbus service is destroyed.
* @see {@link DiscClientInit}
*/
void DiscClientDeinit(void);
/**
* @brief Internal publishing service. Publish its own capability information to other devices,
* and other devices can capture this information to establish connections.
* @see {@link UnPublishServiceInner}
* @param[in] packageName Indicates the pointer to the package name,
* and the name of the relevant package carrying its own capabilities.
* @param[in] info Indicates the pointer to the published information,
* which is used to publish the information body of its own information. For details, see {@link PublishInfo}.
* @param[in] cb Indicates the pointer to the callback of the publishing function,
* which is used to notify itself whether the publishing of its
* own information is successful after the publishing function is triggered. For details, see {@link IPublishCallback}.
* @return <b>SOFTBUS_NO_INIT</b> Failed to publish internal information function.
* @return <b>SOFTBUS_OK</b> The function of internal publishing self information was published successfully.
*/
int32_t PublishServiceInner(const char *packageName, const PublishInfo *info, const IPublishCallback *cb);
/**
* @brief Internal unpublish service. Stop publishing its own information,
* and external devices cannot capture this device's capability information.
* @see {@link PublishServiceInner}
* @param[in] packageName Indicates the pointer to the package name,
* and the name of the relevant package carrying its own capabilities.
* @param[in] publishId ID of the internal release information to be cancelled this time.
* @return <b>SOFTBUS_NO_INIT</b> Internal unpublishing function failed. Other devices can still find the device.
* @return <b>SOFTBUS_OK</b> The internal unpublishing function is successful,
* and the party cannot publish its own information.
*/
int32_t UnpublishServiceInner(const char *packageName, int32_t publishId);
/**
* @brief Internal discovery service. Other devices can be discovered.
* @see {@link StopDiscoveryInner}
* @param[in] packageName Indicates the pointer to the package name,
* and the name of the relevant package carrying its own capabilities.
* @param[in] info Indicates a pointer to published information used
* to discover the body of information for a specific capability. For more information, see {@link SubscribeInfo}.
* @param[in] cb Indicates the pointer to the discovery callback, It is used to inform yourself,
* Whether the discovery capability is successfully started after the discovery function is triggered.
* For more information, see {@link IDiscoveryCallback}.
* @return <b>SOFTBUS_NO_INIT</b> The internal start Discovery Function failed to start. No other devices can be found.
* @return <b>SOFTBUS_OK</b> The internal start discovery function is started successfully.
* You can discover specific capability devices.
*/
int32_t StartDiscoveryInner(const char *packageName, const SubscribeInfo *info, const IDiscoveryCallback *cb);
/**
* @brief Stop discovery service internally. Stop discovering other devices,
* after which other devices cannot be discovered.
* @see {@link StartDiscoveryInner}
* @param[in] packageName Indicates the pointer to the package name,
* and the name of the relevant package carrying its own capabilities.
* @param[in] subscribeId ID to stop discovery this time.
* @return <b>SOFTBUS_NO_INIT</b> The internal stop discovery function cannot be started.
* Other devices can still be found.
* @return <b>SOFTBUS_OK</b> Internal stop discovery function started successfully.
* You cannot discover devices with specific functions.
*/
int32_t StopDiscoveryInner(const char *packageName, int32_t subscribeId);
/**
* @brief The server discovers the local device and calls this callback.
* @see {@link DiscClientOnDiscoverySuccess} or {@link DiscClientOnDiscoverFailed}.
* @param[in] device Indicates a pointer to device information to record the devices on
* which the discovery client was discovered. For more information, see {@link DeviceInfo}.
*/
void DiscClientOnDeviceFound(const DeviceInfo *device);
/**
* @brief When the server subscribes to the local device successfully,
* this callback is called to notify the local device.
* @see {@link DiscClientOnDeviceFound} or {@link DiscClientOnDiscoverFailed}.
* @param[in] subscribeId The id of the subscription information used to record
* the successful discovery of the discovered peer.
*/
void DiscClientOnDiscoverySuccess(int32_t subscribeId);
/**
* @brief When the server fails to subscribe to the local device, this callback is called to notify the local device.
* @see {@link DiscClientOnDiscoverySuccess} or {@link DiscClientOnDeviceFound}.
* @param[in] subscribeId The id of the subscription information used to record the discovered peer discovery failure.
* @param[in] failReason reason of failure. For more information, see {@link DiscoveryFailReason}.
*/
void DiscClientOnDiscoverFailed(int32_t subscribeId, DiscoveryFailReason failReason);
/**
* @brief The local end publishes the service successfully, and the callback is called to notify the local end.
* @see {@link DiscClientOnPublishFail}.
* @param[in] publishId The information id used for the client to publish successfully.
*/
void DiscClientOnPublishSuccess(int32_t publishId);
/**
* @brief The local end fails to publish the service, and this callback is called to notify the local end.
* @see {@link DiscClientOnPublishSuccess}.
* @param[in] publishId The information id used for the client to publish failed.
* @param[in] reason reason of failure. For more information, see {@link PublishFailReason}.
*/
void DiscClientOnPublishFail(int32_t publishId, PublishFailReason reason);
#ifdef __cplusplus
}
#endif
#endif // SOFTBUS_CLIENT_DISC_MANAGER_H

View File

@ -1,166 +0,0 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "client_disc_manager.h"
#include "disc_log.h"
#include "disc_server_proxy.h"
#include "softbus_adapter_mem.h"
#include "softbus_errcode.h"
typedef struct {
IPublishCallback publishCb;
IDiscoveryCallback subscribeCb;
} DiscInfo;
static DiscInfo *g_discInfo = NULL;
int32_t PublishServiceInner(const char *packageName, const PublishInfo *info, const IPublishCallback *cb)
{
g_discInfo->publishCb = *cb;
int32_t ret = ServerIpcPublishService(packageName, info);
if (ret != SOFTBUS_OK) {
DISC_LOGE(DISC_SDK, "Server PublishService failed, ret=%{public}d", ret);
return ret;
}
return SOFTBUS_OK;
}
int32_t UnpublishServiceInner(const char *packageName, int32_t publishId)
{
int32_t ret = ServerIpcUnPublishService(packageName, publishId);
if (ret != SOFTBUS_OK) {
DISC_LOGE(DISC_SDK, "Server UnPublishService failed, ret=%{public}d", ret);
return ret;
}
return SOFTBUS_OK;
}
int32_t StartDiscoveryInner(const char *packageName, const SubscribeInfo *info, const IDiscoveryCallback *cb)
{
if (packageName == NULL || info == NULL || cb == NULL) {
DISC_LOGE(DISC_SDK, "invalid parameter:null");
return SOFTBUS_INVALID_PARAM;
}
g_discInfo->subscribeCb = *cb;
int32_t ret = ServerIpcStartDiscovery(packageName, info);
if (ret != SOFTBUS_OK) {
DISC_LOGE(DISC_SDK, "Server StartDiscovery failed, ret=%{public}d", ret);
return ret;
}
return SOFTBUS_OK;
}
int32_t StopDiscoveryInner(const char *packageName, int32_t subscribeId)
{
int32_t ret = ServerIpcStopDiscovery(packageName, subscribeId);
if (ret != SOFTBUS_OK) {
DISC_LOGE(DISC_SDK, "Server StopDiscovery failed, ret=%{public}d", ret);
return ret;
}
return SOFTBUS_OK;
}
int32_t DiscClientInit(void)
{
if (g_discInfo != NULL) {
SoftBusFree(g_discInfo);
g_discInfo = NULL;
}
g_discInfo = (DiscInfo *)SoftBusCalloc(sizeof(DiscInfo));
if (g_discInfo == NULL) {
DISC_LOGE(DISC_INIT, "Calloc failed");
return SOFTBUS_MALLOC_ERR;
}
if (DiscServerProxyInit() != SOFTBUS_OK) {
DISC_LOGE(DISC_INIT, "disc server proxy init failed.");
SoftBusFree(g_discInfo);
g_discInfo = NULL;
return SOFTBUS_DISC_SERVER_INIT_FAILED;
}
DISC_LOGI(DISC_INIT, "Init success as client side");
return SOFTBUS_OK;
}
void DiscClientDeinit(void)
{
if (g_discInfo == NULL) {
return;
}
SoftBusFree(g_discInfo);
g_discInfo = NULL;
DiscServerProxyDeInit();
DISC_LOGI(DISC_CONTROL, "DeInit success");
}
void DiscClientOnDeviceFound(const DeviceInfo *device)
{
if (device == NULL) {
DISC_LOGE(DISC_SDK, "invalid parameter:null");
return;
}
DISC_LOGI(DISC_SDK, "Sdk OnDeviceFound, capabilityBitmap=%{public}d",
device->capabilityBitmap[0]);
if (g_discInfo == NULL) {
DISC_LOGE(DISC_SDK, "OnDeviceFound callback failed!");
return;
}
g_discInfo->subscribeCb.OnDeviceFound(device);
}
void DiscClientOnDiscoverySuccess(int32_t subscribeId)
{
DISC_LOGI(DISC_SDK, "Sdk OnDiscoverySuccess, subscribeId=%{public}d", subscribeId);
if (g_discInfo == NULL) {
DISC_LOGE(DISC_SDK, "OnDiscoverySuccess callback failed!");
return;
}
g_discInfo->subscribeCb.OnDiscoverySuccess(subscribeId);
}
void DiscClientOnDiscoverFailed(int32_t subscribeId, DiscoveryFailReason failReason)
{
DISC_LOGI(DISC_SDK, "Sdk OnDiscoverFailed, subscribeId=%{public}d", subscribeId);
if (g_discInfo == NULL) {
DISC_LOGE(DISC_SDK, "OnDiscoverFailed callback failed!");
return;
}
g_discInfo->subscribeCb.OnDiscoverFailed(subscribeId, failReason);
}
void DiscClientOnPublishSuccess(int32_t publishId)
{
DISC_LOGI(DISC_SDK, "Sdk OnPublishSuccess, publishId=%{public}d", publishId);
if (g_discInfo == NULL) {
DISC_LOGE(DISC_SDK, "OnPublishSuccess callback failed!");
return;
}
g_discInfo->publishCb.OnPublishSuccess(publishId);
}
void DiscClientOnPublishFail(int32_t publishId, PublishFailReason reason)
{
DISC_LOGI(DISC_SDK, "Sdk OnPublishFail, publishId=%{public}d", publishId);
if (g_discInfo == NULL) {
DISC_LOGE(DISC_SDK, "OnPublishFail callback failed!");
return;
}
g_discInfo->publishCb.OnPublishFail(publishId, reason);
}

View File

@ -1,22 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CLIENT_DISC_SERVICE_H
#define CLIENT_DISC_SERVICE_H
#include "discovery_service.h"
#ifdef __cplusplus
#endif
#endif // CLIENT_DISC_SERVICE_H

View File

@ -1,215 +0,0 @@
/*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "client_disc_service.h"
#include <securec.h>
#include <stdbool.h>
#include <string.h>
#include "client_disc_manager.h"
#include "disc_event.h"
#include "disc_log.h"
#include "softbus_adapter_mem.h"
#include "softbus_client_frame_manager.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_utils.h"
static int32_t PublishInfoCheck(const PublishInfo *info)
{
if ((info->mode != DISCOVER_MODE_PASSIVE) && (info->mode != DISCOVER_MODE_ACTIVE)) {
DISC_LOGE(DISC_SDK, "mode is invalid");
return SOFTBUS_INVALID_PARAM;
}
if ((info->medium < AUTO) || (info->medium > COAP)) {
DISC_LOGE(DISC_SDK, "medium is invalid");
return SOFTBUS_INVALID_PARAM;
}
if ((info->freq < LOW) || (info->freq >= FREQ_BUTT)) {
DISC_LOGE(DISC_SDK, "freq is invalid");
return SOFTBUS_INVALID_PARAM;
}
if ((info->capabilityData == NULL) && (info->dataLen != 0)) {
DISC_LOGE(DISC_SDK, "data is invalid");
return SOFTBUS_INVALID_PARAM;
}
if (info->dataLen == 0) {
return SOFTBUS_OK;
}
if ((info->dataLen > MAX_CAPABILITYDATA_LEN) ||
(strlen((char *)(info->capabilityData)) >= MAX_CAPABILITYDATA_LEN)) {
DISC_LOGE(DISC_SDK, "data exceeds the maximum length");
return SOFTBUS_INVALID_PARAM;
}
return SOFTBUS_OK;
}
static int32_t SubscribeInfoCheck(const SubscribeInfo *info)
{
if ((info->mode != DISCOVER_MODE_PASSIVE) && (info->mode != DISCOVER_MODE_ACTIVE)) {
DISC_LOGE(DISC_SDK, "mode is invalid");
return SOFTBUS_INVALID_PARAM;
}
if ((info->medium < AUTO) || (info->medium > COAP)) {
DISC_LOGE(DISC_SDK, "medium is invalid");
return SOFTBUS_INVALID_PARAM;
}
if ((info->freq < LOW) || (info->freq >= FREQ_BUTT)) {
DISC_LOGE(DISC_SDK, "freq is invalid");
return SOFTBUS_INVALID_PARAM;
}
if ((info->capabilityData == NULL) && (info->dataLen != 0)) {
DISC_LOGE(DISC_SDK, "data is invalid");
return SOFTBUS_INVALID_PARAM;
}
if (info->dataLen == 0) {
return SOFTBUS_OK;
}
if ((info->dataLen > MAX_CAPABILITYDATA_LEN) ||
(strlen((char *)(info->capabilityData)) >= MAX_CAPABILITYDATA_LEN)) {
DISC_LOGE(DISC_SDK, "data exceeds the maximum length");
return SOFTBUS_INVALID_PARAM;
}
return SOFTBUS_OK;
}
static void DfxRecordDiscServerEnd(int32_t serverType, int32_t reason, const char *packageName)
{
if (reason == SOFTBUS_OK) {
return;
}
DiscEventExtra extra = { 0 };
DiscEventExtraInit(&extra);
extra.serverType = serverType;
extra.errcode = reason;
extra.result = EVENT_STAGE_RESULT_FAILED;
char pkgName[PKG_NAME_SIZE_MAX] = { 0 };
if (packageName != NULL && IsValidString(packageName, PKG_NAME_SIZE_MAX - 1) && strncpy_s(pkgName,
PKG_NAME_SIZE_MAX, packageName, PKG_NAME_SIZE_MAX - 1) == EOK) {
extra.callerPkg = pkgName;
}
DISC_EVENT(EVENT_SCENE_DISC, EVENT_STAGE_DISC_SDK, extra);
}
int PublishService(const char *packageName, const PublishInfo *info, const IPublishCallback *cb)
{
if ((packageName == NULL) || (strlen(packageName) >= PKG_NAME_SIZE_MAX) || (info == NULL) || (cb == NULL)) {
DfxRecordDiscServerEnd(SERVER_PUBLISH, SOFTBUS_INVALID_PARAM, packageName);
DISC_LOGE(DISC_SDK, "invalid parameter");
return SOFTBUS_INVALID_PARAM;
}
if (InitSoftBus(packageName) != SOFTBUS_OK) {
DfxRecordDiscServerEnd(SERVER_PUBLISH, SOFTBUS_DISCOVER_NOT_INIT, packageName);
DISC_LOGE(DISC_SDK, "init softbus err");
return SOFTBUS_DISCOVER_NOT_INIT;
}
if (CheckPackageName(packageName) != SOFTBUS_OK) {
DfxRecordDiscServerEnd(SERVER_PUBLISH, SOFTBUS_INVALID_PARAM, packageName);
DISC_LOGE(DISC_SDK, "check packageName failed");
return SOFTBUS_INVALID_PARAM;
}
if (PublishInfoCheck(info) != SOFTBUS_OK) {
DfxRecordDiscServerEnd(SERVER_PUBLISH, SOFTBUS_INVALID_PARAM, packageName);
DISC_LOGE(DISC_SDK, "publish infoCheck failed");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = PublishServiceInner(packageName, info, cb);
DfxRecordDiscServerEnd(SERVER_PUBLISH, ret, packageName);
return ret;
}
int UnPublishService(const char *packageName, int publishId)
{
if ((packageName == NULL) || (strlen(packageName) >= PKG_NAME_SIZE_MAX)) {
DfxRecordDiscServerEnd(SERVER_STOP_PUBLISH, SOFTBUS_INVALID_PARAM, packageName);
DISC_LOGE(DISC_SDK, "invalid packageName");
return SOFTBUS_INVALID_PARAM;
}
if (CheckPackageName(packageName) != SOFTBUS_OK) {
DfxRecordDiscServerEnd(SERVER_STOP_PUBLISH, SOFTBUS_INVALID_PARAM, packageName);
DISC_LOGE(DISC_SDK, "check packageName failed");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = UnpublishServiceInner(packageName, publishId);
DfxRecordDiscServerEnd(SERVER_STOP_PUBLISH, ret, packageName);
return ret;
}
int StartDiscovery(const char *packageName, const SubscribeInfo *info, const IDiscoveryCallback *cb)
{
if ((packageName == NULL) || (strlen(packageName) >= PKG_NAME_SIZE_MAX) || (info == NULL) || (cb == NULL)) {
DfxRecordDiscServerEnd(SERVER_DISCOVERY, SOFTBUS_INVALID_PARAM, packageName);
DISC_LOGE(DISC_SDK, " invalid parameter");
return SOFTBUS_INVALID_PARAM;
}
if (InitSoftBus(packageName) != SOFTBUS_OK) {
DfxRecordDiscServerEnd(SERVER_DISCOVERY, SOFTBUS_DISCOVER_NOT_INIT, packageName);
DISC_LOGE(DISC_SDK, "init softbus err");
return SOFTBUS_DISCOVER_NOT_INIT;
}
if (CheckPackageName(packageName) != SOFTBUS_OK) {
DfxRecordDiscServerEnd(SERVER_DISCOVERY, SOFTBUS_INVALID_PARAM, packageName);
DISC_LOGE(DISC_SDK, "check packageName failed");
return SOFTBUS_INVALID_PARAM;
}
if (SubscribeInfoCheck(info) != SOFTBUS_OK) {
DfxRecordDiscServerEnd(SERVER_DISCOVERY, SOFTBUS_INVALID_PARAM, packageName);
DISC_LOGE(DISC_SDK, "subscribe infoCheck failed");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = StartDiscoveryInner(packageName, info, cb);
DfxRecordDiscServerEnd(SERVER_DISCOVERY, ret, packageName);
return ret;
}
int StopDiscovery(const char *packageName, int subscribeId)
{
if ((packageName == NULL) || (strlen(packageName) >= PKG_NAME_SIZE_MAX)) {
DfxRecordDiscServerEnd(SERVER_STOP_DISCOVERY, SOFTBUS_INVALID_PARAM, packageName);
DISC_LOGE(DISC_SDK, "invalid packageName");
return SOFTBUS_INVALID_PARAM;
}
if (CheckPackageName(packageName) != SOFTBUS_OK) {
DfxRecordDiscServerEnd(SERVER_STOP_DISCOVERY, SOFTBUS_INVALID_PARAM, packageName);
DISC_LOGE(DISC_SDK, "check packageName failed");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = StopDiscoveryInner(packageName, subscribeId);
DfxRecordDiscServerEnd(SERVER_STOP_DISCOVERY, ret, packageName);
return ret;
}

View File

@ -19,7 +19,6 @@
#include <string.h>
#include "client_bus_center_manager.h"
#include "client_disc_manager.h"
#include "client_trans_session_manager.h"
#include "client_trans_socket_manager.h"
#include "comm_log.h"
@ -157,7 +156,6 @@ static void ClientModuleDeinit(void)
BusCenterClientDeinit();
TransClientDeinit();
ConnClientDeinit();
DiscClientDeinit();
}
static int32_t ConnClientInit(void)
@ -190,11 +188,6 @@ static int32_t ClientModuleInit(void)
goto ERR_EXIT;
}
if (DiscClientInit() != SOFTBUS_OK) {
COMM_LOGE(COMM_SDK, "init service manager failed");
goto ERR_EXIT;
}
if (ConnClientInit() != SOFTBUS_OK) {
COMM_LOGE(COMM_SDK, "init connect manager failed");
goto ERR_EXIT;

View File

@ -34,7 +34,6 @@ if (defined(ohos_lite)) {
"$dsoftbus_root_path/sdk/frame/common/src/softbus_client_event_manager.c",
"$dsoftbus_root_path/sdk/frame/common/src/softbus_client_frame_manager.c",
"$dsoftbus_root_path/sdk/frame/small/src/bus_center_client_stub.c",
"$dsoftbus_root_path/sdk/frame/small/src/disc_client_stub.c",
"$dsoftbus_root_path/sdk/frame/small/src/softbus_client_context_manager.c",
"$dsoftbus_root_path/sdk/frame/small/src/softbus_client_stub.c",
"$dsoftbus_root_path/sdk/frame/small/src/softbus_server_proxy.c",

View File

@ -1,39 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DISC_CLIENT_STUB_H
#define DISC_CLIENT_STUB_H
#include "serializer.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
int32_t ClientOnDiscoverySuccess(IpcIo *data, IpcIo *reply);
int32_t ClientOnDiscoverFailed(IpcIo *data, IpcIo *reply);
int32_t ClientOnDeviceFound(IpcIo *data, IpcIo *reply);
int32_t ClientOnPublishSuccess(IpcIo *data, IpcIo *reply);
int32_t ClientOnPublishFail(IpcIo *data, IpcIo *reply);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif // !DISC_CLIENT_STUB_H

View File

@ -1,92 +0,0 @@
/*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "disc_client_stub.h"
#include "client_disc_manager.h"
#include "disc_log.h"
#include "ipc_skeleton.h"
#include "softbus_errcode.h"
int32_t ClientOnDiscoverySuccess(IpcIo *data, IpcIo *reply)
{
if (data == NULL) {
DISC_LOGE(DISC_CONTROL, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
int32_t subscribeId = 0;
ReadInt32(data, &subscribeId);
DiscClientOnDiscoverySuccess(subscribeId);
return SOFTBUS_OK;
}
int32_t ClientOnDiscoverFailed(IpcIo *data, IpcIo *reply)
{
if (data == NULL) {
DISC_LOGE(DISC_CONTROL, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
int32_t subscribeId = 0;
int32_t failReason = 0;
ReadInt32(data, &subscribeId);
ReadInt32(data, &failReason);
DiscClientOnDiscoverFailed(subscribeId, failReason);
return SOFTBUS_OK;
}
int32_t ClientOnDeviceFound(IpcIo *data, IpcIo *reply)
{
if (data == NULL) {
DISC_LOGE(DISC_CONTROL, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
const DeviceInfo *deviceInfo = (const DeviceInfo*)ReadRawData(reply, sizeof(DeviceInfo));
if (deviceInfo == NULL) {
return SOFTBUS_ERR;
}
DiscClientOnDeviceFound(deviceInfo);
return SOFTBUS_OK;
}
int32_t ClientOnPublishSuccess(IpcIo *data, IpcIo *reply)
{
if (data == NULL) {
DISC_LOGE(DISC_CONTROL, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
int32_t publishId = 0;
ReadInt32(data, &publishId);
DiscClientOnPublishSuccess(publishId);
return SOFTBUS_OK;
}
int32_t ClientOnPublishFail(IpcIo *data, IpcIo *reply)
{
if (data == NULL) {
DISC_LOGE(DISC_CONTROL, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
int32_t publishId = 0;
int32_t failReason = 0;
ReadInt32(data, &publishId);
ReadInt32(data, &failReason);
DiscClientOnPublishFail(publishId, failReason);
return SOFTBUS_OK;
}

View File

@ -15,7 +15,6 @@
#include "bus_center_client_stub.h"
#include "comm_log.h"
#include "disc_client_stub.h"
#include "iproxy_client.h"
#include "ipc_skeleton.h"
#include "softbus_adapter_mem.h"
@ -42,11 +41,6 @@ struct SoftBusIpcClientCmd {
};
static struct SoftBusIpcClientCmd g_softBusIpcClientCmdTbl[] = {
{ CLIENT_DISCOVERY_SUCC, ClientOnDiscoverySuccess },
{ CLIENT_DISCOVERY_FAIL, ClientOnDiscoverFailed },
{ CLIENT_DISCOVERY_DEVICE_FOUND, ClientOnDeviceFound },
{ CLIENT_PUBLISH_SUCC, ClientOnPublishSuccess },
{ CLIENT_PUBLISH_FAIL, ClientOnPublishFail },
{ CLIENT_ON_JOIN_RESULT, ClientOnJoinLNNResult },
{ CLIENT_ON_JOIN_METANODE_RESULT, ClientOnJoinMetaNodeResult },
{ CLIENT_ON_LEAVE_RESULT, ClientOnLeaveLNNResult },

View File

@ -17,11 +17,11 @@
#define INTERFACES_INNERKITS_SOFTBUS_CLIENT_H_
#include "data_level_inner.h"
#include "discovery_service.h"
#include "iremote_broker.h"
#include "iremote_object.h"
#include "iremote_proxy.h"
#include "session.h"
#include "softbus_common.h"
#include "softbus_def.h"
namespace OHOS {
@ -29,16 +29,6 @@ class ISoftBusClient : public IRemoteBroker {
public:
~ISoftBusClient() override = default;
virtual void OnDeviceFound(const DeviceInfo *device);
virtual void OnDiscoverFailed(int subscribeId, int failReason);
virtual void OnDiscoverySuccess(int subscribeId);
virtual void OnPublishSuccess(int publishId);
virtual void OnPublishFail(int publishId, int reason);
virtual int32_t OnChannelOpened(const char *sessionName, const ChannelInfo *channel);
virtual int32_t OnChannelOpenFailed(int32_t channelId, int32_t channelType, int32_t errCode);

View File

@ -35,11 +35,6 @@ public:
SoftBusClientStub();
virtual ~SoftBusClientStub() = default;
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
void OnDeviceFound(const DeviceInfo *device) override;
void OnDiscoverFailed(int subscribeId, int failReason) override;
void OnDiscoverySuccess(int subscribeId) override;
void OnPublishSuccess(int publishId) override;
void OnPublishFail(int publishId, int reason) override;
int32_t OnChannelOpened(const char *sessionName, const ChannelInfo *info) override;
int32_t OnChannelOpenFailed(int32_t channelId, int32_t channelType, int32_t errCode) override;
int32_t OnChannelLinkDown(const char *networkId, int32_t routeType) override;
@ -64,11 +59,6 @@ public:
int32_t OnChannelBind(int32_t channelId, int32_t channelType) override;
private:
int32_t OnDeviceFoundInner(MessageParcel &data, MessageParcel &reply);
int32_t OnDiscoverFailedInner(MessageParcel &data, MessageParcel &reply);
int32_t OnDiscoverySuccessInner(MessageParcel &data, MessageParcel &reply);
int32_t OnPublishSuccessInner(MessageParcel &data, MessageParcel &reply);
int32_t OnPublishFailInner(MessageParcel &data, MessageParcel &reply);
int32_t OnChannelOpenedInner(MessageParcel &data, MessageParcel &reply);
int32_t OnChannelOpenFailedInner(MessageParcel &data, MessageParcel &reply);
int32_t OnChannelLinkDownInner(MessageParcel &data, MessageParcel &reply);

View File

@ -29,10 +29,6 @@ public:
: IRemoteProxy<ISoftBusServer>(impl) {}
virtual ~SoftBusServerProxyFrame() = default;
int32_t StartDiscovery(const char *pkgName, const SubscribeInfo *info) override;
int32_t StopDiscovery(const char *pkgName, int subscribeId) override;
int32_t PublishService(const char *pkgName, const PublishInfo *info) override;
int32_t UnPublishService(const char *pkgName, int publishId) override;
int32_t SoftbusRegisterService(const char *clientPkgName, const sptr<IRemoteObject> &object) override;
int32_t CreateSessionServer(const char *pkgName, const char *sessionName) override;

View File

@ -18,30 +18,6 @@
#include "softbus_error_code.h"
namespace OHOS {
void ISoftBusClient::OnDeviceFound(const DeviceInfo *device)
{
COMM_LOGI(COMM_EVENT, "ipc default impl");
}
void ISoftBusClient::OnDiscoverFailed(int subscribeId, int failReason)
{
COMM_LOGI(COMM_EVENT, "ipc default impl");
}
void ISoftBusClient::OnDiscoverySuccess(int subscribeId)
{
COMM_LOGI(COMM_EVENT, "ipc default impl");
}
void ISoftBusClient::OnPublishSuccess(int publishId)
{
COMM_LOGI(COMM_EVENT, "ipc default impl");
}
void ISoftBusClient::OnPublishFail(int publishId, int reason)
{
COMM_LOGI(COMM_EVENT, "ipc default impl");
}
int32_t ISoftBusClient::OnChannelOpened(const char *sessionName, const ChannelInfo *channel)
{
COMM_LOGI(COMM_EVENT, "ipc default impl");

View File

@ -18,7 +18,6 @@
#include <string>
#include "client_bus_center_manager.h"
#include "client_disc_manager.h"
#include "client_trans_channel_callback.h"
#include "client_trans_session_manager.h"
#include "client_trans_socket_manager.h"
@ -36,11 +35,6 @@
namespace OHOS {
SoftBusClientStub::SoftBusClientStub()
{
memberFuncMap_[CLIENT_DISCOVERY_DEVICE_FOUND] = &SoftBusClientStub::OnDeviceFoundInner;
memberFuncMap_[CLIENT_DISCOVERY_SUCC] = &SoftBusClientStub::OnDiscoverySuccessInner;
memberFuncMap_[CLIENT_DISCOVERY_FAIL] = &SoftBusClientStub::OnDiscoverFailedInner;
memberFuncMap_[CLIENT_PUBLISH_SUCC] = &SoftBusClientStub::OnPublishSuccessInner;
memberFuncMap_[CLIENT_PUBLISH_FAIL] = &SoftBusClientStub::OnPublishFailInner;
memberFuncMap_[CLIENT_ON_CHANNEL_OPENED] = &SoftBusClientStub::OnChannelOpenedInner;
memberFuncMap_[CLIENT_ON_CHANNEL_OPENFAILED] = &SoftBusClientStub::OnChannelOpenFailedInner;
memberFuncMap_[CLIENT_ON_CHANNEL_LINKDOWN] = &SoftBusClientStub::OnChannelLinkDownInner;
@ -97,50 +91,6 @@ int32_t SoftBusClientStub::OnClientPermissonChangeInner(MessageParcel &data, Mes
return SOFTBUS_OK;
}
int32_t SoftBusClientStub::OnDeviceFoundInner(MessageParcel &data, MessageParcel &reply)
{
const unsigned char *info = data.ReadBuffer(sizeof(DeviceInfo));
if (info == nullptr) {
return SOFTBUS_TRANS_PROXY_READBUFFER_FAILED;
}
DeviceInfo deviceInfo;
if (memcpy_s(&deviceInfo, sizeof(DeviceInfo), info, sizeof(DeviceInfo)) != EOK) {
return SOFTBUS_MEM_ERR;
}
OnDeviceFound(&deviceInfo);
return SOFTBUS_OK;
}
int32_t SoftBusClientStub::OnDiscoverFailedInner(MessageParcel &data, MessageParcel &reply)
{
int subscribeId = data.ReadInt32();
int failReason = data.ReadInt32();
OnDiscoverFailed(subscribeId, failReason);
return SOFTBUS_OK;
}
int32_t SoftBusClientStub::OnDiscoverySuccessInner(MessageParcel &data, MessageParcel &reply)
{
int subscribeId = data.ReadInt32();
OnDiscoverySuccess(subscribeId);
return SOFTBUS_OK;
}
int32_t SoftBusClientStub::OnPublishSuccessInner(MessageParcel &data, MessageParcel &reply)
{
int publishId = data.ReadInt32();
OnPublishSuccess(publishId);
return SOFTBUS_OK;
}
int32_t SoftBusClientStub::OnPublishFailInner(MessageParcel &data, MessageParcel &reply)
{
int publishId = data.ReadInt32();
int failReason = data.ReadInt32();
OnPublishFail(publishId, failReason);
return SOFTBUS_OK;
}
int32_t SoftBusClientStub::OnClientTransLimitChangeInner(MessageParcel &data, MessageParcel &reply)
{
int32_t channelId;
@ -163,31 +113,6 @@ int32_t SoftBusClientStub::OnClientTransLimitChange(int32_t channelId, uint8_t t
return TransLimitChange(channelId, tos);
}
void SoftBusClientStub::OnDeviceFound(const DeviceInfo *device)
{
DiscClientOnDeviceFound(device);
}
void SoftBusClientStub::OnDiscoverFailed(int subscribeId, int failReason)
{
DiscClientOnDiscoverFailed(subscribeId, (DiscoveryFailReason)failReason);
}
void SoftBusClientStub::OnDiscoverySuccess(int subscribeId)
{
DiscClientOnDiscoverySuccess(subscribeId);
}
void SoftBusClientStub::OnPublishSuccess(int publishId)
{
DiscClientOnPublishSuccess(publishId);
}
void SoftBusClientStub::OnPublishFail(int publishId, int reason)
{
DiscClientOnPublishFail(publishId, (PublishFailReason)reason);
}
int32_t SoftBusClientStub::OnChannelOpened(const char *sessionName, const ChannelInfo *info)
{
return TransOnChannelOpened(sessionName, info);

View File

@ -25,7 +25,6 @@
#include "client_trans_socket_manager.h"
#include "bus_center_server_proxy.h"
#include "comm_log.h"
#include "disc_server_proxy.h"
#include "ipc_skeleton.h"
#include "iremote_broker.h"
#include "iremote_object.h"
@ -176,7 +175,6 @@ void ClientDeathProcTask(void)
}
g_serverProxy.clear();
}
DiscServerProxyDeInit();
TransServerProxyDeInit();
BusCenterServerProxyDeInit();
@ -195,7 +193,6 @@ void ClientDeathProcTask(void)
COMM_LOGE(COMM_SDK, "server proxy init reached the maximum count=%{public}d", cnt);
return;
}
DiscServerProxyInit();
TransServerProxyInit();
BusCenterServerProxyInit();
InnerRegisterService(&sessionServerInfoList);

View File

@ -36,34 +36,6 @@ sptr<IRemoteObject> SoftBusServerProxyFrame::GetRemoteInstance()
return clientCallbackStub_;
}
int32_t SoftBusServerProxyFrame::StartDiscovery(const char *pkgName, const SubscribeInfo *info)
{
(void)pkgName;
(void)info;
return SOFTBUS_OK;
}
int32_t SoftBusServerProxyFrame::StopDiscovery(const char *pkgName, int subscribeId)
{
(void)pkgName;
(void)subscribeId;
return SOFTBUS_OK;
}
int32_t SoftBusServerProxyFrame::PublishService(const char *pkgName, const PublishInfo *info)
{
(void)pkgName;
(void)info;
return SOFTBUS_OK;
}
int32_t SoftBusServerProxyFrame::UnPublishService(const char *pkgName, int publishId)
{
(void)pkgName;
(void)publishId;
return SOFTBUS_OK;
}
int32_t SoftBusServerProxyFrame::SoftbusRegisterService(const char *clientPkgName, const sptr<IRemoteObject>& object)
{
sptr<IRemoteObject> remote = Remote();

View File

@ -29,7 +29,6 @@
"TransOnUdpChannelQosEvent";
"ServerIpcPublishLNN";
"ClientDeleteSession";
"UnpublishServiceInner";
"ClientTransUdpMgrDeinit";
"ServerIpcNotifyAuthSuccess";
"ServerIpcLeaveLNN";
@ -40,7 +39,6 @@
"FreeNodeInfo";
"ServerIpcStreamStats";
"TransTdcSendMessage";
"DiscClientDeinit";
"FindConfigType";
"TransClientDeinit";
"ClientRegisterService";
@ -50,8 +48,6 @@
"BusCenterServerProxyInit";
"ServerIpcStopRefreshLNN";
"TransGetUdpChannel";
"ServerIpcPublishService";
"DiscClientOnPublishSuccess";
"ClientTransProxyDeinit";
"JoinMetaNode";
"ClientTransProxyInit";
@ -59,10 +55,8 @@
"FrameIndexToType";
"ServerIpcStopTimeSync";
"GetMySessionNameInner";
"StartDiscovery";
"RefreshLNNInner";
"LnnOnLeaveResult";
"ServerIpcStopDiscovery";
"GetSessionSide";
"TransOnChannelClosed";
"TransProxyChannelSendBytes";
@ -73,14 +67,12 @@
"ServerIpcCreateSessionServer";
"TransOnUdpChannelOpenFailed";
"CheckSendLen";
"DiscServerProxyInit";
"ClientTransRegLnnOffline";
"ServerIpcStartTimeSync";
"TransCloseStreamChannel";
".init_proc";
"ClientTransChannelSendBytes";
"TransTdcGetHandle";
"ServerIpcUnPublishService";
"GetNodeKeyInfoInner";
"InitPendingPacket";
"DeactiveMetaNode";
@ -119,7 +111,6 @@
"IsServerSideInner";
"TransProxyChannelSendMessage";
"TransDataListInit";
"DiscClientOnDiscoverySuccess";
"TransOnSessionClosed";
"TransGetFileName";
"GetEncryptByChannelId";
@ -140,13 +131,11 @@
"ServerIpcOpenAuthSession";
"CreatePendingPacket";
"CreateSessionServerInner";
"PublishServiceInner";
"RefreshLNN";
"GetPkgNameInner";
"CloseSession";
"CLIENT_NotifyObserver";
"ServerIpcGetLocalDeviceInfo";
"DiscClientInit";
"ClientAddAuthSession";
"TransTdcGetInfoByIdWithIncSeq";
"PublishLNNInner";
@ -170,7 +159,6 @@
"RegisterFileCb";
"InnerOnBytesReceived";
"RemoveSessionServer";
"StopDiscovery";
"ClientGetSessionCallbackById";
"ClientGetDataConfigByChannelId";
"ClientTransUdpMgrInit";
@ -181,13 +169,11 @@
"LnnOnRefreshDeviceFound";
"ServerIpcActiveMetaNode";
"ServerIpcLeaveMetaNode";
"DiscClientOnDeviceFound";
"EventClientInit";
"ServerIpcGetNodeKeyInfo";
"CheckPackageName";
"PublishLNN";
"ClientTransAuthOnDataReceived";
"StopDiscoveryInner";
"SendStream";
"TransSetFileSendListener";
"ClientTransProxyOnChannelOpened";
@ -215,7 +201,6 @@
"TransAuthChannelSendMessage";
"TransGetFileListener";
"ShiftLNNGearInner";
"ServerIpcStartDiscovery";
"ServerIpcJoinMetaNode";
"FileUnLock";
"TransOnUdpChannelOpened";
@ -227,7 +212,6 @@
"GetPeerPidInner";
"StartNStackXDFileClient";
"MetaNodeOnLeaveResult";
"DiscClientOnPublishFail";
"ProcessFileFrameData";
"SendVtpStream";
"TransClientInit";
@ -273,7 +257,6 @@
"IsPathValid";
"TransTdcGetInfoById";
"UnregisterStreamCb";
"PublishService";
"ClientTransChannelSendStream";
"TransTdcSendBytes";
"GetAllNodeDeviceInfo";
@ -284,7 +267,6 @@
"EventClientDeinit";
"FileListToBuffer";
"RTU_CRC";
"UnPublishService";
"SetFileReceiveListener";
"ClientGetSessionDataById";
"ClientTransChannelSendMessage";
@ -300,7 +282,6 @@
"TransTdcStopRead";
"ServerIpcReleaseResources";
"ServerIpcCloseChannel";
"DiscClientOnDiscoverFailed";
"SendBytesInner";
"GetPeerSessionNameInner";
"TransTdcManagerDeinit";
@ -318,7 +299,6 @@
"CloseSessionInner";
"ClientTransTdcOnDataReceived";
"ClientAddSessionServer";
"StartDiscoveryInner";
"InnerOnSessionOpened";
"GrantPermissionInner";
"LeaveMetaNode";
@ -337,7 +317,6 @@
"ClientSetChannelBySessionId";
"StopPublishLNN";
"GetPeerSessionName";
"DiscServerProxyDeInit";
"ServerIpcGetAllMetaNodeInfo";
"TransOnChannelQosEvent";
"ClientGetSessionIntegerDataById";
@ -538,7 +517,6 @@
Communication::SoftBus*;
OHOS::ISoftBusServer*;
"VTT for OHOS::BusCenterServerProxy";
"VTT for OHOS::DiscServerProxy";
"VTT for OHOS::IRemoteStub<OHOS::ISoftBusClient>";
"VTT for OHOS::ISoftBusClient";
"VTT for OHOS::ISoftBusServer";
@ -549,7 +527,6 @@
"construction vtable for OHOS::IPCObjectStub-in-OHOS::IRemoteStub<OHOS::ISoftBusClient>";
"construction vtable for OHOS::IPCObjectStub-in-OHOS::SoftBusClientStub";
"construction vtable for OHOS::IRemoteBroker-in-OHOS::BusCenterServerProxy";
"construction vtable for OHOS::IRemoteBroker-in-OHOS::DiscServerProxy";
"construction vtable for OHOS::IRemoteBroker-in-OHOS::IRemoteStub<OHOS::ISoftBusClient>";
"construction vtable for OHOS::IRemoteBroker-in-OHOS::ISoftBusClient";
"construction vtable for OHOS::IRemoteBroker-in-OHOS::ISoftBusServer";
@ -559,20 +536,17 @@
"construction vtable for OHOS::IRemoteObject-in-OHOS::IRemoteStub<OHOS::ISoftBusClient>";
"construction vtable for OHOS::IRemoteObject-in-OHOS::SoftBusClientStub";
"construction vtable for OHOS::IRemoteProxy<OHOS::ISoftBusServer>-in-OHOS::BusCenterServerProxy";
"construction vtable for OHOS::IRemoteProxy<OHOS::ISoftBusServer>-in-OHOS::DiscServerProxy";
"construction vtable for OHOS::IRemoteProxy<OHOS::ISoftBusServer>-in-OHOS::SoftBusServerProxyFrame";
"construction vtable for OHOS::IRemoteProxy<OHOS::ISoftBusServer>-in-OHOS::TransServerProxy";
"construction vtable for OHOS::IRemoteStub<OHOS::ISoftBusClient>-in-OHOS::SoftBusClientStub";
"construction vtable for OHOS::ISoftBusClient-in-OHOS::IRemoteStub<OHOS::ISoftBusClient>";
"construction vtable for OHOS::ISoftBusClient-in-OHOS::SoftBusClientStub";
"construction vtable for OHOS::ISoftBusServer-in-OHOS::BusCenterServerProxy";
"construction vtable for OHOS::ISoftBusServer-in-OHOS::DiscServerProxy";
"construction vtable for OHOS::ISoftBusServer-in-OHOS::SoftBusServerProxyFrame";
"construction vtable for OHOS::ISoftBusServer-in-OHOS::TransServerProxy";
"construction vtable for OHOS::Parcelable-in-OHOS::IRemoteStub<OHOS::ISoftBusClient>";
"construction vtable for OHOS::Parcelable-in-OHOS::SoftBusClientStub";
"guard variable for OHOS::BusCenterServerProxy::delegator_";
"guard variable for OHOS::DiscServerProxy::delegator_";
"guard variable for OHOS::SoftBusServerProxyFrame::delegator_";
"guard variable for OHOS::TransServerProxy::delegator_";
"non-virtual thunk to OHOS::IRemoteStub<OHOS::ISoftBusClient>::AsObject(void)";
@ -583,18 +557,13 @@
"non-virtual thunk to OHOS::SoftBusClientStub::OnChannelOpened(char const*, ChannelInfo const*)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnChannelQosEvent(int, int, int, int, QosTv const*)";
"non-virtual thunk to OHOS::SoftBusClientStub::SetChannelInfo(char const*, int, int, int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnDeviceFound(DeviceInfo const*)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnDiscoverFailed(int, int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnDiscoverySuccess(int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnJoinLNNResult(void *, unsigned int,char const*, int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnJoinMetaNodeResult(void *, unsigned int, char const*, int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnLeaveLNNResult(char const*, int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnLeaveMetaNodeResult(char const*, int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnNodeBasicInfoChanged(void *, unsigned int, int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnNodeOnlineStateChanged(bool, void *, unsigned int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnPublishFail(int, int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnPublishLNNResult(int, int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnPublishSuccess(int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnRefreshDeviceFound(void const*, unsigned int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnRefreshLNNResult(int, int)";
"non-virtual thunk to OHOS::SoftBusClientStub::OnTimeSyncResult(void const*, unsigned int, int)";
@ -613,12 +582,10 @@
"vtable for Communication::SoftBus::TwoLevelsTlv";
"vtable for Communication::SoftBus::VtpStreamSocket";
"vtable for OHOS::BrokerDelegator<OHOS::BusCenterServerProxy>";
"vtable for OHOS::BrokerDelegator<OHOS::DiscServerProxy>";
"vtable for OHOS::BrokerDelegator<OHOS::SoftBusServerProxyFrame>";
"vtable for OHOS::BrokerDelegator<OHOS::TransServerProxy>";
"vtable for OHOS::BrokerDelegatorBase";
"vtable for OHOS::BusCenterServerProxy";
"vtable for OHOS::DiscServerProxy";
"vtable for OHOS::IRemoteStub<OHOS::ISoftBusClient>";
"vtable for OHOS::ISoftBusClient";
"vtable for OHOS::ISoftBusServer";

View File

@ -26,10 +26,6 @@ public:
: IRemoteProxy<ISoftBusServer>(impl) {}
virtual ~TransServerProxy() = default;
int32_t StartDiscovery(const char *pkgName, const SubscribeInfo *subInfo) override;
int32_t StopDiscovery(const char *pkgName, int32_t subscribeId) override;
int32_t PublishService(const char *pkgName, const PublishInfo *pubInfo) override;
int32_t UnPublishService(const char *pkgName, int32_t publishId) override;
int32_t SoftbusRegisterService(const char *clientPkgName, const sptr<IRemoteObject> &object) override;
int32_t CreateSessionServer(const char *pkgName, const char *sessionName) override;

View File

@ -60,34 +60,6 @@ static sptr<IRemoteObject> GetSystemAbility()
return reply.ReadRemoteObject();
}
int32_t TransServerProxy::StartDiscovery(const char *pkgName, const SubscribeInfo *subInfo)
{
(void)pkgName;
(void)subInfo;
return SOFTBUS_OK;
}
int32_t TransServerProxy::StopDiscovery(const char *pkgName, int32_t subscribeId)
{
(void)pkgName;
(void)subscribeId;
return SOFTBUS_OK;
}
int32_t TransServerProxy::PublishService(const char *pkgName, const PublishInfo *pubInfo)
{
(void)pkgName;
(void)pubInfo;
return SOFTBUS_OK;
}
int32_t TransServerProxy::UnPublishService(const char *pkgName, int32_t publishId)
{
(void)pkgName;
(void)publishId;
return SOFTBUS_OK;
}
int32_t TransServerProxy::SoftbusRegisterService(const char *clientPkgName, const sptr<IRemoteObject> &object)
{
(void)clientPkgName;

View File

@ -23,7 +23,6 @@ if (defined(ohos_lite)) {
features += [
"adapter/unittest:AdapterTest",
"sdk/bus_center/unittest:BusCenterSdkRefreshSmall",
"sdk/discovery/unittest:DiscSdkTest",
"sdk/transmission/trans_channel:TransSdkStreamTest",
]
}
@ -49,7 +48,6 @@ if (defined(ohos_lite)) {
"core/frame:unittest",
"core/transmission:unittest",
"sdk/bus_center:unittest",
"sdk/discovery:unittest",
"sdk/frame/common:unittest",
"sdk/frame/standard:unittest",
"sdk/transmission:unittest",
@ -71,7 +69,6 @@ if (defined(ohos_lite)) {
"core/frame:fuzztest",
"core/transmission:fuzztest",
"sdk/bus_center:fuzztest",
"sdk/discovery:fuzztest",
"sdk/frame:fuzztest",
"sdk/transmission:fuzztest",
]

View File

@ -22,7 +22,6 @@
#include <cstdlib>
#include "bluetooth_mock.h"
#include "discovery_service.h"
#include "disc_ble.h"
#include "disc_log.h"
#include "lnn_local_net_ledger.h"

View File

@ -20,40 +20,6 @@ import("../../../utils/utils.gni")
module_output_path = "dsoftbus/discovery"
ohos_unittest("DiscClientProxyTest") {
module_out_path = module_output_path
sources = [
"$dsoftbus_core_path/discovery/ipc/standard/src/disc_client_proxy.cpp",
"$dsoftbus_core_path/discovery/ipc/standard/src/disc_client_proxy_standard.cpp",
"$dsoftbus_root_path/sdk/frame/standard/src/if_softbus_client.cpp",
"client_info_manager_mock.cpp",
"disc_client_proxy_test.cpp",
"remote_object_mock.cpp",
]
sources += test_utils_src
include_dirs = [
"$dsoftbus_core_path/discovery/ipc/include",
"$dsoftbus_core_path/discovery/ipc/standard/include",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/sdk/frame/standard/include/",
"$dsoftbus_core_path/common/include",
"$dsoftbus_root_path/core/common/dfx/interface/include",
"$dsoftbus_core_path/frame/standard/client_manager/include",
"$softbus_adapter_common/include",
]
include_dirs += test_utils_inc
external_deps = [
"c_utils:utils",
"googletest:gmock",
"googletest:gtest_main",
"hilog:libhilog",
"ipc:ipc_core",
]
}
ohos_unittest("DiscClientOnDeviceFoundTest") {
module_out_path = module_output_path
sources = [
@ -98,8 +64,5 @@ ohos_unittest("DiscClientOnDeviceFoundTest") {
group("unittest") {
testonly = true
deps = [
":DiscClientOnDeviceFoundTest",
":DiscClientProxyTest",
]
deps = [ ":DiscClientOnDeviceFoundTest" ]
}

View File

@ -14,7 +14,6 @@
*/
#include "client_info_manager_mock.h"
#include "disc_client_proxy_standard.h"
#include "remote_object_mock.h"
namespace OHOS {

View File

@ -1,222 +0,0 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "discovery_service.h"
#include "disc_client_proxy.h"
#include "disc_log.h"
#include "softbus_error_code.h"
#include "softbus_server_ipc_interface_code.h"
#include "remote_object_mock.h"
#include "client_info_manager_mock.h"
#include "exception_branch_checker.h"
using namespace testing::ext;
using testing::Return;
namespace OHOS {
class DiscClientProxyTest : public testing::Test {
public:
static void SetUpTestCase() {}
static void TearDownTestCase() {}
void SetUp() override {}
void TearDown() override {}
static inline std::string pkgName = "TestPackage";
static constexpr int SUBSCRIBE_ID = 8;
static constexpr int PUBLISH_ID = 16;
};
/*
* @tc.name: OnDeviceFound001
* @tc.desc: both fail and success case
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscClientProxyTest, OnDeviceFound001, TestSize.Level1)
{
DISC_LOGI(DISC_TEST, "OnDeviceFound001 begin ----");
const DeviceInfo device {};
const InnerDeviceInfoAddtions addition{};
{
sptr<RemoteObjectMock> objectMock = new (std::nothrow) RemoteObjectMock();
RemoteObjectMock::SetupStub(objectMock);
EXPECT_CALL(*objectMock, SendRequest).WillRepeatedly(Return(SOFTBUS_DISCOVER_TEST_CASE_ERRCODE));
ClientInfoManagerMock managerMock;
managerMock.SetupStub();
ExceptionBranchChecker checker("send request failed");
EXPECT_EQ(ClientIpcOnDeviceFound(pkgName.c_str(), &device, &addition), SOFTBUS_OK);
EXPECT_EQ(checker.GetResult(), true);
}
{
sptr<RemoteObjectMock> objectMock = new (std::nothrow) RemoteObjectMock();
RemoteObjectMock::SetupStub(objectMock);
ClientInfoManagerMock managerMock;
managerMock.SetupStub();
EXPECT_EQ(ClientIpcOnDeviceFound(pkgName.c_str(), &device, &addition), SOFTBUS_OK);
EXPECT_EQ(objectMock->GetResult(CLIENT_DISCOVERY_DEVICE_FOUND, &device), true);
}
RemoteObjectMock::Destroy();
DISC_LOGI(DISC_TEST, "OnDeviceFound001 end ----");
}
/*
* @tc.name: OnDiscoverFailed001
* @tc.desc: both fail and success case
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscClientProxyTest, OnDiscoverFailed001, TestSize.Level1)
{
DISC_LOGI(DISC_TEST, "OnDiscoverFailed001 begin ----");
{
sptr<RemoteObjectMock> objectMock = new (std::nothrow) RemoteObjectMock();
RemoteObjectMock::SetupStub(objectMock);
EXPECT_CALL(*objectMock, SendRequest).WillRepeatedly(Return(SOFTBUS_DISCOVER_TEST_CASE_ERRCODE));
ClientInfoManagerMock managerMock;
managerMock.SetupStub();
ExceptionBranchChecker checker("send request failed");
EXPECT_EQ(ClientIpcOnDiscoverFailed(pkgName.c_str(), SUBSCRIBE_ID, DISCOVERY_FAIL_REASON_NOT_SUPPORT_MEDIUM),
SOFTBUS_OK);
EXPECT_EQ(checker.GetResult(), true);
}
{
sptr<RemoteObjectMock> objectMock = new (std::nothrow) RemoteObjectMock();
RemoteObjectMock::SetupStub(objectMock);
ClientInfoManagerMock managerMock;
managerMock.SetupStub();
EXPECT_EQ(ClientIpcOnDiscoverFailed(pkgName.c_str(), SUBSCRIBE_ID, DISCOVERY_FAIL_REASON_NOT_SUPPORT_MEDIUM),
SOFTBUS_OK);
EXPECT_EQ(objectMock->GetResult(CLIENT_DISCOVERY_FAIL, nullptr, 0, SUBSCRIBE_ID,
DISCOVERY_FAIL_REASON_NOT_SUPPORT_MEDIUM), true);
}
RemoteObjectMock::Destroy();
DISC_LOGI(DISC_TEST, "OnDiscoverFailed001 end ----");
}
/*
* @tc.name: DiscoverySuccess001
* @tc.desc: both fail and success case
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscClientProxyTest, DiscoverySuccess001, TestSize.Level1)
{
DISC_LOGI(DISC_TEST, "DiscoverySuccess001 begin ----");
{
sptr<RemoteObjectMock> objectMock = new (std::nothrow) RemoteObjectMock();
RemoteObjectMock::SetupStub(objectMock);
EXPECT_CALL(*objectMock, SendRequest).WillRepeatedly(Return(SOFTBUS_DISCOVER_TEST_CASE_ERRCODE));
ClientInfoManagerMock managerMock;
managerMock.SetupStub();
ExceptionBranchChecker checker("send request failed");
EXPECT_EQ(ClientIpcDiscoverySuccess(pkgName.c_str(), SUBSCRIBE_ID), SOFTBUS_OK);
EXPECT_EQ(checker.GetResult(), true);
}
{
sptr<RemoteObjectMock> objectMock = new (std::nothrow) RemoteObjectMock();
RemoteObjectMock::SetupStub(objectMock);
ClientInfoManagerMock managerMock;
managerMock.SetupStub();
EXPECT_EQ(ClientIpcDiscoverySuccess(pkgName.c_str(), SUBSCRIBE_ID), SOFTBUS_OK);
EXPECT_EQ(objectMock->GetResult(CLIENT_DISCOVERY_SUCC, nullptr, 0, SUBSCRIBE_ID), true);
}
RemoteObjectMock::Destroy();
DISC_LOGI(DISC_TEST, "DiscoverySuccess001 end ----");
}
/*
* @tc.name: OnPublishSuccess001
* @tc.desc: both fail and success case
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscClientProxyTest, OnPublishSuccess001, TestSize.Level1)
{
DISC_LOGI(DISC_TEST, "DiscoverySuccess001 begin ----");
{
sptr<RemoteObjectMock> objectMock = new (std::nothrow) RemoteObjectMock();
RemoteObjectMock::SetupStub(objectMock);
EXPECT_CALL(*objectMock, SendRequest).WillRepeatedly(Return(SOFTBUS_DISCOVER_TEST_CASE_ERRCODE));
ClientInfoManagerMock managerMock;
managerMock.SetupStub();
ExceptionBranchChecker checker("send request failed");
EXPECT_EQ(ClientIpcOnPublishSuccess(pkgName.c_str(), PUBLISH_ID), SOFTBUS_OK);
EXPECT_EQ(checker.GetResult(), true);
}
{
sptr<RemoteObjectMock> objectMock = new (std::nothrow) RemoteObjectMock();
RemoteObjectMock::SetupStub(objectMock);
ClientInfoManagerMock managerMock;
managerMock.SetupStub();
EXPECT_EQ(ClientIpcOnPublishSuccess(pkgName.c_str(), PUBLISH_ID), SOFTBUS_OK);
EXPECT_EQ(objectMock->GetResult(CLIENT_PUBLISH_SUCC, nullptr, PUBLISH_ID), true);
}
RemoteObjectMock::Destroy();
DISC_LOGI(DISC_TEST, "OnPublishSuccess001 end ----");
}
/*
* @tc.name: OnPublishFail001
* @tc.desc: both fail and success case
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscClientProxyTest, OnPublishFail001, TestSize.Level1)
{
DISC_LOGI(DISC_TEST, "OnPublishFail001 begin ----");
{
sptr<RemoteObjectMock> objectMock = new (std::nothrow) RemoteObjectMock();
RemoteObjectMock::SetupStub(objectMock);
EXPECT_CALL(*objectMock, SendRequest).WillRepeatedly(Return(SOFTBUS_DISCOVER_TEST_CASE_ERRCODE));
ClientInfoManagerMock managerMock;
managerMock.SetupStub();
ExceptionBranchChecker checker("send request failed");
EXPECT_EQ(ClientIpcOnPublishFail(pkgName.c_str(), PUBLISH_ID, PUBLISH_FAIL_REASON_NOT_SUPPORT_MEDIUM),
SOFTBUS_OK);
EXPECT_EQ(checker.GetResult(), true);
}
{
sptr<RemoteObjectMock> objectMock = new (std::nothrow) RemoteObjectMock();
RemoteObjectMock::SetupStub(objectMock);
ClientInfoManagerMock managerMock;
managerMock.SetupStub();
EXPECT_EQ(ClientIpcOnPublishFail(pkgName.c_str(), PUBLISH_ID, PUBLISH_FAIL_REASON_NOT_SUPPORT_MEDIUM),
SOFTBUS_OK);
EXPECT_EQ(objectMock->GetResult(CLIENT_PUBLISH_FAIL, nullptr, PUBLISH_ID, 0,
PUBLISH_FAIL_REASON_NOT_SUPPORT_MEDIUM), true);
}
RemoteObjectMock::Destroy();
DISC_LOGI(DISC_TEST, "OnPublishFail001 end ----");
}
}

View File

@ -47,16 +47,6 @@ void RemoteObjectMock::Destroy()
void RemoteObjectMock::SetupStub(const sptr<RemoteObjectMock> &self)
{
SetSelf(self);
EXPECT_CALL(*self, SendRequest(CLIENT_DISCOVERY_DEVICE_FOUND, _, _, _))
.WillRepeatedly(ActionOfSendRequestForOnDeviceFound);
EXPECT_CALL(*self, SendRequest(CLIENT_DISCOVERY_SUCC, _, _, _))
.WillRepeatedly(ActionOfSendRequestForOnDiscoverySuccess);
EXPECT_CALL(*self, SendRequest(CLIENT_DISCOVERY_FAIL, _, _, _))
.WillRepeatedly(ActionOfSendRequestForOnDiscoveryFailed);
EXPECT_CALL(*self, SendRequest(CLIENT_PUBLISH_SUCC, _, _, _))
.WillRepeatedly(ActionOfSendRequestForOnPublishSuccess);
EXPECT_CALL(*self, SendRequest(CLIENT_PUBLISH_FAIL, _, _, _))
.WillRepeatedly(ActionOfSendRequestForOnPublishFail);
}
sptr<RemoteObjectMock> RemoteObjectMock::Get()
@ -94,56 +84,4 @@ bool RemoteObjectMock::GetResult(uint32_t code, const DeviceInfo *deviceInfo, in
return false;
}
return true;
}
int RemoteObjectMock::ActionOfSendRequestForOnDeviceFound(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
DISC_LOGI(DISC_TEST, "code=%{public}u", code);
Get()->code_ = code;
Get()->descriptor_ = data.ReadInterfaceToken();
return memcpy_s(&Get()->deviceInfo_, sizeof(DeviceInfo), data.ReadBuffer(sizeof(DeviceInfo)), sizeof(DeviceInfo));
}
int RemoteObjectMock::ActionOfSendRequestForOnDiscoveryFailed(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
DISC_LOGI(DISC_TEST, "code=%{public}u", code);
Get()->code_ = code;
Get()->descriptor_ = data.ReadInterfaceToken();
Get()->subscribeId_ = data.ReadInt32();
Get()->reason_ = data.ReadInt32();
return 0;
}
int RemoteObjectMock::ActionOfSendRequestForOnDiscoverySuccess(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
DISC_LOGI(DISC_TEST, "code=%{public}u", code);
Get()->code_ = code;
Get()->descriptor_ = data.ReadInterfaceToken();
Get()->subscribeId_ = data.ReadInt32();
return 0;
}
int RemoteObjectMock::ActionOfSendRequestForOnPublishSuccess(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
DISC_LOGI(DISC_TEST, "code=%{public}u", code);
Get()->code_ = code;
Get()->descriptor_ = data.ReadInterfaceToken();
Get()->publishId_ = data.ReadInt32();
return 0;
}
int RemoteObjectMock::ActionOfSendRequestForOnPublishFail(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
DISC_LOGI(DISC_TEST, "code=%{public}u", code);
Get()->code_ = code;
Get()->descriptor_ = data.ReadInterfaceToken();
Get()->publishId_ = data.ReadInt32();
Get()->reason_ = data.ReadInt32();
return 0;
}
}

View File

@ -56,17 +56,6 @@ public:
bool GetResult(uint32_t code, const DeviceInfo *deviceInfo = nullptr, int publishId = 0, int subscribeId = 0,
int reason = 0);
static int ActionOfSendRequestForOnDeviceFound(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option);
static int ActionOfSendRequestForOnDiscoveryFailed(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option);
static int ActionOfSendRequestForOnDiscoverySuccess(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option);
static int ActionOfSendRequestForOnPublishSuccess(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option);
static int ActionOfSendRequestForOnPublishFail(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option);
private:
std::u16string descriptor_;
uint32_t code_ {};

View File

@ -85,45 +85,10 @@ ohos_unittest("DiscManagerMockTest") {
]
}
ohos_unittest("DiscManagerServerTest") {
module_out_path = module_output_path
sources = [
"$dsoftbus_core_path/discovery/manager/src/softbus_disc_server.c",
"softbus_disc_server_mock.cpp",
"softbus_disc_server_test.cpp",
]
include_dirs = [
"$dsoftbus_core_path/common/dfx/hisysevent_adapter/include",
"$dsoftbus_core_path/common/dfx/hidumper_adapter/include",
"$dsoftbus_core_path/common/include",
"$dsoftbus_core_path/discovery/ble/dispatcher/include",
"$dsoftbus_core_path/discovery/coap/interface",
"$dsoftbus_core_path/discovery/interface",
"$dsoftbus_core_path/discovery/ipc/include",
"$dsoftbus_core_path/discovery/manager/include",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$softbus_adapter_common/include",
]
deps = [
"$dsoftbus_root_path/adapter:softbus_adapter",
"$dsoftbus_root_path/core/common:softbus_utils",
]
external_deps = [
"googletest:gmock",
"googletest:gtest_main",
"hilog:libhilog",
]
}
group("unittest") {
testonly = true
deps = [
":DiscManagerMockTest",
":DiscManagerServerTest",
":DiscManagerTest",
]
}

View File

@ -1,83 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "softbus_disc_server_mock.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
DiscMock::DiscMock()
{
mock.store(this);
}
DiscMock::~DiscMock()
{
mock.store(nullptr);
}
extern "C" {
int32_t DiscPublishService(const char *packageName, const PublishInfo *info)
{
return DiscMock::GetDiscMockInterface()->DiscPublishService(packageName, info);
}
int32_t DiscUnPublishService(const char *packageName, int32_t publishId)
{
return DiscMock::GetDiscMockInterface()->DiscUnPublishService(packageName, publishId);
}
int32_t DiscStartDiscovery(const char *packageName, const SubscribeInfo *info, const IServerDiscInnerCallback *cb)
{
return DiscMock::GetDiscMockInterface()->DiscStartDiscovery(packageName, info, cb);
}
int32_t DiscStopDiscovery(const char *packageName, int32_t subscribeId)
{
return DiscMock::GetDiscMockInterface()->DiscStopDiscovery(packageName, subscribeId);
}
int32_t ClientIpcOnPublishFail(const char *pkgName, int32_t publishId, int32_t reason)
{
return DiscMock::GetDiscMockInterface()->ClientIpcOnPublishFail(pkgName, publishId, reason);
}
int32_t ClientIpcOnPublishSuccess(const char *pkgName, int32_t publishId)
{
return DiscMock::GetDiscMockInterface()->ClientIpcOnPublishSuccess(pkgName, publishId);
}
int32_t ClientIpcOnDiscoverFailed(const char *pkgName, int32_t subscribeId, int32_t failReason)
{
return DiscMock::GetDiscMockInterface()->ClientIpcOnDiscoverFailed(pkgName, subscribeId, failReason);
}
int32_t ClientIpcDiscoverySuccess(const char *pkgName, int32_t subscribeId)
{
return DiscMock::GetDiscMockInterface()->ClientIpcDiscoverySuccess(pkgName, subscribeId);
}
int32_t SoftbusReportDiscFault(SoftBusDiscMedium medium, int32_t errCode)
{
return DiscMock::GetDiscMockInterface()->SoftbusReportDiscFault(medium, errCode);
}
int32_t ClientIpcOnDeviceFound(const char *pkgName, const DeviceInfo *device, const InnerDeviceInfoAddtions *additions)
{
return DiscMock::GetDiscMockInterface()->ClientIpcOnDeviceFound(pkgName, device, additions);
}
}
} // namespace OHOS

View File

@ -1,73 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOFTBUS_DISC_SERVER_MOCK_H
#define SOFTBUS_DISC_SERVER_MOCK_H
#include <atomic>
#include "disc_manager.h"
#include "gmock/gmock.h"
#include "softbus_common.h"
#include "softbus_hisysevt_discreporter.h"
namespace OHOS {
class DiscMockInterface {
public:
DiscMockInterface() {}
virtual ~DiscMockInterface() {}
virtual int32_t DiscPublishService(const char *packageName, const PublishInfo *info) = 0;
virtual int32_t DiscUnPublishService(const char *packageName, int32_t publishId) = 0;
virtual int32_t DiscStartDiscovery(const char *packageName, const SubscribeInfo *info,
const IServerDiscInnerCallback *cb) = 0;
virtual int32_t DiscStopDiscovery(const char *packageName, int32_t subscribeId) = 0;
virtual int32_t ClientIpcOnPublishFail(const char *pkgName, int32_t publishId, int32_t reason) = 0;
virtual int32_t ClientIpcOnPublishSuccess(const char *pkgName, int32_t publishId) = 0;
virtual int32_t ClientIpcOnDiscoverFailed(const char *pkgName, int32_t subscribeId, int32_t failReason) = 0;
virtual int32_t ClientIpcDiscoverySuccess(const char *pkgName, int32_t subscribeId) = 0;
virtual int32_t SoftbusReportDiscFault(SoftBusDiscMedium medium, int32_t errCode) = 0;
virtual int32_t ClientIpcOnDeviceFound(const char *pkgName, const DeviceInfo *device,
const InnerDeviceInfoAddtions *additions) = 0;
};
class DiscMock : public DiscMockInterface {
public:
static DiscMock* GetDiscMockInterface()
{
return mock.load();
}
DiscMock();
~DiscMock() override;
MOCK_METHOD(int32_t, DiscPublishService, (const char *packageName, const PublishInfo *info), (override));
MOCK_METHOD(int32_t, DiscUnPublishService, (const char *packageName, int32_t publishId), (override));
MOCK_METHOD(int32_t, DiscStartDiscovery,
(const char *packageName, const SubscribeInfo *info, const IServerDiscInnerCallback *cb), (override));
MOCK_METHOD(int32_t, DiscStopDiscovery, (const char *packageName, int32_t subscribeId), (override));
MOCK_METHOD(int32_t, ClientIpcOnPublishFail, (const char *pkgName, int32_t publishId, int32_t reason), (override));
MOCK_METHOD(int32_t, ClientIpcOnPublishSuccess, (const char *pkgName, int32_t publishId), (override));
MOCK_METHOD(int32_t, ClientIpcOnDiscoverFailed,
(const char *pkgName, int32_t subscribeId, int32_t failReason), (override));
MOCK_METHOD(int32_t, ClientIpcDiscoverySuccess, (const char *pkgName, int32_t subscribeId), (override));
MOCK_METHOD(int32_t, SoftbusReportDiscFault, (SoftBusDiscMedium medium, int32_t errCode), (override));
MOCK_METHOD(int32_t, ClientIpcOnDeviceFound,
(const char *pkgName, const DeviceInfo *device, const InnerDeviceInfoAddtions *additions), (override));
private:
static inline std::atomic<DiscMock*> mock = nullptr;
};
} // namespace OHOS
#endif // SOFTBUS_DISC_SERVER_MOCK_H

View File

@ -1,209 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <securec.h>
#include "disc_log.h"
#include "softbus_common.h"
#include "softbus_disc_server.h"
#include "softbus_disc_server_mock.h"
#include "softbus_errcode.h"
using namespace testing;
using namespace testing::ext;
using testing::Return;
namespace OHOS {
class DiscManagerServerTest : public testing::Test {
public:
static void SetUpTestCase()
{}
static void TearDownTestCase()
{}
void SetUp()
{}
void TearDown()
{}
};
/*
* @tc.name: DiscIpcPublishServiceTest
* @tc.desc: Test the invalid parameter input and normal flow of the DiscIpcPublishService function
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscManagerServerTest, DiscIpcPublishServiceTest, TestSize.Level1)
{
DISC_LOGI(DISC_TEST, "DiscIpcPublishServiceTest start");
PublishInfo publishInfo;
(void)memset_s(&publishInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo));
const char *packageName = "packageName";
EXPECT_EQ(DiscIpcPublishService(nullptr, &publishInfo), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(DiscIpcPublishService(packageName, nullptr), SOFTBUS_INVALID_PARAM);
DiscMock discMock;
EXPECT_CALL(discMock, ClientIpcOnPublishFail).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, ClientIpcOnPublishSuccess).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, SoftbusReportDiscFault).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, DiscPublishService).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
EXPECT_EQ(DiscIpcPublishService(packageName, &publishInfo), SOFTBUS_INVALID_PARAM);
EXPECT_CALL(discMock, DiscPublishService).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_EQ(DiscIpcPublishService(packageName, &publishInfo), SOFTBUS_OK);
DISC_LOGI(DISC_TEST, "DiscIpcPublishServiceTest end");
}
/*
* @tc.name: DiscIpcUnPublishServiceTest
* @tc.desc: Test the invalid parameter input and normal flow of the DiscIpcUnPublishService function
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscManagerServerTest, DiscIpcUnPublishServiceTest, TestSize.Level1)
{
DISC_LOGI(DISC_TEST, "DiscIpcUnPublishServiceTest start");
DiscMock discMock;
EXPECT_CALL(discMock, DiscUnPublishService).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
EXPECT_EQ(DiscIpcUnPublishService(nullptr, 0), SOFTBUS_INVALID_PARAM);
EXPECT_CALL(discMock, DiscUnPublishService).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_EQ(DiscIpcUnPublishService(nullptr, 0), SOFTBUS_OK);
DISC_LOGI(DISC_TEST, "DiscIpcUnPublishServiceTest end");
}
/*
* @tc.name: DiscIpcStartDiscoveryTest
* @tc.desc: Test the invalid parameter input and normal flow of the DiscIpcStartDiscovery function
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscManagerServerTest, DiscIpcStartDiscoveryTest, TestSize.Level1)
{
DISC_LOGI(DISC_TEST, "DiscIpcStartDiscoveryTest start");
SubscribeInfo subscribeInfo;
(void)memset_s(&subscribeInfo, sizeof(subscribeInfo), 0, sizeof(subscribeInfo));
const char *packageName = "packageName";
DiscMock discMock;
EXPECT_EQ(DiscIpcStartDiscovery(nullptr, &subscribeInfo), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(DiscIpcStartDiscovery(packageName, nullptr), SOFTBUS_INVALID_PARAM);
EXPECT_CALL(discMock, ClientIpcOnDiscoverFailed).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, ClientIpcDiscoverySuccess).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, SoftbusReportDiscFault).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, ClientIpcOnDeviceFound).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, DiscStartDiscovery).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_EQ(DiscIpcStartDiscovery(packageName, &subscribeInfo), SOFTBUS_OK);
EXPECT_CALL(discMock, DiscStartDiscovery).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_EQ(DiscIpcStartDiscovery(packageName, &subscribeInfo), SOFTBUS_OK);
DISC_LOGI(DISC_TEST, "DiscIpcStartDiscoveryTest end");
}
/*
* @tc.name: DiscIpcStopDiscoveryTest
* @tc.desc: Test the invalid parameter input and normal flow of the DiscIpcStopDiscovery function
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscManagerServerTest, DiscIpcStopDiscoveryTest, TestSize.Level1)
{
DISC_LOGI(DISC_TEST, "DiscIpcStopDiscoveryTest start");
DiscMock discMock;
EXPECT_CALL(discMock, DiscStopDiscovery).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
EXPECT_EQ(DiscIpcStopDiscovery(nullptr, 0), SOFTBUS_INVALID_PARAM);
EXPECT_CALL(discMock, DiscStopDiscovery).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_EQ(DiscIpcStopDiscovery(nullptr, 0), SOFTBUS_OK);
DISC_LOGI(DISC_TEST, "DiscIpcStopDiscoveryTest end");
}
/*
* @tc.name: PublishErroCodeProcessTest
* @tc.desc: Test the PublishErroCodeProcess function by run DiscIpcPublishService function
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscManagerServerTest, PublishErroCodeProcessTest, TestSize.Level1)
{
DISC_LOGI(DISC_TEST, "PublishErroCodeProcessTest start");
PublishInfo publishInfo;
(void)memset_s(&publishInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo));
const char *packageName = "packageName";
DiscMock discMock;
EXPECT_CALL(discMock, ClientIpcOnPublishFail).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, ClientIpcOnPublishSuccess).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, SoftbusReportDiscFault).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, DiscPublishService).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
EXPECT_EQ(DiscIpcPublishService(packageName, &publishInfo), SOFTBUS_INVALID_PARAM);
EXPECT_CALL(discMock,
DiscPublishService).WillRepeatedly(Return(SOFTBUS_DISCOVER_MANAGER_INVALID_MEDIUM));
EXPECT_EQ(DiscIpcPublishService(packageName, &publishInfo), SOFTBUS_DISCOVER_MANAGER_INVALID_MEDIUM);
DISC_LOGI(DISC_TEST, "PublishErroCodeProcessTest end");
}
/*
* @tc.name: DiscoveryErroCodeProcessTest
* @tc.desc: Test the DiscoveryErroCodeProcess function by run DiscIpcStartDiscovery function
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscManagerServerTest, DiscoveryErroCodeProcessTest, TestSize.Level1)
{
DISC_LOGI(DISC_TEST, "DiscoveryErroCodeProcessTest start");
SubscribeInfo subscribeInfo;
(void)memset_s(&subscribeInfo, sizeof(subscribeInfo), 0, sizeof(subscribeInfo));
const char *packageName = "packageName";
DiscMock discMock;
EXPECT_CALL(discMock, ClientIpcOnDiscoverFailed).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, ClientIpcDiscoverySuccess).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, SoftbusReportDiscFault).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, ClientIpcOnDeviceFound).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, DiscStartDiscovery).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
EXPECT_EQ(DiscIpcStartDiscovery(packageName, &subscribeInfo), SOFTBUS_INVALID_PARAM);
EXPECT_CALL(discMock,
DiscStartDiscovery).WillRepeatedly(Return(SOFTBUS_DISCOVER_MANAGER_INVALID_MEDIUM));
EXPECT_EQ(DiscIpcStartDiscovery(packageName, &subscribeInfo), SOFTBUS_DISCOVER_MANAGER_INVALID_MEDIUM);
DISC_LOGI(DISC_TEST, "DiscoveryErroCodeProcessTest end");
}
/*
* @tc.name: ConvertDiscTypeTest
* @tc.desc: Test the ConvertDiscTypeTest function by run DiscIpcPublishService function
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscManagerServerTest, ConvertDiscTypeTest, TestSize.Level1)
{
DISC_LOGI(DISC_TEST, "ConvertDiscTypeTest start");
PublishInfo deviceinfo1 {
.medium = COAP,
.publishId = 0,
};
PublishInfo deviceinfo2 {
.medium = BLE,
.publishId = 0,
};
PublishInfo deviceinfo3 {
.medium = USB,
.publishId = 0,
};
const char *packageName = "packageName";
DiscMock discMock;
EXPECT_CALL(discMock, ClientIpcOnPublishFail).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, ClientIpcOnPublishSuccess).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, SoftbusReportDiscFault).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(discMock, DiscPublishService).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
EXPECT_EQ(DiscIpcPublishService(packageName, &deviceinfo1), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(DiscIpcPublishService(packageName, &deviceinfo2), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(DiscIpcPublishService(packageName, &deviceinfo3), SOFTBUS_INVALID_PARAM);
DISC_LOGI(DISC_TEST, "ConvertDiscTypeTest end");
}
} // namespace OHOS

View File

@ -30,8 +30,6 @@ constexpr int32_t SOFTBUS_SERVER_SA_ID = 4700;
const std::u16string SOFTBUS_SERVER_STUB_INTERFACE_TOKEN = u"OHOS.ISoftBusServer";
const std::vector<SoftBusFuncId> CODE_LIST = {
MANAGE_REGISTER_SERVICE,
SERVER_PUBLISH_SERVICE,
SERVER_UNPUBLISH_SERVICE,
SERVER_CREATE_SESSION_SERVER,
SERVER_REMOVE_SESSION_SERVER,
SERVER_OPEN_SESSION,
@ -45,8 +43,6 @@ const std::vector<SoftBusFuncId> CODE_LIST = {
SERVER_REMOVE_PERMISSION,
SERVER_STREAM_STATS,
SERVER_GET_SOFTBUS_SPEC_OBJECT,
SERVER_START_DISCOVERY,
SERVER_STOP_DISCOVERY,
SERVER_JOIN_LNN,
SERVER_JOIN_METANODE,
SERVER_LEAVE_LNN,

View File

@ -41,10 +41,6 @@
#define SIZE_NUM_FIVE 5
namespace OHOS {
constexpr int32_t SOFTBUS_FUZZ_TEST_START_DISCOVERY_SUB_SCRIBE_ID = 5;
constexpr int32_t SOFTBUS_FUZZ_TEST_START_DISCOVERY_MODE = 6;
constexpr int32_t SOFTBUS_FUZZ_TEST_START_DISCOVERY_MEDIUM = 7;
constexpr int32_t SOFTBUS_FUZZ_TEST_START_DISCOVERY_FREQ = 8;
constexpr int32_t SOFTBUS_FUZZ_TEST_ADDR_TYPE_LEN = 160;
const std::u16string SOFTBUS_SERVER_STUB_INTERFACE_TOKEN = u"OHOS.ISoftBusServer";
@ -52,9 +48,7 @@ const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken";
enum SoftBusFuncId {
MANAGE_REGISTER_SERVICE = 0,
SERVER_PUBLISH_SERVICE = 128,
SERVER_UNPUBLISH_SERVICE,
SERVER_CREATE_SESSION_SERVER,
SERVER_CREATE_SESSION_SERVER = 128,
SERVER_REMOVE_SESSION_SERVER,
SERVER_OPEN_SESSION,
SERVER_OPEN_AUTH_SESSION,
@ -66,8 +60,6 @@ enum SoftBusFuncId {
SERVER_REMOVE_PERMISSION,
SERVER_STREAM_STATS,
SERVER_GET_SOFTBUS_SPEC_OBJECT,
SERVER_START_DISCOVERY,
SERVER_STOP_DISCOVERY,
SERVER_JOIN_LNN,
SERVER_JOIN_METANODE,
SERVER_LEAVE_LNN,
@ -115,94 +107,6 @@ static bool SendRequestByCommand(const uint8_t *data, size_t size, uint32_t comm
return object->SendRequest(command, datas, reply, option) == ERR_NONE;
}
static void PublishInfoProc(const uint8_t *data, MessageParcel &datas)
{
uint32_t offset = 0;
char pkgName[INPUT_NAME_SIZE_MAX] = "distribdata_test";
if (memcpy_s(pkgName, INPUT_NAME_SIZE_MAX, reinterpret_cast<const char *>(data), INPUT_NAME_SIZE_MAX - 1) != EOK) {
return;
}
pkgName[INPUT_NAME_SIZE_MAX - 1] = '\0';
offset = INPUT_NAME_SIZE_MAX;
int32_t publishId = *reinterpret_cast<const int32_t *>(data + offset);
offset += sizeof(int32_t);
int32_t mode = *reinterpret_cast<const int32_t *>(data + offset);
offset += sizeof(int32_t);
int32_t medium = *reinterpret_cast<const int32_t *>(data + offset);
offset += sizeof(int32_t);
int32_t freq = *reinterpret_cast<const int32_t *>(data + offset);
offset += sizeof(int32_t);
char capability[INPUT_NAME_SIZE_MAX] = "";
if (memcpy_s(capability, INPUT_NAME_SIZE_MAX, reinterpret_cast<const char *>(data),
INPUT_NAME_SIZE_MAX - 1) != EOK) {
return;
}
capability[INPUT_NAME_SIZE_MAX - 1] = '\0';
uint32_t dataLen = *reinterpret_cast<const uint32_t *>(data + offset);
offset += sizeof(uint32_t);
char capabilityData[INPUT_NAME_SIZE_MAX] = "";
if (memcpy_s(capabilityData, INPUT_NAME_SIZE_MAX, reinterpret_cast<const char *>(data),
INPUT_NAME_SIZE_MAX) != EOK) {
return;
}
capabilityData[INPUT_NAME_SIZE_MAX - 1] = '\0';
datas.WriteCString(pkgName);
datas.WriteInt32(publishId);
datas.WriteInt32(mode);
datas.WriteInt32(medium);
datas.WriteInt32(freq);
datas.WriteCString(capability);
datas.WriteUint32(dataLen);
datas.WriteCString(capabilityData);
}
bool PublishServiceFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX * SIZE_NUM_THREE +
sizeof(int32_t) * SIZE_NUM_FOUR + sizeof(uint32_t)) {
return false;
}
MessageParcel datas;
PublishInfoProc(data, datas);
MessageParcel reply;
sptr<OHOS::SoftBusServerStub> SoftBusServer = new OHOS::SoftBusServer(SOFTBUS_SERVER_SA_ID, true);
if (SoftBusServer == nullptr) {
return false;
}
SoftBusServer->PublishServiceInner(datas, reply);
return true;
}
bool UnPublishServiceFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || data == nullptr || size < INPUT_NAME_SIZE_MAX + sizeof(int32_t)) {
return false;
}
uint32_t offset = 0;
char pkgName[INPUT_NAME_SIZE_MAX] = "distribdata_test";
if (memcpy_s(pkgName, INPUT_NAME_SIZE_MAX, reinterpret_cast<const char *>(data), INPUT_NAME_SIZE_MAX - 1) != EOK) {
return false;
}
pkgName[INPUT_NAME_SIZE_MAX - 1] = '\0';
offset = INPUT_NAME_SIZE_MAX;
int32_t publishId = *reinterpret_cast<const int32_t *>(data + offset);
MessageParcel datas;
datas.WriteCString(pkgName);
datas.WriteInt32(publishId);
MessageParcel reply;
sptr<OHOS::SoftBusServerStub> SoftBusServer = new OHOS::SoftBusServer(SOFTBUS_SERVER_SA_ID, true);
if (SoftBusServer == nullptr) {
return false;
}
SoftBusServer->UnpublishServiceInner(datas, reply);
return true;
}
bool CreateSessionServerFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
@ -566,62 +470,6 @@ bool GetSoftbusSpecObjectFuzzTest(const uint8_t *data, size_t size)
return SendRequestByCommand(data, size, SERVER_GET_SOFTBUS_SPEC_OBJECT);
}
bool StartDiscoveryFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr) {
return false;
}
int32_t subscribeId = SOFTBUS_FUZZ_TEST_START_DISCOVERY_SUB_SCRIBE_ID;
int32_t mode = SOFTBUS_FUZZ_TEST_START_DISCOVERY_MODE;
int32_t medium = SOFTBUS_FUZZ_TEST_START_DISCOVERY_MEDIUM;
int32_t freq = SOFTBUS_FUZZ_TEST_START_DISCOVERY_FREQ;
bool boolNum = true;
MessageParcel datas;
datas.WriteBuffer(data, size);
datas.WriteInt32(subscribeId);
datas.WriteInt32(mode);
datas.WriteInt32(medium);
datas.WriteInt32(freq);
datas.WriteBool(boolNum);
datas.WriteInt32(freq);
datas.RewindRead(0);
MessageParcel reply;
sptr<OHOS::SoftBusServerStub> SoftBusServer = new OHOS::SoftBusServer(SOFTBUS_SERVER_SA_ID, true);
if (SoftBusServer == nullptr) {
return false;
}
SoftBusServer->StartDiscoveryInner(datas, reply);
return true;
}
bool StopDiscoveryFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
if (object == nullptr || size < INPUT_NAME_SIZE_MAX + sizeof(int32_t)) {
return false;
}
char pkgName[INPUT_NAME_SIZE_MAX] = "";
uint32_t offset = 0;
if (memcpy_s(pkgName, INPUT_NAME_SIZE_MAX, reinterpret_cast<const char *>(data),
INPUT_NAME_SIZE_MAX - 1) != EOK) {
return false;
}
pkgName[INPUT_NAME_SIZE_MAX - 1] = '\0';
offset += INPUT_NAME_SIZE_MAX;
int32_t publishId = *reinterpret_cast<const int32_t *>(data + offset);
MessageParcel datas;
datas.WriteCString(pkgName);
datas.WriteInt32(publishId);
MessageParcel reply;
sptr<OHOS::SoftBusServerStub> SoftBusServer = new OHOS::SoftBusServer(SOFTBUS_SERVER_SA_ID, true);
if (SoftBusServer == nullptr) {
return false;
}
SoftBusServer->StopDiscoveryInner(datas, reply);
return true;
}
bool JoinLNNFuzzTest(const uint8_t *data, size_t size)
{
sptr<IRemoteObject> object = GetRemoteObject();
@ -1459,8 +1307,6 @@ bool RunFuzzTestCase(const uint8_t *data, size_t size)
OHOS::RemovePermissionFuzzTest(data, size);
OHOS::StreamStatsFuzzTest(data, size);
OHOS::GetSoftbusSpecObjectFuzzTest(data, size);
OHOS::StartDiscoveryFuzzTest(data, size);
OHOS::StopDiscoveryFuzzTest(data, size);
OHOS::JoinLNNFuzzTest(data, size);
OHOS::JoinMetaNodeFuzzTest(data, size);
OHOS::LeaveLNNFuzzTest(data, size);
@ -1480,8 +1326,6 @@ bool RunFuzzTestCase(const uint8_t *data, size_t size)
OHOS::GetAllMetaNodeInfoFuzzTest(data, size);
OHOS::ShiftLNNGearFuzzTest(data, size);
OHOS::RippleStatsFuzzTest(data, size);
OHOS::PublishServiceFuzzTest(data, size);
OHOS::UnPublishServiceFuzzTest(data, size);
OHOS::SoftbusRegisterServiceFuzzTest(data, size);
OHOS::CheckOpenSessionPermissionFuzzTest(data, size);
OHOS::EvaLuateQosInnerFuzzTest(data, size);

View File

@ -258,86 +258,6 @@ HWTEST_F(SoftbusServerStubTest, SoftbusServerStubTest004, TestSize.Level1)
EXPECT_EQ(Security::AccessToken::PERMISSION_DENIED, ret);
}
/**
* @tc.name: SoftbusServerStubTest005
* @tc.desc: Verify the Start and Stop DiscoveryInner function.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftbusServerStubTest, SoftbusServerStubTest005, TestSize.Level1)
{
sptr<OHOS::SoftBusServerStub> softBusServer = new OHOS::SoftBusServer(SOFTBUS_SERVER_SA_ID, true);
ASSERT_NE(nullptr, softBusServer);
softBusServer->InitMemberFuncMap();
softBusServer->InitMemberPermissionMap();
uint32_t ipcCode = SERVER_OPEN_SESSION;
SoftbusReportPermissionFaultEvt(ipcCode);
char test[10] = "test";
int32_t subscribeId = 5;
int32_t mode = 85;
int32_t medium = 4;
int32_t freq = 3;
bool boolNum = true;
unsigned int dataLen = 0;
MessageParcel datas;
MessageParcel reply;
datas.WriteCString(test);
datas.WriteInt32(subscribeId);
datas.WriteInt32(mode);
datas.WriteInt32(medium);
datas.WriteInt32(freq);
datas.WriteBool(boolNum);
datas.WriteBool(boolNum);
datas.WriteCString(test);
datas.WriteUint32(dataLen);
int32_t ret = softBusServer->StartDiscoveryInner(datas, reply);
EXPECT_EQ(SOFTBUS_OK, ret);
datas.WriteCString(test);
datas.WriteInt32(subscribeId);
ret = softBusServer->StopDiscoveryInner(datas, reply);
EXPECT_EQ(SOFTBUS_OK, ret);
}
/**
* @tc.name: SoftbusServerStubTest006
* @tc.desc: Verify the Publish and Unpublish Service Inner function.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftbusServerStubTest, SoftbusServerStubTest006, TestSize.Level1)
{
sptr<OHOS::SoftBusServerStub> softBusServer = new OHOS::SoftBusServer(SOFTBUS_SERVER_SA_ID, true);
ASSERT_NE(nullptr, softBusServer);
char test[10] = "test";
int32_t publishId = 5;
int32_t mode = 85;
int32_t medium = 4;
int32_t freq = 3;
unsigned int dataLen = 0;
MessageParcel datas;
MessageParcel reply;
datas.WriteCString(test);
datas.WriteInt32(publishId);
datas.WriteInt32(mode);
datas.WriteInt32(medium);
datas.WriteInt32(freq);
datas.WriteCString(test);
datas.WriteUint32(dataLen);
int32_t ret = softBusServer->PublishServiceInner(datas, reply);
EXPECT_EQ(SOFTBUS_OK, ret);
datas.WriteCString(test);
datas.WriteInt32(publishId);
ret = softBusServer->UnpublishServiceInner(datas, reply);
EXPECT_EQ(SOFTBUS_OK, ret);
}
/**
* @tc.name: SoftbusServerStubTest007
* @tc.desc: Verify the SoftbusRegisterServiceInner function.

View File

@ -49,7 +49,6 @@ HWTEST_F(TransClientProxyStandardTest, TransClientProxyStandardTest001, TestSize
{
#define TEST_INVALID 0
int32_t ret;
DeviceInfo device;
static const uint32_t SOFTBUS_SA_ID = 4700;
sptr<ISystemAbilityManager> saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
@ -58,16 +57,7 @@ HWTEST_F(TransClientProxyStandardTest, TransClientProxyStandardTest001, TestSize
sptr<TransClientProxy> clientProxy = new (std::nothrow) TransClientProxy(remoteObject);
ASSERT_TRUE(clientProxy != nullptr);
clientProxy->OnDeviceFound(&device);
int tmp = TEST_INVALID;
clientProxy->OnDiscoverFailed(tmp, tmp);
clientProxy->OnDiscoverySuccess(tmp);
clientProxy->OnPublishSuccess(tmp);
clientProxy->OnPublishFail(tmp, tmp);
void *addr = nullptr;
uint32_t addrTypeLen = TEST_INVALID;

View File

@ -24,7 +24,6 @@
*/
#include <stdint.h>
#include "discovery_service.h"
#include "softbus_bus_center.h"
#include "softbus_common.h"

View File

@ -20,7 +20,6 @@
#include <sys/time.h>
#include <unistd.h>
#include "discovery_service.h"
#include "softbus_access_token_test.h"
#include "softbus_adapter_mem.h"
#include "softbus_bus_center.h"

View File

@ -19,7 +19,6 @@
#include <sys/time.h>
#include <unistd.h>
#include "discovery_service.h"
#include "softbus_access_token_test.h"
#include "softbus_bus_center.h"
#include "softbus_server_frame.h"

View File

@ -19,7 +19,6 @@
#include <sys/time.h>
#include <unistd.h>
#include "discovery_service.h"
#include "softbus_access_token_test.h"
#include "softbus_bus_center.h"

View File

@ -18,13 +18,3 @@ group("benchmarktest") {
testonly = true
deps = [ "benchmarktest:benchmarktest" ]
}
group("fuzztest") {
testonly = true
deps = [ "fuzztest:fuzztest" ]
}
group("unittest") {
testonly = true
deps = [ "unittest:unittest" ]
}

View File

@ -1,57 +0,0 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
import("../../../../dsoftbus.gni")
module_output_path = "dsoftbus/discovery"
dsoftbus_root_path = "../../../.."
ohos_unittest("disc_account_test") {
module_out_path = module_output_path
sources = [ "disc_account_test.cpp" ]
include_dirs = [
"$dsoftbus_root_path/core/common/inner_communication",
"$dsoftbus_root_path/adapter/common/include",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/interfaces/inner_kits/transport",
"$dsoftbus_root_path/sdk/discovery/include",
"//commonlibrary/c_utils/base/include",
"//third_party/bounds_checking_function/include",
"unittest/common/",
"$dsoftbus_root_path/sdk/discovery/manager/include",
]
deps = [
"$dsoftbus_root_path/core/common:softbus_utils",
"$dsoftbus_root_path/sdk:softbus_client",
"//third_party/bounds_checking_function:libsec_shared",
"//third_party/bounds_checking_function:libsec_static",
"//third_party/googletest:gtest_main",
]
if (is_standard_system) {
external_deps = [
"c_utils:utils",
"hilog:libhilog",
]
} else {
external_deps = [
"c_utils:utils",
"hilog:libhilog",
]
}
}
group("unittest") {
testonly = true
deps = [ ":disc_account_test" ]
}

View File

@ -1,236 +0,0 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdio>
#include <ctime>
#include <gtest/gtest.h>
#include <securec.h>
#include <sys/time.h>
#include <unistd.h>
#include "discovery_service.h"
#include "inner_session.h"
#include "session.h"
#include "softbus_utils.h"
using namespace testing::ext;
namespace OHOS {
int32_t g_testWay = -1;
int32_t g_accountWay = -1;
int32_t g_publishId = 1;
int32_t g_subscribeId = 1;
enum TEST_WAY {
STARTDISCOVERY_WAY = 0,
PUBLISHSERVICE_WAY
};
enum ACCOUNT_MODE {
SAMEACCOUNT_TRUE = 0,
SAMEACCOUNT_FALSE
};
const char *g_pkgName = "com.objectstore.foundation";
bool g_state = false;
static void Wait(void);
ConnectionAddr g_addr;
ConnectionAddr g_addr1;
static SubscribeInfo g_sInfo = {
.subscribeId = g_subscribeId,
.medium = BLE,
.mode = DISCOVER_MODE_ACTIVE,
.freq = MID,
.capability = "dvKit",
.capabilityData = (unsigned char *)"capdata3",
.dataLen = sizeof("capdata3"),
.isSameAccount = false,
.isWakeRemote = false
};
static PublishInfo g_pInfo = {
.publishId = g_publishId,
.medium = BLE,
.mode = DISCOVER_MODE_PASSIVE,
.freq = MID,
.capability = "dvKit",
.capabilityData = (unsigned char *)"capdata4",
.dataLen = sizeof("capdata4")
};
static void TestDeviceFound(const DeviceInfo *device)
{
if (ConvertBtMacToStr(g_addr.info.ble.bleMac, 18, (const uint8_t *)&(device->addr[0].info.ble.bleMac[0]), 6) != 0) {
return;
}
if (strcmp(g_addr1.info.ble.bleMac, g_addr.info.ble.bleMac) != 0) {
strcpy_s(g_addr1.info.ble.bleMac, BT_MAC_LEN, g_addr.info.ble.bleMac);
printf("[client]TestDeviceFound\r\n");
g_state = true;
}
}
static void TestDiscoverFailed(int subscribeId, DiscoveryFailReason failReason)
{
printf("[test]TestDiscoverFailed\r\n");
}
static void TestDiscoverySuccess(int subscribeId)
{
printf("[test]TestDiscoverySuccess\r\n");
}
static void TestPublishSuccess(int publishId)
{
printf("[test]TestPublishSuccess\r\n");
}
static void TestPublishFail(int publishId, PublishFailReason reason)
{
printf("[test]TestPublishFail\r\n");
}
static IDiscoveryCallback g_subscribeCb = {
.OnDeviceFound = TestDeviceFound,
.OnDiscoverFailed = TestDiscoverFailed,
.OnDiscoverySuccess = TestDiscoverySuccess
};
static IPublishCallback g_publishCb = {
.OnPublishSuccess = TestPublishSuccess,
.OnPublishFail = TestPublishFail
};
class DiscAccountTest : public testing::Test {
public:
DiscAccountTest()
{}
~DiscAccountTest()
{}
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp() override
{}
void TearDown() override
{}
};
void DiscAccountTest::SetUpTestCase(void)
{
printf("********Ble Test Begin*********\r\n");
printf("* 0.discovery *\r\n");
printf("* 1.publish *\r\n");
printf("*******************************\r\n");
printf("input the num:");
if (scanf_s("%d", &g_testWay, sizeof(g_testWay)) < 0) {
printf("input error!\n");
}
getchar();
if (g_testWay == PUBLISHSERVICE_WAY) {
return;
}
printf("***********Account*************\r\n");
printf("* 0.true *\r\n");
printf("* 1.false *\r\n");
printf("*******************************\r\n");
printf("input the num:");
if (scanf_s("%d", &g_accountWay, sizeof(g_accountWay)) < 0) {
printf("input error!\n");
}
getchar();
if (g_accountWay == SAMEACCOUNT_TRUE) {
g_sInfo.isSameAccount = true;
return;
}
g_sInfo.isSameAccount = false;
}
void DiscAccountTest::TearDownTestCase(void)
{
if (g_testWay == STARTDISCOVERY_WAY) {
StopDiscovery(g_pkgName, g_subscribeId);
return;
}
UnPublishService(g_pkgName, g_publishId);
}
static void Wait(void)
{
printf("[test]wait enter...\r\n");
do {
sleep(1);
} while (!g_state);
printf("[test]wait end!\r\n");
g_state = false;
}
static int32_t TestPublishServer()
{
printf("[test]TestPublishServer enter\r\n");
g_pInfo.mode = DISCOVER_MODE_ACTIVE;
int32_t ret = PublishService(g_pkgName, &g_pInfo, &g_publishCb);
EXPECT_TRUE(ret == 0);
printf("[test]TestPublishServer end\r\n");
return ret;
}
static int32_t TestStartDiscovery()
{
printf("[test]TestStartDiscovery enter\r\n");
g_sInfo.mode = DISCOVER_MODE_ACTIVE;
int32_t ret = StartDiscovery(g_pkgName, &g_sInfo, &g_subscribeCb);
EXPECT_TRUE(ret == 0);
printf("[test]TestStartDiscovery end\r\n");
return ret;
}
/**
* @tc.name: StartDiscovery001
* @tc.desc: Verify wrong parameter
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscAccountTest, StartDiscovery001, TestSize.Level0)
{
if (g_testWay != STARTDISCOVERY_WAY) {
printf("[test]start dsicovery test skip...\r\n");
EXPECT_TRUE(0 == 0);
return;
}
int32_t ret = TestStartDiscovery();
EXPECT_TRUE(ret == 0);
Wait();
};
/**
* @tc.name: PublishServiceTest001
* @tc.desc: Verify wrong parameter
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DiscAccountTest, PublishServiceTest001, TestSize.Level0)
{
if (g_testWay != PUBLISHSERVICE_WAY) {
printf("[test]passive test skip...\r\n");
EXPECT_TRUE(0 == 0);
return;
}
int32_t ret = TestPublishServer();
EXPECT_TRUE(ret == 0);
Wait();
};
}

View File

@ -23,8 +23,6 @@ ohos_benchmarktest("DiscoveryTest") {
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/sdk/discovery/include",
"$dsoftbus_root_path/sdk/discovery/manager/include",
]
deps = [ "$dsoftbus_root_path/sdk:softbus_client" ]
external_deps = [

View File

@ -15,7 +15,6 @@
#include <benchmark/benchmark.h>
#include "accesstoken_kit.h"
#include "discovery_service.h"
#include "nativetoken_kit.h"
#include "softbus_bus_center.h"
#include "token_setproc.h"

View File

@ -1,17 +0,0 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
group("fuzztest") {
testonly = true
deps = [ "discoveryservice_fuzzer:DiscoveryServiceFuzzTest" ]
}

View File

@ -1,50 +0,0 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/ohos.gni")
import("//build/test.gni")
import("../../../../../dsoftbus.gni")
##############################fuzztest##########################################
dsoftbus_root_path = "../../../../.."
ohos_fuzztest("DiscoveryServiceFuzzTest") {
module_out_path = dsoftbus_fuzz_out_path
fuzz_config_file =
"$dsoftbus_root_path/tests/sdk/discovery/fuzztest/discoveryservice_fuzzer"
include_dirs = [
"$dsoftbus_root_path/adapter/common/include",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/core/common/inner_communication",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/sdk/discovery/include",
"$dsoftbus_root_path/sdk/discovery/manager/include",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
"-fstack-protector-strong",
]
sources = [ "discoveryservice_fuzzer.cpp" ]
deps = [
"$dsoftbus_root_path/adapter:softbus_adapter",
"$dsoftbus_root_path/sdk:softbus_client",
]
}

View File

@ -1,16 +0,0 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
FUZZ

View File

@ -1,136 +0,0 @@
/*
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "discoveryservice_fuzzer.h"
#include <cstddef>
#include <string>
#include "discovery_service.h"
#define MID_THRESHOLD (UINT8_MAX / FREQ_BUTT * 2)
#define HIGH_THRESHOLD (UINT8_MAX / FREQ_BUTT * 3)
#define SUPER_HIGH_THRESHOLD (UINT8_MAX / FREQ_BUTT * 4)
namespace OHOS {
static std::string TEST_PACKAGE_NAME = "TestPackageName";
static void TestPublishSuccess(int publicId) {}
static void TestPublishFail(int publishId, PublishFailReason reason) {}
static IPublishCallback g_publishCallback = {
.OnPublishSuccess = TestPublishSuccess,
.OnPublishFail = TestPublishFail,
};
static void TestDeviceFound(const DeviceInfo *device) {}
static void TestDiscoverFailed(int subscribeId, DiscoveryFailReason failReason) {}
static void TestDiscoverySuccess(int subscribeId) {}
static IDiscoveryCallback g_discoveryCallback = {
.OnDeviceFound = TestDeviceFound,
.OnDiscoverFailed = TestDiscoverFailed,
.OnDiscoverySuccess = TestDiscoverySuccess,
};
static PublishInfo g_publishInfo;
static DiscoverMode GenerateMode(uint8_t data)
{
if (data < UINT8_MAX / 2) {
return DISCOVER_MODE_ACTIVE;
}
return DISCOVER_MODE_PASSIVE;
}
static ExchangeMedium GenerateMedium(uint8_t data)
{
if (data < UINT8_MAX / MEDIUM_BUTT) {
return AUTO;
}
if (data < UINT8_MAX / MEDIUM_BUTT * 2) {
return BLE;
}
if (data < UINT8_MAX / MEDIUM_BUTT * 3) {
return COAP;
}
if (data < UINT8_MAX / MEDIUM_BUTT * 4) {
return USB;
}
return COAP1;
}
static ExchangeFreq GenerateFreq(uint8_t data)
{
if (data < UINT8_MAX / FREQ_BUTT) {
return LOW;
}
if (data < MID_THRESHOLD) {
return MID;
}
if (data < HIGH_THRESHOLD) {
return HIGH;
}
if (data < SUPER_HIGH_THRESHOLD) {
return SUPER_HIGH;
}
return EXTREME_HIGH;
}
static PublishInfo *GeneratePublishInfo(const uint8_t *data, size_t size)
{
if (size < sizeof(PublishInfo)) {
return &g_publishInfo;
}
g_publishInfo.publishId = *data++;
g_publishInfo.mode = GenerateMode(*data++);
g_publishInfo.medium = GenerateMedium(*data++);
g_publishInfo.freq = GenerateFreq(*data);
return &g_publishInfo;
}
static SubscribeInfo g_subscribeInfo;
static SubscribeInfo *GenerateSubscribeInfo(const uint8_t *data, size_t size)
{
if (size < sizeof(SubscribeInfo)) {
return &g_subscribeInfo;
}
g_subscribeInfo.subscribeId = *data++;
g_subscribeInfo.mode = GenerateMode(*data++);
g_subscribeInfo.medium = GenerateMedium(*data++);
g_subscribeInfo.freq = GenerateFreq(*data++);
g_subscribeInfo.isSameAccount = *data++;
g_subscribeInfo.isWakeRemote = *data;
return &g_subscribeInfo;
}
void DiscoveryServiceTest(const uint8_t* data, size_t size)
{
PublishService(TEST_PACKAGE_NAME.c_str(), GeneratePublishInfo(data, size), &g_publishCallback);
UnPublishService(TEST_PACKAGE_NAME.c_str(), *data);
StartDiscovery(TEST_PACKAGE_NAME.c_str(), GenerateSubscribeInfo(data, size), &g_discoveryCallback);
StopDiscovery(TEST_PACKAGE_NAME.c_str(), *data);
}
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
if (data == nullptr || size < sizeof(int32_t)) {
return 0;
}
OHOS::DiscoveryServiceTest(data, size);
return 0;
}

View File

@ -1,21 +0,0 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DISCOVERYSERVICE_FUZZER_H
#define DISCOVERYSERVICE_FUZZER_H
#define FUZZ_PROJECT_NAME "discoveryservice_fuzzer"
#endif // DISCOVERYSERVICE_FUZZER_H

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -1,33 +0,0 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/component/lite_component.gni")
import("../../../../dsoftbus.gni")
dsoftbus_root_path = "../../../.."
static_library("disc_test") {
sources = [ "discover_test.c" ]
include_dirs = [
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/core/frame/common/include",
]
deps =
[ "$dsoftbus_root_path/sdk/discovery/service:dsoftbus_disc_service_sdk" ]
cflags = [
"-Wall",
"-fPIC",
"-std=c99",
]
ldflags = [ "-fPIC" ]
}

View File

@ -1,322 +0,0 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <securec.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include "discovery_service.h"
#include "lwip/netif.h"
#include "lwip/netifapi.h"
#include "ohos_init.h"
#include "softbus_common.h"
#include "softbus_errcode.h"
#include "softbus_server_frame.h"
#define NET_WORK_NAME "wlan0"
#define TEST_CASE_NUM 10
#define MAXT_WAIT_COUNT 6
#define WIFI_CONFIG_INTERVAL 10
#define TEST_COUNT_INTREVAL 5
#define WAIT_SERVER_READY 5
#define MAX_TEST_COUNT 20
#define NSTACKX_MAX_IP_STRING_LEN 20
#define DISC_TEST_PKG_NAME "DISC_TEST"
static int32_t g_testSuccessCnt = 0;
static int GetSubscribeId(void)
{
static int32_t subscribeId = 0;
subscribeId++;
return subscribeId;
}
static int GetPublishId(void)
{
static int32_t publishId = 0;
publishId++;
return publishId;
}
static SubscribeInfo g_sInfo1 = {
.subscribeId = 1,
.medium = COAP,
.mode = DISCOVER_MODE_PASSIVE,
.freq = MID,
.capability = "ddmpCapability",
.capabilityData = (unsigned char *)"capdata3",
.dataLen = sizeof("capdata3"),
.isSameAccount = true,
.isWakeRemote = false
};
static SubscribeInfo g_sInfo2 = {
.subscribeId = 1,
.mode = DISCOVER_MODE_PASSIVE,
.medium = COAP,
.freq = MID,
.capability = "hicall",
.capabilityData = NULL,
.dataLen = 0,
.isSameAccount = true,
.isWakeRemote = false
};
static SubscribeInfo g_sInfo3 = {
.subscribeId = 1,
.mode = DISCOVER_MODE_ACTIVE,
.medium = COAP,
.freq = MID,
.capability = "ddmpCapability",
.capabilityData = NULL,
.dataLen = 0,
.isSameAccount = true,
.isWakeRemote = false
};
static PublishInfo g_pInfo1 = {
.publishId = 1,
.medium = COAP,
.mode = DISCOVER_MODE_PASSIVE,
.freq = MID,
.capability = "dvKit",
.capabilityData = (unsigned char *)"capdata4",
.dataLen = sizeof("capdata4")
};
static PublishInfo g_pInfo2 = {
.publishId = 1,
.mode = DISCOVER_MODE_ACTIVE,
.medium = COAP,
.freq = MID,
.capability = "dvKit",
.capabilityData = NULL,
.dataLen = 0
};
static void OnDeviceFound(const DeviceInfo *device)
{
if (device == NULL) {
printf("ondevice found device is null\n");
return;
}
printf("***********OnDeviceFound!!!!!******************************************\n");
printf("id : %s.\n", device->devId);
printf("name : %s.\n", device->devName);
printf("device type : %u.\n", device->devType);
printf("capNum : %u.\n", device->capabilityBitmapNum);
for (uint32_t i = 0; i < device->capabilityBitmapNum; i++) {
printf("capBitmap[%u] : %u.\n", i, device->capabilityBitmap[i]);
}
printf("addr num : %u.\n", device->addrNum);
printf("ip : %s.\n", device->addr[0].info.ip.ip);
printf("port : %d.\n", device->addr[0].info.ip.port);
printf("connect type : %d.\n", device->addr[0].type);
printf("peerUid : %s.\n", device->addr[0].peerUid);
printf("hw account hash : %s.\n", device->hwAccountHash);
printf("**********************************************************************\n");
return;
}
static void TestDeviceFound(const DeviceInfo *device)
{
printf("[client]TestDeviceFound\n");
OnDeviceFound(device);
}
static void TestDiscoverFailed(int subscribeId, DiscoveryFailReason failReason)
{
printf("[client]TestDiscoverFailed, subscribeId = %d, failReason = %d\n", subscribeId, failReason);
}
static void TestDiscoverySuccess(int subscribeId)
{
printf("[client]TestDiscoverySuccess, subscribeId = %d\n", subscribeId);
}
static void TestPublishSuccess(int publishId)
{
printf("[client]TestPublishSuccess, publishId = %d\n", publishId);
}
static void TestPublishFail(int publishId, PublishFailReason reason)
{
printf("[client]TestPublishFail, publishId = %d, PublishFailReason = %d\n", publishId, reason);
}
static IDiscoveryCallback g_subscribeCb = {
.OnDeviceFound = TestDeviceFound,
.OnDiscoverFailed = TestDiscoverFailed,
.OnDiscoverySuccess = TestDiscoverySuccess
};
static IPublishCallback g_publishCb = {
.OnPublishSuccess = TestPublishSuccess,
.OnPublishFail = TestPublishFail
};
static void GetLocalWifiIp(char *ip, int32_t len)
{
struct netif *wifiNetIf = NULL;
ip4_addr_t ipaddr;
int32_t ret;
int32_t cnt = 0;
while (cnt < MAXT_WAIT_COUNT) {
cnt++;
sleep(WIFI_CONFIG_INTERVAL);
wifiNetIf = netifapi_netif_find(NET_WORK_NAME);
if (wifiNetIf == NULL) {
printf("netif find device failed.\n");
continue;
}
ret = netifapi_netif_get_addr(wifiNetIf, &ipaddr, NULL, NULL);
if (ret != 0) {
printf("netif get ip addr failed, ret = %d.\n", ret);
continue;
}
if (ipaddr.addr == 0) {
printf("wifi is not connected.\n");
continue;
}
break;
}
inet_ntop(AF_INET, &ipaddr, ip, len);
printf("wifi connected, device ip = %s.\n", ip);
}
static void TestPassivePubSrv1(void)
{
g_pInfo1.publishId = GetPublishId();
if (PublishService(DISC_TEST_PKG_NAME, &g_pInfo1, &g_publishCb) != SOFTBUS_OK) {
printf("test failed, [%s].\n", __FUNCTION__);
return;
}
g_testSuccessCnt++;
}
static void TestActivePubSrv2(void)
{
g_pInfo2.publishId = GetPublishId();
if (PublishService(DISC_TEST_PKG_NAME, &g_pInfo2, &g_publishCb) != SOFTBUS_OK) {
printf("test failed, [%s].\n", __FUNCTION__);
return;
}
g_testSuccessCnt++;
}
static void TestUnPubSrv1(void)
{
if (UnPublishService(DISC_TEST_PKG_NAME, g_pInfo1.publishId) != SOFTBUS_OK) {
printf("test failed, [%s].\n", __FUNCTION__);
return;
}
g_testSuccessCnt++;
}
static void TestUnPubSrv2(void)
{
if (UnPublishService(DISC_TEST_PKG_NAME, g_pInfo2.publishId) != SOFTBUS_OK) {
printf("test failed, [%s].\n", __FUNCTION__);
return;
}
g_testSuccessCnt++;
}
static void TestPassiveStartDisc1(void)
{
g_sInfo1.subscribeId = GetSubscribeId();
if (StartDiscovery(DISC_TEST_PKG_NAME, &g_sInfo1, &g_subscribeCb) != SOFTBUS_OK) {
printf("test failed, [%s].\n", __FUNCTION__);
return;
}
g_testSuccessCnt++;
}
static void TestPassiveStartDisc2(void)
{
g_sInfo2.subscribeId = GetSubscribeId();
if (StartDiscovery(DISC_TEST_PKG_NAME, &g_sInfo2, &g_subscribeCb) != SOFTBUS_OK) {
printf("test failed, [%s].\n", __FUNCTION__);
return;
}
g_testSuccessCnt++;
}
static void TestActiveStartDisc3(void)
{
g_sInfo3.subscribeId = GetSubscribeId();
if (StartDiscovery(DISC_TEST_PKG_NAME, &g_sInfo3, &g_subscribeCb) != SOFTBUS_OK) {
printf("test failed, [%s].\n", __FUNCTION__);
return;
}
g_testSuccessCnt++;
}
static void TestStopDisc1(void)
{
if (StopDiscovery(DISC_TEST_PKG_NAME, g_sInfo1.subscribeId) != SOFTBUS_OK) {
printf("test failed, [%s].\n", __FUNCTION__);
return;
}
g_testSuccessCnt++;
}
static void TestStopDisc2(void)
{
if (StopDiscovery(DISC_TEST_PKG_NAME, g_sInfo2.subscribeId) != SOFTBUS_OK) {
printf("test failed, [%s].\n", __FUNCTION__);
return;
}
g_testSuccessCnt++;
}
static void TestStopDisc3(void)
{
if (StopDiscovery(DISC_TEST_PKG_NAME, g_sInfo3.subscribeId) != SOFTBUS_OK) {
printf("test failed, [%s].\n", __FUNCTION__);
return;
}
g_testSuccessCnt++;
}
static void DiscoveryTestEntry(void)
{
InitSoftBusServer();
sleep(WAIT_SERVER_READY);
char ip[NSTACKX_MAX_IP_STRING_LEN] = {0};
int32_t testCnt = 0;
GetLocalWifiIp(ip, NSTACKX_MAX_IP_STRING_LEN);
while (testCnt < MAX_TEST_COUNT) {
TestPassivePubSrv1();
TestActivePubSrv2();
TestPassiveStartDisc1();
TestPassiveStartDisc2();
TestActiveStartDisc3();
sleep(TEST_COUNT_INTREVAL);
TestUnPubSrv1();
TestUnPubSrv2();
TestStopDisc1();
TestStopDisc2();
TestStopDisc3();
testCnt++;
printf("*****test index: %d / %d *******\n", testCnt, MAX_TEST_COUNT);
printf("*****success: %d / %d *****\n", g_testSuccessCnt, TEST_CASE_NUM * MAX_TEST_COUNT);
}
}
SYS_SERVICE_INIT_PRI(DiscoveryTestEntry, 4); // 4 : priority

View File

@ -1,169 +0,0 @@
# Copyright (c) 2021-2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("../../../../dsoftbus.gni")
dsoftbus_root_path = "../../../.."
if (defined(ohos_lite)) {
import("//build/lite/config/component/lite_component.gni")
import("//build/lite/config/test.gni")
if (ohos_build_type == "debug") {
unittest("DiscSdkTest") {
output_extension = "bin"
output_dir = "$root_out_dir/test/unittest/dsoftbus"
sources = [
"disc_sdk_test.cpp",
"disc_sdk_test_bt_status_virtual.c",
]
include_dirs = [
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/sdk/bus_center/manager/include",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/tests/sdk/common/include",
]
deps = [
"$dsoftbus_root_path/sdk:softbus_client",
"$dsoftbus_root_path/tests/sdk/common:softbus_access_token_test",
]
}
}
} else {
import("//build/test.gni")
module_output_path = "dsoftbus/discovery"
ohos_unittest("DiscSdkOnlyL2Test") {
module_out_path = module_output_path
sources = [ "disc_sdk_only_l2_test.cpp" ]
include_dirs = [
"$dsoftbus_root_path/core/common/inner_communication",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/sdk/discovery/include",
"$dsoftbus_root_path/sdk/discovery/manager/include",
"$dsoftbus_root_path/tests/sdk/common/include",
"unittest/common/",
]
deps = [
"$dsoftbus_root_path/sdk:softbus_client",
"$dsoftbus_root_path/tests/sdk/common:softbus_access_token_test",
]
external_deps = [
"bounds_checking_function:libsec_static",
"c_utils:utils",
"googletest:gtest_main",
"hilog:libhilog",
]
}
ohos_unittest("DiscSdkTest") {
module_out_path = module_output_path
sources = [ "disc_sdk_test.cpp" ]
include_dirs = [
"$dsoftbus_root_path/sdk/bus_center/manager/include",
"$dsoftbus_root_path/core/common/inner_communication",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/sdk/discovery/include",
"unittest/common/",
"$dsoftbus_root_path/sdk/discovery/manager/include",
"$dsoftbus_root_path/tests/sdk/common/include",
]
deps = [
"$dsoftbus_root_path/sdk:softbus_client",
"$dsoftbus_root_path/tests/sdk/common:softbus_access_token_test",
]
external_deps = [
"bounds_checking_function:libsec_static",
"c_utils:utils",
"googletest:gtest_main",
"hilog:libhilog",
]
if (support_bluetooth &&
(dsoftbus_feature_conn_br || dsoftbus_feature_conn_ble)) {
sources += [ "disc_sdk_test_bt_status.c" ]
external_deps += [ "bluetooth:btframework" ]
} else {
sources += [ "disc_sdk_test_bt_status_virtual.c" ]
}
}
ohos_unittest("DiscSdkAutoTest") {
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
module_out_path = module_output_path
sources = [ "disc_sdk_auto_test.cpp" ]
include_dirs = [
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/tests/sdk/common/include",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/interfaces/kits/discovery",
]
deps = [
"$dsoftbus_root_path/sdk:softbus_client",
"$dsoftbus_root_path/tests/sdk/common:softbus_access_token_test",
]
external_deps = [
"bounds_checking_function:libsec_static",
"c_utils:utils",
"googletest:gtest_main",
"hilog:libhilog",
]
if (support_bluetooth &&
(dsoftbus_feature_conn_br || dsoftbus_feature_conn_ble)) {
sources += [ "disc_sdk_test_bt_status.c" ]
external_deps += [ "bluetooth:btframework" ]
} else {
sources += [ "disc_sdk_test_bt_status_virtual.c" ]
}
}
ohos_unittest("DiscSdkManagerTest") {
module_out_path = module_output_path
sources = [ "disc_sdk_manager_test.cpp" ]
include_dirs = [
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/sdk/discovery/ipc/include",
"$dsoftbus_root_path/sdk/discovery/ipc/standard/include",
"$dsoftbus_root_path/sdk/discovery/manager/include",
"$dsoftbus_root_path/tests/sdk/common/include",
]
deps = [
"$dsoftbus_root_path/sdk:softbus_client",
"$dsoftbus_root_path/tests/sdk/common:softbus_access_token_test",
]
external_deps = [
"c_utils:utils",
"googletest:gtest_main",
"hilog:libhilog",
]
}
group("unittest") {
testonly = true
deps = [
":DiscSdkAutoTest",
":DiscSdkManagerTest",
":DiscSdkOnlyL2Test",
":DiscSdkTest",
]
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,366 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include "client_disc_manager.h"
#include "disc_server_proxy.h"
#include "softbus_errcode.h"
using namespace testing::ext;
namespace OHOS {
static int32_t g_subscribeId = 0;
static int32_t g_publishId = 0;
static char g_pkgName[] = "Softbus_Kits";
static bool g_isFound = false;
static bool g_discSuccessFlag = false;
static bool g_discFailedFlag = false;
static bool g_pubSuccessFlag = false;
static bool g_pubFailedFlag = false;
class DiscSdkManagerTest : public testing::Test {
public:
DiscSdkManagerTest()
{}
~DiscSdkManagerTest()
{}
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp() override
{}
void TearDown() override
{}
};
void DiscSdkManagerTest::SetUpTestCase(void)
{}
void DiscSdkManagerTest::TearDownTestCase(void)
{}
static SubscribeInfo g_subscribeInfo = {
.subscribeId = 1,
.mode = DISCOVER_MODE_PASSIVE,
.medium = COAP,
.freq = MID,
.isSameAccount = true,
.isWakeRemote = false,
.capability = "dvKit",
.capabilityData = (unsigned char *)"capdata",
.dataLen = strlen("capdata")
};
static PublishInfo g_publishInfo = {
.publishId = 1,
.mode = DISCOVER_MODE_PASSIVE,
.medium = COAP,
.freq = MID,
.capability = "dvKit",
.capabilityData = (unsigned char *)"capdata",
.dataLen = strlen("capdata")
};
static void TestDeviceFound(const DeviceInfo *device)
{
printf("[client]TestDeviceFound\n");
g_isFound = true;
}
static void TestDiscoverFailed(int32_t subscribeId, DiscoveryFailReason failReason)
{
printf("[client]TestDiscoverFailed\n");
g_discFailedFlag = true;
}
static void TestDiscoverySuccess(int32_t subscribeId)
{
printf("[client]TestDiscoverySuccess\n");
g_discSuccessFlag = true;
}
static void TestPublishSuccess(int32_t publishId)
{
printf("[client]TestPublishSuccess\n");
g_pubSuccessFlag = true;
}
static void TestPublishFail(int32_t publishId, PublishFailReason reason)
{
printf("[client]TestPublishFail\n");
g_pubFailedFlag = true;
}
static IDiscoveryCallback g_subscribeCb = {
.OnDeviceFound = TestDeviceFound,
.OnDiscoverFailed = TestDiscoverFailed,
.OnDiscoverySuccess = TestDiscoverySuccess
};
static IPublishCallback g_publishCb = {
.OnPublishSuccess = TestPublishSuccess,
.OnPublishFail = TestPublishFail
};
/**
* @tc.name: PublishServiceInnerTest001
* @tc.desc: Test PublishServiceInner when ServerIpcPublishService failed.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: The g_serverProxy is not initialized and return SOFTBUS_NO_INIT.
*/
HWTEST_F(DiscSdkManagerTest, PublishServiceInnerTest001, TestSize.Level1)
{
int32_t ret = DiscClientInit();
EXPECT_EQ(ret, SOFTBUS_OK);
DiscServerProxyDeInit();
ret = PublishServiceInner(g_pkgName, &g_publishInfo, &g_publishCb);
EXPECT_EQ(ret, SOFTBUS_NO_INIT);
DiscClientDeinit();
}
/**
* @tc.name: UnpublishServiceInnerTest001
* @tc.desc: Test UnpublishServiceInner when ServerIpcUnPublishService failed.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: The g_serverProxy is not initialized and return SOFTBUS_NO_INIT.
*/
HWTEST_F(DiscSdkManagerTest, UnpublishServiceInnerTest001, TestSize.Level1)
{
int32_t ret = UnpublishServiceInner(g_pkgName, g_publishId);
EXPECT_EQ(ret, SOFTBUS_NO_INIT);
}
/**
* @tc.name: StartDiscoveryInnerTest001
* @tc.desc: Test StartDiscoveryInner when ServerIpcStartDiscovery failed.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: The g_serverProxy is not initialized and return SOFTBUS_NO_INIT.
*/
HWTEST_F(DiscSdkManagerTest, StartDiscoveryInnerTest001, TestSize.Level1)
{
int32_t ret = DiscClientInit();
EXPECT_EQ(ret, SOFTBUS_OK);
DiscServerProxyDeInit();
ret = StartDiscoveryInner(g_pkgName, &g_subscribeInfo, &g_subscribeCb);
EXPECT_EQ(ret, SOFTBUS_NO_INIT);
DiscClientDeinit();
}
/**
* @tc.name: StopDiscoveryInnerTest001
* @tc.desc: Test StopDiscoveryInner when ServerIpcStopDiscovery failed.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: The g_serverProxy is not initialized and return SOFTBUS_NO_INIT.
*/
HWTEST_F(DiscSdkManagerTest, StopDiscoveryInnerTest001, TestSize.Level1)
{
int32_t ret = StopDiscoveryInner(g_pkgName, g_subscribeId);
EXPECT_EQ(ret, SOFTBUS_NO_INIT);
}
/**
* @tc.name: DiscClientOnDeviceFoundTest001
* @tc.desc: The first call to DiscClientOnDeviceFound parameter is null, the second call g_discInfo is not
* initialized, and the third call is normal.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: Test DiscClientOnDeviceFound when g_discInfo is null and normal.
*/
HWTEST_F(DiscSdkManagerTest, DiscClientOnDeviceFoundTest001, TestSize.Level1)
{
DeviceInfo device;
DiscClientOnDeviceFound(nullptr);
EXPECT_FALSE(g_isFound);
DiscClientOnDeviceFound(&device);
EXPECT_FALSE(g_isFound);
int32_t ret = DiscClientInit();
EXPECT_EQ(ret, SOFTBUS_OK);
DiscServerProxyDeInit();
ret = StartDiscoveryInner(g_pkgName, &g_subscribeInfo, &g_subscribeCb);
EXPECT_EQ(ret, SOFTBUS_NO_INIT);
DiscClientOnDeviceFound(&device);
EXPECT_TRUE(g_isFound);
DiscClientDeinit();
}
/**
* @tc.name: DiscClientOnDiscoverySuccessTest001
* @tc.desc: The first call to DiscClientOnDiscoverySuccess g_discInfo is null, the second call is normal.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: Test DiscClientOnDiscoverySuccess when g_discInfo is null and normal.
*/
HWTEST_F(DiscSdkManagerTest, DiscClientOnDiscoverySuccessTest001, TestSize.Level1)
{
DiscClientOnDiscoverySuccess(g_subscribeId);
EXPECT_FALSE(g_discSuccessFlag);
int32_t ret = DiscClientInit();
EXPECT_EQ(ret, SOFTBUS_OK);
DiscServerProxyDeInit();
ret = StartDiscoveryInner(g_pkgName, &g_subscribeInfo, &g_subscribeCb);
EXPECT_EQ(ret, SOFTBUS_NO_INIT);
DiscClientOnDiscoverySuccess(g_subscribeId);
EXPECT_TRUE(g_discSuccessFlag);
DiscClientDeinit();
}
/**
* @tc.name: DiscClientOnDiscoverFailedTest001
* @tc.desc: The first call to DiscClientOnDiscoverFailed g_discInfo is null, the second call is normal.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: Test DiscClientOnDiscoverFailed when g_discInfo is null and normal.
*/
HWTEST_F(DiscSdkManagerTest, DiscClientOnDiscoverFailedTest001, TestSize.Level1)
{
DiscClientOnDiscoverFailed(g_subscribeId, DISCOVERY_FAIL_REASON_NOT_SUPPORT_MEDIUM);
EXPECT_FALSE(g_discFailedFlag);
int32_t ret = DiscClientInit();
EXPECT_EQ(ret, SOFTBUS_OK);
DiscServerProxyDeInit();
ret = StartDiscoveryInner(g_pkgName, &g_subscribeInfo, &g_subscribeCb);
EXPECT_EQ(ret, SOFTBUS_NO_INIT);
DiscClientOnDiscoverFailed(g_subscribeId, DISCOVERY_FAIL_REASON_NOT_SUPPORT_MEDIUM);
EXPECT_TRUE(g_discFailedFlag);
DiscClientDeinit();
}
/**
* @tc.name: DiscClientOnPublishSuccessTest001
* @tc.desc: The first call to DiscClientOnPublishSuccess g_discInfo is null, the second call is normal.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: Test DiscClientOnPublishSuccess when g_discInfo is null and normal.
*/
HWTEST_F(DiscSdkManagerTest, DiscClientOnPublishSuccessTest001, TestSize.Level1)
{
DiscClientOnPublishSuccess(g_publishId);
EXPECT_FALSE(g_pubSuccessFlag);
int32_t ret = DiscClientInit();
EXPECT_EQ(ret, SOFTBUS_OK);
DiscServerProxyDeInit();
ret = PublishServiceInner(g_pkgName, &g_publishInfo, &g_publishCb);
EXPECT_EQ(ret, SOFTBUS_NO_INIT);
DiscClientOnPublishSuccess(g_publishId);
EXPECT_TRUE(g_pubSuccessFlag);
DiscClientDeinit();
}
/**
* @tc.name: DiscClientOnPublishFailTest001
* @tc.desc: The first call to DiscClientOnPublishFail g_discInfo is null, the second call is normal.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: Test DiscClientOnPublishFail when g_discInfo is null and normal.
*/
HWTEST_F(DiscSdkManagerTest, DiscClientOnPublishFailTest001, TestSize.Level1)
{
DiscClientOnPublishFail(g_publishId, PUBLISH_FAIL_REASON_NOT_SUPPORT_MEDIUM);
EXPECT_FALSE(g_pubFailedFlag);
int32_t ret = DiscClientInit();
EXPECT_EQ(ret, SOFTBUS_OK);
DiscServerProxyDeInit();
ret = PublishServiceInner(g_pkgName, &g_publishInfo, &g_publishCb);
EXPECT_EQ(ret, SOFTBUS_NO_INIT);
DiscClientOnPublishFail(g_publishId, PUBLISH_FAIL_REASON_NOT_SUPPORT_MEDIUM);
EXPECT_TRUE(g_pubFailedFlag);
DiscClientDeinit();
}
/**
* @tc.name: DiscServerProxyInitTest001
* @tc.desc: Test DiscServerProxyInit again.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: The g_serverProxy is initialized and return SOFTBUS_OK.
*/
HWTEST_F(DiscSdkManagerTest, DiscServerProxyInitTest001, TestSize.Level1)
{
int32_t ret = DiscServerProxyInit();
EXPECT_EQ(ret, SOFTBUS_OK);
ret = DiscServerProxyInit();
EXPECT_EQ(ret, SOFTBUS_OK);
DiscServerProxyDeInit();
}
/**
* @tc.name: ServerIpcPublishServiceTest001
* @tc.desc: Test the first call to ServerIpcPublishService.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: The g_serverProxy is not initialized and return SOFTBUS_NO_INIT.
*/
HWTEST_F(DiscSdkManagerTest, ServerIpcPublishServiceTest001, TestSize.Level1)
{
int32_t ret = ServerIpcPublishService(g_pkgName, &g_publishInfo);
EXPECT_EQ(ret, SOFTBUS_NO_INIT);
}
/**
* @tc.name: ServerIpcUnPublishServiceTest001
* @tc.desc: Test the first call to ServerIpcUnPublishService.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: The g_serverProxy is not initialized and return SOFTBUS_NO_INIT.
*/
HWTEST_F(DiscSdkManagerTest, ServerIpcUnPublishServiceTest001, TestSize.Level1)
{
int32_t ret = ServerIpcUnPublishService(g_pkgName, g_publishId);
EXPECT_EQ(ret, SOFTBUS_NO_INIT);
}
/**
* @tc.name: ServerIpcStartDiscoveryTest001
* @tc.desc: Test the first call to ServerIpcStartDiscovery.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: The g_serverProxy is not initialized and return SOFTBUS_NO_INIT.
*/
HWTEST_F(DiscSdkManagerTest, ServerIpcStartDiscoveryTest001, TestSize.Level1)
{
int32_t ret = ServerIpcStartDiscovery(g_pkgName, &g_subscribeInfo);
EXPECT_EQ(ret, SOFTBUS_NO_INIT);
}
/**
* @tc.name: ServerIpcStopDiscoveryTest001
* @tc.desc: Test the first call to ServerIpcStopDiscovery.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: The g_serverProxy is not initialized and return SOFTBUS_NO_INIT.
*/
HWTEST_F(DiscSdkManagerTest, ServerIpcStopDiscoveryTest001, TestSize.Level1)
{
int32_t ret = ServerIpcStopDiscovery(g_pkgName, g_subscribeId);
EXPECT_EQ(ret, SOFTBUS_NO_INIT);
}
} // namespace OHOS

View File

@ -1,191 +0,0 @@
/*
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdio>
#include <ctime>
#include <gtest/gtest.h>
#include <sys/time.h>
#include <unistd.h>
#include "softbus_access_token_test.h"
#include "softbus_bus_center.h"
using namespace testing::ext;
namespace OHOS {
static int g_subscribeId = 0;
static int g_publishId = 0;
static const char *g_pkgName = "Softbus_Kits";
class DiscSdkOnlyL2Test : public testing::Test {
public:
DiscSdkOnlyL2Test()
{}
~DiscSdkOnlyL2Test()
{}
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp() override
{}
void TearDown() override
{}
};
void DiscSdkOnlyL2Test::SetUpTestCase(void)
{
SetAceessTokenPermission("discSdkOnlyL2Test");
}
void DiscSdkOnlyL2Test::TearDownTestCase(void)
{}
static int GetSubscribeId(void)
{
g_subscribeId++;
return g_subscribeId;
}
static int GetPublishId(void)
{
g_publishId++;
return g_publishId;
}
static SubscribeInfo g_sInfo = {
.subscribeId = 1,
.mode = DISCOVER_MODE_PASSIVE,
.medium = COAP,
.freq = MID,
.isSameAccount = true,
.isWakeRemote = false,
.capability = "dvKit",
.capabilityData = (unsigned char *)"capdata3",
.dataLen = strlen("capdata3")
};
static PublishInfo g_pInfo = {
.publishId = 1,
.mode = DISCOVER_MODE_PASSIVE,
.medium = COAP,
.freq = MID,
.capability = "dvKit",
.capabilityData = (unsigned char *)"capdata4",
.dataLen = strlen("capdata4")
};
static void TestDeviceFound(const DeviceInfo *device)
{
printf("[client]TestDeviceFound\n");
}
static void TestOnDiscoverResult(int32_t refreshId, RefreshResult reason)
{
(void)refreshId;
(void)reason;
printf("[client]TestDiscoverResult\n");
}
static void TestOnPublishResult(int publishId, PublishResult reason)
{
(void)publishId;
(void)reason;
printf("[client]TestPublishResult\n");
}
static IRefreshCallback g_refreshCb = {
.OnDeviceFound = TestDeviceFound,
.OnDiscoverResult = TestOnDiscoverResult
};
static IPublishCb g_publishCb = {
.OnPublishResult = TestOnPublishResult,
};
/**
* @tc.name: StopPublishLNNTest004
* @tc.desc: not start publish.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: The StopPublishLNN operates normally.
*/
HWTEST_F(DiscSdkOnlyL2Test, StopPublishLNNTest001, TestSize.Level2)
{
int ret;
int tmpId = GetPublishId();
ret = StopPublishLNN(g_pkgName, tmpId);
EXPECT_TRUE(ret != 0);
}
/**
* @tc.name: StopPublishLNNTest005
* @tc.desc: Verify StopPublishLNN again.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: The StopPublishLNN operates normally.
*/
HWTEST_F(DiscSdkOnlyL2Test, StopPublishLNNTest002, TestSize.Level2)
{
int ret;
int tmpId = GetPublishId();
g_pInfo.publishId = tmpId;
PublishLNN(g_pkgName, &g_pInfo, &g_publishCb);
ret = StopPublishLNN(g_pkgName, tmpId);
EXPECT_TRUE(ret == 0);
ret = StopPublishLNN(g_pkgName, tmpId);
EXPECT_TRUE(ret != 0);
}
/**
* @tc.name: StopRefreshLNNTest004
* @tc.desc: not start discover.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: The StopRefreshLNN operates normally.
*/
HWTEST_F(DiscSdkOnlyL2Test, StopRefreshLNNTest001, TestSize.Level2)
{
int ret;
int tmpId = GetSubscribeId();
ret = StopRefreshLNN(g_pkgName, tmpId);
EXPECT_TRUE(ret != 0);
}
/**
* @tc.name: StopRefreshLNNTest005
* @tc.desc: Verify StopRefreshLNN again.
* @tc.in: Test Moudle, Test Number, Test Levels.
* @tc.out: NonZero
* @tc.type: FUNC
* @tc.require: The StopRefreshLNN operates normally.
*/
HWTEST_F(DiscSdkOnlyL2Test, StopRefreshLNNTest002, TestSize.Level2)
{
int ret;
int tmpId = GetSubscribeId();
g_sInfo.subscribeId = tmpId;
RefreshLNN(g_pkgName, &g_sInfo, &g_refreshCb);
ret = StopRefreshLNN(g_pkgName, tmpId);
EXPECT_TRUE(ret == 0);
ret = StopRefreshLNN(g_pkgName, tmpId);
EXPECT_TRUE(ret != 0);
}
} // namespace OHOS

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "disc_sdk_test_bt_status.h"
#include "c_header/ohos_bt_gap.h"
bool SoftbusTestGetBtStatus(void)
{
return IsBleEnabled();
}

Some files were not shown because too many files have changed in this diff Show More