1 /*
2  * Copyright (c) 2023 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 <map>
17 #include <mutex>
18 #include <vector>
19 
20 #include "noncopyable.h"
21 #include "singleton.h"
22 
23 namespace OHOS {
24 namespace Rosen {
25 class EventStage final {
26     DECLARE_DELAYED_SINGLETON(EventStage);
27 public:
28     DISALLOW_COPY_AND_MOVE(EventStage);
29     void SetAnrStatus(int32_t persistentId, bool status);
30     bool CheckAnrStatus(int32_t persistentId);
31     void SaveANREvent(int32_t persistentId, int32_t eventId, int32_t timerId);
32     std::vector<int32_t> GetTimerIds(int32_t persistentId);
33     std::vector<int32_t> DelEvents(int32_t persistentId, int32_t eventId);
34     void OnSessionLost(int32_t persistentId);
35 private:
36     struct EventTime {
37         int32_t eventId { 0 };
38         int32_t timerId { -1 };
39     };
40     std::mutex mutex_;
41     std::map<int32_t, std::vector<EventTime>> events_;
42     std::map<int32_t, bool> isAnrProcess_;
43 };
44 } // namespace Rosen
45 } // namespace OHOS
46