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 "network/session_pool.h" 17 18 namespace OHOS { 19 namespace Storage { 20 namespace DistributedFile { 21 using namespace std; 22 HoldSession(shared_ptr<BaseSession> session)23void SessionPool::HoldSession(shared_ptr<BaseSession> session) 24 { 25 lock_guard lock(sessionPoolLock_); 26 talker_->SinkSessionTokernel(session); 27 AddSessionToPool(session); 28 } 29 ReleaseSession(const int32_t fd)30void SessionPool::ReleaseSession(const int32_t fd) 31 { 32 lock_guard lock(sessionPoolLock_); 33 for (auto iter = usrSpaceSessionPool_.begin(); iter != usrSpaceSessionPool_.end();) { 34 if ((*iter)->GetHandle() == fd) { 35 (*iter)->Release(); 36 iter = usrSpaceSessionPool_.erase(iter); 37 } else { 38 ++iter; 39 } 40 } 41 } 42 ReleaseSession(const string & cid)43void SessionPool::ReleaseSession(const string &cid) 44 { 45 talker_->SinkOfflineCmdToKernel(cid); 46 lock_guard lock(sessionPoolLock_); 47 for (auto iter = usrSpaceSessionPool_.begin(); iter != usrSpaceSessionPool_.end();) { 48 if ((*iter)->GetCid() == cid) { 49 (*iter)->Release(); 50 iter = usrSpaceSessionPool_.erase(iter); 51 } else { 52 ++iter; 53 } 54 } 55 } 56 ReleaseAllSession()57void SessionPool::ReleaseAllSession() 58 { 59 lock_guard lock(sessionPoolLock_); 60 for (auto iter = usrSpaceSessionPool_.begin(); iter != usrSpaceSessionPool_.end();) { 61 talker_->SinkOfflineCmdToKernel((*iter)->GetCid()); 62 /* device offline, session release by softbus */ 63 iter = usrSpaceSessionPool_.erase(iter); 64 } 65 } 66 AddSessionToPool(shared_ptr<BaseSession> session)67void SessionPool::AddSessionToPool(shared_ptr<BaseSession> session) 68 { 69 usrSpaceSessionPool_.push_back(session); 70 } 71 } // namespace DistributedFile 72 } // namespace Storage 73 } // namespace OHOS