106f6ba60Sopenharmony_ci/*
206f6ba60Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2021-2023. All rights reserved.
306f6ba60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
406f6ba60Sopenharmony_ci * you may not use this file except in compliance with the License.
506f6ba60Sopenharmony_ci * You may obtain a copy of the License at
606f6ba60Sopenharmony_ci *
706f6ba60Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
806f6ba60Sopenharmony_ci *
906f6ba60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1006f6ba60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1106f6ba60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1206f6ba60Sopenharmony_ci * See the License for the specific language governing permissions and
1306f6ba60Sopenharmony_ci * limitations under the License.
1406f6ba60Sopenharmony_ci */
1506f6ba60Sopenharmony_ci
1606f6ba60Sopenharmony_ci#ifndef PLUGIN_MODULE_H
1706f6ba60Sopenharmony_ci#define PLUGIN_MODULE_H
1806f6ba60Sopenharmony_ci
1906f6ba60Sopenharmony_ci#include <chrono>
2006f6ba60Sopenharmony_ci#include <memory>
2106f6ba60Sopenharmony_ci#include <string>
2206f6ba60Sopenharmony_ci
2306f6ba60Sopenharmony_ci#include "buffer_writer.h"
2406f6ba60Sopenharmony_ci#include "writer_adapter.h"
2506f6ba60Sopenharmony_ci
2606f6ba60Sopenharmony_cistruct PluginModuleInfo {
2706f6ba60Sopenharmony_ci    std::string name;
2806f6ba60Sopenharmony_ci    uint32_t bufferSizeHint = 0;
2906f6ba60Sopenharmony_ci    bool isStandaloneFileData = false;
3006f6ba60Sopenharmony_ci    std::string outFileName = "";
3106f6ba60Sopenharmony_ci    std::string pluginVersion = "";
3206f6ba60Sopenharmony_ci};
3306f6ba60Sopenharmony_ci
3406f6ba60Sopenharmony_cistruct PluginModuleStruct;
3506f6ba60Sopenharmony_cistruct WriterStruct;
3606f6ba60Sopenharmony_ci
3706f6ba60Sopenharmony_ciusing BufferWriterPtr = STD_PTR(shared, BufferWriter);
3806f6ba60Sopenharmony_ci
3906f6ba60Sopenharmony_ciclass PluginModule {
4006f6ba60Sopenharmony_cipublic:
4106f6ba60Sopenharmony_ci    enum class SampleMode {
4206f6ba60Sopenharmony_ci        UNKNOWN,
4306f6ba60Sopenharmony_ci        POLLING,
4406f6ba60Sopenharmony_ci        STREAMING,
4506f6ba60Sopenharmony_ci    };
4606f6ba60Sopenharmony_ci    explicit PluginModule(const std::string& path = "");
4706f6ba60Sopenharmony_ci    ~PluginModule();
4806f6ba60Sopenharmony_ci    std::string ComputeSha256();
4906f6ba60Sopenharmony_ci
5006f6ba60Sopenharmony_ci    bool Load();
5106f6ba60Sopenharmony_ci    bool Unload();
5206f6ba60Sopenharmony_ci
5306f6ba60Sopenharmony_ci    SampleMode GetSampleMode() const;
5406f6ba60Sopenharmony_ci    bool GetInfo(PluginModuleInfo& info);
5506f6ba60Sopenharmony_ci    bool GetPluginName(std::string& pluginName);
5606f6ba60Sopenharmony_ci    bool GetBufferSizeHint(uint32_t& bufferSizeHint);
5706f6ba60Sopenharmony_ci    bool GetStandaloneFileData();
5806f6ba60Sopenharmony_ci    bool GetOutFileName(std::string& outFileName);
5906f6ba60Sopenharmony_ci    bool GetPluginVersion(std::string& pluginVersion);
6006f6ba60Sopenharmony_ci    std::string GetPath();
6106f6ba60Sopenharmony_ci    std::string GetPluginName();
6206f6ba60Sopenharmony_ci    bool IsRunning();
6306f6ba60Sopenharmony_ci    bool IsLoaded();
6406f6ba60Sopenharmony_ci    bool BindFunctions();
6506f6ba60Sopenharmony_ci
6606f6ba60Sopenharmony_ci    bool StartSession(const uint8_t* buffer, uint32_t size);
6706f6ba60Sopenharmony_ci    bool StopSession();
6806f6ba60Sopenharmony_ci    int32_t ReportResult(uint8_t* buffer, uint32_t size);
6906f6ba60Sopenharmony_ci    PluginReportResultOptimizeCallback ReportResultOptimize();
7006f6ba60Sopenharmony_ci    bool ReportBasicData();
7106f6ba60Sopenharmony_ci
7206f6ba60Sopenharmony_ci    bool RegisterWriter(const BufferWriterPtr writer, bool isProtobufSerialize = true);
7306f6ba60Sopenharmony_ci    WriterPtr GetWriter();
7406f6ba60Sopenharmony_ci
7506f6ba60Sopenharmony_ci    void SetConfigData(const std::string& data);
7606f6ba60Sopenharmony_ci    std::string GetConfigData() const;
7706f6ba60Sopenharmony_ci
7806f6ba60Sopenharmony_ci    void SetClockId(clockid_t clockId);
7906f6ba60Sopenharmony_ci    clockid_t GetClockId() const;
8006f6ba60Sopenharmony_ci
8106f6ba60Sopenharmony_ciprivate:
8206f6ba60Sopenharmony_ci    void* handle_;
8306f6ba60Sopenharmony_ci    bool running_;
8406f6ba60Sopenharmony_ci    std::string path_;
8506f6ba60Sopenharmony_ci    std::string pluginName_;
8606f6ba60Sopenharmony_ci    std::string configData_;
8706f6ba60Sopenharmony_ci    clockid_t clockId_ = CLOCK_REALTIME;
8806f6ba60Sopenharmony_ci    PluginModuleStruct* structPtr_;
8906f6ba60Sopenharmony_ci    std::shared_ptr<WriterAdapter> writerAdapter_;
9006f6ba60Sopenharmony_ci    std::chrono::steady_clock::time_point lastTime_;
9106f6ba60Sopenharmony_ci    bool first_ = true;
9206f6ba60Sopenharmony_ci    bool isProtobufSerialize_ = true;
9306f6ba60Sopenharmony_ci};
9406f6ba60Sopenharmony_ci
9506f6ba60Sopenharmony_ci#endif // !PLUGIN_MODULE_H
96