更换定时器

Signed-off-by: Wuhongbo <wuhongbo7@h-partners.com>
This commit is contained in:
Wuhongbo 2024-01-06 11:13:48 +08:00
parent b8547624eb
commit c40d99153b
8 changed files with 52 additions and 24 deletions

View File

@ -44,17 +44,21 @@ IApServiceCallbacks& WifiHotspotManager::GetApCallback()
}
#ifndef OHOS_ARCH_LITE
void WifiHotspotManager::UnloadHotspotSaTimerCallback()
static void UnloadHotspotSaTimerCallback()
{
WifiSaLoadManager::GetInstance().UnloadWifiSa(WIFI_HOTSPOT_ABILITY_ID);
StopUnloadApSaTimer();
WifiManager::GetInstance().GetWifiHotspotManager()->StopUnloadApSaTimer();
}
void WifiHotspotManager::StopUnloadApSaTimer(void)
{
WIFI_LOGI("StopUnloadApSaTimer! unloadHotspotSaTimerId:%{public}u", unloadHotspotSaTimerId);
std::unique_lock<std::mutex> lock(unloadHotspotSaTimerMutex);
WifiTimer::GetInstance()->UnRegister(unloadHotspotSaTimerId);
if (unloadHotspotSaTimerId == 0) {
return;
}
MiscServices::TimeServiceClient::GetInstance()->StopTimer(unloadHotspotSaTimerId);
MiscServices::TimeServiceClient::GetInstance()->DestroyTimer(unloadHotspotSaTimerId);
unloadHotspotSaTimerId = 0;
return;
}
@ -64,8 +68,12 @@ void WifiHotspotManager::StartUnloadApSaTimer(void)
WIFI_LOGI("StartUnloadApSaTimer! unloadHotspotSaTimerId:%{public}u", unloadHotspotSaTimerId);
std::unique_lock<std::mutex> lock(unloadHotspotSaTimerMutex);
if (unloadHotspotSaTimerId == 0) {
WifiTimer::TimerCallback timeoutCallback = std::bind(&WifiHotspotManager::UnloadHotspotSaTimerCallback, this);
WifiTimer::GetInstance()->Register(timeoutCallback, unloadHotspotSaTimerId, TIMEOUT_UNLOAD_WIFI_SA);
std::shared_ptr<WifiSysTimer> wifiSysTimer = std::make_shared<WifiSysTimer>(false, 0, true, false);
wifiSysTimer->SetCallbackInfo(UnloadHotspotSaTimerCallback);
unloadHotspotSaTimerId = MiscServices::TimeServiceClient::GetInstance()->CreateTimer(wifiSysTimer);
int64_t currentTime = MiscServices::TimeServiceClient::GetInstance()->GetWallTimeMs();
MiscServices::TimeServiceClient::GetInstance()->StartTimer(unloadHotspotSaTimerId,
currentTime + TIMEOUT_UNLOAD_WIFI_SA);
WIFI_LOGI("RegisterUnloadHotspotSaTimer success! unloadHotspotSaTimerId:%{public}u", unloadHotspotSaTimerId);
}
return;

View File

@ -37,7 +37,6 @@ public:
private:
void InitApCallback(void);
void UnloadHotspotSaTimerCallback();
void DealApStateChanged(ApState bState, int id = 0);
void DealApGetStaJoin(const StationInfo &info, int id = 0);
void DealApGetStaLeave(const StationInfo &info, int id = 0);

View File

@ -130,17 +130,21 @@ ErrCode WifiP2pManager::AutoStopP2pService()
}
#ifndef OHOS_ARCH_LITE
void WifiP2pManager::UnloadP2PSaTimerCallback()
static void UnloadP2PSaTimerCallback()
{
WifiSaLoadManager::GetInstance().UnloadWifiSa(WIFI_P2P_ABILITY_ID);
StopUnloadP2PSaTimer();
WifiManager::GetInstance().GetWifiP2pManager()->StopUnloadP2PSaTimer();
}
void WifiP2pManager::StopUnloadP2PSaTimer(void)
{
WIFI_LOGI("StopUnloadP2PSaTimer! unloadP2PSaTimerId:%{public}u", unloadP2PSaTimerId);
std::unique_lock<std::mutex> lock(unloadP2PSaTimerMutex);
WifiTimer::GetInstance()->UnRegister(unloadP2PSaTimerId);
if (unloadP2PSaTimerId == 0) {
return;
}
MiscServices::TimeServiceClient::GetInstance()->StopTimer(unloadP2PSaTimerId);
MiscServices::TimeServiceClient::GetInstance()->DestroyTimer(unloadP2PSaTimerId);
unloadP2PSaTimerId = 0;
return;
}
@ -150,8 +154,12 @@ void WifiP2pManager::StartUnloadP2PSaTimer(void)
WIFI_LOGI("StartUnloadP2PSaTimer! unloadP2PSaTimerId:%{public}u", unloadP2PSaTimerId);
std::unique_lock<std::mutex> lock(unloadP2PSaTimerMutex);
if (unloadP2PSaTimerId == 0) {
WifiTimer::TimerCallback timeoutCallback = std::bind(&WifiP2pManager::UnloadP2PSaTimerCallback, this);
WifiTimer::GetInstance()->Register(timeoutCallback, unloadP2PSaTimerId, TIMEOUT_UNLOAD_WIFI_SA);
std::shared_ptr<WifiSysTimer> wifiSysTimer = std::make_shared<WifiSysTimer>(false, 0, true, false);
wifiSysTimer->SetCallbackInfo(UnloadP2PSaTimerCallback);
unloadP2PSaTimerId = MiscServices::TimeServiceClient::GetInstance()->CreateTimer(wifiSysTimer);
int64_t currentTime = MiscServices::TimeServiceClient::GetInstance()->GetWallTimeMs();
MiscServices::TimeServiceClient::GetInstance()->StartTimer(unloadP2PSaTimerId,
currentTime + TIMEOUT_UNLOAD_WIFI_SA);
WIFI_LOGI("StartUnloadP2PSaTimer success! unloadP2PSaTimerId:%{public}u", unloadP2PSaTimerId);
}
return;

View File

@ -39,7 +39,6 @@ public:
private:
void InitP2pCallback(void);
void UnloadP2PSaTimerCallback();
void DealP2pStateChanged(P2pState bState);
void DealP2pPeersChanged(const std::vector<WifiP2pDevice> &vPeers);
void DealP2pServiceChanged(const std::vector<WifiP2pServiceInfo> &vServices);

View File

@ -44,17 +44,21 @@ IScanSerivceCallbacks& WifiScanManager::GetScanCallback()
}
#ifndef OHOS_ARCH_LITE
void WifiScanManager::UnloadScanSaTimerCallback()
static void UnloadScanSaTimerCallback()
{
WifiSaLoadManager::GetInstance().UnloadWifiSa(WIFI_SCAN_ABILITY_ID);
StopUnloadScanSaTimer();
WifiManager::GetInstance().GetWifiScanManager()->StopUnloadScanSaTimer();
}
void WifiScanManager::StopUnloadScanSaTimer(void)
{
WIFI_LOGI("StopUnloadScanSaTimer! unloadScanSaTimerId:%{public}u", unloadScanSaTimerId);
std::unique_lock<std::mutex> lock(unloadScanSaTimerMutex);
WifiTimer::GetInstance()->UnRegister(unloadScanSaTimerId);
if (unloadScanSaTimerId == 0) {
return;
}
MiscServices::TimeServiceClient::GetInstance()->StopTimer(unloadScanSaTimerId);
MiscServices::TimeServiceClient::GetInstance()->DestroyTimer(unloadScanSaTimerId);
unloadScanSaTimerId = 0;
return;
}
@ -64,8 +68,12 @@ void WifiScanManager::StartUnloadScanSaTimer(void)
WIFI_LOGI("StartUnloadScanSaTimer! unloadScanSaTimerId:%{public}u", unloadScanSaTimerId);
std::unique_lock<std::mutex> lock(unloadScanSaTimerMutex);
if (unloadScanSaTimerId == 0) {
WifiTimer::TimerCallback timeoutCallback = std::bind(&WifiScanManager::UnloadScanSaTimerCallback, this);
WifiTimer::GetInstance()->Register(timeoutCallback, unloadScanSaTimerId, TIMEOUT_UNLOAD_WIFI_SA);
std::shared_ptr<WifiSysTimer> wifiSysTimer = std::make_shared<WifiSysTimer>(false, 0, true, false);
wifiSysTimer->SetCallbackInfo(UnloadScanSaTimerCallback);
unloadScanSaTimerId = MiscServices::TimeServiceClient::GetInstance()->CreateTimer(wifiSysTimer);
int64_t currentTime = MiscServices::TimeServiceClient::GetInstance()->GetWallTimeMs();
MiscServices::TimeServiceClient::GetInstance()->StartTimer(unloadScanSaTimerId,
currentTime + TIMEOUT_UNLOAD_WIFI_SA);
WIFI_LOGI("StartUnloadScanSaTimer success! unloadScanSaTimerId:%{public}u", unloadScanSaTimerId);
}
return;

View File

@ -38,7 +38,6 @@ public:
private:
void InitScanCallback(void);
void UnloadScanSaTimerCallback();
void DealScanOpenRes(int instId = 0);
void DealScanCloseRes(int instId = 0);
void DealScanFinished(int state, int instId = 0);

View File

@ -45,17 +45,21 @@ StaServiceCallback& WifiStaManager::GetStaCallback()
}
#ifndef OHOS_ARCH_LITE
void WifiStaManager::UnloadStaSaTimerCallback()
static void UnloadStaSaTimerCallback()
{
WifiSaLoadManager::GetInstance().UnloadWifiSa(WIFI_DEVICE_ABILITY_ID);
StopUnloadStaSaTimer();
WifiManager::GetInstance().GetWifiStaManager()->StopUnloadStaSaTimer();
}
void WifiStaManager::StopUnloadStaSaTimer(void)
{
WIFI_LOGI("StopUnloadStaSaTimer! unloadStaSaTimerId:%{public}u", unloadStaSaTimerId);
std::unique_lock<std::mutex> lock(unloadStaSaTimerMutex);
WifiTimer::GetInstance()->UnRegister(unloadStaSaTimerId);
if (unloadStaSaTimerId == 0) {
return;
}
MiscServices::TimeServiceClient::GetInstance()->StopTimer(unloadStaSaTimerId);
MiscServices::TimeServiceClient::GetInstance()->DestroyTimer(unloadStaSaTimerId);
unloadStaSaTimerId = 0;
return;
}
@ -65,8 +69,12 @@ void WifiStaManager::StartUnloadStaSaTimer(void)
WIFI_LOGI("StartUnloadStaSaTimer! unloadStaSaTimerId:%{public}u", unloadStaSaTimerId);
std::unique_lock<std::mutex> lock(unloadStaSaTimerMutex);
if (unloadStaSaTimerId == 0) {
WifiTimer::TimerCallback timeoutCallback = std::bind(&WifiStaManager::UnloadStaSaTimerCallback, this);
WifiTimer::GetInstance()->Register(timeoutCallback, unloadStaSaTimerId, TIMEOUT_UNLOAD_WIFI_SA);
std::shared_ptr<WifiSysTimer> wifiSysTimer = std::make_shared<WifiSysTimer>(false, 0, true, false);
wifiSysTimer->SetCallbackInfo(UnloadStaSaTimerCallback);
unloadStaSaTimerId = MiscServices::TimeServiceClient::GetInstance()->CreateTimer(wifiSysTimer);
int64_t currentTime = MiscServices::TimeServiceClient::GetInstance()->GetWallTimeMs();
MiscServices::TimeServiceClient::GetInstance()->StartTimer(unloadStaSaTimerId,
currentTime + TIMEOUT_UNLOAD_WIFI_SA);
WIFI_LOGI("StartUnloadStaSaTimer success! unloadStaSaTimerId:%{public}u", unloadStaSaTimerId);
}
return;

View File

@ -37,7 +37,6 @@ public:
private:
void InitStaCallback(void);
void ForceStopWifi(int instId = 0);
void UnloadStaSaTimerCallback();
void DealStaOpenRes(OperateResState state, int instId = 0);
void DealStaCloseRes(OperateResState state, int instId = 0);
void DealStaConnChanged(OperateResState state, const WifiLinkedInfo &info, int instId = 0);