1 /* 2 * Copyright (c) 2021 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 PLUGIN_MANAGER_H 17 #define PLUGIN_MANAGER_H 18 19 #include <map> 20 #include <memory> 21 #include <string> 22 #include <vector> 23 24 #include "manager_interface.h" 25 #include "plugin_module.h" 26 #include "schedule_task_manager.h" 27 28 class ProfilerPluginConfig; 29 class PluginResult; 30 class CommandPoller; 31 32 using CommandPollerPtr = STD_PTR(shared, CommandPoller); 33 using PluginModulePtr = STD_PTR(shared, PluginModule); 34 35 class PluginManager : public ManagerInterface { 36 public: 37 virtual ~PluginManager(); 38 bool AddPlugin(const std::string& pluginPath); 39 bool RemovePlugin(const std::string& pluginPath); 40 41 bool LoadPlugin(const std::string& pluginName); 42 bool UnloadPlugin(const std::string& pluginName); 43 bool UnloadPlugin(const uint32_t pluginId); 44 45 // CommandPoller will call the following four interfaces after receiving the command 46 bool CreatePluginSession(const std::vector<ProfilerPluginConfig>& config); 47 bool DestroyPluginSession(const std::vector<uint32_t>& pluginIds); 48 bool StartPluginSession(const std::vector<uint32_t>& pluginIds, const std::vector<ProfilerPluginConfig>& config, 49 PluginResult& result); 50 bool StopPluginSession(const std::vector<uint32_t>& pluginIds); 51 bool ReportPluginBasicData(const std::vector<uint32_t>& pluginIds); 52 53 // call the 'PluginModule::ReportResult' and 'PluginManager::SubmitResult' according to 'pluginId' 54 // creat PluginResult for current plug-in inside 55 bool PullResult(uint32_t pluginId); 56 57 // for test 58 virtual bool SubmitResult(const PluginResult& pluginResult); 59 bool CreateWriter(std::string pluginName, uint32_t bufferSize, int smbFd, int eventFd); 60 bool ResetWriter(uint32_t pluginId); 61 void SetCommandPoller(const CommandPollerPtr& p); 62 bool RegisterPlugin(const PluginModulePtr& plugin, const std::string& pluginPath, 63 const PluginModuleInfo& pluginInfo); 64 65 private: 66 std::map<uint32_t, std::shared_ptr<PluginModule>> pluginModules_; 67 std::map<std::string, uint32_t> pluginIds_; // pluginName maps to pluginId 68 CommandPollerPtr commandPoller_; 69 ScheduleTaskManager scheduleTaskManager_; 70 std::map<std::string, std::string> pluginPathAndNameMap_; 71 }; 72 73 #endif // PLUGIN_MANAGER_H 74