1 /*
2  * Copyright (c) 2023 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 AUDIO_VOLUME_PARSER_H
16 #define AUDIO_VOLUME_PARSER_H
17 
18 #include <libxml/parser.h>
19 #include <libxml/tree.h>
20 #include <map>
21 #include <string>
22 #include <vector>
23 #include <unordered_map>
24 #include "audio_errors.h"
25 #include "audio_info.h"
26 #include "audio_policy_log.h"
27 #include "audio_volume_config.h"
28 
29 namespace OHOS {
30 namespace AudioStandard {
31 
32 #ifdef USE_CONFIG_POLICY
33 static constexpr char AUDIO_VOLUME_CONFIG_FILE[] = "etc/audio/audio_volume_config.xml";
34 #else
35 static constexpr char AUDIO_VOLUME_CONFIG_FILE[] = "system/etc/audio/audio_volume_config.xml";
36 #endif
37 class AudioVolumeParser {
38 public:
39     AudioVolumeParser();
40     virtual ~AudioVolumeParser();
41     int32_t LoadConfig(StreamVolumeInfoMap &streamVolumeInfoMap);
42 private:
43     std::map<std::string, AudioVolumeType> audioStreamMap_;
44     std::map<std::string, DeviceVolumeType> audioDeviceMap_;
45 
46     void ParseStreamInfos(xmlNode *node, StreamVolumeInfoMap &streamVolumeInfoMap);
47     void ParseStreamVolumeInfoAttr(xmlNode *node, std::shared_ptr<StreamVolumeInfo> &streamVolInfo);
48     void ParseDeviceVolumeInfos(xmlNode *node, std::shared_ptr<StreamVolumeInfo> &streamVolInfo);
49     void ParseVolumePoints(xmlNode *node, std::shared_ptr<DeviceVolumeInfo> &deviceVolInfo);
50     int32_t ParseVolumeConfig(const char *path, StreamVolumeInfoMap &streamVolumeInfoMap);
51     void WriteVolumeConfigErrorEvent();
52 };
53 } // namespace AudioStandard
54 } // namespace OHOS
55 #endif // AUDIO_VOLUME_PARSER_H
56