• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2023 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 #ifndef NATIVE_NET_CONN_ADAPTER_H
16 #define NATIVE_NET_CONN_ADAPTER_H
17 
18 #include <map>
19 #include <mutex>
20 
21 #include "http_proxy.h"
22 #include "net_all_capabilities.h"
23 #include "net_conn_callback_stub.h"
24 #include "net_connection_type.h"
25 #include "net_handle.h"
26 #include "net_link_info.h"
27 #include "refbase.h"
28 
29 namespace OHOS::NetManagerStandard {
30 
31 int32_t Conv2NetHandle(NetHandle &netHandleObj, NetConn_NetHandle *netHandle);
32 
33 int32_t Conv2NetHandleObj(NetConn_NetHandle *netHandle, NetHandle &netHandleObj);
34 
35 int32_t Conv2NetHandleList(const std::list<sptr<NetHandle>> &netHandleObjList, NetConn_NetHandleList *netHandleList);
36 
37 int32_t Conv2NetLinkInfo(NetLinkInfo &infoObj, NetConn_ConnectionProperties *prop);
38 
39 int32_t Conv2NetAllCapabilities(NetAllCapabilities &netAllCapsObj, NetConn_NetCapabilities *netAllCaps);
40 
41 int32_t ConvFromNetAllCapabilities(NetAllCapabilities &netAllCapsObj, NetConn_NetCapabilities *netAllCaps);
42 
43 int32_t Conv2HttpProxy(const HttpProxy &httpProxyObj, NetConn_HttpProxy *httpProxy);
44 
45 void ConvertNetConn2HttpProxy(const NetConn_HttpProxy &netConn, HttpProxy &httpProxyObj);
46 
47 int32_t Conv2TraceRouteInfo(
48     const std::string &traceRouteInfoStr, NetConn_TraceRouteInfo *traceRouteInfo, uint32_t maxJumpNumber);
49 
50 int32_t Conv2TraceRouteInfoRtt(const std::string &rttStr, uint32_t (*rtt)[NETCONN_MAX_RTT_NUM]);
51 
52 class NetConnCallbackStubAdapter : public NetConnCallbackStub {
53 public:
54     NetConnCallbackStubAdapter(NetConn_NetConnCallback *callback);
55 
56     int32_t NetAvailable(sptr<NetHandle> &netHandle) override;
57     int32_t NetCapabilitiesChange(sptr<NetHandle> &netHandle, const sptr<NetAllCapabilities> &netAllCap) override;
58     int32_t NetConnectionPropertiesChange(sptr<NetHandle> &netHandle, const sptr<NetLinkInfo> &info) override;
59     int32_t NetLost(sptr<NetHandle> &netHandle) override;
60     int32_t NetUnavailable() override;
61     int32_t NetBlockStatusChange(sptr<NetHandle> &netHandle, bool blocked) override;
62 
63 private:
64     NetConn_NetConnCallback callback_{};
65 };
66 
67 class NetConnCallbackManager {
68 public:
69     static NetConnCallbackManager &GetInstance();
70     int32_t RegisterNetConnCallback(NetConn_NetSpecifier *specifier, NetConn_NetConnCallback *netConnCallback,
71                                     const uint32_t &timeout, uint32_t *callbackId);
72     int32_t UnregisterNetConnCallback(uint32_t callbackId);
73 
74 private:
75     NetConnCallbackManager() = default;
76     std::mutex callbackMapMutex_;
77     std::map<uint32_t, sptr<INetConnCallback>> callbackMap_;
78     uint32_t index_{0};
79 };
80 
81 } // namespace OHOS::NetManagerStandard
82 #endif /* NATIVE_NET_CONN_ADAPTER_H */