• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
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 PLUGIN_MANAGER_H
17 #define PLUGIN_MANAGER_H
18 
19 #include <map>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 #include <unordered_map>
24 #include <unordered_set>
25 #include "plugin_service.ipc.h"
26 #include "manager_interface.h"
27 #include "network_profiler_manager.h"
28 #include "plugin_module.h"
29 #include "schedule_task_manager.h"
30 
31 class ProfilerPluginConfig;
32 class PluginResult;
33 class CommandPoller;
34 
35 using CommandPollerPtr = STD_PTR(shared, CommandPoller);
36 using PluginModulePtr = STD_PTR(shared, PluginModule);
37 
38 class PluginManager : public ManagerInterface {
39 public:
40     virtual ~PluginManager();
41     bool AddPlugin(const std::string& pluginPath);
42     bool RemovePlugin(const std::string& pluginPath);
43 
44     bool LoadPlugin(const std::string& pluginName);
45     bool UnloadPlugin(const std::string& pluginName);
46     bool UnloadPlugin(const uint32_t pluginId);
47 
48     // CommandPoller will call the following four interfaces after receiving the command
49     bool CreatePluginSession(const std::vector<ProfilerPluginConfig>& config);
50     bool DestroyPluginSession(const std::vector<uint32_t>& pluginIds);
51     bool StartPluginSession(const std::vector<uint32_t>& pluginIds, const std::vector<ProfilerPluginConfig>& config,
52                                 PluginResult& result);
53     bool StopPluginSession(const std::vector<uint32_t>& pluginIds);
54     bool ReportPluginBasicData(const std::vector<uint32_t>& pluginIds);
55 
56     // call the 'PluginModule::ReportResult' and 'PluginManager::SubmitResult' according to 'pluginId'
57     // creat PluginResult for  current plug-in inside
58     bool PullResult(uint32_t pluginId, bool isProtobufSerialize = true);
59     bool StopAllPluginSession();
60 
61     // for test
62     virtual bool SubmitResult(const PluginResult& pluginResult);
63     bool CreateWriter(std::string pluginName, uint32_t bufferSize, int smbFd, int eventFd,
64                       bool isProtobufSerialize = true);
65     bool PullState(uint32_t pluginId);
66     bool ResetWriter(uint32_t pluginId);
67     void SetCommandPoller(const CommandPollerPtr& p);
68     bool RegisterPlugin(const PluginModulePtr& plugin, const std::string& pluginPath,
69                         const PluginModuleInfo& pluginInfo);
70     void AddNetworkProfilerManager(std::shared_ptr<OHOS::Developtools::Profiler::NetworkProfilerManager>
71                                    networkProfilerMgr);
72 
73 private:
74     std::map<uint32_t, std::shared_ptr<PluginModule>> pluginModules_;
75     std::map<std::string, uint32_t> pluginIds_; // pluginName maps to pluginId
76     std::unordered_set<std::string> loadedPlugins_;
77     CommandPollerPtr commandPoller_;
78     ScheduleTaskManager scheduleTaskManager_;
79     std::map<std::string, std::string> pluginPathAndNameMap_;
80     std::unordered_map<std::string, int32_t> scheduleTask_; // key is plugin name, value is timerfd.
81     std::shared_ptr<OHOS::Developtools::Profiler::NetworkProfilerManager> networkProfilerMgr_{nullptr};
82 };
83 
84 #endif // PLUGIN_MANAGER_H
85