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 16#include <mutex> 17 18#include "hidump_plugin.h" 19#include "plugin_module_api.h" 20 21namespace { 22constexpr uint32_t MAX_BUFFER_SIZE = 4 * 1024 * 1024; 23std::unique_ptr<HidumpPlugin> g_plugin = nullptr; 24std::mutex g_taskMutex; 25} // namespace 26 27static int HidumpSessionStart(const uint8_t* configData, uint32_t configSize) 28{ 29 std::lock_guard<std::mutex> guard(g_taskMutex); 30 CHECK_NOTNULL(g_plugin, -1, "%s: no HidumpPlugin created!", __func__); 31 return g_plugin->Start(configData, configSize); 32} 33 34static int HidumpSessionStop() 35{ 36 std::lock_guard<std::mutex> guard(g_taskMutex); 37 CHECK_NOTNULL(g_plugin, -1, "%s: no HidumpPlugin created!", __func__); 38 g_plugin->Stop(); 39 g_plugin.reset(); 40 return 0; 41} 42 43static int HidumpRegisterWriterStruct(WriterStruct* writer) 44{ 45 std::lock_guard<std::mutex> guard(g_taskMutex); 46 g_plugin = std::make_unique<HidumpPlugin>(); 47 g_plugin->SetWriter(writer); 48 return 0; 49} 50 51static PluginModuleCallbacks g_callbacks = { 52 .onPluginSessionStart = HidumpSessionStart, 53 .onPluginReportResult = 0, 54 .onPluginSessionStop = HidumpSessionStop, 55 .onRegisterWriterStruct = (RegisterWriterStructCallback)HidumpRegisterWriterStruct, 56}; 57 58EXPORT_API PluginModuleStruct g_pluginModule = { 59 .callbacks = &g_callbacks, 60 .name = "hidump-plugin", 61 .version = "1.02", 62 .resultBufferSizeHint = MAX_BUFFER_SIZE, 63};