• 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 #include "status_mgr_center/form_render_status.h"
17 #include "fms_log_wrapper.h"
18 
19 namespace OHOS {
20 namespace AppExecFwk {
FormRenderStatus()21 FormRenderStatus::FormRenderStatus()
22 {
23     HILOG_DEBUG("create FormRenderStatus");
24 }
25 
~FormRenderStatus()26 FormRenderStatus::~FormRenderStatus()
27 {
28     HILOG_DEBUG("destroy FormRenderStatus");
29 }
30 
HasFormStatus(const int64_t formId)31 bool FormRenderStatus::HasFormStatus(const int64_t formId)
32 {
33     std::shared_lock<std::shared_mutex> lock(formStatusMutex_);
34     return !(formStatusMap_.find(formId) == formStatusMap_.end());
35 }
36 
GetFormStatus(const int64_t formId)37 FormFsmStatus FormRenderStatus::GetFormStatus(const int64_t formId)
38 {
39     std::shared_lock<std::shared_mutex> lock(formStatusMutex_);
40     auto iter = formStatusMap_.find(formId);
41     if (iter == formStatusMap_.end()) {
42         HILOG_ERROR("formStatusMap_ do not exist, formId:%{public}" PRId64, formId);
43         return FormFsmStatus::INIT;
44     }
45 
46     return iter->second;
47 }
48 
SetFormStatus(const int64_t formId,FormFsmStatus formStatus)49 void FormRenderStatus::SetFormStatus(const int64_t formId, FormFsmStatus formStatus)
50 {
51     std::unique_lock<std::shared_mutex> lock(formStatusMutex_);
52     auto iter = formStatusMap_.find(formId);
53     if (iter == formStatusMap_.end()) {
54         HILOG_INFO("set new form status, formId:%{public}" PRId64 ", status is %{public}d.",
55             formId,
56             static_cast<int32_t>(formStatus));
57         formStatusMap_.emplace(formId, formStatus);
58         return;
59     }
60 
61     iter->second = formStatus;
62     HILOG_INFO(
63         "set form status, formId:%{public}" PRId64 ", status is %{public}d.", formId, static_cast<int32_t>(formStatus));
64 }
65 
DeleteFormStatus(const int64_t formId)66 void FormRenderStatus::DeleteFormStatus(const int64_t formId)
67 {
68     std::unique_lock<std::shared_mutex> lock(formStatusMutex_);
69     HILOG_INFO("formId:%{public}" PRId64, formId);
70     auto iter = formStatusMap_.find(formId);
71     if (iter != formStatusMap_.end()) {
72         formStatusMap_.erase(iter);
73     }
74 }
75 }  // namespace AppExecFwk
76 }  // namespace OHOS
77