• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "sys_event_db_mgr.h"
17 
18 #include <cinttypes>
19 #include <ctime>
20 #include <string>
21 
22 #include "file_util.h"
23 #include "logger.h"
24 #include "sys_event_dao.h"
25 #include "sys_event_db_backup.h"
26 #include "sys_event_db_clean.h"
27 #include "sys_event.h"
28 #include "time_util.h"
29 
30 namespace OHOS {
31 namespace HiviewDFX {
32 DEFINE_LOG_TAG("HiView-SysEventDbMgr");
33 using EventStore::SysEventDao;
SaveToStore(std::shared_ptr<SysEvent> sysevent) const34 void SysEventDbMgr::SaveToStore(std::shared_ptr<SysEvent> sysevent) const
35 {
36     SysEventDao::Insert(sysevent);
37     HIVIEW_LOGD("save sys event %{public}" PRId64 ", %{public}s", sysevent->GetSeq(), sysevent->eventName_.c_str());
38 }
39 
StartCheckStoreTask(std::shared_ptr<EventLoop> looper)40 void SysEventDbMgr::StartCheckStoreTask(std::shared_ptr<EventLoop> looper)
41 {
42     if (looper == nullptr) {
43         HIVIEW_LOGE("can not init check store task as looper null");
44         return;
45     }
46     HIVIEW_LOGI("init check store task");
47     auto statusTask = std::bind(&SysEventDbMgr::CheckStore, this);
48     int delay = TimeUtil::SECONDS_PER_MINUTE * 10; // ten minute
49     looper->AddTimerEvent(nullptr, nullptr, statusTask, delay, true);
50 }
51 
CheckStore()52 void SysEventDbMgr::CheckStore()
53 {
54     SysEventDbClean sysEventDbClean;
55     SysEventDbBackup sysEventDbBackup(backupTime_);
56     if (!sysEventDbClean.CleanDbStore()) {
57         sysEventDbBackup.Recover();
58         return;
59     }
60     sysEventDbBackup.CheckDbStoreBroken();
61 }
62 } // namespace HiviewDFX
63 } // namespace OHOS