• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 
16 #ifndef OHOS_WIFI_NET_CHECK_H
17 #define OHOS_WIFI_NET_CHECK_H
18 
19 #include <unistd.h>
20 #include <cstring>
21 #include <fstream>
22 #include <vector>
23 #include <condition_variable>
24 #include <mutex>
25 #include <thread>
26 #include "wifi_log.h"
27 #include "sta_define.h"
28 #include "http_request.h"
29 #include "wifi_errcode.h"
30 
31 #define DEFAULT_PORTAL_HTTPS_URL ""
32 
33 namespace OHOS {
34 namespace Wifi {
35 class StaNetworkCheck {
36     FRIEND_GTEST(StaNetworkCheck);
37 public:
38     explicit StaNetworkCheck(NetStateHandler handle);
39     virtual ~StaNetworkCheck();
40     /**
41      * @Description : Start NetCheck thread
42      *
43      * @Return success : WIFI_OPT_SUCCESS  failed : WIFI_OPT_FAILED
44      */
45     virtual ErrCode InitNetCheckThread();
46     /**
47      * @Description : wake up the DHCP processing thread.
48      *
49      * @param ipType - Type of IP to be obtained [in]
50      */
51     virtual void SignalNetCheckThread();
52     /**
53      * @Description : stop the NetCheck processing thread.
54      *
55      */
56     virtual void StopNetCheckThread();
57 
58 private:
59     std::thread *pDealNetCheckThread;
60     NetStateHandler netStateHandler;
61     StaNetState lastNetState;
62 
63     /**
64      * @Description : Detect Internet ability
65      *
66      */
67     bool HttpDetection();
68     /**
69      * @Description : NetCheck thread function
70      *
71      */
72     void RunNetCheckThreadFunc();
73     /**
74      * @Description : Exit the NetCheck thread.
75      *
76      */
77     void ExitNetCheckThread();
78 
79 private:
80     std::mutex mMutex;
81     std::condition_variable mCondition;
82     std::condition_variable mCondition_timeout;
83     bool isStopNetCheck;
84     bool isExitNetCheckThread;
85 };
86 }  // namespace Wifi
87 }  // namespace OHOS
88 #endif