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