/* * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef NET_ACTIVATE_H #define NET_ACTIVATE_H #include #include #include #include #include "i_net_conn_callback.h" #include "net_specifier.h" #include "net_supplier.h" class NetSupplier; namespace OHOS { namespace NetManagerStandard { constexpr uint32_t DEFAULT_REQUEST_ID = 0; constexpr uint32_t MIN_REQUEST_ID = DEFAULT_REQUEST_ID + 1; constexpr uint32_t MAX_REQUEST_ID = 0x7FFFFFFF; class INetActivateCallback { public: virtual ~INetActivateCallback() = default; public: virtual void OnNetActivateTimeOut(uint32_t reqId) = 0; }; class NetActivate : public std::enable_shared_from_this { public: using TimeOutHandler = std::function; public: NetActivate(const sptr &specifier, const sptr &callback, std::weak_ptr timeoutCallback, const uint32_t &timeoutMS, const std::shared_ptr &netActEventHandler, const int32_t registerType = REGISTER); ~NetActivate(); bool MatchRequestAndNetwork(sptr supplier, bool skipCheckIdent = false); void SetRequestId(uint32_t reqId); uint32_t GetRequestId() const; sptr GetServiceSupply() const; void SetServiceSupply(sptr netServiceSupplied); sptr GetNetCallback(); sptr GetNetSpecifier(); int32_t GetRegisterType() const; std::set GetBearType() const; void StartTimeOutNetAvailable(); private: bool CompareByNetworkIdent(const std::string &ident, NetBearType bearerType, bool skipCheckIdent); bool CompareByNetworkCapabilities(const NetCaps &netCaps); bool CompareByNetworkNetType(NetBearType bearerType); bool CompareByNetworkBand(uint32_t netLinkUpBand, uint32_t netLinkDownBand); bool HaveCapability(NetCap netCap) const; bool HaveTypes(const std::set &bearerTypes) const; void TimeOutNetAvailable(); private: uint32_t requestId_ = 1; sptr netSpecifier_ = nullptr; sptr netConnCallback_ = nullptr; sptr netServiceSupplied_ = nullptr; uint32_t timeoutMS_ = 0; std::weak_ptr timeoutCallback_; std::shared_ptr netActEventHandler_; std::string activateName_ = ""; int32_t registerType_ = REGISTER; }; } // namespace NetManagerStandard } // namespace OHOS #endif // NET_ACTIVATE_H