1 /* 2 * Copyright (c) 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 RINGTONE_COMMON_NAPI_H 17 #define RINGTONE_COMMON_NAPI_H 18 19 #include <string> 20 21 #include "meta/format.h" 22 23 #include "napi/native_api.h" 24 #include "napi/native_node_api.h" 25 26 namespace OHOS { 27 namespace Media { 28 const int32_t NAPI_ERR_NO_PERMISSION = 201; 29 const int32_t NAPI_ERR_PERMISSION_DENIED = 202; 30 const int32_t NAPI_ERR_INPUT_INVALID = 401; 31 const int32_t NAPI_ERR_URI_ERROR = 20700001; 32 const int32_t NAPI_ERR_OPERATE_NOT_ALLOWED = 5400102; 33 const int32_t NAPI_ERR_IO_ERROR = 5400103; 34 const int32_t NAPI_ERR_INVALID_PARAM = 6800101; 35 const int32_t NAPI_ERR_NO_MEMORY = 6800102; 36 const int32_t NAPI_ERR_UNSUPPORTED = 6800104; 37 const int32_t NAPI_ERR_SYSTEM = 6800301; 38 const int32_t NAPI_ERR_UNSUPPORTED_OPERATION = 20700003; 39 40 const std::string NAPI_ERR_NO_PERMISSION_INFO = "Permission denied"; 41 const std::string NAPI_ERR_PERMISSION_DENIED_INFO = "Caller is not a system application"; 42 const std::string NAPI_ERR_INPUT_INVALID_INFO = "input parameter type or number mismatch"; 43 const std::string NAPI_ERR_URI_ERROR_INFO = "Tone type mismatch"; 44 const std::string NAPI_ERR_OPERATE_NOT_ALLOWED_INFO = "Operation is not allowed"; 45 const std::string NAPI_ERR_IO_ERROR_INFO = "I/O error"; 46 const std::string NAPI_ERR_INVALID_PARAM_INFO = "invalid parameter"; 47 const std::string NAPI_ERR_NO_MEMORY_INFO = "allocate memory failed"; 48 const std::string NAPI_ERR_SYSTEM_INFO = "system error"; 49 const std::string NAPI_ERR_UNSUPPORTED_OPERATION_INFO = "Unsupported operation"; 50 51 class RingtoneCommonNapi { 52 public: 53 RingtoneCommonNapi() = delete; 54 ~RingtoneCommonNapi() = delete; 55 static std::string GetStringArgument(napi_env env, napi_value value); 56 static void ThrowError(napi_env env, int32_t code, const std::string &errMessage); 57 static std::string GetMessageByCode(int32_t &code); 58 }; 59 } // namespace Media 60 } // namespace OHOS 61 #endif // RINGTONE_COMMON_NAPI_H