mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-24 09:20:04 +00:00
add CancelConnectCommand
Signed-off-by: zona <qiudefen@huawei.com>
This commit is contained in:
parent
ea73271ee4
commit
2f8671d2fd
@ -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) {
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
|
||||
void OnSuccess(const WifiDirectLink &link) const;
|
||||
void OnFailure(WifiDirectErrorCode reason) const;
|
||||
bool IsSameCommand(const WifiDirectConnectInfo &info);
|
||||
|
||||
protected:
|
||||
ConnectInfo info_;
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -41,6 +41,22 @@ 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)) {
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "cancel command requestId=%{public}d pid=%{public}d", info.requestId, info.pid);
|
||||
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);
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user