!6256 add CancelConnectCommand

Merge pull request !6256 from 邱德粉/0525
This commit is contained in:
openharmony_ci 2024-05-25 14:22:58 +00:00 committed by Gitee
commit 2e9a00e446
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 30 additions and 0 deletions

View File

@ -108,6 +108,11 @@ void ConnectCommand::PreferNegotiateChannel()
info_.channel_ = innerLink->GetNegotiateChannel();
}
bool ConnectCommand::IsSameCommand(const WifiDirectConnectInfo &info)
{
return (info.requestId == info_.info_.requestId) && (info.pid == info_.info_.pid);
}
void ConnectCommand::DfxRecord(bool isSuccess, WifiDirectErrorCode reason) const
{
if (isSuccess) {

View File

@ -47,6 +47,7 @@ public:
void OnSuccess(const WifiDirectLink &link) const;
void OnFailure(WifiDirectErrorCode reason) const;
bool IsSameCommand(const WifiDirectConnectInfo &info);
protected:
ConnectInfo info_;

View File

@ -137,6 +137,12 @@ static int32_t ConnectDevice(struct WifiDirectConnectInfo *info, struct WifiDire
return ret;
}
static int32_t CancelConnectDevice(const struct WifiDirectConnectInfo *info)
{
CONN_CHECK_AND_RETURN_RET_LOGW(info != nullptr, SOFTBUS_INVALID_PARAM, CONN_WIFI_DIRECT, "info is null");
return OHOS::SoftBus::WifiDirectSchedulerFactory::GetInstance().GetScheduler().CancelConnectDevice(*info);
}
static int32_t DisconnectDevice(struct WifiDirectDisconnectInfo *info, struct WifiDirectDisconnectCallback *callback)
{
CONN_CHECK_AND_RETURN_RET_LOGW(info != nullptr, SOFTBUS_INVALID_PARAM, CONN_WIFI_DIRECT, "info is null");
@ -367,6 +373,7 @@ static struct WifiDirectManager g_manager = {
.allocateListenerModuleId = AllocateListenerModuleId,
.freeListenerModuleId = FreeListenerModuleId,
.connectDevice = ConnectDevice,
.cancelConnectDevice = CancelConnectDevice,
.disconnectDevice = DisconnectDevice,
.registerStatusListener = RegisterStatusListener,
.prejudgeAvailability = PrejudgeAvailability,

View File

@ -38,6 +38,7 @@ struct WifiDirectManager {
void (*freeListenerModuleId)(int32_t moduleId);
int32_t (*connectDevice)(struct WifiDirectConnectInfo *info, struct WifiDirectConnectCallback *callback);
int32_t (*cancelConnectDevice)(const struct WifiDirectConnectInfo *info);
int32_t (*disconnectDevice)(struct WifiDirectDisconnectInfo *info, struct WifiDirectDisconnectCallback *callback);
void (*registerStatusListener)(struct WifiDirectStatusListener *listener);
int32_t (*prejudgeAvailability)(const char *remoteNetworkId, enum WifiDirectLinkType linkType);

View File

@ -41,6 +41,21 @@ int WifiDirectScheduler::ConnectDevice(const WifiDirectConnectInfo &info, const
return ret;
}
int WifiDirectScheduler::CancelConnectDevice(const WifiDirectConnectInfo &info)
{
CONN_LOGI(CONN_WIFI_DIRECT, "requestId=%{public}d pid=%{public}d", info.requestId, info.pid);
std::lock_guard commandLock(commandLock_);
for (auto itc = commandList_.begin(); itc != commandList_.end(); itc++) {
auto connectCommand = std::dynamic_pointer_cast<ConnectCommand>(*itc);
if (connectCommand != nullptr && connectCommand->IsSameCommand(info)) {
commandList_.erase(itc);
return SOFTBUS_OK;
}
}
return SOFTBUS_NOT_FIND;
}
int WifiDirectScheduler::ConnectDevice(const std::shared_ptr<ConnectCommand> &command, bool markRetried)
{
return ConnectDevice(command->GetConnectInfo().info_, command->GetConnectCallback(), markRetried);

View File

@ -39,6 +39,7 @@ public:
int ConnectDevice(const WifiDirectConnectInfo &info, const WifiDirectConnectCallback &callback,
bool markRetried = false);
int ConnectDevice(const std::shared_ptr<ConnectCommand> &command, bool markRetried = false);
int CancelConnectDevice(const WifiDirectConnectInfo &info);
int DisconnectDevice(WifiDirectDisconnectInfo &info, WifiDirectDisconnectCallback &callback);
template<typename Command>