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 #ifndef PLUGIN_SESSION_MANAGER_H 16 #define PLUGIN_SESSION_MANAGER_H 17 18 #include "plugin_service.h" 19 #include "plugin_session.h" 20 21 #include <mutex> 22 23 using PluginSessionPtr = std::shared_ptr<PluginSession>; 24 25 class PluginSessionManager { 26 public: 27 PluginSessionManager(const PluginServiceWeakPtr& pluginService); 28 ~PluginSessionManager(); 29 30 bool CreatePluginSessions(const std::vector<ProfilerPluginConfig>& pluginConfigs, 31 const std::vector<ProfilerSessionConfig::BufferConfig>& bufferConfigs, 32 const ProfilerDataRepeaterPtr& dataRepeater, 33 const ProfilerStateRepeaterPtr& stateRepeater); 34 35 bool CreatePluginSessions(const std::vector<ProfilerPluginConfig>& pluginConfigs, 36 const ProfilerDataRepeaterPtr& dataRepeater, 37 const ProfilerStateRepeaterPtr& stateRepeater); 38 39 bool RemovePluginSessions(const std::vector<std::string>& nameList); 40 41 bool InvalidatePluginSessions(const std::vector<std::string>& nameList); 42 43 bool StartPluginSessions(const std::vector<std::string>& nameList); 44 bool StopPluginSessions(const std::vector<std::string>& nameList); 45 bool RefreshPluginSession(); 46 47 bool CheckStatus(const std::vector<std::string>& nameList, PluginSession::State state); 48 std::vector<PluginSession::State> GetStatus(const std::vector<std::string>& nameList); 49 50 private: 51 bool CheckBufferConfig(const ProfilerSessionConfig::BufferConfig& bufferConfig); 52 bool CheckPluginSha256(const ProfilerPluginConfig& pluginConfig); 53 PluginSessionPtr CreatePluginSession(const ProfilerPluginConfig& pluginConfig, 54 const ProfilerSessionConfig::BufferConfig& bufferConfig, 55 const ProfilerDataRepeaterPtr& dataRepeater, 56 const ProfilerStateRepeaterPtr& stateRepeater); 57 PluginSessionPtr CreatePluginSession(const ProfilerPluginConfig& pluginConfig, 58 const ProfilerDataRepeaterPtr& dataRepeater, 59 const ProfilerStateRepeaterPtr& stateRepeater); 60 61 private: 62 std::mutex mutex_; 63 PluginServiceWeakPtr pluginService_; 64 65 // plugin session data: 66 std::map<std::string, PluginSessionPtr> pluginSessions_; 67 std::vector<std::string> pluginNameList_; 68 }; 69 70 #endif // PLUGIN_SESSION_MANAGER_H