1bc2ed2b3Sopenharmony_ci/* 2bc2ed2b3Sopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd. 3bc2ed2b3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4bc2ed2b3Sopenharmony_ci * you may not use this file except in compliance with the License. 5bc2ed2b3Sopenharmony_ci * You may obtain a copy of the License at 6bc2ed2b3Sopenharmony_ci * 7bc2ed2b3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bc2ed2b3Sopenharmony_ci * 9bc2ed2b3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bc2ed2b3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11bc2ed2b3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bc2ed2b3Sopenharmony_ci * See the License for the specific language governing permissions and 13bc2ed2b3Sopenharmony_ci * limitations under the License. 14bc2ed2b3Sopenharmony_ci */ 15bc2ed2b3Sopenharmony_ci#ifndef NFC_WIFI_CONN_MGR_H 16bc2ed2b3Sopenharmony_ci#define NFC_WIFI_CONN_MGR_H 17bc2ed2b3Sopenharmony_ci 18bc2ed2b3Sopenharmony_ci#include <shared_mutex> 19bc2ed2b3Sopenharmony_ci#include "ndef_wifi_data_parser.h" 20bc2ed2b3Sopenharmony_ci#include "nfc_event_handler.h" 21bc2ed2b3Sopenharmony_ci#include "wifi_device.h" 22bc2ed2b3Sopenharmony_ci 23bc2ed2b3Sopenharmony_cinamespace OHOS { 24bc2ed2b3Sopenharmony_cinamespace NFC { 25bc2ed2b3Sopenharmony_cinamespace TAG { 26bc2ed2b3Sopenharmony_ciclass WifiConnectionManager { 27bc2ed2b3Sopenharmony_cipublic: 28bc2ed2b3Sopenharmony_ci static WifiConnectionManager& GetInstance(); 29bc2ed2b3Sopenharmony_ci void Initialize(std::weak_ptr<NfcService> nfcService); 30bc2ed2b3Sopenharmony_ci 31bc2ed2b3Sopenharmony_ci void TryConnectWifi(std::shared_ptr<WifiData> data); 32bc2ed2b3Sopenharmony_ci void OnWifiNtfClicked(); 33bc2ed2b3Sopenharmony_ci void HandleWifiEnableFailed(); 34bc2ed2b3Sopenharmony_ci void HandleWifiConnectFailed(); 35bc2ed2b3Sopenharmony_ci void OnWifiEnabled(); 36bc2ed2b3Sopenharmony_ci void OnWifiConnected(); 37bc2ed2b3Sopenharmony_ciprotected: 38bc2ed2b3Sopenharmony_ci // wifi common event receiver 39bc2ed2b3Sopenharmony_ci class WifiCommonEventReceiver; 40bc2ed2b3Sopenharmony_ciprivate: 41bc2ed2b3Sopenharmony_ci WifiConnectionManager(); 42bc2ed2b3Sopenharmony_ci ~WifiConnectionManager() {} 43bc2ed2b3Sopenharmony_ci // wifi common event 44bc2ed2b3Sopenharmony_ci void SubscribeWifiCommonEvents(); 45bc2ed2b3Sopenharmony_ci void UnsubscribeWifiCommonEvents(); 46bc2ed2b3Sopenharmony_ci // timeout event messages 47bc2ed2b3Sopenharmony_ci void SendMsgToEvtHandler(NfcCommonEvent evt, int64_t delay); 48bc2ed2b3Sopenharmony_ci void RemoveMsgFromEvtHandler(NfcCommonEvent evt); 49bc2ed2b3Sopenharmony_ci // step 1: wifi state check 50bc2ed2b3Sopenharmony_ci std::shared_ptr<Wifi::WifiDevice> GetWifiDevPtr(); 51bc2ed2b3Sopenharmony_ci bool IsWifiEnabled(); 52bc2ed2b3Sopenharmony_ci bool HandleEnableWifi(); 53bc2ed2b3Sopenharmony_ci // step 2: wifi connect 54bc2ed2b3Sopenharmony_ci bool IsSameSsid(); 55bc2ed2b3Sopenharmony_ci bool HandleConnectWifi(); 56bc2ed2b3Sopenharmony_ci // clear function 57bc2ed2b3Sopenharmony_ci void OnFinish(); 58bc2ed2b3Sopenharmony_ci 59bc2ed2b3Sopenharmony_ciprivate: 60bc2ed2b3Sopenharmony_ci std::weak_ptr<NfcService> nfcService_ {}; 61bc2ed2b3Sopenharmony_ci std::shared_mutex mutex_ {}; 62bc2ed2b3Sopenharmony_ci bool isInitialized_ = false; 63bc2ed2b3Sopenharmony_ci}; 64bc2ed2b3Sopenharmony_ci} // namespace TAG 65bc2ed2b3Sopenharmony_ci} // namespace NFC 66bc2ed2b3Sopenharmony_ci} // namespace OHOS 67bc2ed2b3Sopenharmony_ci#endif // NFC_WIFI_CONN_MGR_H