1209bc2fbSopenharmony_ci/*
2209bc2fbSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
3209bc2fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4209bc2fbSopenharmony_ci * you may not use this file except in compliance with the License.
5209bc2fbSopenharmony_ci * You may obtain a copy of the License at
6209bc2fbSopenharmony_ci *
7209bc2fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8209bc2fbSopenharmony_ci *
9209bc2fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10209bc2fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11209bc2fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12209bc2fbSopenharmony_ci * See the License for the specific language governing permissions and
13209bc2fbSopenharmony_ci * limitations under the License.
14209bc2fbSopenharmony_ci */
15209bc2fbSopenharmony_ci
16209bc2fbSopenharmony_ci#ifndef RELIABILITY_HANDLER_CHECKER_H
17209bc2fbSopenharmony_ci#define RELIABILITY_HANDLER_CHECKER_H
18209bc2fbSopenharmony_ci
19209bc2fbSopenharmony_ci#include <atomic>
20209bc2fbSopenharmony_ci#include <string>
21209bc2fbSopenharmony_ci
22209bc2fbSopenharmony_ci#include "dumper.h"
23209bc2fbSopenharmony_ci#include "event_handler.h"
24209bc2fbSopenharmony_ci
25209bc2fbSopenharmony_cinamespace OHOS {
26209bc2fbSopenharmony_cinamespace HiviewDFX {
27209bc2fbSopenharmony_cienum CheckStatus {
28209bc2fbSopenharmony_ci    COMPLETED = 0,
29209bc2fbSopenharmony_ci    WAITING = 1,
30209bc2fbSopenharmony_ci    WAITED_HALF = 2,
31209bc2fbSopenharmony_ci};
32209bc2fbSopenharmony_ci
33209bc2fbSopenharmony_ciclass HandlerChecker : public std::enable_shared_from_this<HandlerChecker> {
34209bc2fbSopenharmony_cipublic:
35209bc2fbSopenharmony_ci    HandlerChecker(std::string name, std::shared_ptr<AppExecFwk::EventHandler> handler)
36209bc2fbSopenharmony_ci        : name_(name), handler_(handler) {};
37209bc2fbSopenharmony_ci    ~HandlerChecker() {};
38209bc2fbSopenharmony_ci
39209bc2fbSopenharmony_cipublic:
40209bc2fbSopenharmony_ci    void ScheduleCheck();
41209bc2fbSopenharmony_ci    int GetCheckState();
42209bc2fbSopenharmony_ci    std::shared_ptr<AppExecFwk::EventHandler> GetHandler() const;
43209bc2fbSopenharmony_ci    std::string GetDumpInfo();
44209bc2fbSopenharmony_ci
45209bc2fbSopenharmony_ciprivate:
46209bc2fbSopenharmony_ci    std::string name_;
47209bc2fbSopenharmony_ci    std::shared_ptr<AppExecFwk::EventHandler> handler_;
48209bc2fbSopenharmony_ci    std::atomic<bool> isCompleted_ = true;
49209bc2fbSopenharmony_ci    bool taskSlow = false;
50209bc2fbSopenharmony_ci};
51209bc2fbSopenharmony_ci
52209bc2fbSopenharmony_ciclass HandlerDumper : public AppExecFwk::Dumper {
53209bc2fbSopenharmony_cipublic:
54209bc2fbSopenharmony_ci    void Dump(const std::string &message) override;
55209bc2fbSopenharmony_ci    std::string GetTag() override;
56209bc2fbSopenharmony_ci    std::string GetDumpInfo();
57209bc2fbSopenharmony_ciprivate:
58209bc2fbSopenharmony_ci    std::string dumpInfo_;
59209bc2fbSopenharmony_ci};
60209bc2fbSopenharmony_ci} // end of namespace HiviewDFX
61209bc2fbSopenharmony_ci} // end of namespace OHOS
62209bc2fbSopenharmony_ci#endif
63