• 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 virtual RefBase {
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     ~NetActivate();
51     bool MatchRequestAndNetwork(sptr<NetSupplier> supplier);
52     void SetRequestId(uint32_t reqId);
53     uint32_t GetRequestId() const;
54     sptr<NetSupplier> GetServiceSupply() const;
55     void SetServiceSupply(sptr<NetSupplier> netServiceSupplied);
56     sptr<INetConnCallback> GetNetCallback();
57     sptr<NetSpecifier> GetNetSpecifier();
58 
59 private:
60     bool CompareByNetworkIdent(const std::string &ident);
61     bool CompareByNetworkCapabilities(const NetCaps &netCaps);
62     bool CompareByNetworkNetType(NetBearType bearerType);
63     bool CompareByNetworkBand(uint32_t netLinkUpBand, uint32_t netLinkDownBand);
64     bool HaveCapability(NetCap netCap) const;
65     bool HaveTypes(const std::set<NetBearType> &bearerTypes) const;
66     void TimeOutNetAvailable();
67 
68 private:
69     uint32_t requestId_ = 1;
70     sptr<NetSpecifier> netSpecifier_ = nullptr;
71     sptr<INetConnCallback> netConnCallback_ = nullptr;
72     sptr<NetSupplier> netServiceSupplied_ = nullptr;
73     uint32_t timeoutMS_ = 0;
74     std::weak_ptr<INetActivateCallback> timeoutCallback_;
75     std::string activateName_ = "";
76 };
77 } // namespace NetManagerStandard
78 } // namespace OHOS
79 #endif // NET_ACTIVATE_H