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 constexpr int16_t INVALID_TASK_TYPE = -2; 28 constexpr int16_t ALL_EVENT_TASK_TYPE = -1; 29 struct SettingDbParam { 30 // name of the congifured setting db parameter 31 std::string name; 32 33 // the value set when the parameter is enabled 34 std::string enabledVal; 35 }; 36 37 struct ExportConfig { 38 // name of the module which this config belong to 39 std::string moduleName; 40 41 // setting db parameter associated with export ability switch 42 SettingDbParam exportSwitchParam; 43 44 // setting db parameter associated with system upgrade 45 SettingDbParam sysUpgradeParam; 46 47 // the directory to store exported event file 48 std::string exportDir; 49 50 // the maximum capacity of the export directory, unit: Mb 51 int64_t maxCapcity = 0; 52 53 // the maximum size of the export event file, unit: Mb 54 int64_t maxSize = 0; 55 56 // the executing cycle for exporting&expiring task, unit: hour 57 int64_t taskCycle = 0; 58 59 // the config files for events configured to export 60 std::vector<std::string> eventsConfigFiles; 61 62 // the maximum count of day for event files to store. unit: day 63 int64_t dayCnt = 0; 64 65 int16_t taskType = INVALID_TASK_TYPE; 66 67 std::string inheritedModule; 68 69 // true: a event would be posted after event export finished 70 bool needPostEvent = false; 71 }; 72 73 class ExportConfigParser { 74 public: 75 ExportConfigParser(const std::string& configFile, const std::string& moduleName); 76 virtual ~ExportConfigParser(); 77 78 public: 79 std::shared_ptr<ExportConfig> Parse(); 80 81 private: 82 bool ParseSettingDbParam(SettingDbParam& settingDbParam, const std::string& paramKey); 83 bool ParseResidualContent(std::shared_ptr<ExportConfig> config); 84 bool ParseTaskType(std::shared_ptr<ExportConfig> config); 85 bool ParseTaskExecutingCycle(std::shared_ptr<ExportConfig> config); 86 87 private: 88 cJSON* jsonRoot_ = nullptr; 89 std::string moduleName_; 90 }; 91 } // HiviewDFX 92 } // OHOS 93 94 #endif // HIVIEW_BASE_EVENT_EXPORT_CONFIG_PARSER_H 95