1/*
2 * Copyright (c) 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#include "dm_error_message.h"
17
18#include "dm_constants.h"  // for ERR_DM_AUTH_BUSINESS_BUSY, ERR_DM_AUTH_FAILED
19
20namespace OHOS {
21namespace DistributedHardware {
22typedef struct ERROR_INFO {
23    int errCode;
24    std::string errMsg;
25} ERROR_INFO;
26
27ERROR_INFO g_errorMessages[] = {
28    {ERR_DM_FAILED, "dm process execution failed."},
29    {ERR_DM_TIME_OUT, "dm process execution timeout."},
30    {ERR_DM_NOT_INIT, "dm service is not initialized, please try again later."},
31    {ERR_DM_INIT_FAILED, "dm service initialize failed."},
32    {ERR_DM_POINT_NULL, "dm service null pointer exception occurred."},
33    {ERR_DM_INPUT_PARA_INVALID, "the function call input para is invalid."},
34    {ERR_DM_NO_PERMISSION, "no permission for function call."},
35    {ERR_DM_MALLOC_FAILED, "memory allocation failed."},
36    {ERR_DM_DISCOVERY_FAILED, "device discovery failed."},
37    {ERR_DM_MAP_KEY_ALREADY_EXISTS, "map key already exists."},
38    {ERR_DM_IPC_WRITE_FAILED, "ipc write object failed."},
39    {ERR_DM_IPC_COPY_FAILED, "ipc copy data failed."},
40    {ERR_DM_IPC_SEND_REQUEST_FAILED, "ipc send request failed."},
41    {ERR_DM_UNSUPPORTED_IPC_COMMAND, "ipc command not supported."},
42    {ERR_DM_IPC_RESPOND_FAILED, "ipc process failed to receive response."},
43    {ERR_DM_DISCOVERY_REPEATED, "repeat device discovery warning."},
44    {ERR_DM_UNSUPPORTED_AUTH_TYPE, "auth type not supported."},
45    {ERR_DM_AUTH_BUSINESS_BUSY, "authentication service is busy."},
46    {ERR_DM_AUTH_OPEN_SESSION_FAILED, "open auth session failed."},
47    {ERR_DM_AUTH_PEER_REJECT, "remote device refused to authorization."},
48    {ERR_DM_AUTH_REJECT, "local device refused to authorization."},
49    {ERR_DM_AUTH_FAILED, "authentication failed."},
50    {ERR_DM_AUTH_NOT_START, "auth process not started."},
51    {ERR_DM_AUTH_MESSAGE_INCOMPLETE, "authentication message is incomplete."},
52    {ERR_DM_CREATE_GROUP_FAILED, "create group failed."},
53    {ERR_DM_IPC_READ_FAILED, "ipc read object failed."},
54    {ERR_DM_PUBLISH_FAILED, "device publish failed."},
55    {ERR_DM_PUBLISH_REPEATED, "repeat device publish warning."},
56};
57
58std::string GetErrorString(int failedReason)
59{
60    std::string errorMessage = "undefined error code.";
61    for (uint32_t i = 0; i < (sizeof(g_errorMessages) / sizeof(g_errorMessages[0])); i++) {
62        if (failedReason == g_errorMessages[i].errCode) {
63            errorMessage = g_errorMessages[i].errMsg;
64            break;
65        }
66    }
67    return errorMessage;
68}
69} // namespace DistributedHardware
70} // namespace OHOS
71