• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "core/common/form_manager.h"
17 
18 #include "unistd.h"
19 
20 #include "base/log/log.h"
21 #include "base/utils/utils.h"
22 
23 namespace OHOS::Ace {
FormManager()24 FormManager::FormManager() {}
25 
~FormManager()26 FormManager::~FormManager() {}
27 
AddSubContainer(int64_t formId,const RefPtr<SubContainer> & subContainer)28 void FormManager::AddSubContainer(int64_t formId, const RefPtr<SubContainer>& subContainer)
29 {
30     std::lock_guard<std::mutex> lock(mutex_);
31     subContainerMap_.insert_or_assign(formId, subContainer);
32 }
33 
RemoveSubContainer(int64_t formId)34 void FormManager::RemoveSubContainer(int64_t formId)
35 {
36     std::lock_guard<std::mutex> lock(mutex_);
37     subContainerMap_.erase(formId);
38 }
39 
GetSubContainer(int64_t formId)40 RefPtr<SubContainer> FormManager::GetSubContainer(int64_t formId)
41 {
42     std::lock_guard<std::mutex> lock(mutex_);
43     auto subContainer = subContainerMap_.find(formId);
44     if (subContainer != subContainerMap_.end()) {
45         return subContainer->second;
46     } else {
47         return nullptr;
48     }
49 }
50 
SetFormUtils(const std::shared_ptr<FormUtils> & formUtils)51 void FormManager::SetFormUtils(const std::shared_ptr<FormUtils>& formUtils)
52 {
53     std::lock_guard<std::mutex> lock(formUtilsMutex_);
54     CHECK_NULL_VOID_NOLOG(formUtils);
55     formUtils_ = formUtils;
56 }
57 
GetFormUtils()58 std::shared_ptr<FormUtils> FormManager::GetFormUtils()
59 {
60     std::lock_guard<std::mutex> lock(formUtilsMutex_);
61     CHECK_NULL_RETURN_NOLOG(formUtils_, nullptr);
62     return formUtils_;
63 }
64 
65 } // namespace OHOS::Ace
66