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 AddExtensionPlugin(std::shared_ptr<IPlugin> extensionPlugin, uint32_t basicPluginCode, 38 ExecuteStrategy strategy) override; 39 virtual ~PluginManager(); 40 void LoadPlugin(); 41 void UnloadPlugin(); 42 43 void DumpPlugin(); 44 private: 45 std::map<std::uint32_t, std::shared_ptr<IPlugin>> pluginsCode_; 46 std::map<std::string, std::shared_ptr<IPlugin>> pluginsName_; 47 std::map<std::uint32_t, std::uint32_t> extensionPluginMap_; 48 std::map<std::uint32_t, ExecuteStrategy> executeStrategyMap_; 49 std::vector<void *> pluginHandles_; 50 static std::mutex mutexLock_; 51 static std::shared_ptr<PluginManager> instance_; 52 PluginManager(); 53 void LoadPlugin(const std::string &pluginPath); 54 std::shared_ptr<IPlugin> GetPluginByCode(std::uint32_t code); 55 std::shared_ptr<IPluginExecuteStrategy> CreateExecuteStrategy(ExecuteStrategy strategy); 56 std::shared_ptr<IPluginExecuteStrategy> enhanceStrategy_ = std::make_shared<EnhanceExecuteStrategy>(); 57 std::shared_ptr<IPluginExecuteStrategy> singleStrategy_ = std::make_shared<SingleExecuteStrategy>(); 58 std::shared_ptr<IPluginExecuteStrategy> replaceStrategy_ = std::make_shared<ReplaceExecuteStrategy>(); 59 }; 60 } // namespace EDM 61 } // namespace OHOS 62 63 #endif // SERVICES_EDM_INCLUDE_EDM_PLUGIN_MANAGER_H 64