class IPlugin {
public:
virtual ~IPlugin() = default;
virtual const long long GetVersion() const = 0;
virtual const char *GetName() const = 0;
/**
* Get plugin inference mode.
*
* @return Inference mode, synchronous or asynchronous.
*/
virtual const char *GetInferMode() const = 0;
/**
* Algorithmic inference interface for synchronous tasks.
*
* @param [in] request Request task which contains the specific information of the task.
* @param [out] response Results of encapsulated algorithmic inference.
* @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
*/
virtual int SyncProcess(IRequest *request, IResponse *&response) = 0;
/**
* Algorithmic inference interface for asynchronous tasks.
*
* @param [in] request Request task which contains the specific information of the task.
* @param [in] callback Callback which is used to return the result of asynchronous inference.
* @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
*/
virtual int AsyncProcess(IRequest *request, IPluginCallback *callback) = 0;
/**
* Initialize plugin.
*
* @param [in] transactionId Transaction ID.
* @param [in] inputInfo Data information needed to initialize plugin.
* @param [out] outputInfo The returned data information of initializing plugin.
* @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
*/
virtual int Prepare(long long transactionId, const DataInfo &inputInfo, DataInfo &outputInfo) = 0;
/**
* Unload model and plugin.
*
* @param [in] isFullUnload Whether to unload completely.
* @param [in] transactionId Transaction ID.
* @param [in] inputInfo Data information needed to unload model and plugin.
* @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
*/
virtual int Release(bool isFullUnload, long long transactionId, const DataInfo &inputInfo) = 0;
/**
* Set the configuration parameters of the plugin.
*
* @param [in] optionType The type of setting option.
* @param [in] inputInfo Configuration parameter needed to set up the plugin.
* @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
*/
virtual int SetOption(int optionType, const DataInfo &inputInfo) = 0;
/**
* Get the configuration parameters of plugin.
*
* @param [in] optionType The type of getting option.
* @param [in] inputInfo Parameter information for getting options.
* @param [out] outputInfo The configuration information of plugin.
* @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
*/
virtual int GetOption(int optionType, const DataInfo &inputInfo, DataInfo &outputInfo) = 0;
};
typedef IPlugin *(*IPLUGIN_INTERFACE)();
} // namespace AI
} // namespace OHOS
#endif // I_PLUGIN_H
class EngineAdapter {
public:
virtual ~EngineAdapter() = default;
/* Initializes the algorithm and get the algorithm execution handle */
virtual int32_t Init(const char *modelPath, intptr_t &handle) = 0;
/* De-Initializes all the algorithms. */
virtual int32_t Deinit() = 0;
/* Makes the model based on the given handle Inference once. */
virtual int32_t Invoke(intptr_t handle) = 0;
/* Gets the inputBuffer and inputSize after the handle related model is initialized. */
virtual int32_t GetInputAddr(intptr_t handle, uint16_t nodeId,
uintptr_t &inputBuffer, size_t &inputSize) = 0;
/* Gets the outputBuffer and outputSize after the handle related model is initialized. */
virtual int32_t GetOutputAddr(intptr_t handle, uint16_t nodeId,
uintptr_t &outputBuffer, size_t &outputSize) = 0;
/* Release the algorithm based on the given handle. */
virtual int32_t ReleaseHandle(intptr_t handle) = 0;
};