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 SYNC_MSG_HANDLER_H 17 #define SYNC_MSG_HANDLER_H 18 19 #include "platform/queuepool/queue_pool.h" 20 #include "platform/semaphore/include/simple_event_notifier.h" 21 #include "plugin/i_plugin.h" 22 #include "protocol/data_channel/include/i_request.h" 23 #include "protocol/data_channel/include/i_response.h" 24 #include "protocol/retcode_inner/aie_retcode_inner.h" 25 #include "server_executor/include/i_handler.h" 26 #include "server_executor/include/task.h" 27 #include "utils/aie_macros.h" 28 29 namespace OHOS { 30 namespace AI { 31 class SyncMsgHandler : public IHandler { 32 public: 33 SyncMsgHandler(Queue<Task> &queue, IPlugin *pluginAlgorithm); 34 35 ~SyncMsgHandler() override = default; 36 37 /** 38 * Deal with sync task. 39 * 40 * @param [in] task Task info need to be processed. 41 * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise. 42 */ 43 int Process(const Task &task) override; 44 45 /** 46 * Set pluginAlgorithm. 47 * 48 * @param [in] pluginAlgorithm Algorithm function symbol of dynamic library. 49 */ 50 void SetPluginAlgorithm(IPlugin *pluginAlgorithm) override; 51 52 /** 53 * Add request to the end of processing queue. 54 * 55 * @param [in] request info needed for algorithm. 56 * @param [in, out] notifier Semaphore. 57 * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise. 58 */ 59 int SendRequest(IRequest *request, SimpleEventNotifier<IResponse> ¬ifier); 60 61 /** 62 * Receive response. 63 * 64 * @param [in] timeOut Delayed time, measured by millisecond. 65 * @param [in, out] notifier Semaphore. 66 * @param [out] response Response info. 67 * @return Returns RETCODE_SUCCESS(0) if the operation is successful, returns a non-zero value otherwise. 68 */ 69 int ReceiveResponse(int timeOut, SimpleEventNotifier<IResponse> ¬ifier, IResponse *&response); 70 71 private: 72 Queue<Task> &queue_; 73 IPlugin *pluginAlgorithm_; 74 }; 75 } // namespace AI 76 } // namespace OHOS 77 78 #endif // SYNC_MSG_HANDLER_H