• 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 #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     bool RefreshPluginSession();
44 
45     bool CheckStatus(const std::vector<std::string>& nameList, PluginSession::State state);
46     std::vector<PluginSession::State> GetStatus(const std::vector<std::string>& nameList);
47 
48 private:
49     bool CheckBufferConfig(const ProfilerSessionConfig::BufferConfig& bufferConfig);
50     bool CheckPluginSha256(const ProfilerPluginConfig& pluginConfig);
51     PluginSessionPtr CreatePluginSession(const ProfilerPluginConfig& pluginConfig,
52                                          const ProfilerSessionConfig::BufferConfig& bufferConfig,
53                                          const ProfilerDataRepeaterPtr& dataRepeater);
54     PluginSessionPtr CreatePluginSession(const ProfilerPluginConfig& pluginConfig,
55                                          const ProfilerDataRepeaterPtr& dataRepeater);
56 
57 private:
58     std::mutex mutex_;
59     PluginServiceWeakPtr pluginService_;
60 
61     // plugin session data:
62     std::map<std::string, PluginSessionPtr> pluginSessions_;
63     std::vector<std::string> pluginNameList_;
64 };
65 
66 #endif // PLUGIN_SESSION_MANAGER_H