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 #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 OccupySession(int sessionId, uint8_t linkType); 36 bool FindSession(int sessionId); 37 void HoldSession(std::shared_ptr<BaseSession> session); 38 uint8_t ReleaseSession(const int32_t fd); 39 void ReleaseSession(const std::string &cid, const uint8_t linkType); 40 void ReleaseAllSession(); 41 42 private: 43 std::recursive_mutex sessionPoolLock_; 44 std::list<std::shared_ptr<BaseSession>> usrSpaceSessionPool_; 45 std::shared_ptr<KernelTalker> &talker_; 46 std::map<int, uint8_t> occupySession_; 47 48 void AddSessionToPool(std::shared_ptr<BaseSession> session); 49 }; 50 } // namespace DistributedFile 51 } // namespace Storage 52 } // namespace OHOS 53 #endif // SESSION_POOL_H