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 EXTRACT_RULE_H 16 #define EXTRACT_RULE_H 17 #include <list> 18 #include <map> 19 #include <string> 20 #include <vector> 21 22 #include <json/json.h> 23 24 #include "syntax_rules.h" 25 namespace OHOS { 26 namespace HiviewDFX { 27 class ExtractRule { 28 public: 29 void ParseExtractRule(const std::string& eventType, const std::string& config, const std::string& fullPath); 30 const std::vector<std::string>& GetFeatureId(); GetExtractRule()31 const std::map<std::string, FeatureSet>& GetExtractRule() { return featureSets_; }; GetSegStatusCfg()32 const std::map<std::string, std::vector<std::string>>& GetSegStatusCfg() { return segStatusCfgMap_; }; 33 34 private: 35 static constexpr int JSON_ARRAY_THRESHOLD = 50; 36 37 void ParseSegStatusCfg(const Json::Value& json); 38 void ParseRule(const std::string& eventType, const Json::Value& json, const std::string& fullPath); 39 bool IsMatchId(const std::string& eventType, const std::string& featureId) const; 40 bool IsMatchPath(const std::string& sourceFile, const std::string& name, const std::string& pattern, 41 std::string& desPath) const; 42 std::vector<std::string> SplitFeatureId(const Json::Value& oject) const; 43 void ParseRule(const Json::Value& oject, std::list<FeatureRule>& features) const; 44 void ParseRuleParam(const Json::Value& oject, std::list<FeatureRule>& features, const std::string& type) const; 45 void GetExtractParam(const Json::Value& rules, 46 std::map<std::string, std::string>& param, const std::string& preKey) const; 47 std::vector<std::string> GetJsonArray(const Json::Value& json, const std::string& param); 48 49 private: 50 std::map<std::string, FeatureSet> featureSets_; 51 std::map<std::string, std::string> lockInfoMap_; 52 std::vector<std::string> featureIds_; 53 std::map<std::string, std::vector<std::string>> segStatusCfgMap_; // key: name value: [matchKey, desc] 54 }; 55 } // namespace HiviewDFX 56 } // namespace OHOS 57 #endif /* EXTRACT_RULE_H */