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