1 /* 2 * Copyright (c) 2023-2024 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_STATUS_MGR_H 17 #define OHOS_FORM_FWK_FORM_STATUS_MGR_H 18 19 #include <singleton.h> 20 #include <string> 21 #include <unordered_map> 22 #include <shared_mutex> 23 24 #include "iremote_object.h" 25 26 namespace OHOS { 27 namespace AppExecFwk { 28 enum class FormStatus { 29 UNPROCESSABLE, 30 RECOVERED, 31 RECOVERING, 32 RECYCLED, 33 RECYCLING, 34 }; 35 36 class FormStatusMgr final : public DelayedRefSingleton<FormStatusMgr> { 37 DECLARE_DELAYED_REF_SINGLETON(FormStatusMgr) 38 public: 39 DISALLOW_COPY_AND_MOVE(FormStatusMgr); 40 public: 41 void AddFormStatus(const int64_t formId, FormStatus formStatus); 42 void DeleteFormStatus(const int64_t formId); 43 44 bool GetFormStatus(const int64_t formId, FormStatus &formStatus); 45 bool SetFormStatus(const int64_t formId, FormStatus formStatus); 46 47 bool isProcessableFormStatus(const int64_t formId); 48 49 /* 50 * @brief Reset form status by id. 51 * @param formIds The Id list of forms. 52 */ 53 void ResetFormStatus(const int64_t &formId); 54 55 /* 56 * @brief Send render form message to form_status_mgr. 57 * @param formIds The Id list of forms. 58 * @param want The want of forms to be recycled. 59 */ 60 void OnRenderFormDone(const int64_t &formId); 61 62 /** 63 * @brief Send recover form message to form_status_mgr. 64 * @param formIds The Id list of forms. 65 * @param want The want of forms to be recycled. 66 */ 67 void OnRecoverFormDone(const int64_t &formId); 68 69 /** 70 * @brief Send recycle form message to form_status_mgr. 71 * @param formIds The Id list of forms. 72 * @param want The want of forms to be recycled. 73 */ 74 void OnRecycleFormDone(const int64_t &formId); 75 76 private: 77 // <formId, formStatus> 78 std::shared_mutex formStatusMutex_; 79 std::unordered_map<int64_t, FormStatus> formStatusMap_; 80 }; 81 } // namespace AppExecFwk 82 } // namespace OHOS 83 #endif // OHOS_FORM_FWK_FORM_STATUS_MGR_H 84