• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 OHOS_FORM_FWK_FORM_EVENT_QUEUE_H
17 #define OHOS_FORM_FWK_FORM_EVENT_QUEUE_H
18 
19 #include <string>
20 #include <mutex>
21 #include <queue>
22 
23 #include "status_mgr_center/form_status_common.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 
28 class FormEventTaskInfo {
29 public:
30     FormEventTaskInfo() = default;
FormEventTaskInfo(int64_t formId,FormFsmEvent formEvent,std::function<void ()> func)31     FormEventTaskInfo(int64_t formId, FormFsmEvent formEvent, std::function<void()> func)
32         : formId_(formId), formEvent_(formEvent), func_(func)
33     {}
34 
getFormId()35     inline int64_t getFormId() const
36     {
37         return formId_;
38     }
39 
getFormEvent()40     inline FormFsmEvent getFormEvent() const
41     {
42         return formEvent_;
43     }
44 
getFunc()45     inline std::function<void()> getFunc() const
46     {
47         return func_;
48     }
49 
50 protected:
51     int64_t formId_;              // Form ID
52     FormFsmEvent formEvent_;      // Form FSM event
53     std::function<void()> func_;  // Executing Function
54 };
55 
56 class FormEventQueue final {
57 public:
58     explicit FormEventQueue(int64_t formId);
59     ~FormEventQueue();
60 
61     /**
62      * @brief Push form event to queue
63      * @param eventInfo Form event task information
64      */
65     void PushFormEvent(FormEventTaskInfo &eventInfo);
66 
67     /**
68      * @brief Pop form event from queue
69      * @param eventInfo Form event task information
70      * @return Returns true if the queue is empty, false otherwise
71      */
72     bool PopFormEvent(FormEventTaskInfo &eventInfo);
73 
74     /**
75      * @brief Check if the event queue is empty
76      * @return Returns true if the queue is empty, false otherwise
77      */
78     bool IsEventQueueEmpty();
79 
80     /**
81      * @brief Get the event queue
82      * @return Returns the reference to the event queue
83      */
84     const std::queue<FormEventTaskInfo> &GetEventQueue();
85 
86 private:
87     std::mutex eventQueueMutex_;
88     std::queue<FormEventTaskInfo> eventQueue_;
89     int64_t formId_;
90 };
91 }  // namespace AppExecFwk
92 }  // namespace OHOS
93 #endif  // OHOS_FORM_FWK_FORM_EVENT_QUEUE_H
94