• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SERVER_EXECUTOR_H
17 #define SERVER_EXECUTOR_H
18 
19 #include <mutex>
20 
21 #include "platform/queuepool/queue.h"
22 #include "platform/queuepool/queue_pool.h"
23 #include "platform/threadpool/include/thread.h"
24 #include "platform/threadpool/include/thread_pool.h"
25 #include "protocol/struct_definition/aie_info_define.h"
26 #include "server_executor/include/engine_manager.h"
27 #include "server_executor/include/i_async_task_manager.h"
28 #include "server_executor/include/i_engine_manager.h"
29 #include "server_executor/include/i_future_listener.h"
30 #include "server_executor/include/i_sync_task_manager.h"
31 #include "utils/aie_macros.h"
32 
33 namespace OHOS {
34 namespace AI {
35 class ServerExecutor : public ISyncTaskManager, public IAsyncTaskManager, public IEngineManager {
36     FORBID_COPY_AND_ASSIGN(ServerExecutor);
37     FORBID_CREATE_BY_SELF(ServerExecutor);
38 public:
39     /**
40      * Use singleton pattern.
41      *
42      * @return Pointer to the singleton.
43      */
44     static ServerExecutor *GetInstance();
45 
46     /**
47      * Destroy the singleton.
48      */
49     static void ReleaseInstance();
50 
51     /**
52      * Process sync execute request.
53      *
54      * @param [in] request Algorithm input.
55      * @param [out] response Algorithm output.
56      * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise.
57      */
58     int SyncExecute(IRequest *request, IResponse *&response) override;
59 
60     /**
61      * process async execute request
62      *
63      * @param [in] request Algorithm input.
64      * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise.
65      */
66     int AsyncExecute(IRequest *request) override;
67 
68     /**
69      * Register listener by Transaction ID.
70      *
71      * @param [in] listener Listener for async execution.
72      * @param [in] transactionId Transaction ID.
73      * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise.
74      */
75     int RegisterListener(IFutureListener *listener, long long transactionId) override;
76 
77     /**
78      * Unregister listener by Transaction ID.
79      *
80      * @param [in] transactionId Transaction ID.
81      * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise.
82      */
83     int UnRegisterListener(long long transactionId) override;
84 
85     /**
86      * Start engine
87      *
88      * @param [in] transactionId Transaction ID.
89      * @param [in] algoInfo Algorithm info.
90      * @param [in] inputInfo Parameter info for starting engine.
91      * @param [out] outputInfo Parameter info for starting engine.
92      * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise.
93      */
94     int StartEngine(long long transactionId, const AlgorithmInfo &algoInfo, const DataInfo &inputInfo,
95         DataInfo &outputInfo) override;
96 
97     /**
98      * Stop engine
99      *
100      * @param [in] transactionId Transaction ID.
101      * @param [in] inputInfo Parameter information for stopping engine.
102      * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise.
103      */
104     int StopEngine(long long transactionId, const DataInfo &inputInfo) override;
105 
106     /**
107      * Set the configuration parameters of the plugin.
108      *
109      * @param [in] transactionId Transaction ID.
110      * @param [in] optionType The type of setting option.
111      * @param [in] inputInfo Parameter information for setting options.
112      * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise.
113      */
114     int SetOption(long long transactionId, int optionType, const DataInfo &inputInfo) override;
115 
116     /**
117      * Get the configuration parameters of the plugin.
118      *
119      * @param [in] transactionId Transaction ID.
120      * @param [in] optionType The type of getting option.
121      * @param [in] inputInfo Parameter information for getting options.
122      * @param [out] outputInfo The configuration parameter information.
123      * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise.
124      */
125     int GetOption(long long transactionId, int optionType, const DataInfo &inputInfo,
126         DataInfo &outputInfo) override;
127 
128 private:
129     int Initialize();
130     void Uninitialize();
131 
132 private:
133     static std::mutex mutex_;
134     static ServerExecutor *instance_;
135 
136 private:
137     EngineManager *engineMgr_;
138 };
139 } // namespace AI
140 } // namespace OHOS
141 
142 #endif // SERVER_EXECUTOR_H