1b1b8bc3fSopenharmony_ci/* 2b1b8bc3fSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3b1b8bc3fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4b1b8bc3fSopenharmony_ci * you may not use this file except in compliance with the License. 5b1b8bc3fSopenharmony_ci * You may obtain a copy of the License at 6b1b8bc3fSopenharmony_ci * 7b1b8bc3fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8b1b8bc3fSopenharmony_ci * 9b1b8bc3fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10b1b8bc3fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11b1b8bc3fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12b1b8bc3fSopenharmony_ci * See the License for the specific language governing permissions and 13b1b8bc3fSopenharmony_ci * limitations under the License. 14b1b8bc3fSopenharmony_ci */ 15b1b8bc3fSopenharmony_ci 16b1b8bc3fSopenharmony_ci#ifndef NET_ACTIVATE_H 17b1b8bc3fSopenharmony_ci#define NET_ACTIVATE_H 18b1b8bc3fSopenharmony_ci 19b1b8bc3fSopenharmony_ci#include <functional> 20b1b8bc3fSopenharmony_ci#include <memory> 21b1b8bc3fSopenharmony_ci#include <string> 22b1b8bc3fSopenharmony_ci#include <vector> 23b1b8bc3fSopenharmony_ci 24b1b8bc3fSopenharmony_ci#include "i_net_conn_callback.h" 25b1b8bc3fSopenharmony_ci#include "net_specifier.h" 26b1b8bc3fSopenharmony_ci#include "net_supplier.h" 27b1b8bc3fSopenharmony_ciclass NetSupplier; 28b1b8bc3fSopenharmony_ci 29b1b8bc3fSopenharmony_cinamespace OHOS { 30b1b8bc3fSopenharmony_cinamespace NetManagerStandard { 31b1b8bc3fSopenharmony_ciconstexpr uint32_t DEFAULT_REQUEST_ID = 0; 32b1b8bc3fSopenharmony_ciconstexpr uint32_t MIN_REQUEST_ID = DEFAULT_REQUEST_ID + 1; 33b1b8bc3fSopenharmony_ciconstexpr uint32_t MAX_REQUEST_ID = 0x7FFFFFFF; 34b1b8bc3fSopenharmony_ciclass INetActivateCallback { 35b1b8bc3fSopenharmony_cipublic: 36b1b8bc3fSopenharmony_ci virtual ~INetActivateCallback() = default; 37b1b8bc3fSopenharmony_ci 38b1b8bc3fSopenharmony_cipublic: 39b1b8bc3fSopenharmony_ci virtual void OnNetActivateTimeOut(uint32_t reqId) = 0; 40b1b8bc3fSopenharmony_ci}; 41b1b8bc3fSopenharmony_ci 42b1b8bc3fSopenharmony_ciclass NetActivate : public std::enable_shared_from_this<NetActivate> { 43b1b8bc3fSopenharmony_cipublic: 44b1b8bc3fSopenharmony_ci using TimeOutHandler = std::function<int32_t(uint32_t &reqId)>; 45b1b8bc3fSopenharmony_ci 46b1b8bc3fSopenharmony_cipublic: 47b1b8bc3fSopenharmony_ci NetActivate(const sptr<NetSpecifier> &specifier, const sptr<INetConnCallback> &callback, 48b1b8bc3fSopenharmony_ci std::weak_ptr<INetActivateCallback> timeoutCallback, const uint32_t &timeoutMS, 49b1b8bc3fSopenharmony_ci const std::shared_ptr<AppExecFwk::EventHandler> &netActEventHandler, uint32_t uid = 0, 50b1b8bc3fSopenharmony_ci const int32_t registerType = REGISTER); 51b1b8bc3fSopenharmony_ci ~NetActivate(); 52b1b8bc3fSopenharmony_ci bool MatchRequestAndNetwork(sptr<NetSupplier> supplier, bool skipCheckIdent = false); 53b1b8bc3fSopenharmony_ci void SetRequestId(uint32_t reqId); 54b1b8bc3fSopenharmony_ci uint32_t GetRequestId() const; 55b1b8bc3fSopenharmony_ci sptr<NetSupplier> GetServiceSupply() const; 56b1b8bc3fSopenharmony_ci void SetServiceSupply(sptr<NetSupplier> netServiceSupplied); 57b1b8bc3fSopenharmony_ci sptr<INetConnCallback> GetNetCallback(); 58b1b8bc3fSopenharmony_ci sptr<NetSpecifier> GetNetSpecifier(); 59b1b8bc3fSopenharmony_ci int32_t GetRegisterType() const; 60b1b8bc3fSopenharmony_ci std::set<NetBearType> GetBearType() const; 61b1b8bc3fSopenharmony_ci void StartTimeOutNetAvailable(); 62b1b8bc3fSopenharmony_ci uint32_t GetUid() const; 63b1b8bc3fSopenharmony_ci 64b1b8bc3fSopenharmony_ciprivate: 65b1b8bc3fSopenharmony_ci bool CompareByNetworkIdent(const std::string &ident, NetBearType bearerType, bool skipCheckIdent); 66b1b8bc3fSopenharmony_ci bool CompareByNetworkCapabilities(const NetCaps &netCaps); 67b1b8bc3fSopenharmony_ci bool CompareByNetworkNetType(NetBearType bearerType); 68b1b8bc3fSopenharmony_ci bool CompareByNetworkBand(uint32_t netLinkUpBand, uint32_t netLinkDownBand); 69b1b8bc3fSopenharmony_ci bool HaveCapability(NetCap netCap) const; 70b1b8bc3fSopenharmony_ci bool HaveTypes(const std::set<NetBearType> &bearerTypes) const; 71b1b8bc3fSopenharmony_ci void TimeOutNetAvailable(); 72b1b8bc3fSopenharmony_ci 73b1b8bc3fSopenharmony_ciprivate: 74b1b8bc3fSopenharmony_ci uint32_t requestId_ = 1; 75b1b8bc3fSopenharmony_ci sptr<NetSpecifier> netSpecifier_ = nullptr; 76b1b8bc3fSopenharmony_ci sptr<INetConnCallback> netConnCallback_ = nullptr; 77b1b8bc3fSopenharmony_ci sptr<NetSupplier> netServiceSupplied_ = nullptr; 78b1b8bc3fSopenharmony_ci uint32_t timeoutMS_ = 0; 79b1b8bc3fSopenharmony_ci std::weak_ptr<INetActivateCallback> timeoutCallback_; 80b1b8bc3fSopenharmony_ci std::shared_ptr<AppExecFwk::EventHandler> netActEventHandler_; 81b1b8bc3fSopenharmony_ci std::string activateName_ = ""; 82b1b8bc3fSopenharmony_ci uint32_t uid_ = 0; 83b1b8bc3fSopenharmony_ci int32_t registerType_ = REGISTER; 84b1b8bc3fSopenharmony_ci}; 85b1b8bc3fSopenharmony_ci} // namespace NetManagerStandard 86b1b8bc3fSopenharmony_ci} // namespace OHOS 87b1b8bc3fSopenharmony_ci#endif // NET_ACTIVATE_H