• 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 #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     bool ReportBasicData();
70 
71     bool RegisterWriter(const BufferWriterPtr writer);
72     WriterPtr GetWriter();
73 
74     void SetConfigData(const std::string& data);
75     std::string GetConfigData() const;
76 
77 private:
78     void* handle_;
79     bool running_;
80     std::string path_;
81     std::string pluginName_;
82     std::string configData_;
83     PluginModuleStruct* structPtr_;
84 
85     std::shared_ptr<WriterAdapter> writerAdapter_;
86 
87     std::chrono::steady_clock::time_point lastTime_;
88     bool first_ = true;
89 };
90 
91 #endif // !PLUGIN_MODULE_H
92