1 /*
2  * Copyright (c) 2023-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 FRAMEWORK_NATIVE_UNIFIED_COLLECTION_COLLECTOR_TRACE_STORAGE_H
17 #define FRAMEWORK_NATIVE_UNIFIED_COLLECTION_COLLECTOR_TRACE_STORAGE_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <string>
22 
23 #include "rdb_store.h"
24 #include "app_event_task_storage.h"
25 
26 namespace OHOS {
27 namespace HiviewDFX {
28 struct TraceFlowRecord {
29     std::string systemTime;
30     std::string callerName;
31     int64_t usedSize = 0;
32 };
33 
34 class TraceStorage {
35 public:
36     TraceStorage(const std::string& dbStorePath);
37     ~TraceStorage() = default;
38     void Store(const TraceFlowRecord& traceFlowRecord);
39     void Query(TraceFlowRecord& traceFlowRecord);
40 
41     bool QueryAppEventTask(int32_t uid, int32_t date, AppEventTask& appEventTask);
42     bool StoreAppEventTask(AppEventTask& appEventTask);
43     void RemoveOldAppEventTask(int32_t eventDate);
44 
45 private:
46     void InitDbStore();
47     void InsertTable(const TraceFlowRecord& traceFlowRecord);
48     void QueryTable(TraceFlowRecord& traceFlowRecord);
49     void UpdateTable(const TraceFlowRecord& traceFlowRecord);
50 
51 private:
52     std::string dbStorePath_;
53     std::shared_ptr<NativeRdb::RdbStore> dbStore_;
54     std::shared_ptr<AppEventTaskStorage> appTaskStore_;
55 }; // TraceStorage
56 } // namespace HiviewDFX
57 } // namespace OHOS
58 #endif // FRAMEWORK_NATIVE_UNIFIED_COLLECTION_COLLECTOR_TRACE_STORAGE_H
59