1 /*
2  * Copyright (c) 2024 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 #ifndef FAULT_DETECTOR_BASE_H
16 #define FAULT_DETECTOR_BASE_H
17 
18 #include <map>
19 #include <memory>
20 #include <unordered_map>
21 
22 #include "fault_common_base.h"
23 #include "fault_info_base.h"
24 #include "fault_state_base.h"
25 
26 namespace OHOS {
27 namespace HiviewDFX {
28 class FaultStateBase;
29 
30 class FaultDetectorBase {
31 public:
FaultDetectorBase()32     FaultDetectorBase() {};
~FaultDetectorBase()33     virtual ~FaultDetectorBase() {};
34     virtual FaultStateBase* GetStateObj(FaultStateType stateType) = 0;
35     virtual ErrCode MainProcess() = 0;
36     virtual void OnChangeState(std::shared_ptr<FaultInfoBase> &monitorInfo, FaultStateType stateType) = 0;
37     virtual ErrCode ExeNextStateProcess(std::shared_ptr<FaultInfoBase> monitorInfo, FaultStateType stateType) = 0;
38 
39 protected:
40     std::unordered_map<int64_t, std::string> monitoredPidList_;
41     std::unordered_map<int64_t, std::shared_ptr<FaultInfoBase>> monitoredPidsInfo_;
42     std::map<std::string, int64_t> processedPids_;
43 };
44 } // HiviewDFX
45 } // OHOS
46 
47 #endif // FAULT_DETECTOR_BASE_H
48