• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 HIVIEW_BASE_EVENT_EXPORT_JSON_WRITER_H
17 #define HIVIEW_BASE_EVENT_EXPORT_JSON_WRITER_H
18 
19 #include <functional>
20 #include <map>
21 #include <string>
22 #include <unordered_map>
23 #include <vector>
24 
25 #include "cJSON.h"
26 #include "export_db_storage.h"
27 
28 namespace OHOS {
29 namespace HiviewDFX {
30 class ExportJsonFileWriter {
31 public:
32     ExportJsonFileWriter(const std::string& moduleName, const std::string& eventVersion, const std::string& exportDir,
33         int64_t maxFileSize);
34 
35 public:
36     using ExportJsonFileZippedListener = std::function<void(const std::string&, const std::string&)>;
37     void SetExportJsonFileZippedListener(ExportJsonFileZippedListener listener);
38 
39     void ClearEventCache();
40 
41 public:
42     bool Write();
43     bool AppendEvent(const std::string& domain, const std::string& name, const std::string& eventStr);
44 
45 private:
46     std::string moduleName_;
47     std::string eventVersion_;
48     std::string exportDir_;
49     int64_t maxFileSize_ = 0;
50     int64_t totalJsonStrSize_ = 0;
51     ExportJsonFileZippedListener exportJsonFileZippedListener_;
52     // <domain, <name, eventContentString>>
53     std::unordered_map<std::string, std::vector<std::pair<std::string, std::string>>> sysEventMap_;
54 };
55 } // namespace HiviewDFX
56 } // namespace OHOS
57 
58 #endif // HIVIEW_BASE_EVENT_EXPORT_JSON_WRITER_H