• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_PARAM_INVALID = 401,
31     ERR_FORM_EXTERNAL_SYSTEMCAP_ERROR = 801,
32     ERR_FORM_EXTERNAL_KERNEL_ERROR = 16500001,
33     ERR_FORM_EXTERNAL_KERNEL_MALLOC_ERROR = 16500002,
34     ERR_FORM_EXTERNAL_IPC_ERROR = 16500050,
35     ERR_FORM_EXTERNAL_SERVICE_CONNECTION_ERROR = 16500060,
36     ERR_FORM_EXTERNAL_GET_INFO_FAILED = 16500100,
37     ERR_FORM_EXTERNAL_NOT_SYSTEM_APP = 16500101,
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 };
46 
47 /**
48  * @class FormErrors
49  * FormErrors is used to access form error message.
50  */
51 class FormErrors final : public DelayedRefSingleton<FormErrors> {
52     DECLARE_DELAYED_REF_SINGLETON(FormErrors)
53 public:
54     DISALLOW_COPY_AND_MOVE(FormErrors);
55 
56     /**
57      * @brief Get the error message content.
58      *
59      * @param errCode Error code.
60      * @return Message content.
61      */
62     std::string GetErrorMessage(int errCode);
63 
64     /**
65      * @brief Get external error code by internal error code.
66      *
67      * @param internalErrorCode Internal error code.
68      * @return External error code.
69      */
70     int32_t QueryExternalErrorCode(int32_t internalErrorCode);
71 
72     /**
73      * @brief Get external error message by error code.
74      *
75      * @param internalErrorCode Internal error code.
76      * @param externalErrorCode External error code.
77      * @return External error message.
78      */
79     std::string QueryExternalErrorMessage(int32_t internalErrorCode, int32_t externalErrorCode);
80 
81     /**
82      * @brief Get external error message by external error code.
83      *
84      * @param externalErrorCode External error code.
85      * @return External error message.
86      */
87     std::string GetErrorMsgByExternalErrorCode(int32_t externalErrorCode);
88 
89 private:
90     /**
91     * @brief Init error message map object.
92     *
93     */
94     void InitErrorMessageMap();
95 
96 private:
97     std::map<ErrCode, std::string> errorMessageMap_;
98 };
99 }  // namespace AppExecFwk
100 }  // namespace OHOS
101 #endif  // OHOS_FORM_FWK_FORM_ERRORS_H