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_CONFIG_PARSER_H 17 #define HIVIEW_BASE_EVENT_EXPORT_CONFIG_PARSER_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 23 #include "cJSON.h" 24 25 namespace OHOS { 26 namespace HiviewDFX { 27 struct SettingDbParam { 28 // name of the congifured setting db parameter 29 std::string name; 30 31 // the value set when the parameter is enabled 32 std::string enabledVal; 33 }; 34 35 struct ExportConfig { 36 // name of the module which this config belong to 37 std::string moduleName; 38 39 // setting db parameter associated with export ability switch 40 SettingDbParam exportSwitchParam; 41 42 // setting db parameter associated with system upgrade 43 SettingDbParam sysUpgradeParam; 44 45 // the directory to store exported event file 46 std::string exportDir; 47 48 // the maximum capacity of the export directory, unit: Mb 49 int64_t maxCapcity = 0; 50 51 // the maximum size of the export event file, unit: Mb 52 int64_t maxSize = 0; 53 54 // the executing cycle for exporting&expiring task, unit: hour 55 int64_t taskCycle = 0; 56 57 // the config files for events configured to export 58 std::vector<std::string> eventsConfigFiles; 59 60 // the maximum count of day for event files to store. unit: day 61 int64_t dayCnt = 0; 62 }; 63 64 class ExportConfigParser { 65 public: 66 ExportConfigParser(const std::string& configFile); 67 virtual ~ExportConfigParser(); 68 69 public: 70 std::shared_ptr<ExportConfig> Parse(); 71 72 private: 73 bool ParseSettingDbParam(SettingDbParam& settingDbParam, const std::string& paramKey); 74 bool ParseResidualContent(std::shared_ptr<ExportConfig> config); 75 76 private: 77 cJSON* jsonRoot_ = nullptr; 78 }; 79 } // HiviewDFX 80 } // OHOS 81 82 #endif // HIVIEW_BASE_EVENT_EXPORT_CONFIG_PARSER_H 83