1 /*
2  * Copyright (c) 2022 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 RESSCHED_SERVICES_RESSCHEDMGR_RESSCHEDFWK_INCLUDE_PLUGIN_SWITCH_H
17 #define RESSCHED_SERVICES_RESSCHEDMGR_RESSCHEDFWK_INCLUDE_PLUGIN_SWITCH_H
18 
19 #include <memory>
20 #include <mutex>
21 
22 #include "libxml/parser.h"
23 #include "libxml/xpath.h"
24 
25 #include "config_info.h"
26 
27 namespace OHOS {
28 namespace ResourceSchedule {
29 struct PluginInfo {
30     std::string libPath;
31     bool switchOn = false;
32 };
33 
34 class PluginSwitch {
35 public:
36     /**
37      * Load the config file, parse the xml stream and construct the objects.
38      *
39      * @param configFile The xml filepath.
40      * @param isRssExe Calling service is resource schedule executor.
41      * @return Returns true if parse successfully.
42      */
43     bool LoadFromConfigContent(const std::string& content, bool isRssExe = false);
44 
45     /**
46      * Get all plugin info, about plugin switch status.
47      *
48      * @return Returns the plugin info.
49      */
50     std::list<PluginInfo> GetPluginSwitch();
51 
52 private:
53     static bool IsInvalidNode(const xmlNode& currNode);
54     static bool FillinPluginInfo(const xmlNode* currNode, PluginInfo& info, bool isRssExe = false);
55 
56     using PluginInfoMap = std::map<std::string, std::string>;
57 
58     std::map<std::string, PluginInfo> pluginSwitchMap_;
59 };
60 } // namespace ResourceSchedule
61 } // namespace OHOS
62 
63 #endif // RESSCHED_SERVICES_RESSCHEDMGR_RESSCHEDFWK_INCLUDE_PLUGIN_SWITCH_H
64