• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 WEARABLE_DISTRIBUTED_NET_AGENT_H
17 #define WEARABLE_DISTRIBUTED_NET_AGENT_H
18 
19 #include <cstdint>
20 #include "battery_srv_client.h"
21 #include "net_all_capabilities.h"
22 #include "net_conn_client.h"
23 #include "net_link_info.h"
24 #include "net_manager_ext_constants.h"
25 #include "net_supplier_info.h"
26 #include "wearable_distributed_net_static_configuration.h"
27 
28 namespace OHOS {
29 namespace NetManagerStandard {
30 constexpr int32_t NET_SCORE_WITH_CHARGE_STATE = 50;
31 constexpr int32_t NET_SCORE_WITH_UNCHARGE_STATE = 80;
32 namespace {
33     using ChargeState = OHOS::PowerMgr::BatteryChargeState;
34 }
35 class WearableDistributedNetAgent : public std::enable_shared_from_this<WearableDistributedNetAgent> {
36 public:
37     static WearableDistributedNetAgent &GetInstance();
38     int32_t SetupWearableDistributedNetwork(const int32_t tcpPortId, const int32_t udpPortId, const bool isMetered);
39     int32_t EnableWearableDistributedNetwork(bool enableFlag);
40     int32_t TearDownWearableDistributedNetwork();
41     int32_t UpdateNetScore(const bool isCharging);
42     int32_t UpdateMeteredStatus(const bool isMetered);
43 
44 private:
45     int32_t RegisterNetSupplier(const bool isMetered);
46     int32_t UnregisterNetSupplier();
47     int32_t UpdateNetSupplierInfo(const bool isAvailable);
48     int32_t UpdateNetLinkInfo();
49     void ObtainNetCaps(const bool isMetered);
50     void SetNetSupplierInfo(NetSupplierInfo &networkSupplierInfo);
51     int32_t SetNetLinkInfo(NetLinkInfo &networkLinkInfo);
52     int32_t DisableWearableDistributedNetForward();
53     int32_t EnableWearableDistributedNetForward(const int32_t tcpPortId, const int32_t udpPortId);
54     int32_t ClearWearableDistributedNetForwardConfig();
55     void SetInitNetScore(OHOS::PowerMgr::BatteryChargeState chargeState);
56     void SetScoreBaseNetStatus(const bool isAvailable);
57     void SetScoreBaseChargeStatus(const bool isCharging);
58     int32_t UpdateNetCaps(const bool isMetered);
59 
60 private:
61     uint32_t netSupplierId_ = 0;
62     std::set<NetCap> netCaps_;
63     WearableDistributedNetStaticConfiguration staticConfiguration_;
64     NetSupplierInfo netSupplierInfo_;
65     NetLinkInfo netLinkInfo_;
66     bool isMetered_ = false;
67     int32_t score_ = NET_SCORE_WITH_UNCHARGE_STATE;
68 };
69 } // namespace NetManagerStandard
70 } // namespace OHOS
71 #endif // WEARABLE_DISTRIBUTED_NET_MANAGEMENT_H
72