• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
34 class PluginManager : public ManagerInterface {
35 public:
36     virtual ~PluginManager();
37     bool AddPlugin(const std::string& pluginPath);
38     bool RemovePlugin(const std::string& pluginPath);
39 
40     bool LoadPlugin(const std::string& pluginName);
41     bool UnloadPlugin(const std::string& pluginName);
42     bool UnloadPlugin(const uint32_t pluginId);
43 
44     // CommandPoller will call the following four interfaces after receiving the command
45     bool CreatePluginSession(const std::vector<ProfilerPluginConfig>& config);
46     bool DestroyPluginSession(const std::vector<uint32_t>& pluginIds);
47     bool StartPluginSession(const std::vector<uint32_t>& pluginIds, const std::vector<ProfilerPluginConfig>& config);
48     bool StopPluginSession(const std::vector<uint32_t>& pluginIds);
49 
50     // call the 'PluginModule::ReportResult' and 'PluginManager::SubmitResult' according to 'pluginId'
51     // creat PluginResult for  current plug-in inside
52     bool PullResult(uint32_t pluginId);
53 
54     // for test
55     virtual bool SubmitResult(const PluginResult& pluginResult);
56     bool CreateWriter(std::string pluginName, uint32_t bufferSize, int smbFd, int eventFd);
57     bool ResetWriter(uint32_t pluginId);
58     void SetCommandPoller(const CommandPollerPtr& p);
59 
60 private:
61     std::map<uint32_t, std::shared_ptr<PluginModule>> pluginModules_;
62     std::map<std::string, uint32_t> pluginIds_; // pluginName maps to pluginId
63     CommandPollerPtr commandPoller_;
64     ScheduleTaskManager scheduleTaskManager_;
65     std::map<std::string, std::string> pluginPathAndNameMap_;
66 };
67 
68 #endif // PLUGIN_MANAGER_H
69