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 HIVIEW_BASE_PLUGIN_PROXY_H 16 #define HIVIEW_BASE_PLUGIN_PROXY_H 17 18 #include <ctime> 19 #include <memory> 20 #include <mutex> 21 22 #include "event.h" 23 #include "plugin.h" 24 #include "plugin_config.h" 25 26 namespace OHOS { 27 namespace HiviewDFX { 28 class PluginProxy : public Plugin { 29 public: PluginProxy()30 PluginProxy() {}; ~PluginProxy()31 virtual ~PluginProxy() {}; 32 bool OnEvent(std::shared_ptr<Event>& event) override; 33 bool CanProcessEvent(std::shared_ptr<Event> event) override; 34 bool CanProcessMoreEvents() override; 35 std::string GetHandlerInfo() override; 36 void Dump(int fd __UNUSED, const std::vector<std::string>& cmds) override; 37 void OnEventListeningCallback(const Event &msg) override; 38 bool LoadPluginIfNeed(); 39 void DestroyInstanceIfNeed(time_t maxIdleTime); HoldInstance()40 bool HoldInstance() 41 { 42 return (plugin_ != nullptr); 43 } SetPluginConfig(const PluginConfig::PluginInfo & config)44 void SetPluginConfig(const PluginConfig::PluginInfo& config) 45 { 46 config_ = config; 47 } GetPluginConfig()48 const PluginConfig::PluginInfo& GetPluginConfig() 49 { 50 return config_; 51 } 52 53 private: 54 std::shared_ptr<Plugin> plugin_; 55 std::mutex lock_; 56 PluginConfig::PluginInfo config_; 57 }; 58 } // namespace HiviewDFX 59 } // namespace OHOS 60 #endif // HIVIEW_BASE_PLUGIN_PROXY_H 61