1/*
2 * Copyright (c) 2022 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 OHOS_SESSION_STACK_H
17#define OHOS_SESSION_STACK_H
18
19#include <string>
20
21#include "session_container.h"
22
23namespace OHOS::AVSession {
24class SessionStack : public SessionContainer {
25public:
26    int32_t AddSession(pid_t pid, const std::string& abilityName, sptr<AVSessionItem>& item) override;
27
28    std::vector<sptr<AVSessionItem>> RemoveSession(pid_t pid) override;
29
30    sptr<AVSessionItem> RemoveSession(pid_t pid, const std::string& abilityName) override;
31
32    sptr<AVSessionItem> RemoveSession(const std::string& sessionId) override;
33
34    sptr<AVSessionItem> GetSession(pid_t pid, const std::string& abilityName) override;
35
36    std::vector<sptr<AVSessionItem>> GetSessionsByPid(pid_t pid) override;
37
38    bool PidHasSession(pid_t pid) override;
39
40    bool UidHasSession(int32_t uid) override;
41
42    sptr<AVSessionItem> GetSessionById(const std::string& sessionId) override;
43
44    std::vector<sptr<AVSessionItem>> GetAllSessions() override;
45
46    void UpdateSessionSort(sptr<AVSessionItem>& item) override;
47
48    bool IsEmpty() override;
49
50    int32_t getAllSessionNum() override;
51
52private:
53    std::map<std::pair<pid_t, std::string>, sptr<AVSessionItem>> sessions_;
54    std::list<sptr<AVSessionItem>> stack_;
55    std::recursive_mutex sessionStackLock_;
56};
57} // namespace OHOS::AVSession
58#endif // OHOS_SESSION_STACK_H
59