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_SESSION_H 17 #define PLUGIN_SESSION_H 18 19 #include <mutex> 20 #include "logging.h" 21 #include "nocopyable.h" 22 #include "plugin_service_types.pb.h" 23 #include "profiler_service_types.pb.h" 24 25 class PluginService; 26 class ProfilerDataRepeater; 27 28 using PluginServiceWeakPtr = STD_PTR(weak, PluginService); 29 using ProfilerDataRepeaterPtr = STD_PTR(shared, ProfilerDataRepeater); 30 31 class PluginSession { 32 public: 33 PluginSession(const ProfilerPluginConfig& pluginConfig, 34 const PluginServiceWeakPtr& pluginService, 35 const ProfilerDataRepeaterPtr& dataRepeater); 36 PluginSession(const ProfilerPluginConfig& pluginConfig, 37 const ProfilerSessionConfig::BufferConfig& bufferConfig, 38 const PluginServiceWeakPtr& pluginService, 39 const ProfilerDataRepeaterPtr& dataRepeater); 40 ~PluginSession(); 41 42 bool Start(); 43 bool Stop(); 44 45 bool IsAvailable() const; 46 47 enum State { 48 INVALID = -1, 49 INITIAL = 0, 50 CREATED = 1, 51 STARTED = 2, 52 }; 53 54 void Invalidate(); 55 56 State GetState() const; 57 58 private: 59 bool Create(); 60 bool StopLocked(); 61 bool Destroy(); 62 63 private: 64 mutable std::mutex mutex_; 65 State state_; 66 bool withBufferConfig_; 67 ProfilerPluginConfig pluginConfig_; 68 ProfilerSessionConfig::BufferConfig bufferConfig_; 69 PluginServiceWeakPtr pluginService_; 70 ProfilerDataRepeaterPtr dataRepeater_; 71 72 DISALLOW_COPY_AND_MOVE(PluginSession); 73 }; 74 75 #endif // !PLUGIN_SESSION_H 76