• 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 NET_ACTIVATE_H
17 #define NET_ACTIVATE_H
18 
19 #include <functional>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "i_net_conn_callback.h"
25 #include "net_specifier.h"
26 #include "net_supplier.h"
27 
28 class NetSupplier;
29 
30 namespace OHOS {
31 namespace NetManagerStandard {
32 constexpr uint32_t DEFAULT_REQUEST_ID = 0;
33 constexpr uint32_t MIN_REQUEST_ID = DEFAULT_REQUEST_ID + 1;
34 constexpr uint32_t MAX_REQUEST_ID = 0x7FFFFFFF;
35 class INetActivateCallback {
36 public:
37     virtual ~INetActivateCallback() = default;
38 
39 public:
40     virtual void OnNetActivateTimeOut(uint32_t reqId) = 0;
41 };
42 
43 class NetActivate : public std::enable_shared_from_this<NetActivate> {
44 public:
45     using TimeOutHandler = std::function<int32_t(uint32_t &reqId)>;
46 
47 public:
48     NetActivate(const sptr<NetSpecifier> &specifier, const sptr<INetConnCallback> &callback,
49                 std::weak_ptr<INetActivateCallback> timeoutCallback, const uint32_t &timeoutMS,
50                 const std::shared_ptr<AppExecFwk::EventHandler> &netActEventHandler);
51     ~NetActivate();
52     bool MatchRequestAndNetwork(sptr<NetSupplier> supplier);
53     void SetRequestId(uint32_t reqId);
54     uint32_t GetRequestId() const;
55     sptr<NetSupplier> GetServiceSupply() const;
56     void SetServiceSupply(sptr<NetSupplier> netServiceSupplied);
57     sptr<INetConnCallback> GetNetCallback();
58     sptr<NetSpecifier> GetNetSpecifier();
59     void StartTimeOutNetAvailable();
60 private:
61     bool CompareByNetworkIdent(const std::string &ident);
62     bool CompareByNetworkCapabilities(const NetCaps &netCaps);
63     bool CompareByNetworkNetType(NetBearType bearerType);
64     bool CompareByNetworkBand(uint32_t netLinkUpBand, uint32_t netLinkDownBand);
65     bool HaveCapability(NetCap netCap) const;
66     bool HaveTypes(const std::set<NetBearType> &bearerTypes) const;
67     void TimeOutNetAvailable();
68 
69 private:
70     uint32_t requestId_ = 1;
71     sptr<NetSpecifier> netSpecifier_ = nullptr;
72     sptr<INetConnCallback> netConnCallback_ = nullptr;
73     sptr<NetSupplier> netServiceSupplied_ = nullptr;
74     uint32_t timeoutMS_ = 0;
75     std::weak_ptr<INetActivateCallback> timeoutCallback_;
76     std::shared_ptr<AppExecFwk::EventHandler> netActEventHandler_;
77     std::string activateName_ = "";
78 };
79 } // namespace NetManagerStandard
80 } // namespace OHOS
81 #endif // NET_ACTIVATE_H