• 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 
16 #ifndef ETHERNET_MANAGER_H
17 #define ETHERNET_MANAGER_H
18 
19 #include <string>
20 
21 #include "i_ethernet_service.h"
22 #include "parcel.h"
23 #include "singleton.h"
24 
25 namespace OHOS {
26 namespace NetManagerStandard {
27 class EthernetClient {
28     DECLARE_DELAYED_SINGLETON(EthernetClient)
29 
30 public:
31 
32     /**
33      *  Set the network interface configuration
34      *
35      * @param Network interface name
36      * @param Network interface parameters
37      * @return Returns 0 as success, other values as failure
38      */
39     int32_t SetIfaceConfig(const std::string &iface, sptr<InterfaceConfiguration> &ic);
40 
41     /**
42      *  Gets the network interface configuration parameters
43      *
44      * @param Network interface name
45      * @return Parameter is returned on success, null on failure
46      */
47     int32_t GetIfaceConfig(const std::string &iface, sptr<InterfaceConfiguration> &ifaceConfig);
48 
49     /**
50      *  Gets the network interface configuration parameters
51      *
52      * @param Network interface name
53      * @return Returns 1 for device open (active), 0 for device closed (inactive), and -1 for failure
54      */
55     int32_t IsIfaceActive(const std::string &iface, int32_t &activeStatus);
56 
57     /**
58      *  Gets the list of active devices
59      *
60      * @return Return to device List
61      */
62     int32_t GetAllActiveIfaces(std::vector<std::string> &activeIfaces);
63 
64     /**
65      *  Reset all configuration information
66      *
67      * @return Returns 0 as success, other values as failure
68      */
69     int32_t ResetFactory();
70 
71     /**
72      *  Set the specified network port up
73      *
74      * @return Returns 0 as success, other values as failure
75      */
76     int32_t SetInterfaceUp(const std::string &iface);
77 
78     /**
79      *  Set the specified network port down
80      *
81      * @return Returns 0 as success, other values as failure
82      */
83     int32_t SetInterfaceDown(const std::string &iface);
84 
85     /**
86      *  Set the specified network port configuration
87      *
88      * @return Returns 'true' as success, 'false' values as failure
89      */
90     int32_t GetInterfaceConfig(const std::string &iface, OHOS::nmd::InterfaceConfigurationParcel &cfg);
91 
92 private:
93     class EthernetDeathRecipient : public IRemoteObject::DeathRecipient {
94     public:
EthernetDeathRecipient(EthernetClient & client)95         explicit EthernetDeathRecipient(EthernetClient &client) : client_(client) {}
96         ~EthernetDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)97         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
98         {
99             client_.OnRemoteDied(remote);
100         }
101 
102     private:
103         EthernetClient &client_;
104     };
105 
106 private:
107     sptr<IEthernetService> GetProxy();
108     void OnRemoteDied(const wptr<IRemoteObject> &remote);
109 
110 private:
111     std::mutex mutex_;
112     sptr<IEthernetService> ethernetService_;
113     sptr<IRemoteObject::DeathRecipient> deathRecipient_;
114 };
115 } // namespace NetManagerStandard
116 } // namespace OHOS
117 #endif // ETHERNET_MANAGER_H