• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include <mutex>
16 #include <sys/types.h>
17 
18 #include "hisysevent_plugin.h"
19 #include "plugin_module_api.h"
20 
21 namespace {
22 constexpr uint32_t MAX_BUFFER_SIZE = 4 * 1024 * 1024;
23 std::unique_ptr<HisyseventPlugin> g_plugin = nullptr;
24 std::mutex g_taskMutex;
25 } // namespace
26 
HisyseventSessionStart(const uint8_t * configData,uint32_t configSize)27 static int HisyseventSessionStart(const uint8_t* configData, uint32_t configSize)
28 {
29     std::lock_guard<std::mutex> guard(g_taskMutex);
30     CHECK_NOTNULL(g_plugin, -1, "start Hisysevent session FAILED!");
31     return g_plugin->Start(configData, configSize);
32 }
33 
HisyseventSessionStop()34 static int HisyseventSessionStop()
35 {
36     std::lock_guard<std::mutex> guard(g_taskMutex);
37     g_plugin->Stop();
38     g_plugin.reset();
39     return 0;
40 }
41 
HisyseventRegisterWriterStruct(WriterStruct * writer)42 static int HisyseventRegisterWriterStruct(WriterStruct* writer)
43 {
44     std::lock_guard<std::mutex> guard(g_taskMutex);
45     g_plugin = std::make_unique<HisyseventPlugin>();
46     g_plugin->SetWriter(writer);
47     return 0;
48 }
49 
50 static PluginModuleCallbacks g_callbacks = {
51     .onPluginSessionStart = HisyseventSessionStart,
52     .onPluginReportResult = 0,
53     .onPluginSessionStop = HisyseventSessionStop,
54     .onRegisterWriterStruct = (RegisterWriterStructCallback)HisyseventRegisterWriterStruct,
55 };
56 
57 EXPORT_API PluginModuleStruct g_pluginModule = {
58     .callbacks = &g_callbacks,
59     .name = "hisysevent-plugin",
60     .version = "1.02",
61     .resultBufferSizeHint = MAX_BUFFER_SIZE,
62 };