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 RELIABILITY_HANDLER_CHECKER_H 17 #define RELIABILITY_HANDLER_CHECKER_H 18 19 #include <atomic> 20 #include <string> 21 22 #include "dumper.h" 23 #include "event_handler.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 enum CheckStatus { 28 COMPLETED = 0, 29 WAITING = 1, 30 WAITED_HALF = 2, 31 }; 32 33 class HandlerChecker { 34 public: HandlerChecker(std::string name,std::shared_ptr<AppExecFwk::EventHandler> handler)35 HandlerChecker(std::string name, std::shared_ptr<AppExecFwk::EventHandler> handler) 36 : name_(name), handler_(handler) {}; ~HandlerChecker()37 ~HandlerChecker() {}; 38 39 public: 40 void ScheduleCheck(); 41 int GetCheckState(); 42 std::shared_ptr<AppExecFwk::EventHandler> GetHandler() const; 43 std::string GetDumpInfo(); 44 45 private: 46 std::string name_; 47 std::shared_ptr<AppExecFwk::EventHandler> handler_; 48 std::atomic<bool> isCompleted_ = true; 49 bool taskSlow = false; 50 }; 51 52 class HandlerDumper : public AppExecFwk::Dumper { 53 public: 54 void Dump(const std::string &message) override; 55 std::string GetTag() override; 56 std::string GetDumpInfo(); 57 private: 58 std::string dumpInfo_; 59 }; 60 } // end of namespace HiviewDFX 61 } // end of namespace OHOS 62 #endif 63