• 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 };
30 
31 struct PluginModuleStruct;
32 struct WriterStruct;
33 
34 using BufferWriterPtr = STD_PTR(shared, BufferWriter);
35 
36 class PluginModule {
37 public:
38     enum SampleMode {
39         UNKNOWN,
40         POLLING,
41         STREAMING,
42     };
43     explicit PluginModule(const std::string& path = "");
44     ~PluginModule();
45     std::string ComputeSha256();
46 
47     bool Load();
48     bool Unload();
49 
50     SampleMode GetSampleMode() const;
51     bool GetInfo(PluginModuleInfo& info);
52     bool GetPluginName(std::string& pluginName);
53     bool GetBufferSizeHint(uint32_t& bufferSizeHint);
54     bool IsRunning();
55     bool IsLoaded();
56     bool BindFunctions();
57 
58     bool StartSession(const uint8_t* buffer, uint32_t size);
59     bool StopSession();
60     int32_t ReportResult(uint8_t* buffer, uint32_t size);
61 
62     bool RegisterWriter(const BufferWriterPtr writer);
63     WriterPtr GetWriter();
64 
65     void SetConfigData(const std::string& data);
66     std::string GetConfigData() const;
67 
68 private:
69     void* handle_;
70     bool running_;
71     std::string path_;
72     std::string pluginName_;
73     std::string configData_;
74     PluginModuleStruct* structPtr_;
75 
76     std::shared_ptr<WriterAdapter> writerAdapter_;
77 
78     std::chrono::steady_clock::time_point lastTime_;
79     bool first_ = true;
80 };
81 
82 #endif // !PLUGIN_MODULE_H
83