• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 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 OHOS_WIFI_IF_CONFIG_H
16 #define OHOS_WIFI_IF_CONFIG_H
17 
18 #include <memory>
19 #include "wifi_log.h"
20 #include "dhcp_define.h"
21 
22 namespace OHOS {
23 namespace Wifi {
24 typedef enum IpType {
25     IPTYPE_IPV4,
26     IPTYPE_IPV6,
27     IPTYPE_MIX,
28     IPTYPE_BUTT,
29 } IpType;
30 
31 class IfConfig {
32 public:
33     IfConfig();
34     ~IfConfig();
35 
36     static IfConfig &GetInstance();
37 
38     void FlushIpAddr(const std::string &ifName, const int &ipType);
39 
40     void AddIpAddr(const std::string &ifName, const std::string &ipAddr, const std::string &mask, const int &ipType);
41 
42     void SetProxy(bool isAuto, const std::string &proxy, const std::string &port, const std::string &noProxys,
43         const std::string &pac);
44 
45     bool ExecCommand(const std::vector<std::string> &vecCommandArg);
46 
47     bool GetIpAddr(const std::string& ifName, std::string& ipAddr);
48 
49 private:
50     /**
51      * @Description : Use synchronous mode to execute the command, the current thread will be blocked
52      *    until the command execution is complete.
53      *
54      * @param cmd - command
55      * @return bool - true: success, false: failed
56      */
57     bool SyncExecuteCommand(const std::string& cmd);
58 
59     /**
60      * @Description : Start a new thread to execute the command, the current thread will not be blocked
61      *
62      * @param cmd - command
63      * @return bool - true: success, false: failed
64      */
65     bool AsyncExecuteCommand(const std::string& cmd);
66 
67     /**
68      * @Description : Check if the interface name is valid
69      */
70     bool CheckIfaceValid(const std::string& ifname);
71 };
72 }  // namespace Wifi
73 }  // namespace OHOS
74 #endif
75