1 /* 2 * Copyright (c) 2024-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_AFFINITY_PARSER_H 17 #define AUDIO_AFFINITY_PARSER_H 18 19 #include <vector> 20 #include <unordered_map> 21 #include <string> 22 #include <sstream> 23 24 #include "iport_observer.h" 25 #include "parser.h" 26 #include "audio_affinity_manager.h" 27 #include "audio_xml_parser.h" 28 29 namespace OHOS { 30 namespace AudioStandard { 31 using namespace std; 32 33 class AudioAffinityParser : public Parser { 34 public: 35 static constexpr char AFFINITY_CONFIG_FILE[] = "/system/etc/audio/audio_affinity_config.xml"; 36 37 bool LoadConfiguration() final; 38 void Destroy() final; 39 AudioAffinityParser(AudioAffinityManager * affinityManager)40 AudioAffinityParser(AudioAffinityManager *affinityManager) 41 { 42 audioAffinityManager_ = affinityManager; 43 curNode_ = AudioXmlNode::Create(); 44 } 45 ~AudioAffinityParser()46 virtual ~AudioAffinityParser() 47 { 48 Destroy(); 49 curNode_ = nullptr; 50 } 51 GetAffinityDeviceInfo()52 std::vector<AffinityDeviceInfo>& GetAffinityDeviceInfo() 53 { 54 return affinityDeviceInfoArray_; 55 } 56 57 private: 58 bool ParseInternal(std::shared_ptr<AudioXmlNode> curNode); 59 void ParserAffinityGroups(std::shared_ptr<AudioXmlNode> curNode, const DeviceFlag& deviceFlag); 60 void ParserAffinityGroupAttribute(std::shared_ptr<AudioXmlNode> curNode, const DeviceFlag& deviceFlag); 61 void ParserAffinityGroupDeviceInfos(std::shared_ptr<AudioXmlNode> curNode, AffinityDeviceInfo& deviceInfo); 62 63 std::shared_ptr<AudioXmlNode> curNode_ = nullptr; 64 AudioAffinityManager* audioAffinityManager_ = nullptr; 65 std::vector<AffinityDeviceInfo> affinityDeviceInfoArray_ = {}; 66 }; 67 } // namespace AudioStandard 68 } // namespace OHOS 69 #endif // AUDIO_DEVICE_AFFINITY_PARSER_H 70