1 /* 2 * Copyright (c) 2021-2024 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 #ifndef SESSION_POOL_H 17 #define SESSION_POOL_H 18 19 #include <list> 20 #include <memory> 21 #include <mutex> 22 #include <set> 23 #include <map> 24 25 #include "network/base_session.h" 26 #include "network/kernel_talker.h" 27 28 namespace OHOS { 29 namespace Storage { 30 namespace DistributedFile { 31 class SessionPool final : protected NoCopyable { 32 public: SessionPool(std::shared_ptr<KernelTalker> & talker)33 explicit SessionPool(std::shared_ptr<KernelTalker> &talker) : talker_(talker) {} 34 ~SessionPool() = default; 35 void HoldSession(std::shared_ptr<BaseSession> session, const std::string backStage); 36 void ReleaseSession(const int32_t fd); 37 void ReleaseSession(const std::string &cid, bool releaseServer); 38 void ReleaseAllSession(); 39 bool CheckIfGetSession(const int32_t fd); 40 void SinkOffline(const std::string &cid); 41 bool FindSocketId(int32_t socketId); 42 private: 43 std::recursive_mutex sessionPoolLock_; 44 std::list<std::shared_ptr<BaseSession>> usrSpaceSessionPool_; 45 std::shared_ptr<KernelTalker> &talker_; 46 47 void AddSessionToPool(std::shared_ptr<BaseSession> session); 48 bool FindCid(const std::string &cid); 49 }; 50 } // namespace DistributedFile 51 } // namespace Storage 52 } // namespace OHOS 53 #endif // SESSION_POOL_H