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 ENGINE_WORKER_H 17 #define ENGINE_WORKER_H 18 19 #include "protocol/retcode_inner/aie_retcode_inner.h" 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/data_channel/include/i_request.h" 26 #include "protocol/data_channel/include/i_response.h" 27 #include "server_executor/include/task.h" 28 29 namespace OHOS { 30 namespace AI { 31 class EngineWorker : public IWorker { 32 public: 33 explicit EngineWorker(Queue<Task> &queue); 34 ~EngineWorker() override = default; 35 36 /** 37 * Get worker name, and cannot return null. 38 * 39 * @return Worker name. 40 */ 41 const char *GetName() const override; 42 43 /** 44 * Thread will call OneAction loop, until the thread is stopped or return false. 45 * 46 * @return true thread is running, false thread is stop. 47 */ 48 bool OneAction() override; 49 50 /** 51 * The method is called when thread stop, it is still run in thread. 52 */ 53 void Uninitialize() override; 54 55 private: 56 Queue<Task> &queue_; 57 }; 58 } // namespace AI 59 } // namespace OHOS 60 61 #endif // ENGINE_WORKER_H