1 /* 2 * Copyright (c) 2021-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 #include "handler_checker.h" 17 #include "xcollie_utils.h" 18 19 namespace OHOS { 20 namespace HiviewDFX { ScheduleCheck()21void HandlerChecker::ScheduleCheck() 22 { 23 if (!isCompleted_ || handler_ == nullptr) { 24 return; 25 } 26 27 isCompleted_.store(false); 28 auto f = [this] () { 29 this->isCompleted_.store(true); 30 }; 31 if (!handler_->PostTask(f, "XCollie Watchdog Task", 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) { 32 XCOLLIE_LOGE("XCollie Watchdog Task PostTask False."); 33 } 34 } 35 GetCheckState()36int HandlerChecker::GetCheckState() 37 { 38 if (isCompleted_) { 39 taskSlow = false; 40 return CheckStatus::COMPLETED; 41 } else { 42 if (!taskSlow) { 43 taskSlow = true; 44 return CheckStatus::WAITED_HALF; 45 } else { 46 return CheckStatus::WAITING; 47 } 48 } 49 } 50 GetDumpInfo()51std::string HandlerChecker::GetDumpInfo() 52 { 53 std::string ret; 54 if (handler_ != nullptr) { 55 HandlerDumper handlerDumper; 56 handler_->Dump(handlerDumper); 57 ret = handlerDumper.GetDumpInfo(); 58 } 59 return ret; 60 } 61 62 GetHandler() const63std::shared_ptr<AppExecFwk::EventHandler> HandlerChecker::GetHandler() const 64 { 65 return handler_; 66 } 67 Dump(const std::string & message)68void HandlerDumper::Dump(const std::string &message) 69 { 70 XCOLLIE_LOGD("message is %{public}s", message.c_str()); 71 dumpInfo_ += message; 72 } 73 GetTag()74std::string HandlerDumper::GetTag() 75 { 76 return ""; 77 } 78 GetDumpInfo()79std::string HandlerDumper::GetDumpInfo() 80 { 81 return dumpInfo_; 82 } 83 } // end of namespace HiviewDFX 84 } // end of namespace OHOS 85