1 /*
2  * Copyright (c) 2021-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 #include "sys_event_db_mgr.h"
17 
18 #include <cinttypes>
19 #include <ctime>
20 #include <string>
21 
22 #include "file_util.h"
23 #include "hiview_logger.h"
24 #include "sys_event_dao.h"
25 #include "time_util.h"
26 
27 namespace OHOS {
28 namespace HiviewDFX {
29 using EventStore::SysEventDao;
30 DEFINE_LOG_TAG("HiView-SysEventDbMgr");
31 
SaveToStore(std::shared_ptr<SysEvent> event) const32 void SysEventDbMgr::SaveToStore(std::shared_ptr<SysEvent> event) const
33 {
34     SysEventDao::Insert(event);
35     HIVIEW_LOGD("save sys event %{public}" PRId64 ", %{public}s", event->GetEventSeq(), event->eventName_.c_str());
36 }
37 
StartCheckStoreTask(std::shared_ptr<EventLoop> looper)38 void SysEventDbMgr::StartCheckStoreTask(std::shared_ptr<EventLoop> looper)
39 {
40     if (looper == nullptr) {
41         HIVIEW_LOGE("can not init check store task as looper null");
42         return;
43     }
44     HIVIEW_LOGI("init check store task");
45     auto statusTask = std::bind(&SysEventDbMgr::CheckStore, this);
46     int delay = TimeUtil::SECONDS_PER_HOUR; // 1 hour
47     looper->AddTimerEvent(nullptr, nullptr, statusTask, delay, true);
48 }
49 
CheckStore()50 void SysEventDbMgr::CheckStore()
51 {
52     HIVIEW_LOGI("start to check store");
53     SysEventDao::Clear();
54 }
55 } // namespace HiviewDFX
56 } // namespace OHOS