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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_FORM_MANAGER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_FORM_MANAGER_H
18 
19 #include <mutex>
20 #include <unordered_map>
21 
22 #include "base/utils/macros.h"
23 #include "base/utils/noncopyable.h"
24 #include "base/utils/singleton.h"
25 #include "core/components/form/resource/form_utils.h"
26 #include "core/components/form/sub_container.h"
27 
28 namespace OHOS::Ace {
29 
30 class ACE_EXPORT FormManager final : public Singleton<FormManager> {
31     DECLARE_SINGLETON(FormManager);
32 
33 public:
34     void AddSubContainer(int64_t formId, const RefPtr<SubContainer>& subContainer);
35     void RemoveSubContainer(int64_t formId);
36     RefPtr<SubContainer> GetSubContainer(int64_t formId);
37     void SetFormUtils(const std::shared_ptr<FormUtils>& formUtils);
38     std::shared_ptr<FormUtils> GetFormUtils();
39     void NotifyIsSizeChangeByRotate(
40         bool isRotate, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction);
GetRSTransaction()41     std::weak_ptr<Rosen::RSTransaction> GetRSTransaction()
42     {
43         return rsTransaction_;
44     }
IsSizeChangeByRotate()45     bool IsSizeChangeByRotate()
46     {
47         return isRotate_;
48     }
49 
50 private:
51     std::mutex mutex_;
52     std::unordered_map<int64_t, RefPtr<SubContainer>> subContainerMap_;
53     std::mutex nonmatchedContainerMutex_;
54     std::unordered_map<std::string, RefPtr<SubContainer>> nonmatchedContainerMap_;
55     std::mutex formUtilsMutex_;
56     std::shared_ptr<FormUtils> formUtils_;
57     std::weak_ptr<Rosen::RSTransaction> rsTransaction_;
58     bool isRotate_ = false;
59 };
60 
61 } // namespace OHOS::Ace
62 
63 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_FORM_MANAGER_H
64