1 /*
2  * Copyright (c) 2020-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 /**
17  * @addtogroup UI_Common
18  * @{
19  *
20  * @brief Defines common UI capabilities, such as image and text processing.
21  *
22  * @since 1.0
23  * @version 1.0
24  */
25 
26 /**
27  * @file task.h
28  *
29  * @brief Declares the <b>Task</b> class of the graphics module, which provides functions for setting the running period
30  * and time of a task.
31  *
32  * @since 1.0
33  * @version 1.0
34  */
35 
36 #ifndef GRAPHIC_LITE_TASK_H
37 #define GRAPHIC_LITE_TASK_H
38 
39 #include <cstdint>
40 
41 #include "gfx_utils/heap_base.h"
42 
43 namespace OHOS {
44 /**
45  * @brief Represents the <b>Task</b> class of the graphics module.
46  *        This class provides functions for setting the running period and time of a task.
47  *
48  * @since 1.0
49  * @version 1.0
50  */
51 class Task : public HeapBase {
52 public:
53     /**
54      * @brief A constructor used to create a <b>Task</b> instance.
55      */
Task()56     Task() : period_(DEFAULT_TASK_PERIOD), lastRun_(0) {}
57 
58     /**
59      * @brief A constructor used to create a <b>Task</b> instance with the specified running period.
60      * @param period Indicates the running period of this task.
61      */
Task(uint32_t period)62     Task(uint32_t period) : period_(period), lastRun_(0) {}
63 
64     /**
65      * @brief A destructor used to delete the <b>Task</b> instance.
66      */
~Task()67     virtual ~Task() {}
68 
69     /**
70      * @brief Sets the running period for this task.
71      * @param period Indicates the running period to set.
72      */
SetPeriod(uint32_t period)73     void SetPeriod(uint32_t period)
74     {
75         period_ = period;
76     }
77 
78     /**
79      * @brief Sets the end time for this task.
80      * @param lastRun Indicates the end time to set.
81      */
SetLastRun(uint32_t lastRun)82     void SetLastRun(uint32_t lastRun)
83     {
84         lastRun_ = lastRun;
85     }
86 
87     /**
88      * @brief Obtains the running period of this task.
89      * @return Returns the running period.
90      */
GetPeriod()91     uint32_t GetPeriod() const
92     {
93         return period_;
94     }
95 
96     /**
97      * @brief Obtains the end time of this task.
98      * @return Returns the end time.
99      */
GetLastRun()100     uint32_t GetLastRun() const
101     {
102         return lastRun_;
103     }
104 
105     /**
106      * @brief Executes this task.
107      */
108     void TaskExecute();
109 
110     /**
111      * @brief Called when this task is executed.
112      */
113     virtual void Callback() = 0;
114 
115     /**
116      * @brief Initializes this task.
117      */
118     virtual void Init();
119 
120 protected:
121     uint32_t period_;  /* call period in ms unit */
122     uint32_t lastRun_; /* last run time */
123 };
124 } // namespace OHOS
125 #endif // GRAPHIC_LITE_TASK_H
126