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 "form_status_print.h"
17 #include <unordered_map>
18 #include "fms_log_wrapper.h"
19
20 namespace OHOS {
21 namespace AppExecFwk {
22 namespace {
23 const static std::unordered_map<FormFsmStatus, std::string> FORM_STATUS_STRING_MAP = {
24 { FormFsmStatus::INIT, "[INIT]" },
25 { FormFsmStatus::RENDERED, "[RENDERED]" },
26 { FormFsmStatus::RECYCLED, "[RECYCLED]" },
27 { FormFsmStatus::RENDERING, "[RENDERING]" },
28 { FormFsmStatus::RECYCLING_DATA, "[RECYCLING_DATA]" },
29 { FormFsmStatus::RECYCLING, "[RECYCLING]" },
30 { FormFsmStatus::RECOVERING, "[RECOVERING]" },
31 { FormFsmStatus::DELETING, "[DELETING]" },
32 { FormFsmStatus::UNPROCESSABLE, "[UNPROCESSABLE]" },
33 };
34 const static std::unordered_map<FormFsmEvent, std::string> FORM_EVENT_STRING_MAP = {
35 { FormFsmEvent::RENDER_FORM, "[RENDER_FORM]" },
36 { FormFsmEvent::RENDER_FORM_DONE, "[RENDER_FORM_DONE]" },
37 { FormFsmEvent::RENDER_FORM_FAIL, "[RENDER_FORM_FAIL]" },
38 { FormFsmEvent::RECYCLE_DATA, "[RECYCLE_DATA]" },
39 { FormFsmEvent::RECYCLE_DATA_DONE, "[RECYCLE_DATA_DONE]" },
40 { FormFsmEvent::RECYCLE_DATA_FAIL, "[RECYCLE_DATA_FAIL]" },
41 { FormFsmEvent::RECYCLE_FORM, "[RECYCLE_FORM]" },
42 { FormFsmEvent::RECYCLE_FORM_DONE, "[RECYCLE_FORM_DONE]" },
43 { FormFsmEvent::RECYCLE_FORM_FAIL, "[RECYCLE_FORM_FAIL]" },
44 { FormFsmEvent::RECOVER_FORM, "[RECOVER_FORM]" },
45 { FormFsmEvent::RECOVER_FORM_DONE, "[RECOVER_FORM_DONE]" },
46 { FormFsmEvent::RECOVER_FORM_FAIL, "[RECOVER_FORM_FAIL]" },
47 { FormFsmEvent::DELETE_FORM, "[DELETE_FORM]" },
48 { FormFsmEvent::DELETE_FORM_DONE, "[DELETE_FORM_DONE]" },
49 { FormFsmEvent::DELETE_FORM_FAIL, "[DELETE_FORM_FAIL]" },
50 { FormFsmEvent::DELETE_FORM_FINISH, "[DELETE_FORM_FINISH]" },
51 { FormFsmEvent::EXECUTION_TIMEOUT, "[EXECUTION_TIMEOUT]" },
52 { FormFsmEvent::RELOAD_FORM, "[RELOAD_FORM]" },
53 };
54 }
55
FormStatusToString(const FormFsmStatus status)56 std::string FormStatusPrint::FormStatusToString(const FormFsmStatus status)
57 {
58 std::string value = std::to_string(static_cast<int>(status));
59 const auto iter = FORM_STATUS_STRING_MAP.find(status);
60 if (iter != FORM_STATUS_STRING_MAP.end()) {
61 value = iter->second;
62 }
63 return value;
64 }
65
FormEventToString(const FormFsmEvent event)66 std::string FormStatusPrint::FormEventToString(const FormFsmEvent event)
67 {
68 std::string value = std::to_string(static_cast<int>(event));
69 const auto iter = FORM_EVENT_STRING_MAP.find(event);
70 if (iter != FORM_EVENT_STRING_MAP.end()) {
71 value = iter->second;
72 }
73 return value;
74 }
75 } // namespace AppExecFwk
76 } // namespace OHOS