1 /* 2 * Copyright (c) 2021-2022 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 ST_XML_PARSER_H 17 #define ST_XML_PARSER_H 18 19 #include <list> 20 #include <libxml/parser.h> 21 #include <libxml/tree.h> 22 #include <unordered_map> 23 #include <string> 24 25 #include "audio_module_info.h" 26 #include "iport_observer.h" 27 #include "parser.h" 28 29 namespace OHOS { 30 namespace AudioStandard { 31 class XMLParser : public Parser { 32 public: 33 static constexpr char CONFIG_FILE[] = "vendor/etc/audio/audio_policy_config.xml"; 34 35 bool LoadConfiguration() final; 36 bool Parse() final; 37 void Destroy() final; 38 XMLParser(IPortObserver & observer)39 explicit XMLParser(IPortObserver &observer) 40 : mPortObserver(observer), 41 mDoc(nullptr) 42 { 43 } 44 ~XMLParser()45 virtual ~XMLParser() 46 { 47 Destroy(); 48 } 49 private: 50 NodeName GetNodeNameAsInt(xmlNode &node); 51 bool ParseInternal(xmlNode &node); 52 void ParseDeviceClass(xmlNode &node); 53 void ParseModules(xmlNode &node, std::string &className); 54 void ParsePorts(xmlNode &node, AudioModuleInfo &moduleInfo); 55 void ParsePort(xmlNode &node, AudioModuleInfo &moduleInfo); 56 void ParseAudioInterrupt(xmlNode &node); 57 void ParseUpdateRouteSupport(xmlNode &node); 58 void ParseAudioLatency(xmlNode &node); 59 void ParseSinkLatency(xmlNode &node); 60 void ParseGroups(xmlNode& node, NodeName type); 61 void ParseGroup(xmlNode& node, NodeName type); 62 void ParseGroupModule(xmlNode& node, NodeName type, std::string groupName); 63 std::string ExtractPropertyValue(const std::string &propName, xmlNode &node); 64 ClassType GetDeviceClassType(const std::string &deviceClass); 65 66 IPortObserver &mPortObserver; 67 xmlDoc *mDoc; 68 ClassType deviceClassType_; 69 std::unordered_map<ClassType, std::list<AudioModuleInfo>> xmlParsedDataMap_; 70 std::unordered_map<std::string, std::string> volumeGroupMap_; 71 std::unordered_map<std::string, std::string> interruptGroupMap_; 72 }; 73 } // namespace AudioStandard 74 } // namespace OHOS 75 76 #endif // ST_XML_PARSER_H 77