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 I_PLUGIN_H
17#define I_PLUGIN_H
18
19#include "plugin/i_plugin_callback.h"
20#include "protocol/data_channel/include/i_request.h"
21#include "protocol/data_channel/include/i_response.h"
22#include "protocol/retcode_inner/aie_retcode_inner.h"
23
24namespace OHOS {
25namespace AI {
26const char * const PLUGIN_INTERFACE_NAME = "PLUGIN_INTERFACE";
27
28#define PLUGIN_INTERFACE_IMPL(PluginName) \
29    extern "C" IPlugin* PLUGIN_INTERFACE() \
30    { \
31        return new PluginName(); \
32    } \
33
34class IPlugin {
35public:
36    virtual ~IPlugin() = default;
37
38    virtual const long long GetVersion() const = 0;
39
40    virtual const char *GetName() const = 0;
41
42    /**
43     * Get plugin inference mode.
44     *
45     * @return Inference mode, synchronous or asynchronous.
46     */
47    virtual const char *GetInferMode() const = 0;
48
49    /**
50     * Algorithmic inference interface for synchronous tasks.
51     *
52     * @param [in] request Request task which contains the specific information of the task.
53     * @param [out] response Results of encapsulated algorithmic inference.
54     * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
55     */
56    virtual int SyncProcess(IRequest *request, IResponse *&response) = 0;
57
58    /**
59     * Algorithmic inference interface for asynchronous tasks.
60     *
61     * @param [in] request Request task which contains the specific information of the task.
62     * @param [in] callback Callback which is used to return the result of asynchronous inference.
63     * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
64     */
65    virtual int AsyncProcess(IRequest *request, IPluginCallback *callback) = 0;
66
67    /**
68     * Initialize plugin.
69     *
70     * @param [in] transactionId Transaction ID.
71     * @param [in] inputInfo Data information needed to initialize plugin.
72     * @param [out] outputInfo The returned data information of initializing plugin.
73     * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
74     */
75    virtual int Prepare(long long transactionId, const DataInfo &inputInfo, DataInfo &outputInfo) = 0;
76
77    /**
78     * Unload model and plugin.
79     *
80     * @param [in] isFullUnload Whether to unload completely.
81     * @param [in] transactionId Transaction ID.
82     * @param [in] inputInfo Data information needed to unload model and plugin.
83     * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
84     */
85    virtual int Release(bool isFullUnload, long long transactionId, const DataInfo &inputInfo) = 0;
86
87    /**
88     * Set the configuration parameters of the plugin.
89     *
90     * @param [in] optionType The type of setting option.
91     * @param [in] inputInfo Configuration parameter needed to set up the plugin.
92     * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
93     */
94    virtual int SetOption(int optionType, const DataInfo &inputInfo) = 0;
95
96    /**
97     * Get the configuration parameters of plugin.
98     *
99     * @param [in] optionType The type of getting option.
100     * @param [in] inputInfo Parameter information for getting options.
101     * @param [out] outputInfo The configuration information of plugin.
102     * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
103     */
104    virtual int GetOption(int optionType, const DataInfo &inputInfo, DataInfo &outputInfo) = 0;
105};
106
107typedef IPlugin *(*IPLUGIN_INTERFACE)();
108} // namespace AI
109} // namespace OHOS
110
111#endif // I_PLUGIN_H