• 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 
16 #include <mutex>
17 #include <sys/types.h>
18 
19 #include "process_data_plugin.h"
20 #include "plugin_module_api.h"
21 
22 namespace {
23 constexpr uint32_t MAX_BUFFER_SIZE = 4 * 1024 * 1024;
24 std::unique_ptr<ProcessDataPlugin> g_plugin = nullptr;
25 std::mutex g_taskMutex;
26 } // namespace
27 
ProcessDataPluginSessionStart(const uint8_t * configData,uint32_t configSize)28 static int ProcessDataPluginSessionStart(const uint8_t* configData, uint32_t configSize)
29 {
30     std::lock_guard<std::mutex> guard(g_taskMutex);
31     g_plugin = std::make_unique<ProcessDataPlugin>();
32     return g_plugin->Start(configData, configSize);
33 }
34 
ProcessPluginReportResult(uint8_t * bufferData,uint32_t bufferSize)35 static int ProcessPluginReportResult(uint8_t* bufferData, uint32_t bufferSize)
36 {
37     std::lock_guard<std::mutex> guard(g_taskMutex);
38     if (g_plugin == nullptr) {
39         return -1;
40     }
41     return g_plugin->Report(bufferData, bufferSize);
42 }
43 
ProcessPluginSessionStop()44 static int ProcessPluginSessionStop()
45 {
46     std::lock_guard<std::mutex> guard(g_taskMutex);
47     g_plugin->Stop();
48     g_plugin = nullptr;
49     return 0;
50 }
51 
ProcessRegisterWriterStruct(const WriterStruct * writer)52 static int ProcessRegisterWriterStruct(const WriterStruct* writer)
53 {
54     return 0;
55 }
56 
57 static PluginModuleCallbacks g_callbacks = {
58     .onPluginSessionStart = ProcessDataPluginSessionStart,
59     .onPluginReportResult = ProcessPluginReportResult,
60     .onPluginSessionStop = ProcessPluginSessionStop,
61     .onRegisterWriterStruct = ProcessRegisterWriterStruct,
62 };
63 
64 EXPORT_API PluginModuleStruct g_pluginModule = {
65     .callbacks = &g_callbacks,
66     .name = "process-plugin",
67     .version = "1.02",
68     .resultBufferSizeHint = MAX_BUFFER_SIZE,
69 };