1f7a47986Sopenharmony_ci/*
2f7a47986Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3f7a47986Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4f7a47986Sopenharmony_ci * you may not use this file except in compliance with the License.
5f7a47986Sopenharmony_ci * You may obtain a copy of the License at
6f7a47986Sopenharmony_ci *
7f7a47986Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8f7a47986Sopenharmony_ci *
9f7a47986Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10f7a47986Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11f7a47986Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f7a47986Sopenharmony_ci * See the License for the specific language governing permissions and
13f7a47986Sopenharmony_ci * limitations under the License.
14f7a47986Sopenharmony_ci */
15f7a47986Sopenharmony_ci
16f7a47986Sopenharmony_ci#ifndef SERVICES_EDM_INCLUDE_EDM_PLUGIN_MANAGER_H
17f7a47986Sopenharmony_ci#define SERVICES_EDM_INCLUDE_EDM_PLUGIN_MANAGER_H
18f7a47986Sopenharmony_ci
19f7a47986Sopenharmony_ci#include <map>
20f7a47986Sopenharmony_ci#include <memory>
21f7a47986Sopenharmony_ci
22f7a47986Sopenharmony_ci#include "enhance_execute_strategy.h"
23f7a47986Sopenharmony_ci#include "iplugin.h"
24f7a47986Sopenharmony_ci#include "iplugin_execute_strategy.h"
25f7a47986Sopenharmony_ci#include "iplugin_manager.h"
26f7a47986Sopenharmony_ci#include "replace_execute_strategy.h"
27f7a47986Sopenharmony_ci#include "single_execute_strategy.h"
28f7a47986Sopenharmony_ci
29f7a47986Sopenharmony_cinamespace OHOS {
30f7a47986Sopenharmony_cinamespace EDM {
31f7a47986Sopenharmony_ciclass PluginManager : public std::enable_shared_from_this<PluginManager>, IPluginManager {
32f7a47986Sopenharmony_cipublic:
33f7a47986Sopenharmony_ci    static std::shared_ptr<PluginManager> GetInstance();
34f7a47986Sopenharmony_ci    std::shared_ptr<IPlugin> GetPluginByFuncCode(std::uint32_t funcCode);
35f7a47986Sopenharmony_ci    std::shared_ptr<IPlugin> GetPluginByPolicyName(const std::string &policyName);
36f7a47986Sopenharmony_ci    bool AddPlugin(std::shared_ptr<IPlugin> plugin) override;
37f7a47986Sopenharmony_ci    bool AddExtensionPlugin(std::shared_ptr<IPlugin> extensionPlugin, uint32_t basicPluginCode,
38f7a47986Sopenharmony_ci        ExecuteStrategy strategy) override;
39f7a47986Sopenharmony_ci    virtual ~PluginManager();
40f7a47986Sopenharmony_ci    void LoadPlugin();
41f7a47986Sopenharmony_ci    void UnloadPlugin();
42f7a47986Sopenharmony_ci
43f7a47986Sopenharmony_ci    void DumpPlugin();
44f7a47986Sopenharmony_ciprivate:
45f7a47986Sopenharmony_ci    std::map<std::uint32_t, std::shared_ptr<IPlugin>> pluginsCode_;
46f7a47986Sopenharmony_ci    std::map<std::string, std::shared_ptr<IPlugin>> pluginsName_;
47f7a47986Sopenharmony_ci    std::map<std::uint32_t, std::uint32_t> extensionPluginMap_;
48f7a47986Sopenharmony_ci    std::map<std::uint32_t, ExecuteStrategy> executeStrategyMap_;
49f7a47986Sopenharmony_ci    std::vector<void *> pluginHandles_;
50f7a47986Sopenharmony_ci    static std::mutex mutexLock_;
51f7a47986Sopenharmony_ci    static std::shared_ptr<PluginManager> instance_;
52f7a47986Sopenharmony_ci    PluginManager();
53f7a47986Sopenharmony_ci    void LoadPlugin(const std::string &pluginPath);
54f7a47986Sopenharmony_ci    std::shared_ptr<IPlugin> GetPluginByCode(std::uint32_t code);
55f7a47986Sopenharmony_ci    std::shared_ptr<IPluginExecuteStrategy> CreateExecuteStrategy(ExecuteStrategy strategy);
56f7a47986Sopenharmony_ci    std::shared_ptr<IPluginExecuteStrategy> enhanceStrategy_ = std::make_shared<EnhanceExecuteStrategy>();
57f7a47986Sopenharmony_ci    std::shared_ptr<IPluginExecuteStrategy> singleStrategy_ = std::make_shared<SingleExecuteStrategy>();
58f7a47986Sopenharmony_ci    std::shared_ptr<IPluginExecuteStrategy> replaceStrategy_ = std::make_shared<ReplaceExecuteStrategy>();
59f7a47986Sopenharmony_ci};
60f7a47986Sopenharmony_ci} // namespace EDM
61f7a47986Sopenharmony_ci} // namespace OHOS
62f7a47986Sopenharmony_ci
63f7a47986Sopenharmony_ci#endif // SERVICES_EDM_INCLUDE_EDM_PLUGIN_MANAGER_H
64