• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 AUDIO_DEVICE_PARSER_H
17 #define AUDIO_DEVICE_PARSER_H
18 
19 #include <list>
20 #include <unordered_map>
21 #include <string>
22 #include <sstream>
23 
24 #include "audio_policy_log.h"
25 #include "parser.h"
26 #include "audio_device_manager.h"
27 #include "audio_xml_parser.h"
28 
29 namespace OHOS {
30 namespace AudioStandard {
31 
32 enum DeviceNodeName {
33     UNKNOWN_NODE = -1,
34     ADAPTER,
35     DEVICES,
36     DEVICE,
37 };
38 
39 class AudioDeviceParser : public Parser {
40 public:
41     static constexpr char PRIVACY_TYPE[] = "privacy";
42     static constexpr char PUBLIC_TYPE[] = "public";
43     static constexpr char DEVICE_CONFIG_FILE[] = "etc/audio/audio_device_privacy.xml";
44 
45     bool LoadConfiguration() final;
46     void Destroy() final;
47 
AudioDeviceParser(AudioDeviceManager * audioDeviceManager)48     AudioDeviceParser(AudioDeviceManager *audioDeviceManager)
49     {
50         curNode_ = AudioXmlNode::Create();
51         audioDeviceManager_ = audioDeviceManager;
52     }
53 
~AudioDeviceParser()54     virtual ~AudioDeviceParser()
55     {
56         AUDIO_INFO_LOG("AudioDeviceParser dtor");
57         Destroy();
58         curNode_ = nullptr;
59     }
60 
61 private:
62     DeviceNodeName GetDeviceNodeNameAsInt(std::shared_ptr<AudioXmlNode> curNode);
63     bool ParseInternal(std::shared_ptr<AudioXmlNode> curNode);
64     void ParseDevicePrivacyInfo(std::shared_ptr<AudioXmlNode> curNode, std::list<DevicePrivacyInfo> &deviceLists);
65     void ParserDevicePrivacyInfoList(std::shared_ptr<AudioXmlNode> curNode, std::list<DevicePrivacyInfo> &deviceLists);
66     void ParseAudioDevicePrivacyType(std::shared_ptr<AudioXmlNode> curNode, AudioDevicePrivacyType &deviceType);
67     void ParseDeviceRole(const std::string &deviceRole, uint32_t &deviceRoleFlag);
68     void ParseDeviceCategory(const std::string &deviceCategory, uint32_t &deviceCategoryFlag);
69     void ParseDeviceUsage(const std::string &deviceUsage, uint32_t &deviceUsageFlag);
70     AudioDevicePrivacyType GetDevicePrivacyType(const std::string &devicePrivacyType);
71 
72     std::shared_ptr<AudioXmlNode> curNode_ = nullptr;
73     AudioDevicePrivacyType devicePrivacyType_ = {};
74     AudioDeviceManager *audioDeviceManager_;
75     std::unordered_map<AudioDevicePrivacyType, std::list<DevicePrivacyInfo>> devicePrivacyMaps_ = {};
76 };
77 } // namespace AudioStandard
78 } // namespace OHOS
79 
80 #endif // AUDIO_DEVICE_PARSER_H
81