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 BASE_EVENT_STORE_SYS_EVENT_SEQ_MGR_H 17 #define BASE_EVENT_STORE_SYS_EVENT_SEQ_MGR_H 18 19 #include <atomic> 20 21 namespace OHOS { 22 namespace HiviewDFX { 23 namespace EventStore { 24 constexpr char SEQ_PERSISTS_FILE_NAME[] = "event_sequence"; 25 constexpr char SEQ_PERSISTS_BACKUP_FILE_NAME[] = "event_sequence_backup"; 26 27 class SysEventSequenceManager { 28 public: 29 static SysEventSequenceManager& GetInstance(); 30 void SetSequence(int64_t seq); 31 int64_t GetSequence(); 32 int64_t GetStartSequence(); 33 34 private: 35 SysEventSequenceManager(); 36 ~SysEventSequenceManager() = default; 37 38 private: 39 void WriteSeqToFile(int64_t seq); 40 void ReadSeqFromFile(int64_t& seq); 41 std::string GetSequenceFile() const; 42 43 private: 44 std::atomic<int64_t> curSeq_ = 0; 45 int64_t startSeq_ = 0; // keep the initial sequence when hiview started, for event restore use 46 }; 47 } // namespace EventStore 48 } // namespace HiviewDFX 49 } // namespace OHOS 50 51 #endif // BASE_EVENT_STORE_SYS_EVENT_SEQ_MGR_H