• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
24 #include "network/base_session.h"
25 #include "network/kernel_talker.h"
26 
27 namespace OHOS {
28 namespace Storage {
29 namespace DistributedFile {
30 class SessionPool final : protected NoCopyable {
31 public:
SessionPool(std::shared_ptr<KernelTalker> & talker)32     explicit SessionPool(std::shared_ptr<KernelTalker> &talker) : talker_(talker) {}
33     ~SessionPool() = default;
34     void HoldSession(std::shared_ptr<BaseSession> session);
35     void ReleaseSession(const int32_t fd);
36     void ReleaseSession(const std::string &cid);
37     void ReleaseAllSession();
38 
39 private:
40     std::recursive_mutex sessionPoolLock_;
41     std::list<std::shared_ptr<BaseSession>> usrSpaceSessionPool_;
42     std::shared_ptr<KernelTalker> &talker_;
43 
44     void AddSessionToPool(std::shared_ptr<BaseSession> session);
45 };
46 } // namespace DistributedFile
47 } // namespace Storage
48 } // namespace OHOS
49 #endif // SESSION_POOL_H