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 OHOS_ABILITY_RUNTIME_ABILITY_POST_EVENT_TIMEOUT_H
17 #define OHOS_ABILITY_RUNTIME_ABILITY_POST_EVENT_TIMEOUT_H
18 
19 #include <memory>
20 #include <atomic>
21 #include <mutex>
22 #include <string>
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 class AbilityHandler;
27 class AbilityPostEventTimeout : public std::enable_shared_from_this<AbilityPostEventTimeout> {
28 public:
29     AbilityPostEventTimeout(std::string str, std::shared_ptr<AbilityHandler> &eventHandler);
30     ~AbilityPostEventTimeout();
31 
32     void TimingBegin(int64_t delaytime = defalutDelayTime);
33     void TimeEnd();
34 
35 protected:
36     void TimeOutProc();
37 
38 private:
39     // default delaytime is 5000ms
40     static const int64_t defalutDelayTime;
41 
42     std::string task_;
43     std::shared_ptr<AbilityHandler> handler_;
44     std::mutex mtx_;
45     bool taskExec_;
46 
47     static std::atomic<uint32_t> allocationId_;
48 };
49 }  // namespace AppExecFwk
50 }  // namespace OHOS
51 #endif  // OHOS_ABILITY_RUNTIME_ABILITY_POST_EVENT_TIMEOUT_H
52