• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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_ERRORS_H
17 #define OHOS_FORM_FWK_FORM_ERRORS_H
18 
19 #include <cstring>
20 #include <map>
21 
22 #include "errors.h"
23 #include "nocopyable.h"
24 #include "singleton.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 enum {
29     ERR_FORM_EXTERNAL_PERMISSION_DENIED = 201,
30     ERR_FORM_EXTERNAL_NOT_SYSTEM_APP = 202,
31     ERR_FORM_EXTERNAL_PARAM_INVALID = 401,
32     ERR_FORM_EXTERNAL_SYSTEMCAP_ERROR = 801,
33     ERR_FORM_EXTERNAL_KERNEL_ERROR = 16500001,
34     ERR_FORM_EXTERNAL_KERNEL_MALLOC_ERROR = 16500002,
35     ERR_FORM_EXTERNAL_IPC_ERROR = 16500050,
36     ERR_FORM_EXTERNAL_SERVICE_CONNECTION_ERROR = 16500060,
37     ERR_FORM_EXTERNAL_GET_INFO_FAILED = 16500100,
38     ERR_FORM_EXTERNAL_FUNCTIONAL_ERROR = 16501000,
39     ERR_FORM_EXTERNAL_FORM_ID_NOT_EXIST = 16501001,
40     ERR_FORM_EXTERNAL_FORM_NUM_EXCEEDS_UPPER_BOUND = 16501002,
41     ERR_FORM_EXTERNAL_OPERATION_FORM_NOT_SELF = 16501003,
42     ERR_FORM_EXTERNAL_ABILITY_NOT_INSTALLED = 16501004,
43     ERR_FORM_EXTERNAL_CONNECT_RENDER_FAILED = 16501005,
44     ERR_FORM_EXTERNAL_RENDER_DIED = 16501006,
45     ERR_FORM_EXTERNAL_FORM_NOT_TRUST = 16501007,
46     ERR_FORM_EXTERNAL_ADD_FORM_TIME_OUT = 16501008,
47     ERR_FORM_EXTERNAL_FORM_STATUS_TIMIE_OUT = 16501009,
48     ERR_FORM_EXTERNAL_SET_OPERATION_FAILED = 16501010,
49     ERR_FORM_EXTERNAL_LIVE_OP_UNSUPPORTED = 16501011,
50     ERR_FORM_EXTERNAL_FORM_DIMENSION_ERROR = 16501012,
51 };
52 
53 /**
54  * @class FormErrors
55  * FormErrors is used to access form error message.
56  */
57 class FormErrors final : public DelayedRefSingleton<FormErrors> {
58     DECLARE_DELAYED_REF_SINGLETON(FormErrors)
59 public:
60     DISALLOW_COPY_AND_MOVE(FormErrors);
61 
62     /**
63      * @brief Get the error message content.
64      *
65      * @param errCode Error code.
66      * @return Message content.
67      */
68     std::string GetErrorMessage(int errCode);
69 
70     /**
71      * @brief Get external error code by internal error code.
72      *
73      * @param internalErrorCode Internal error code.
74      * @return External error code.
75      */
76     int32_t QueryExternalErrorCode(int32_t internalErrorCode);
77 
78     /**
79      * @brief Get external error message by error code.
80      *
81      * @param internalErrorCode Internal error code.
82      * @param externalErrorCode External error code.
83      * @return External error message.
84      */
85     std::string QueryExternalErrorMessage(int32_t internalErrorCode, int32_t externalErrorCode);
86 
87     /**
88      * @brief Get external error message by external error code.
89      *
90      * @param externalErrorCode External error code.
91      * @return External error message.
92      */
93     std::string GetErrorMsgByExternalErrorCode(int32_t externalErrorCode);
94 
95 private:
96     /**
97     * @brief Init error message map object.
98     *
99     */
100     void InitErrorMessageMap();
101 
102 private:
103     std::map<ErrCode, std::string> errorMessageMap_;
104 };
105 }  // namespace AppExecFwk
106 }  // namespace OHOS
107 #endif  // OHOS_FORM_FWK_FORM_ERRORS_H
108