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 16 #ifndef SYS_EVENT_REPEAT_GUARD_H 17 #define SYS_EVENT_REPEAT_GUARD_H 18 19 #include "sys_event.h" 20 #include "sys_event_doc_reader.h" 21 22 namespace OHOS { 23 namespace HiviewDFX { 24 template<class T> 25 struct EventRawDataInfo { EventRawDataInfoEventRawDataInfo26 EventRawDataInfo(uint8_t* rawData) 27 { 28 Parse(rawData); 29 } 30 ParseEventRawDataInfo31 void Parse(uint8_t* rawData) 32 { 33 /* rawData formate: 34 dataSize|header|TraceInfo(when isTraceOpened == 1) 35 */ 36 dataSize = *(reinterpret_cast<int32_t*>(rawData)); 37 dataPos = sizeof(int32_t); 38 head = *(reinterpret_cast<T*>(rawData + dataPos)); 39 dataPos += sizeof(T); 40 if (head.isTraceOpened == 1) { 41 dataPos += sizeof(EventRaw::TraceInfo); 42 } 43 dataPos += sizeof(int32_t); 44 }; 45 IsLogPackedEventRawDataInfo46 bool IsLogPacked() 47 { 48 constexpr uint8_t logLowBit = 5; 49 constexpr uint8_t logNotPacked = 1; 50 return (head.log >> logLowBit) != logNotPacked; 51 } 52 T head; 53 int32_t dataPos = 0; 54 int32_t dataSize = 0; 55 }; 56 57 class SysEventRepeatGuard { 58 public: 59 static void Check(SysEvent& event); 60 static void RegisterListeningUeSwitch(); 61 static void UnregisterListeningUeSwitch(); 62 private: 63 static bool IsEventRepeat(SysEvent& event); 64 static int64_t GetMinValidTime(); 65 static bool GetEventUniqueId(SysEvent& event, std::string& uniqueId); 66 }; 67 } // HiviewDFX 68 } // OHOS 69 70 #endif // SYS_EVENT_REPEAT_GUARD_H