1 /*
2  * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXTTIMER_TEXTTIMER_CONTROLLER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXTTIMER_TEXTTIMER_CONTROLLER_H
18 
19 #include "base/memory/ace_type.h"
20 #include <functional>
21 
22 namespace OHOS::Ace {
23 using TimerFuncImpl = std::function<void()>;
24 using TimerInputImpl = std::function<void(int32_t)>;
25 
26 class TextTimerController : public virtual AceType {
27     DECLARE_ACE_TYPE(TextTimerController, AceType);
28 
29 public:
Start()30     void Start()
31     {
32         if (start_) {
33             start_();
34         }
35     }
36 
OnStart(const TimerFuncImpl & start)37     void OnStart(const TimerFuncImpl& start)
38     {
39         start_ = start;
40     }
41 
Pause()42     void Pause()
43     {
44         if (pause_) {
45             pause_();
46         }
47     }
48 
OnPause(const TimerFuncImpl & pause)49     void OnPause(const TimerFuncImpl& pause)
50     {
51         pause_ = pause;
52     }
53 
Reset()54     void Reset()
55     {
56         if (reset_) {
57             reset_();
58         }
59     }
60 
OnReset(const TimerFuncImpl & reset)61     void OnReset(const TimerFuncImpl& reset)
62     {
63         reset_ = reset;
64     }
65 
HasInitialized()66     bool HasInitialized() const
67     {
68         return start_ && pause_ && reset_;
69     }
70 
71 private:
72     TimerFuncImpl start_;
73     TimerFuncImpl pause_;
74     TimerFuncImpl reset_;
75 };
76 } // namespace OHOS::Ace
77 
78 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXTTIMER_TEXTTIMER_CONTROLLER_H
79