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 #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 34 bool CreatePluginSessions(const std::vector<ProfilerPluginConfig>& pluginConfigs, 35 const ProfilerDataRepeaterPtr& dataRepeater); 36 37 bool RemovePluginSessions(const std::vector<std::string>& nameList); 38 39 bool InvalidatePluginSessions(const std::vector<std::string>& nameList); 40 41 bool StartPluginSessions(const std::vector<std::string>& nameList); 42 bool StopPluginSessions(const std::vector<std::string>& nameList); 43 44 bool CheckStatus(const std::vector<std::string>& nameList, PluginSession::State state); 45 std::vector<PluginSession::State> GetStatus(const std::vector<std::string>& nameList); 46 47 private: 48 bool CheckBufferConfig(const ProfilerSessionConfig::BufferConfig& bufferConfig); 49 bool CheckPluginSha256(const ProfilerPluginConfig& pluginConfig); 50 PluginSessionPtr CreatePluginSession(const ProfilerPluginConfig& pluginConfig, 51 const ProfilerSessionConfig::BufferConfig& bufferConfig, 52 const ProfilerDataRepeaterPtr& dataRepeater); 53 PluginSessionPtr CreatePluginSession(const ProfilerPluginConfig& pluginConfig, 54 const ProfilerDataRepeaterPtr& dataRepeater); 55 56 private: 57 std::mutex mutex_; 58 PluginServiceWeakPtr pluginService_; 59 60 // plugin session data: 61 std::map<std::string, PluginSessionPtr> pluginSessions_; 62 }; 63 64 #endif // PLUGIN_SESSION_MANAGER_H