• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 SERVICES_EDM_INCLUDE_EDM_PLUGIN_MANAGER_H
17 #define SERVICES_EDM_INCLUDE_EDM_PLUGIN_MANAGER_H
18 
19 #include <map>
20 #include <memory>
21 
22 #include "enhance_execute_strategy.h"
23 #include "iplugin.h"
24 #include "iplugin_execute_strategy.h"
25 #include "iplugin_manager.h"
26 #include "replace_execute_strategy.h"
27 #include "single_execute_strategy.h"
28 
29 namespace OHOS {
30 namespace EDM {
31 class PluginManager : public std::enable_shared_from_this<PluginManager>, IPluginManager {
32 public:
33     static std::shared_ptr<PluginManager> GetInstance();
34     std::shared_ptr<IPlugin> GetPluginByFuncCode(std::uint32_t funcCode);
35     std::shared_ptr<IPlugin> GetPluginByPolicyName(const std::string &policyName);
36     bool AddPlugin(std::shared_ptr<IPlugin> plugin) override;
37     bool AddPersistentPlugin(std::shared_ptr<IPlugin> plugin) override;
38     bool AddExtensionPlugin(std::shared_ptr<IPlugin> extensionPlugin, uint32_t basicPluginCode,
39         ExecuteStrategy strategy) override;
40     virtual ~PluginManager();
41     void LoadPlugin();
42     void UnloadPlugin();
43 
44     void DumpPlugin();
45 
46 private:
47     std::map<std::uint32_t, std::shared_ptr<IPlugin>> pluginsCode_;
48     std::map<std::string, std::shared_ptr<IPlugin>> pluginsName_;
49     std::map<std::uint32_t, std::shared_ptr<IPlugin>> persistentPluginsCode_;
50     std::map<std::string, std::shared_ptr<IPlugin>> persistentPluginsName_;
51     std::map<std::uint32_t, std::uint32_t> extensionPluginMap_;
52     std::map<std::uint32_t, ExecuteStrategy> executeStrategyMap_;
53     std::vector<void *> pluginHandles_;
54     static std::mutex mutexLock_;
55     static std::shared_ptr<PluginManager> instance_;
56     PluginManager();
57     void LoadPlugin(const std::string &pluginPath);
58     bool AddPluginInner(std::shared_ptr<IPlugin> plugin, bool isPersistent);
59     void DumpPluginInner(std::map<std::uint32_t, std::shared_ptr<IPlugin>> pluginsCode,
60         std::map<std::string, std::shared_ptr<IPlugin>> pluginsName);
61     void DumpPluginConfig(IPlugin::PolicyPermissionConfig config);
62     std::shared_ptr<IPlugin> GetPluginByCode(std::uint32_t code);
63     std::shared_ptr<IPluginExecuteStrategy> CreateExecuteStrategy(ExecuteStrategy strategy);
64     std::shared_ptr<IPluginExecuteStrategy> enhanceStrategy_ = std::make_shared<EnhanceExecuteStrategy>();
65     std::shared_ptr<IPluginExecuteStrategy> singleStrategy_ = std::make_shared<SingleExecuteStrategy>();
66     std::shared_ptr<IPluginExecuteStrategy> replaceStrategy_ = std::make_shared<ReplaceExecuteStrategy>();
67 };
68 } // namespace EDM
69 } // namespace OHOS
70 
71 #endif // SERVICES_EDM_INCLUDE_EDM_PLUGIN_MANAGER_H
72