• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 REQUEST_NETWORK_H
17 #define REQUEST_NETWORK_H
18 
19 #include <memory>
20 
21 #include "cxx.h"
22 #include "net_all_capabilities.h"
23 #include "net_conn_callback_stub.h"
24 #include "net_handle.h"
25 #include "net_link_info.h"
26 
27 namespace OHOS::Request {
28 using namespace OHOS::NetManagerStandard;
29 struct NetworkInner;
30 struct NetworkTaskManagerTx;
31 class RequestNetCallbackStub : public NetConnCallbackStub {
32 public:
33     RequestNetCallbackStub(rust::box<NetworkInner> network, rust::box<NetworkTaskManagerTx> task_manager,
34         rust::fn<void(const NetworkTaskManagerTx &task_manager)> notifyTaskManagerOnline,
35         rust::fn<void(const NetworkTaskManagerTx &task_manager)> notifyTaskManagerOffline);
36     ~RequestNetCallbackStub();
37 
38     int32_t NetAvailable(sptr<NetHandle> &netHandle) override;
39     int32_t NetLost(sptr<NetHandle> &netHandle) override;
40     int32_t NetUnavailable() override;
41     int32_t NetCapabilitiesChange(sptr<NetHandle> &netHandle, const sptr<NetAllCapabilities> &netAllCap) override;
42 
43 private:
44     void HandleNetCap(const sptr<NetAllCapabilities> &netAllCap);
45     bool IsRoaming();
46     NetworkInner *networkNotifier_;
47     NetworkTaskManagerTx *task_manager_;
48     rust::fn<void(const NetworkTaskManagerTx &task_manager)> notifyTaskManagerOnline_;
49     rust::fn<void(const NetworkTaskManagerTx &task_manager)> notifyTaskManagerOffline_;
50 #ifdef REQUEST_TELEPHONY_CORE_SERVICE
51     std::mutex roamingMutex_;
52 #endif
53 };
54 
55 class NetworkRegistry {
56 public:
57     NetworkRegistry(sptr<RequestNetCallbackStub> callback);
58     ~NetworkRegistry();
59 
60 private:
61     sptr<RequestNetCallbackStub> callback_;
62 };
63 
64 std::unique_ptr<NetworkRegistry> RegisterNetworkChange(rust::box<NetworkInner> notifier,
65     rust::box<NetworkTaskManagerTx> task_manager,
66     rust::fn<void(const NetworkTaskManagerTx &task_manager)> notifyTaskManagerOnline,
67     rust::fn<void(const NetworkTaskManagerTx &task_manager)> notifyTaskManagerOffline);
68 
69 } // namespace OHOS::Request
70 #endif