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 #ifndef OHOS_APP_DISPATCHER_THREADING_TASK_DISPATCHER_HANDLER_H 16 #define OHOS_APP_DISPATCHER_THREADING_TASK_DISPATCHER_HANDLER_H 17 18 #include <memory> 19 #include "task.h" 20 namespace OHOS { 21 namespace AppExecFwk { 22 23 /** 24 * Interface for handling post a task. 25 * 26 */ 27 class TaskDispatcherHandler { 28 public: 29 /** 30 * Dispatch a task asynchronously. 31 * 32 * @param task The task to post. 33 * @return true if successfully post a task, otherwise false. 34 */ 35 virtual bool Dispatch(const std::shared_ptr<Runnable> &runnable) = 0; 36 /** 37 * Dispatch a task synchronously. 38 * 39 * @param task The task to post. 40 * @return true if successfully post a task, otherwise false. 41 */ 42 virtual bool DispatchSync(const std::shared_ptr<Runnable> &runnable) = 0; 43 44 /** 45 * Dispatch a task asynchronously at specific time point. 46 * 47 * @param task The task to post. 48 * @param delayMs The delay time expected to post the task, in milli second. 49 * @return true if successfully post a task, otherwise false. 50 */ 51 virtual bool Dispatch(const std::shared_ptr<Runnable> &runnable, long delayMs) = 0; 52 }; 53 54 } // namespace AppExecFwk 55 } // namespace OHOS 56 57 #endif 58