• 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_MEDIALIBRARY_CLIENT_ERRNO_H
17 #define OHOS_MEDIALIBRARY_CLIENT_ERRNO_H
18 
19 #include <errno.h>
20 #include <unordered_map>
21 
22 #include "medialibrary_errno.h"
23 
24 namespace OHOS {
25 namespace Media {
26 constexpr int32_t FILEIO_MODULE_CODE = 139;
27 constexpr int32_t UFM_MODULE_CODE = 140;
28 constexpr int32_t UFM_SYSCAP_BASE = 202;
29 
30 #define MODULE_OFFSET  100000
31 #define MODULE_CODE(code) (((code) * MODULE_OFFSET))
32 #define UFM_JS_ERR(moduleCode, errCode) ((MODULE_CODE(moduleCode))  + (errCode))
33 // file io common error code
34 constexpr int32_t JS_ERR_NO_SUCH_FILE      = UFM_JS_ERR(FILEIO_MODULE_CODE, 2);         // no such file
35 constexpr int32_t JS_ERR_NO_MEM            = UFM_JS_ERR(FILEIO_MODULE_CODE, 11);        // cannot allocate memory
36 constexpr int32_t JS_ERR_PERMISSION_DENIED = UFM_JS_ERR(FILEIO_MODULE_CODE, 12);        // permission deny
37 constexpr int32_t JS_ERR_FILE_EXIST        = UFM_JS_ERR(FILEIO_MODULE_CODE, 15);        // file has exist
38 constexpr int32_t JS_ERR_PARAMETER_INVALID = UFM_JS_ERR(FILEIO_MODULE_CODE, 20);        // input parameter invalid
39 
40 // userfileMananger error code
41 constexpr int32_t JS_E_DISPLAYNAME    = UFM_JS_ERR(UFM_MODULE_CODE, 1);
42 constexpr int32_t JS_E_URI            = UFM_JS_ERR(UFM_MODULE_CODE, 2);
43 constexpr int32_t JS_E_FILE_EXTENSION = UFM_JS_ERR(UFM_MODULE_CODE, 3);
44 constexpr int32_t JS_E_TRASHED        = UFM_JS_ERR(UFM_MODULE_CODE, 4);
45 constexpr int32_t JS_E_OPEN_MODE      = UFM_JS_ERR(UFM_MODULE_CODE, 5);
46 constexpr int32_t JS_E_NOT_ALBUM      = UFM_JS_ERR(UFM_MODULE_CODE, 6);
47 constexpr int32_t JS_E_ROOT_DIR       = UFM_JS_ERR(UFM_MODULE_CODE, 7);
48 constexpr int32_t JS_E_MOVE_DENIED    = UFM_JS_ERR(UFM_MODULE_CODE, 8);
49 constexpr int32_t JS_E_RENAME_DENIED  = UFM_JS_ERR(UFM_MODULE_CODE, 9);
50 constexpr int32_t JS_E_RELATIVEPATH   = UFM_JS_ERR(UFM_MODULE_CODE, 10);
51 constexpr int32_t JS_INNER_FAIL       = UFM_JS_ERR(UFM_MODULE_CODE, 11);
52 // file type is not allow in the directory
53 constexpr int32_t JS_E_FILE_TYPE      = UFM_JS_ERR(UFM_MODULE_CODE, 12);
54 constexpr int32_t JS_E_NO_MEMORY      = UFM_JS_ERR(UFM_MODULE_CODE, 13);    // no memory left
55 constexpr int32_t JS_E_FILE_KEY       = UFM_JS_ERR(UFM_MODULE_CODE, 14);    // wrong member name
56 constexpr int32_t JS_E_INPUT          = UFM_JS_ERR(UFM_MODULE_CODE, 15);
57 
58 constexpr int32_t JS_E_NAMETOOLONG    = UFM_JS_ERR(UFM_SYSCAP_BASE, 36);
59 
60 // trans server errorCode to js Error code
61 const std::unordered_map<int, int> trans2JsError = {
62     { E_PERMISSION_DENIED,    JS_ERR_PERMISSION_DENIED },
63     { E_FAIL,                 JS_INNER_FAIL },
64     { E_NO_SUCH_FILE,         JS_ERR_NO_SUCH_FILE },
65     { E_FILE_EXIST,           JS_ERR_FILE_EXIST },
66     { E_NO_MEMORY,            JS_E_NO_MEMORY },
67     { E_FILE_NAME_INVALID,    JS_E_DISPLAYNAME },
68     { E_CHECK_EXTENSION_FAIL, JS_E_FILE_TYPE },
69     { E_FILE_OPER_FAIL,       JS_INNER_FAIL },
70     { -ENAMETOOLONG,          JS_E_NAMETOOLONG },
71     { -EINVAL,                JS_ERR_PARAMETER_INVALID },
72     { -ENOMEM,                JS_ERR_NO_MEM },
73 };
74 
75 const std::unordered_map<int, std::string> jsErrMap = {
76     { JS_ERR_PERMISSION_DENIED, "without medialibrary permission" },
77     { JS_INNER_FAIL,            "medialibrary inner fail" },
78     { JS_ERR_PARAMETER_INVALID, "invalid parameter" },
79     { JS_E_DISPLAYNAME,         "display name invalid" },
80     { JS_ERR_NO_SUCH_FILE,      "no such file" },
81     { JS_ERR_FILE_EXIST,        "file has existed" },
82     { JS_E_FILE_TYPE,           "file type is not allow in the directory" },
83     { JS_E_FILE_KEY,            "member not exist" },
84     { JS_ERR_NO_MEM,            "cannot allocate memory" },
85     { JS_E_NAMETOOLONG,         "file name is too long" },
86 };
87 
88 const std::unordered_map<int32_t, int32_t> ClientErrTable {
89     { E_INVALID_DISPLAY_NAME, JS_E_DISPLAYNAME },
90     { E_FILE_NAME_INVALID, JS_E_DISPLAYNAME },
91     { E_URI_INVALID, JS_E_URI },
92     { E_INVALID_URI, JS_E_URI },
93     { E_DISTIBUTED_URI_NO_SUPPORT, JS_E_URI },
94     { E_URI_IS_NOT_ALBUM, JS_E_URI },
95     { E_DIR_CHECK_DIR_FAIL, JS_E_ROOT_DIR },
96     { E_CHECK_MEDIATYPE_MATCH_EXTENSION_FAIL, JS_E_FILE_EXTENSION },
97     { E_CHECK_MEDIATYPE_FAIL, JS_E_FILE_EXTENSION },
98     { E_CHECK_EXTENSION_FAIL, JS_E_FILE_EXTENSION },
99     { E_OPENFILE_INVALID_FLAG, JS_E_OPEN_MODE },
100     { E_NO_SUCH_FILE, JS_ERR_NO_SUCH_FILE },
101     { E_FILE_EXIST, JS_ERR_FILE_EXIST },
102     { E_DENIED_MOVE, JS_E_MOVE_DENIED },
103     { E_DENIED_RENAME, JS_E_RENAME_DENIED },
104 };
105 } // namespace Media
106 } // namespace OHOS
107 
108 
109 #endif  // OHOS_MEDIALIBRARY_CLIENT_ERRNO_H
110