• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_EVENT_HUB_H
17 #define COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_EVENT_HUB_H
18 
19 #include <functional>
20 
21 #include "base/memory/ace_type.h"
22 #include "core/components_ng/event/event_hub.h"
23 
24 namespace OHOS::Ace::NG {
25 
26 using MovingPhotoEventFunc = std::function<void()>;
27 
28 class MovingPhotoEventHub : public EventHub {
29     DECLARE_ACE_TYPE(MovingPhotoEventHub, EventHub)
30 
31 public:
32     MovingPhotoEventHub() = default;
33     ~MovingPhotoEventHub() override = default;
34 
SetOnComplete(MovingPhotoEventFunc && onComplete)35     void SetOnComplete(MovingPhotoEventFunc&& onComplete)
36     {
37         onComplete_ = std::move(onComplete);
38     }
39 
GetOnComplete()40     MovingPhotoEventFunc GetOnComplete()
41     {
42         return onComplete_;
43     }
44 
FireCompleteEvent()45     void FireCompleteEvent()
46     {
47         if (onComplete_) {
48             auto onComplete = onComplete_;
49             onComplete();
50         }
51     }
52 
SetOnStart(MovingPhotoEventFunc && onStart)53     void SetOnStart(MovingPhotoEventFunc&& onStart)
54     {
55         onStart_ = std ::move(onStart);
56     }
57 
GetOnStart()58     MovingPhotoEventFunc GetOnStart()
59     {
60         return onStart_;
61     }
62 
FireStartEvent()63     void FireStartEvent()
64     {
65         if (onStart_) {
66             auto onStart = onStart_;
67             onStart();
68         }
69     }
70 
SetOnPause(MovingPhotoEventFunc && onPause)71     void SetOnPause(MovingPhotoEventFunc&& onPause)
72     {
73         onPause_ = std ::move(onPause);
74     }
75 
FirePauseEvent()76     void FirePauseEvent()
77     {
78         if (onPause_) {
79             auto onPause = onPause_;
80             onPause();
81         }
82     }
83 
SetOnStop(MovingPhotoEventFunc && onStop)84     void SetOnStop(MovingPhotoEventFunc&& onStop)
85     {
86         onStop_ = std ::move(onStop);
87     }
88 
GetOnStop()89     MovingPhotoEventFunc GetOnStop()
90     {
91         return onStop_;
92     }
93 
FireStopEvent()94     void FireStopEvent()
95     {
96         if (onStop_) {
97             auto onStop = onStop_;
98             onStop();
99         }
100     }
101 
SetOnFinish(MovingPhotoEventFunc && onFinish)102     void SetOnFinish(MovingPhotoEventFunc&& onFinish)
103     {
104         onFinish_ = std ::move(onFinish);
105     }
106 
GetOnFinish()107     MovingPhotoEventFunc GetOnFinish()
108     {
109         return onFinish_;
110     }
111 
FireFinishEvent()112     void FireFinishEvent()
113     {
114         if (onFinish_) {
115             auto onFinish = onFinish_;
116             onFinish();
117         }
118     }
119 
SetOnError(MovingPhotoEventFunc && onError)120     void SetOnError(MovingPhotoEventFunc&& onError)
121     {
122         onError_ = std ::move(onError);
123     }
124 
GetOnError()125     MovingPhotoEventFunc GetOnError()
126     {
127         return onError_;
128     }
129 
FireErrorEvent()130     void FireErrorEvent()
131     {
132         if (onError_) {
133             auto onError = onError_;
134             onError();
135         }
136     }
137 
138 private:
139     MovingPhotoEventFunc onComplete_;
140     MovingPhotoEventFunc onStart_;
141     MovingPhotoEventFunc onStop_;
142     MovingPhotoEventFunc onPause_;
143     MovingPhotoEventFunc onFinish_;
144     MovingPhotoEventFunc onError_;
145 };
146 
147 } // namespace OHOS::Ace::NG
148 
149 #endif // COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_EVENT_HUB_H
150