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_XCOLLIE_H 17 #define RELIABILITY_XCOLLIE_H 18 #include <string> 19 #include "singleton.h" 20 #include "xcollie_checker.h" 21 #include "xcollie_define.h" 22 23 namespace OHOS { 24 namespace HiviewDFX { 25 class XCollie : public Singleton<XCollie> { 26 DECLARE_SINGLETON(XCollie); 27 public: 28 // register XCollieChecker for service watchdog 29 // checker : XCollieChecker object 30 // type : watchdog type. the value can be:XCOLLIE_LOCK, XCOLLIE_THREAD, XCOLLIE_LOCK|XCOLLIE_Thread 31 void RegisterXCollieChecker(const sptr<XCollieChecker> &checker, unsigned int type); 32 33 // set timer 34 // name : timer name 35 // timeout : timeout, unit s 36 // func : callback 37 // arg : the callback's param 38 // flag : timer timeout operation. the value can be: 39 // XCOLLIE_FLAG_DEFAULT :do all callback function 40 // XCOLLIE_FLAG_NOOP : do nothing but the caller defined function 41 // XCOLLIE_FLAG_LOG : generate log file 42 // XCOLLIE_FLAG_RECOVERY : die when timeout 43 // return: the timer id 44 int SetTimer(const std::string &name, unsigned int timeout, 45 std::function<void (void *)> func, void *arg, unsigned int flag); 46 47 // cancel timer 48 // id: timer id 49 void CancelTimer(int id); 50 51 // update timer 52 // id: timer id 53 // timeout: timeout, unit s 54 bool UpdateTimer(int id, unsigned int timeout); 55 }; 56 } // end of namespace HiviewDFX 57 } // end of namespace OHOS 58 #endif 59 60