• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
24 #include "audio_module_info.h"
25 #include "iport_observer.h"
26 #include "parser.h"
27 
28 namespace OHOS {
29 namespace AudioStandard {
30 class XMLParser : public Parser {
31 public:
32     static constexpr char CONFIG_FILE[] = "/etc/audio/audio_policy_config.xml";
33 
34     bool LoadConfiguration() final;
35     bool Parse() final;
36     void Destroy() final;
37 
XMLParser(IPortObserver & observer)38     explicit XMLParser(IPortObserver &observer)
39         : mPortObserver(observer),
40           mDoc(nullptr)
41     {
42     }
43 
~XMLParser()44     virtual ~XMLParser()
45     {
46         Destroy();
47     }
48 private:
49     NodeName GetNodeNameAsInt(xmlNode &node);
50     bool ParseInternal(xmlNode &node);
51     void ParseDeviceClass(xmlNode &node);
52     void ParseModules(xmlNode &node, std::string &className);
53     void ParsePorts(xmlNode &node, AudioModuleInfo &moduleInfo);
54     void ParsePort(xmlNode &node, AudioModuleInfo &moduleInfo);
55     void ParseAudioInterrupt(xmlNode &node);
56     std::string ExtractPropertyValue(const std::string &propName, xmlNode &node);
57     ClassType GetDeviceClassType(const std::string &deviceClass);
58 
59     IPortObserver &mPortObserver;
60     xmlDoc *mDoc;
61     ClassType deviceClassType_;
62     std::unordered_map<ClassType, std::list<AudioModuleInfo>> xmlParsedDataMap_;
63 };
64 } // namespace AudioStandard
65 } // namespace OHOS
66 
67 #endif // ST_XML_PARSER_H
68