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_STRATEGY_ROUTER_PARSER_H 17 #define AUDIO_STRATEGY_ROUTER_PARSER_H 18 19 #include <unordered_map> 20 #include <string> 21 #include <sstream> 22 23 #include "audio_policy_log.h" 24 #include "iport_observer.h" 25 #include "parser.h" 26 #include "router_base.h" 27 #include "audio_xml_parser.h" 28 29 namespace OHOS { 30 namespace AudioStandard { 31 using namespace std; 32 class AudioStrategyRouterParser : public Parser { 33 public: 34 static constexpr char DEVICE_CONFIG_FILE[] = "/system/etc/audio/audio_strategy_router.xml"; 35 36 bool LoadConfiguration() final; 37 void Destroy() final; 38 AudioStrategyRouterParser()39 AudioStrategyRouterParser() 40 { 41 curNode_ = AudioXmlNode::Create(); 42 AUDIO_DEBUG_LOG("AudioStrategyRouterParser ctor"); 43 } 44 ~AudioStrategyRouterParser()45 ~AudioStrategyRouterParser() 46 { 47 AUDIO_DEBUG_LOG("AudioStrategyRouterParser dtor"); 48 Destroy(); 49 curNode_ = nullptr; 50 } 51 52 std::vector<std::unique_ptr<RouterBase>> mediaRenderRouters_; 53 std::vector<std::unique_ptr<RouterBase>> callRenderRouters_; 54 std::vector<std::unique_ptr<RouterBase>> callCaptureRouters_; 55 std::vector<std::unique_ptr<RouterBase>> ringRenderRouters_; 56 std::vector<std::unique_ptr<RouterBase>> toneRenderRouters_; 57 std::vector<std::unique_ptr<RouterBase>> recordCaptureRouters_; 58 std::vector<std::unique_ptr<RouterBase>> voiceMessageRouters_; 59 60 private: 61 bool ParseInternal(std::shared_ptr<AudioXmlNode> curNode); 62 void ParserStrategyInfo(std::shared_ptr<AudioXmlNode> curNode); 63 void AddRouters(std::vector<std::unique_ptr<RouterBase>> &routers, string &routeName); 64 std::vector<std::string> split(const std::string &line, const std::string &sep); 65 std::shared_ptr<AudioXmlNode> curNode_ = nullptr; 66 }; 67 } // namespace AudioStandard 68 } // namespace OHOS 69 70 #endif // AUDIO_STRATEGY_ROUTER_PARSER_H 71