1 /* 2 * Copyright (C) 2021 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 #ifndef HIVIEW_PLUGIN_EVENT_LOGGER_CONFIG_H 16 #define HIVIEW_PLUGIN_EVENT_LOGGER_CONFIG_H 17 #include <fstream> 18 #include <string> 19 #include <unordered_map> 20 namespace OHOS { 21 namespace HiviewDFX { 22 class EventLoggerConfig { 23 public: 24 EventLoggerConfig(); 25 explicit EventLoggerConfig(std::string configPath); ~EventLoggerConfig()26 ~EventLoggerConfig(){}; 27 28 struct EventLoggerConfigData { 29 int id; 30 std::string name; 31 std::string action; 32 int interval; 33 }; 34 35 bool FindConfigLine(int eventId, std::string eventName, EventLoggerConfigData &configOut); 36 std::unordered_map<std::string, EventLoggerConfigData> GetConfig(); 37 GetVersion()38 std::string GetVersion() const 39 { 40 return version_; 41 }; 42 private: 43 std::ifstream in_; 44 std::string configPath_; 45 std::string version_; 46 47 bool OpenConfig(); 48 void CloseConfig(); 49 bool FindConfigVersion(); 50 bool ParseConfigData(std::function<bool(EventLoggerConfigData&)> func); 51 }; 52 } // namespace HiviewDFX 53 } // namespace OHOS 54 #endif // HIVIEW_PLUGIN_EVENT_LOG_COLLECTOR_H 55