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 NET_SUPPLIER_H 17 #define NET_SUPPLIER_H 18 19 #include <map> 20 #include <memory> 21 #include <set> 22 #include <string> 23 #include <vector> 24 25 #include "i_net_supplier_callback.h" 26 #include "i_net_conn_callback.h" 27 #include "network.h" 28 #include "net_caps.h" 29 #include "net_specifier.h" 30 #include "net_supplier_info.h" 31 32 namespace OHOS { 33 namespace NetManagerStandard { 34 enum CallbackType { 35 CALL_TYPE_UNKNOWN = 0, 36 CALL_TYPE_AVAILABLE = 1, 37 CALL_TYPE_LOSTING = 2, 38 CALL_TYPE_LOST = 3, 39 CALL_TYPE_UPDATE_CAP = 4, 40 CALL_TYPE_UPDATE_LINK = 5, 41 CALL_TYPE_UNAVAILABLE = 6, 42 CALL_TYPE_BLOCK_STATUS = 7, 43 }; 44 45 class NetSupplier : public virtual RefBase { 46 public: 47 NetSupplier(NetBearType bearerType, const std::string &netSupplierIdent, const std::set<NetCap> &netCaps); 48 ~NetSupplier() = default; 49 bool operator==(const NetSupplier &netSupplier) const; 50 void SetNetwork(const std::shared_ptr<Network> &network); 51 void UpdateNetSupplierInfo(const NetSupplierInfo &netSupplierInfo); 52 int32_t UpdateNetLinkInfo(const NetLinkInfo &netLinkInfo); 53 uint32_t GetSupplierId() const; 54 NetBearType GetNetSupplierType() const; 55 std::string GetNetSupplierIdent() const; 56 bool CompareNetCaps(const std::set<NetCap> caps) const; 57 bool HasNetCap(NetCap cap) const; 58 bool HasNetCaps(const std::set<NetCap> &caps) const; 59 const NetCaps &GetNetCaps() const; 60 NetAllCapabilities GetNetCapabilities() const; 61 bool GetRoaming() const; 62 int8_t GetStrength() const; 63 uint16_t GetFrequency() const; 64 int32_t GetSupplierUid() const; 65 std::shared_ptr<Network> GetNetwork() const; 66 int32_t GetNetId() const; 67 sptr<NetHandle> GetNetHandle() const; 68 void UpdateNetConnState(NetConnState netConnState); 69 bool IsConnecting() const; 70 bool IsConnected() const; 71 void SetNetValid(bool ifValid); 72 bool IsNetValidated(); 73 void SetNetScore(int32_t score); 74 int32_t GetNetScore() const; 75 void SetRealScore(int32_t score); 76 int32_t GetRealScore(); 77 bool SupplierConnection(const std::set<NetCap> &netCaps); 78 bool SupplierDisconnection(const std::set<NetCap> &netCaps); 79 void SetRestrictBackground(bool restrictBackground); 80 bool GetRestrictBackground() const; 81 bool RequestToConnect(uint32_t reqId); 82 void AddRequestIdToList(uint32_t requestId); 83 int32_t SelectAsBestNetwork(uint32_t reqId); 84 void ReceiveBestScore(uint32_t reqId, int32_t bestScore, uint32_t supplierId); 85 int32_t CancelRequest(uint32_t reqId); 86 void RemoveBestRequest(uint32_t reqId); 87 std::set<uint32_t> &GetBestRequestList(); 88 void SetDefault(); 89 void ClearDefault(); 90 void RegisterSupplierCallback(const sptr<INetSupplierCallback> &callback); 91 92 private: 93 NetBearType netSupplierType_; 94 std::string netSupplierIdent_; 95 NetCaps netCaps_; 96 NetLinkInfo netLinkInfo_; 97 NetSupplierInfo netSupplierInfo_; 98 NetAllCapabilities netAllCapabilities_; 99 uint32_t supplierId_ = 0; 100 int32_t netScore_ = 0; 101 int32_t netRealScore_ = 0; 102 std::set<uint32_t> requestList_; 103 std::set<uint32_t> bestReqList_; 104 sptr<INetSupplierCallback> netController_ = nullptr; 105 std::shared_ptr<Network> network_ = nullptr; 106 sptr<NetHandle> netHandle_ = nullptr; 107 bool restrictBackground_ = true; 108 }; 109 } // namespace NetManagerStandard 110 } // namespace OHOS 111 #endif // NET_SUPPLIER_H 112