1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2023. 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 #ifndef PLUGIN_MODULE_H 17 #define PLUGIN_MODULE_H 18 19 #include <chrono> 20 #include <memory> 21 #include <string> 22 23 #include "buffer_writer.h" 24 #include "writer_adapter.h" 25 26 struct PluginModuleInfo { 27 std::string name; 28 uint32_t bufferSizeHint = 0; 29 bool isStandaloneFileData = false; 30 std::string outFileName = ""; 31 std::string pluginVersion = ""; 32 }; 33 34 struct PluginModuleStruct; 35 struct WriterStruct; 36 37 using BufferWriterPtr = STD_PTR(shared, BufferWriter); 38 39 class PluginModule { 40 public: 41 enum class SampleMode { 42 UNKNOWN, 43 POLLING, 44 STREAMING, 45 }; 46 explicit PluginModule(const std::string& path = ""); 47 ~PluginModule(); 48 std::string ComputeSha256(); 49 50 bool Load(); 51 bool Unload(); 52 53 SampleMode GetSampleMode() const; 54 bool GetInfo(PluginModuleInfo& info); 55 bool GetPluginName(std::string& pluginName); 56 bool GetBufferSizeHint(uint32_t& bufferSizeHint); 57 bool GetStandaloneFileData(); 58 bool GetOutFileName(std::string& outFileName); 59 bool GetPluginVersion(std::string& pluginVersion); 60 std::string GetPath(); 61 std::string GetPluginName(); 62 bool IsRunning(); 63 bool IsLoaded(); 64 bool BindFunctions(); 65 66 bool StartSession(const uint8_t* buffer, uint32_t size); 67 bool StopSession(); 68 int32_t ReportResult(uint8_t* buffer, uint32_t size); 69 PluginReportResultOptimizeCallback ReportResultOptimize(); 70 bool ReportBasicData(); 71 72 bool RegisterWriter(const BufferWriterPtr writer, bool isProtobufSerialize = true); 73 WriterPtr GetWriter(); 74 75 void SetConfigData(const std::string& data); 76 std::string GetConfigData() const; 77 78 void SetClockId(clockid_t clockId); 79 clockid_t GetClockId() const; 80 bool CheckDataReady(); 81 82 private: 83 void* handle_; 84 bool running_; 85 std::string path_; 86 std::string pluginName_; 87 std::string configData_; 88 clockid_t clockId_ = CLOCK_REALTIME; 89 PluginModuleStruct* structPtr_; 90 std::shared_ptr<WriterAdapter> writerAdapter_; 91 std::chrono::steady_clock::time_point lastTime_; 92 bool first_ = true; 93 bool isProtobufSerialize_ = true; 94 }; 95 96 #endif // !PLUGIN_MODULE_H 97