• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "netinterface.h"
17 #include "netmanager_base_log.h"
18 
19 #include <shared_mutex>
20 
21 namespace OHOS::NetManagerStandard {
22 std::map<NetInterfaceCallbackObserver *, NetInterface *> NET_INTERFACES;
23 std::shared_mutex g_netInterfacesMutex;
24 
NetInterface(std::shared_ptr<EventManager> & eventManager)25 NetInterface::NetInterface(std::shared_ptr<EventManager>& eventManager)
26     : observer_(new NetInterfaceCallbackObserver),
27       manager_(eventManager)
28 {
29 }
30 
MakeNetInterface(std::shared_ptr<EventManager> & eventManager)31 NetInterface *NetInterface::MakeNetInterface(std::shared_ptr<EventManager>& eventManager)
32 {
33     std::unique_lock<std::shared_mutex> lock(g_netInterfacesMutex);
34     auto netInterface = new NetInterface(eventManager);
35     NET_INTERFACES[netInterface->observer_.GetRefPtr()] = netInterface;
36     return netInterface;
37 }
38 
DeleteNetInterface(NetInterface * netInterface)39 void NetInterface::DeleteNetInterface(NetInterface *netInterface)
40 {
41     std::unique_lock<std::shared_mutex> lock(g_netInterfacesMutex);
42     NET_INTERFACES.erase(netInterface->observer_.GetRefPtr());
43     delete netInterface;
44 }
45 
GetObserver() const46 sptr<NetInterfaceCallbackObserver> NetInterface::GetObserver() const
47 {
48     return observer_;
49 }
50 
GetEventManager() const51 std::shared_ptr<EventManager> NetInterface::GetEventManager() const
52 {
53     return manager_;
54 }
NetInterface()55 NetInterface::NetInterface() {}
56 
57 } // namespace OHOS::NetManagerStandard
58