/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include "plugin_module_api.h" #include "memory_data_plugin.h" namespace { constexpr uint32_t MAX_BUFFER_SIZE = 4 * 1024 * 1024; std::unique_ptr g_plugin = nullptr; std::mutex g_taskMutex; } // namespace static int MemDataPluginSessionStart(const uint8_t* configData, uint32_t configSize) { std::lock_guard guard(g_taskMutex); g_plugin = std::make_unique(); return g_plugin->Start(configData, configSize); } static int MemPluginReportResult(uint8_t* bufferData, uint32_t bufferSize) { std::lock_guard guard(g_taskMutex); return g_plugin->Report(bufferData, bufferSize); } static int MemPluginSessionStop() { std::lock_guard guard(g_taskMutex); g_plugin->Stop(); g_plugin = nullptr; return 0; } static int MemRegisterWriterStruct(const WriterStruct* writer) { return 0; } static PluginModuleCallbacks g_callbacks = { .onPluginSessionStart = MemDataPluginSessionStart, .onPluginReportResult = MemPluginReportResult, .onPluginSessionStop = MemPluginSessionStop, .onRegisterWriterStruct = MemRegisterWriterStruct, }; EXPORT_API PluginModuleStruct g_pluginModule = { .callbacks = &g_callbacks, .name = "memory-plugin", .version = "1.01", .resultBufferSizeHint = MAX_BUFFER_SIZE, };