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_TEXT_CLOCK_TEXT_CLOCK_CONTROLLER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_CLOCK_TEXT_CLOCK_CONTROLLER_H
18 
19 #include "base/memory/ace_type.h"
20 
21 #include <functional>
22 
23 namespace OHOS::Ace {
24 using StatusCallback = std::function<void()>;
25 class ACE_EXPORT TextClockController : public AceType {
26     DECLARE_ACE_TYPE(TextClockController, AceType);
27 public:
28     TextClockController() = default;
29     ~TextClockController() override = default;
30 
OnStart(StatusCallback statusCallback)31     void OnStart(StatusCallback statusCallback)
32     {
33         start_ = std::move(statusCallback);
34     }
35 
OnStop(StatusCallback statusCallback)36     void OnStop(StatusCallback statusCallback)
37     {
38         stop_ = std::move(statusCallback);
39     }
40 
Start()41     void Start()
42     {
43         if (start_) {
44             start_();
45         }
46     }
47 
Stop()48     void Stop()
49     {
50         if (stop_) {
51             stop_();
52         }
53     }
54 
HasInitialized()55     bool HasInitialized() const
56     {
57         return start_ && stop_;
58     }
59 
60 private:
61     StatusCallback start_;
62     StatusCallback stop_;
63 };
64 }
65 
66 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_CLOCK_TEXT_CLOCK_CONTROLLER_H
67