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 AI_SERVICE_H
17 #define AI_SERVICE_H
18 
19 #include "iproxy_client.h"
20 #include "iproxy_server.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define AI_SERVICE "ai_service"
27 #define AI_FEATURE "ai_feature"
28 
29 enum FUNC_ID {
30     ID_INIT_ENGINE = 0,
31     ID_LOAD_ALGORITHM,
32     ID_SYNC_EXECUTE_ALGORITHM,
33     ID_ASYNC_EXECUTE_ALGORITHM,
34     ID_UNLOAD_ALGORITHM,
35     ID_DESTROY_ENGINE,
36     ID_SET_OPTION,
37     ID_GET_OPTION,
38     ID_REGISTER_CALLBACK,
39     ID_UNREGISTER_CALLBACK,
40 };
41 
42 enum CALLBACK_ID {
43     ON_ASYNC_PROCESS_CODE = 0,
44 };
45 
46 typedef struct AiInterface {
47     INHERIT_SERVER_IPROXY;
48 
49     /**
50      * @brief Initialize engine configuration and get the client ID from ai server.
51      *
52      * @param [in] configInfo Engine configuration information.
53      * @return Client ID.
54      */
55     int (*InitEngine)(const ConfigInfo *configInfo);
56 
57     /**
58      * @brief Load algorithm plugin and model based on algorithm information and client information.
59      *
60      * @param [in] clientInfo Client information.
61      * @param [in] algoInfo Algorithm information.
62      * @param [in] inputInfo Data information needed to load algorithm plugin.
63      * @param [out] outputInfo The returned data information after loading the algorithm plugin.
64      * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
65      */
66     int (*LoadAlgorithm)(const ClientInfo *clientInfo, const AlgorithmInfo *algoInfo,
67         const DataInfo *inputInfo, DataInfo *outputInfo);
68 
69     /**
70      * @brief Algorithmic inference interface for synchronous tasks.
71      *
72      * @param [in] clientInfo Client information.
73      * @param [in] algoInfo Algorithm information.
74      * @param [in] inputInfo Data information needed to synchronous execution algorithm.
75      * @param [out] outputInfo Algorithm inference results.
76      * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
77      */
78     int (*SyncExecuteAlgorithm)(const ClientInfo *clientInfo, const AlgorithmInfo *algoInfo,
79         const DataInfo *inputInfo, DataInfo *outputInfo);
80 
81     /**
82      * @brief Algorithmic inference interface for asynchronous tasks.
83      *
84      * @param [in] clientInfo Client information.
85      * @param [in] algoInfo Algorithm information.
86      * @param [in] inputInfo Data information needed to asynchronous execution algorithm.
87      * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
88      */
89     int (*AsyncExecuteAlgorithm)(const ClientInfo *clientInfo, const AlgorithmInfo *algoInfo,
90         const DataInfo *inputInfo);
91 
92     /**
93      * @brief Unload algorithm model and plugin based on algorithm information and client information.
94      *
95      * @param [in] clientInfo Client information.
96      * @param [in] algoInfo Algorithm information.
97      * @param [in] inputInfo Data information needed to unload algorithm plugin.
98      * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
99      */
100     int (*UnloadAlgorithm)(const ClientInfo *clientInfo, const AlgorithmInfo *algoInfo, const DataInfo *inputInfo);
101 
102     /**
103      * @brief Disconnect the link between the client and the server, and destroy the engine information
104      *        corresponding to the client.
105      *
106      * @param [in] clientInfo Client information.
107      * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
108      */
109     int (*DestroyEngine)(const ClientInfo *clientInfo);
110 
111     /**
112      * @brief Set the configuration parameters of the engine or plugin.
113      *
114      * @param [in] clientInfo Client information.
115      * @param [in] optionType The type of setting option.
116      * @param [in] inputInfo Configuration parameter needed to set up the engine or plugin.
117      * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
118      */
119     int (*SetOption)(const ClientInfo *clientInfo, int optionType, const DataInfo *inputInfo);
120 
121     /**
122      * @brief Get the configuration parameters of the engine or plugin.
123      *
124      * @param [in] clientInfo Client information.
125      * @param [in] optionType The type of getting option.
126      * @param [in] inputInfo Parameter information for getting options.
127      * @param [out] outputInfo The configuration parameter information.
128      * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
129      */
130     int (*GetOption)(const ClientInfo *clientInfo, int optionType,
131         const DataInfo *inputInfo, DataInfo *outputInfo);
132 
133     /**
134      * @brief Unregister callback function of client.
135      *
136      * @param [in] clientInfo Client information.
137      * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
138      */
139     int (*UnregisterCallback)(const ClientInfo *clientInfo);
140 } AiInterface;
141 
142 #ifdef __cplusplus
143 }
144 #endif
145 
146 #endif // AI_SERVICE_H
147