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_define.h"
21 
22 using XCollieCallback = std::function<void (void *)>;
23 namespace OHOS {
24 namespace HiviewDFX {
25 class XCollie : public Singleton<XCollie> {
26     DECLARE_SINGLETON(XCollie);
27 public:
28     // set timer
29     // name : timer name
30     // timeout : timeout, unit s
31     // func : callback
32     // arg : the callback's param
33     // flag : timer timeout operation. the value can be:
34     //                               XCOLLIE_FLAG_DEFAULT :do all callback function
35     //                               XCOLLIE_FLAG_NOOP  : do nothing but the caller defined function
36     //                               XCOLLIE_FLAG_LOG :  generate log file
37     //                               XCOLLIE_FLAG_RECOVERY  : die when timeout
38     // return: the timer id
39     int SetTimer(const std::string &name, unsigned int timeout,
40         XCollieCallback func, void *arg, unsigned int flag);
41 
42     // cancel timer
43     // id: timer id
44     void CancelTimer(int id);
45 
46     // set timer and count
47     // name: timer and count name
48     // timeLimit: event occured time limt
49     // countLimit: event occured count limit
50     int SetTimerCount(const std::string &name, unsigned int timeLimit, int countLimit);
51 
52     // trigger timer count
53     // name: tigger name
54     // bTrigger: trigger or cancel
55     // message: need report pid current message
56     void TriggerTimerCount(const std::string &name, bool bTrigger, const std::string &message);
57 };
58 } // end of namespace HiviewDFX
59 } // end of namespace OHOS
60 #endif
61 
62