• 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 ETHERNET_MANAGER_H
17 #define ETHERNET_MANAGER_H
18 
19 #include <string>
20 
21 #include "parcel.h"
22 #include "singleton.h"
23 
24 #include "i_ethernet_service.h"
25 
26 namespace OHOS {
27 namespace NetManagerStandard {
28 class EthernetClient {
29     DECLARE_DELAYED_SINGLETON(EthernetClient)
30 
31 public:
32     /**
33      * @brief 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      * @brief Gets the network interface configuration parameters
42      *
43      * @param Network interface name
44      * @return Parameter is returned on success, null on failure
45      */
46     sptr<InterfaceConfiguration> GetIfaceConfig(const std::string &iface);
47     /**
48      * @brief Gets the network interface configuration parameters
49      *
50      * @param Network interface name
51      * @return Returns 1 for device open (active), 0 for device closed (inactive), and -1 for failure
52      */
53     int32_t IsIfaceActive(const std::string &iface);
54     /**
55      * @brief Gets the list of active devices
56      *
57      * @return Return to device List
58      */
59     std::vector<std::string> GetAllActiveIfaces();
60     int32_t ResetFactory();
61 
62 private:
63     class EthernetDeathRecipient : public IRemoteObject::DeathRecipient {
64     public:
EthernetDeathRecipient(EthernetClient & client)65         explicit EthernetDeathRecipient(EthernetClient &client) : client_(client) {}
66         ~EthernetDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)67         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
68         {
69             client_.OnRemoteDied(remote);
70         }
71 
72     private:
73         EthernetClient &client_;
74     };
75 
76 private:
77     sptr<IEthernetService> GetProxy();
78     void OnRemoteDied(const wptr<IRemoteObject> &remote);
79 
80 private:
81     std::mutex mutex_;
82     sptr<IEthernetService> ethernetService_;
83     sptr<IRemoteObject::DeathRecipient> deathRecipient_;
84 };
85 } // namespace NetManagerStandard
86 } // namespace OHOS
87 #endif // ETHERNET_MANAGER_H