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_ASYNC_TASK_MANAGER_H
17 #define I_ASYNC_TASK_MANAGER_H
18 
19 #include "protocol/data_channel/include/i_request.h"
20 #include "server_executor/include/i_future.h"
21 #include "server_executor/include/i_future_listener.h"
22 
23 namespace OHOS {
24 namespace AI {
25 class IAsyncTaskManager {
26 public:
27     virtual ~IAsyncTaskManager() = default;
28 
29     /**
30      * Algorithmic inference for asynchronous tasks. You need to override this function to
31      * implement your own processing logic.
32      *
33      * @param [in] request Request information of asynchronous task.
34      * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise.
35      */
36     virtual int AsyncExecute(IRequest *request) = 0;
37 
38     /**
39      * Register callback for the transactionId. You need to override this function to
40      * implement your own processing logic.
41      *
42      * @param [in] listener Callback.
43      * @param [in] transactionId Transaction ID.
44      * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
45      */
46     virtual int RegisterListener(IFutureListener *listener, long long transactionId) = 0;
47 
48     /**
49      * Unregister the callback corresponding to transactionId. You need to override this function to
50      * implement your own processing logic.
51      *
52      * @param [in] transactionId Transaction ID.
53      * @return Returns 0 if the operation is successful, returns a non-zero value otherwise.
54      */
55     virtual int UnRegisterListener(long long transactionId) = 0;
56 };
57 
58 IAsyncTaskManager *GetAsyncTaskManager();
59 } // namespace AI
60 } // namespace OHOS
61 
62 #endif // I_ASYNC_TASK_MANAGER_H