179a732c7Sopenharmony_ci/* 279a732c7Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 379a732c7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 479a732c7Sopenharmony_ci * you may not use this file except in compliance with the License. 579a732c7Sopenharmony_ci * You may obtain a copy of the License at 679a732c7Sopenharmony_ci * 779a732c7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 879a732c7Sopenharmony_ci * 979a732c7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1079a732c7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1179a732c7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1279a732c7Sopenharmony_ci * See the License for the specific language governing permissions and 1379a732c7Sopenharmony_ci * limitations under the License. 1479a732c7Sopenharmony_ci */ 1579a732c7Sopenharmony_ci 1679a732c7Sopenharmony_ci#include "dm_error_message.h" 1779a732c7Sopenharmony_ci 1879a732c7Sopenharmony_ci#include "dm_constants.h" // for ERR_DM_AUTH_BUSINESS_BUSY, ERR_DM_AUTH_FAILED 1979a732c7Sopenharmony_ci 2079a732c7Sopenharmony_cinamespace OHOS { 2179a732c7Sopenharmony_cinamespace DistributedHardware { 2279a732c7Sopenharmony_citypedef struct ERROR_INFO { 2379a732c7Sopenharmony_ci int errCode; 2479a732c7Sopenharmony_ci std::string errMsg; 2579a732c7Sopenharmony_ci} ERROR_INFO; 2679a732c7Sopenharmony_ci 2779a732c7Sopenharmony_ciERROR_INFO g_errorMessages[] = { 2879a732c7Sopenharmony_ci {ERR_DM_FAILED, "dm process execution failed."}, 2979a732c7Sopenharmony_ci {ERR_DM_TIME_OUT, "dm process execution timeout."}, 3079a732c7Sopenharmony_ci {ERR_DM_NOT_INIT, "dm service is not initialized, please try again later."}, 3179a732c7Sopenharmony_ci {ERR_DM_INIT_FAILED, "dm service initialize failed."}, 3279a732c7Sopenharmony_ci {ERR_DM_POINT_NULL, "dm service null pointer exception occurred."}, 3379a732c7Sopenharmony_ci {ERR_DM_INPUT_PARA_INVALID, "the function call input para is invalid."}, 3479a732c7Sopenharmony_ci {ERR_DM_NO_PERMISSION, "no permission for function call."}, 3579a732c7Sopenharmony_ci {ERR_DM_MALLOC_FAILED, "memory allocation failed."}, 3679a732c7Sopenharmony_ci {ERR_DM_DISCOVERY_FAILED, "device discovery failed."}, 3779a732c7Sopenharmony_ci {ERR_DM_MAP_KEY_ALREADY_EXISTS, "map key already exists."}, 3879a732c7Sopenharmony_ci {ERR_DM_IPC_WRITE_FAILED, "ipc write object failed."}, 3979a732c7Sopenharmony_ci {ERR_DM_IPC_COPY_FAILED, "ipc copy data failed."}, 4079a732c7Sopenharmony_ci {ERR_DM_IPC_SEND_REQUEST_FAILED, "ipc send request failed."}, 4179a732c7Sopenharmony_ci {ERR_DM_UNSUPPORTED_IPC_COMMAND, "ipc command not supported."}, 4279a732c7Sopenharmony_ci {ERR_DM_IPC_RESPOND_FAILED, "ipc process failed to receive response."}, 4379a732c7Sopenharmony_ci {ERR_DM_DISCOVERY_REPEATED, "repeat device discovery warning."}, 4479a732c7Sopenharmony_ci {ERR_DM_UNSUPPORTED_AUTH_TYPE, "auth type not supported."}, 4579a732c7Sopenharmony_ci {ERR_DM_AUTH_BUSINESS_BUSY, "authentication service is busy."}, 4679a732c7Sopenharmony_ci {ERR_DM_AUTH_OPEN_SESSION_FAILED, "open auth session failed."}, 4779a732c7Sopenharmony_ci {ERR_DM_AUTH_PEER_REJECT, "remote device refused to authorization."}, 4879a732c7Sopenharmony_ci {ERR_DM_AUTH_REJECT, "local device refused to authorization."}, 4979a732c7Sopenharmony_ci {ERR_DM_AUTH_FAILED, "authentication failed."}, 5079a732c7Sopenharmony_ci {ERR_DM_AUTH_NOT_START, "auth process not started."}, 5179a732c7Sopenharmony_ci {ERR_DM_AUTH_MESSAGE_INCOMPLETE, "authentication message is incomplete."}, 5279a732c7Sopenharmony_ci {ERR_DM_CREATE_GROUP_FAILED, "create group failed."}, 5379a732c7Sopenharmony_ci {ERR_DM_IPC_READ_FAILED, "ipc read object failed."}, 5479a732c7Sopenharmony_ci {ERR_DM_PUBLISH_FAILED, "device publish failed."}, 5579a732c7Sopenharmony_ci {ERR_DM_PUBLISH_REPEATED, "repeat device publish warning."}, 5679a732c7Sopenharmony_ci}; 5779a732c7Sopenharmony_ci 5879a732c7Sopenharmony_cistd::string GetErrorString(int failedReason) 5979a732c7Sopenharmony_ci{ 6079a732c7Sopenharmony_ci std::string errorMessage = "undefined error code."; 6179a732c7Sopenharmony_ci for (uint32_t i = 0; i < (sizeof(g_errorMessages) / sizeof(g_errorMessages[0])); i++) { 6279a732c7Sopenharmony_ci if (failedReason == g_errorMessages[i].errCode) { 6379a732c7Sopenharmony_ci errorMessage = g_errorMessages[i].errMsg; 6479a732c7Sopenharmony_ci break; 6579a732c7Sopenharmony_ci } 6679a732c7Sopenharmony_ci } 6779a732c7Sopenharmony_ci return errorMessage; 6879a732c7Sopenharmony_ci} 6979a732c7Sopenharmony_ci} // namespace DistributedHardware 7079a732c7Sopenharmony_ci} // namespace OHOS 71