1 /* 2 * Copyright (C) 2023 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 SECURITY_GUARD_AUDIT_EVENT_MEM_RDB_HELPER_H 17 #define SECURITY_GUARD_AUDIT_EVENT_MEM_RDB_HELPER_H 18 19 #include "rdb_predicates.h" 20 #include "values_bucket.h" 21 22 #include "timer.h" 23 24 #include "database_helper.h" 25 #include "config_define.h" 26 #include "store_define.h" 27 28 namespace OHOS::Security::SecurityGuard { 29 class AuditEventMemRdbHelper : public DatabaseHelper { 30 public: 31 static DatabaseHelper &GetInstance(); 32 int Init() override; 33 void Release() override; 34 int QueryAllEvent(std::vector<SecEvent> &events) override; 35 int QueryAllEventFromMem(std::vector<SecEvent> &events) override; 36 int FlushAllEvent() override; 37 38 private: 39 AuditEventMemRdbHelper(); 40 ~AuditEventMemRdbHelper(); 41 int QueryEventFromMemByDate(std::vector<SecEvent> &events, std::string date); 42 void DeleteRedundantData(const std::unordered_map<int64_t, int64_t> &countMap); 43 int DeleteFlushDataFromMem(std::string date); 44 int DeleteExpiredDataFromMain(std::string date); 45 Utils::Timer timer_{"sg_db_flush"}; 46 uint32_t timerId_{}; 47 }; 48 } // namespace OHOS::Security::SecurityGuard { 49 #endif // SECURITY_GUARD_AUDIT_EVENT_MEM_RDB_HELPER_H