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_ASYNC_HANDLER_H
17 #define SA_ASYNC_HANDLER_H
18 
19 #include "client_executor/include/async_handler.h"
20 
21 namespace OHOS {
22 namespace AI {
23 void SaClientCallback(int sessionId, const DataInfo &result, int resultCode, int requestId);
24 void SaDeathCallback();
25 
26 class SaAsyncHandler : public AsyncHandler {
27     FORBID_COPY_AND_ASSIGN(SaAsyncHandler);
28     FORBID_CREATE_BY_SELF(SaAsyncHandler);
29 
30 public:
31     static SaAsyncHandler *GetInstance();
32     static void ReleaseInstance();
33 
34     /**
35      * Register client callback for algorithm async processing.
36      *
37      * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise.
38      */
39     int RegisterAsyncClientCb() override;
40 
41     /**
42      * Unregister client callback for algorithm async processing.
43      *
44      * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise.
45      */
46     int UnRegisterAsyncClientCb() override;
47 
48     /**
49      * Register dead callback to transfer dead message of aiserver to sdk/third-party application.
50      *
51      * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise.
52      */
53     int RegisterServiceDeathCb() override;
54 
55     /**
56      * Unregister dead callback to transfer dead message of aiserver to sdk/third-party application.
57      *
58      * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise.
59      */
60     int UnRegisterServiceDeathCb() override;
61 
62 private:
63     static std::mutex instance_mutex_;
64     static SaAsyncHandler *instance_;
65 };
66 } // namespace AI
67 } // namespace OHOS
68 
69 #endif // SA_ASYNC_HANDLER_H