• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #include "net_conn_callback_test.h"
17 
18 #include "net_mgr_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace NetManagerStandard {
NetConnCallbackTest()22 NetConnCallbackTest::NetConnCallbackTest() {}
23 
~NetConnCallbackTest()24 NetConnCallbackTest::~NetConnCallbackTest() {}
25 
NotifyAll()26 void NetConnCallbackTest::NotifyAll()
27 {
28     std::unique_lock<std::mutex> callbackLock(callbackMutex_);
29     cv_.notify_all();
30 }
31 
WaitFor(int timeoutSecond)32 void NetConnCallbackTest::WaitFor(int timeoutSecond)
33 {
34     std::unique_lock<std::mutex> callbackLock(callbackMutex_);
35     cv_.wait_for(callbackLock, std::chrono::seconds(timeoutSecond));
36 }
37 
NetAvailable(sptr<NetHandle> & netHandle)38 int32_t NetConnCallbackTest::NetAvailable(sptr<NetHandle> &netHandle)
39 {
40     if (netHandle != nullptr) {
41         return 0;
42     }
43 
44     NETMGR_LOG_D("NetAvailable: netId = %{public}d", netHandle->GetNetId());
45     NotifyAll();
46     return 0;
47 }
48 
NetCapabilitiesChange(sptr<NetHandle> & netHandle,const sptr<NetAllCapabilities> & netAllCap)49 int32_t NetConnCallbackTest::NetCapabilitiesChange(
50     sptr<NetHandle> &netHandle, const sptr<NetAllCapabilities> &netAllCap)
51 {
52     if (netHandle == nullptr || netAllCap == nullptr) {
53         return 0;
54     }
55 
56     NETMGR_LOG_D("NetCapabilitiesChange: netId = [%{public}d]", netHandle->GetNetId());
57     NETMGR_LOG_D("[%{public}s]", netAllCap->ToString("|").c_str());
58     NotifyAll();
59     return 0;
60 }
61 
NetConnectionPropertiesChange(sptr<NetHandle> & netHandle,const sptr<NetLinkInfo> & info)62 int32_t NetConnCallbackTest::NetConnectionPropertiesChange(sptr<NetHandle> &netHandle,
63     const sptr<NetLinkInfo> &info)
64 {
65     if (netHandle == nullptr || info == nullptr) {
66         return 0;
67     }
68     NETMGR_LOG_D("NetConnectionPropertiesChange: netId = %{public}d info = %{public}s", netHandle->GetNetId(),
69         info->ToString(" ").c_str());
70     NotifyAll();
71     return 0;
72 }
73 
NetLost(sptr<NetHandle> & netHandle)74 int32_t NetConnCallbackTest::NetLost(sptr<NetHandle> &netHandle)
75 {
76     if (netHandle == nullptr) {
77         return 0;
78     }
79     NETMGR_LOG_D("NetLost: netId = %{public}d", netHandle->GetNetId());
80     NotifyAll();
81     return 0;
82 }
83 
NetUnavailable()84 int32_t NetConnCallbackTest::NetUnavailable()
85 {
86     NETMGR_LOG_D("NetUnavailable");
87     NotifyAll();
88     return 0;
89 }
90 
NetBlockStatusChange(sptr<NetHandle> & netHandle,bool isBlocked)91 int32_t NetConnCallbackTest::NetBlockStatusChange(sptr<NetHandle> &netHandle, bool isBlocked)
92 {
93     NETMGR_LOG_D("NetConnCallbackTest::NetLost: netId = %{public}d bolcked = %{public}s",
94         netHandle->GetNetId(), isBlocked ? "true" : "false");
95     NotifyAll();
96     return 0;
97 }
98 } // namespace NetManagerStandard
99 } // namespace OHOS
100