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