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 #include "status_mgr_center/form_event_queue.h"
17 #include "fms_log_wrapper.h"
18
19 namespace OHOS {
20 namespace AppExecFwk {
FormEventQueue(int64_t formId)21 FormEventQueue::FormEventQueue(int64_t formId) : formId_(formId)
22 {
23 HILOG_INFO("create FormEventQueue, formId :%{public}" PRId64 ". ", formId_);
24 }
25
~FormEventQueue()26 FormEventQueue::~FormEventQueue()
27 {
28 HILOG_INFO("destroy FormEventQueue, formId :%{public}" PRId64 ". ", formId_);
29 }
30
PushFormEvent(FormEventTaskInfo & eventInfo)31 void FormEventQueue::PushFormEvent(FormEventTaskInfo &eventInfo)
32 {
33 std::lock_guard<std::mutex> lock(eventQueueMutex_);
34 HILOG_INFO("formId :%{public}" PRId64 ". ", formId_);
35 if (eventInfo.getFormId() != formId_) {
36 HILOG_ERROR("formId is invalid");
37 return;
38 }
39 eventQueue_.push(eventInfo);
40 }
41
PopFormEvent(FormEventTaskInfo & eventInfo)42 bool FormEventQueue::PopFormEvent(FormEventTaskInfo &eventInfo)
43 {
44 std::lock_guard<std::mutex> lock(eventQueueMutex_);
45 if (eventQueue_.empty()) {
46 HILOG_INFO("eventQueue_ is empty, formId :%{public}" PRId64 ". ", formId_);
47 return false;
48 }
49 HILOG_INFO("eventQueue_ not empty, formId :%{public}" PRId64 ". ", formId_);
50 eventInfo = eventQueue_.front();
51 eventQueue_.pop();
52 return true;
53 }
54
IsEventQueueEmpty()55 bool FormEventQueue::IsEventQueueEmpty()
56 {
57 std::lock_guard<std::mutex> lock(eventQueueMutex_);
58 if (eventQueue_.empty()) {
59 HILOG_INFO("eventQueue_ is empty, formId :%{public}" PRId64 ". ", formId_);
60 return true;
61 }
62 HILOG_INFO("eventQueue_ not empty, formId :%{public}" PRId64 ". ", formId_);
63 return false;
64 }
65
GetEventQueue()66 const std::queue<FormEventTaskInfo> &FormEventQueue::GetEventQueue()
67 {
68 std::lock_guard<std::mutex> lock(eventQueueMutex_);
69 return eventQueue_;
70 }
71 } // namespace AppExecFwk
72 } // namespace OHOS
73