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