• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 "network_session_manager.h"
17 #include "network/session/base_network_session.h"
18 
19 namespace OHOS {
20 namespace Sharing {
NetworkSessionManager()21 NetworkSessionManager::NetworkSessionManager()
22 {
23     SHARING_LOGD("trace.");
24 }
25 
~NetworkSessionManager()26 NetworkSessionManager::~NetworkSessionManager()
27 {
28     SHARING_LOGD("trace.");
29 }
30 
Add(int32_t fd,BaseNetworkSession::Ptr & session)31 void NetworkSessionManager::Add(int32_t fd, BaseNetworkSession::Ptr &session)
32 {
33     SHARING_LOGD("trace.");
34     std::lock_guard<std::mutex> lock(sessionMux_);
35     sessions_.emplace(fd, session);
36 }
37 
Remove(int32_t fd)38 void NetworkSessionManager::Remove(int32_t fd)
39 {
40     SHARING_LOGD("trace.");
41     std::lock_guard<std::mutex> lock(sessionMux_);
42     auto itemItr = sessions_.find(fd);
43     if (itemItr != sessions_.end()) {
44         if (itemItr->second) {
45             itemItr->second->Shutdown();
46         }
47         sessions_.erase(itemItr);
48     }
49 }
50 
RemoveAll()51 void NetworkSessionManager::RemoveAll()
52 {
53     SHARING_LOGD("trace.");
54     std::lock_guard<std::mutex> lock(sessionMux_);
55     for (auto &item : sessions_) {
56         if (item.second) {
57             item.second->Shutdown();
58         }
59     }
60     sessions_.clear();
61 }
62 
GetLogFlag(void)63 int8_t NetworkSessionManager::GetLogFlag(void)
64 {
65     SHARING_LOGD("trace.");
66     return logFlag_;
67 }
68 
SetLogFlag(int8_t flag)69 void NetworkSessionManager::SetLogFlag(int8_t flag)
70 {
71     SHARING_LOGD("trace.");
72     logFlag_ = flag;
73 }
74 } // namespace Sharing
75 } // namespace OHOS