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 SA_CLIENT_PROXY_H 17 #define SA_CLIENT_PROXY_H 18 19 #include <unistd.h> 20 21 #include "iproxy_client.h" 22 #include "iunknown.h" 23 #include "ipc_skeleton.h" 24 #include "registry.h" 25 #include "securec.h" 26 27 #include "protocol/retcode_inner/aie_retcode_inner.h" 28 #include "protocol/struct_definition/aie_info_define.h" 29 30 namespace OHOS { 31 namespace AI { 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 void HosInit(); 37 IClientProxy *GetRemoteIUnknown(void); 38 39 /** 40 * Invoke SA server, to connect the server and get the client ID and server uid. 41 * 42 * @param [in] proxy SA proxy to call ai server interfaces. 43 * @param [in] configInfo Engine configuration information. 44 * @param [out] clientInfo Client information. 45 * @return Returns 0 if the operation is successful, returns a non-zero value otherwise. 46 */ 47 int InitSaEngine(IClientProxy &proxy, const ConfigInfo &configInfo, ClientInfo &clientInfo); 48 49 /** 50 * Invoke SA server, to load algorithm plugin and model. 51 * 52 * @param [in] proxy SA proxy to call ai server interfaces. 53 * @param [in] clientInfo Client information. 54 * @param [in] algorithmInfo Algorithm information. 55 * @param [in] inputInfo Data information needed to load algorithm plugin. 56 * @param [out] outputInfo The returned data information after loading the algorithm plugin. 57 * @return Returns 0 if the operation is successful, returns a non-zero value otherwise. 58 */ 59 int LoadAlgorithmProxy(IClientProxy &proxy, const ClientInfo &clientInfo, const AlgorithmInfo &algoInfo, 60 const DataInfo &inputInfo, DataInfo &outputInfo); 61 62 /** 63 * Invoke SA server, to execute algorithm inference synchronously. 64 * 65 * @param [in] proxy SA proxy to call ai server interfaces. 66 * @param [in] clientInfo Client information. 67 * @param [in] AlgorithmInfo Algorithm information. 68 * @param [in] inputInfo Data information needed to synchronous execution algorithm. 69 * @param [out] outputInfo Algorithm inference results. 70 * @return Returns 0 if the operation is successful, returns a non-zero value otherwise. 71 */ 72 int SyncExecAlgorithmProxy(IClientProxy &proxy, const ClientInfo &clientInfo, const AlgorithmInfo &algoInfo, 73 const DataInfo &inputInfo, DataInfo &outputInfo); 74 75 /** 76 * Invoke SA server, to execute algorithm inference asynchronously. 77 * 78 * @param [in] proxy SA proxy to call ai server interfaces. 79 * @param [in] clientInfo Client information. 80 * @param [in] algorithmInfo Algorithm information. 81 * @param [in] inputInfo Data information needed to asynchronous execution algorithm. 82 * @return Returns 0 if the operation is successful, returns a non-zero value otherwise. 83 */ 84 int AsyncExecuteAlgorithmProxy(IClientProxy &proxy, const ClientInfo &clientInfo, const AlgorithmInfo &algoInfo, 85 const DataInfo &inputInfo); 86 87 /** 88 * Invoke SA server, to unload algorithm plugin and model based on algorithm information and client information. 89 * 90 * @param [in] proxy SA proxy to call ai server interfaces. 91 * @param [in] clientInfo Client information. 92 * @param [in] algorithmInfo Algorithm information. 93 * @param [in] inputInfo Data information needed to load algorithm plugin. 94 * @return Returns 0 if the operation is successful, returns a non-zero value otherwise. 95 */ 96 int UnloadAlgorithmProxy(IClientProxy &proxy, const ClientInfo &clientInfo, const AlgorithmInfo &algoInfo, 97 const DataInfo &inputInfo); 98 99 /** 100 * Invoke SA server, to disconnect the client from the server, release and destroy information of the client. 101 * 102 * @param [in] proxy SA proxy to call ai server interfaces. 103 * @param [in] clientInfo Client information. 104 * @return Returns 0 if the operation is successful, returns a non-zero value otherwise. 105 */ 106 int DestroyEngineProxy(IClientProxy &proxy, const ClientInfo &clientInfo); 107 108 /** 109 * Release SA client proxy. 110 * 111 * @param [in] proxy SA proxy acquired from SA manager. 112 * @return Returns 0 if the operation is successful, returns a non-zero value otherwise. 113 */ 114 void ReleaseIUnknown(IUnknown &proxy); 115 116 /** 117 * Invoke SA server, to set the configuration parameters of the engine or plugin. 118 * 119 * @param [in] proxy SA proxy to call ai server interfaces. 120 * @param [in] clientInfo Client information. 121 * @param [in] optionType The type of setting option. 122 * @param [in] inputInfo Configuration parameter needed to set up the engine or plugin. 123 * @return Returns 0 if the operation is successful, returns a non-zero value otherwise. 124 */ 125 int SetOptionProxy(IClientProxy &proxy, const ClientInfo &clientInfo, int optionType, const DataInfo &inputInfo); 126 127 /** 128 * Invoke SA server, to get the configuration parameters of the engine or plugin. 129 * 130 * @param [in] proxy SA proxy to call ai server interfaces. 131 * @param [in] clientInfo Client information. 132 * @param [in] optionType The type of getting option. 133 * @param [in] inputInfo Parameter information for getting options. 134 * @param [out] outputInfo The configuration parameter information. 135 * @return Returns 0 if the operation is successful, returns a non-zero value otherwise. 136 */ 137 int GetOptionProxy(IClientProxy &proxy, const ClientInfo &clientInfo, int optionType, 138 const DataInfo &inputInfo, DataInfo &outputInfo); 139 140 /** 141 * Invoke SA server, to register listener for async processing. 142 * 143 * @param [in] proxy SA proxy to call ai server interfaces. 144 * @param [in] clientInfo Client information. 145 * @return Returns 0 if the operation is successful, returns a non-zero value otherwise. 146 */ 147 int RegisterCallbackProxy(IClientProxy &proxy, const ClientInfo &clientInfo, OnRemoteRequest asyncCallback); 148 149 /** 150 * Invoke SA server, to unregister listener for async processing. 151 * 152 * @param [in] proxy SA proxy to call ai server interfaces. 153 * @param [in] clientInfo Client information. 154 * @return Returns 0 if the operation is successful, returns a non-zero value otherwise. 155 */ 156 int UnregisterCallbackProxy(IClientProxy &proxy, const ClientInfo &clientInfo); 157 158 #ifdef __cplusplus 159 } 160 #endif 161 } // namespace AI 162 } // namespace OHOS 163 164 #endif // SA_CLIENT_PROXY_H 165