• 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_SERVICE_H
17 #define ETHERNET_SERVICE_H
18 
19 #include <cstdint>
20 #include <iosfwd>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include "ethernet_management.h"
26 #include "ethernet_service_common.h"
27 #include "ethernet_service_stub.h"
28 #include "refbase.h"
29 #include "singleton.h"
30 #include "system_ability.h"
31 
32 namespace OHOS {
33 namespace NetManagerStandard {
34 class EthernetService : public SystemAbility,
35                         public EthernetServiceStub,
36                         public std::enable_shared_from_this<EthernetService> {
37     DECLARE_DELAYED_SINGLETON(EthernetService)
38     DECLARE_SYSTEM_ABILITY(EthernetService)
39 
40     enum ServiceRunningState {
41         STATE_STOPPED = 0,
42         STATE_RUNNING,
43     };
44 
45 public:
46     void OnStart() override;
47     void OnStop() override;
48     int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override;
49 
50     int32_t SetIfaceConfig(const std::string &iface, sptr<InterfaceConfiguration> &ic) override;
51     int32_t GetIfaceConfig(const std::string &iface, sptr<InterfaceConfiguration> &ifaceConfig) override;
52     int32_t IsIfaceActive(const std::string &iface, int32_t &activeStatus) override;
53     int32_t GetAllActiveIfaces(std::vector<std::string> &activeIfaces) override;
54     int32_t ResetFactory() override;
55     int32_t SetInterfaceUp(const std::string &iface) override;
56     int32_t SetInterfaceDown(const std::string &iface) override;
57     int32_t GetInterfaceConfig(const std::string &iface, OHOS::nmd::InterfaceConfigurationParcel &config) override;
58 
59 protected:
60     void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
61 
62 private:
63     bool Init();
64     void InitManagement();
65 
66 private:
67     ServiceRunningState state_ = ServiceRunningState::STATE_STOPPED;
68     bool registerToService_ = false;
69     uint16_t dependentServiceState_ = 0;
70     std::unique_ptr<EthernetManagement> ethManagement_;
71     sptr<EthernetServiceCommon> serviceComm_ = nullptr;
72 };
73 } // namespace NetManagerStandard
74 } // namespace OHOS
75 #endif // ETHERNET_SERVICE_H
76