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 #include "icamera_util.h"
17 #include "camera_error_code.h"
18 #include "camera_util.h"
19 #include "camera_log.h"
20 
21 namespace OHOS {
22 namespace CameraStandard {
ServiceToCameraError(int32_t ret)23 int32_t ServiceToCameraError(int32_t ret)
24 {
25     int32_t err = CameraErrorCode::SERVICE_FATL_ERROR;
26     switch (ret) {
27         case CAMERA_OK:
28             err = 0;
29             break;
30         case CAMERA_ALLOC_ERROR:
31             err = CameraErrorCode::SERVICE_FATL_ERROR;
32             break;
33         case CAMERA_INVALID_ARG:
34             err = CameraErrorCode::SERVICE_FATL_ERROR;
35             break;
36         case CAMERA_UNSUPPORTED:
37             err = CameraErrorCode::DEVICE_DISABLED;
38             break;
39         case CAMERA_DEVICE_BUSY:
40             err = CameraErrorCode::CONFLICT_CAMERA;
41             break;
42         case CAMERA_DEVICE_CLOSED:
43             err = CameraErrorCode::DEVICE_DISABLED;
44             break;
45         case CAMERA_DEVICE_REQUEST_TIMEOUT:
46             err = CameraErrorCode::SERVICE_FATL_ERROR;
47             break;
48         case CAMERA_STREAM_BUFFER_LOST:
49             err = CameraErrorCode::SERVICE_FATL_ERROR;
50             break;
51         case CAMERA_INVALID_SESSION_CFG:
52             err = CameraErrorCode::SERVICE_FATL_ERROR;
53             break;
54         case CAMERA_CAPTURE_LIMIT_EXCEED:
55             err = CameraErrorCode::SERVICE_FATL_ERROR;
56             break;
57         case CAMERA_INVALID_STATE:
58             err = CameraErrorCode::SERVICE_FATL_ERROR;
59             break;
60         case CAMERA_UNKNOWN_ERROR:
61             err = CameraErrorCode::SERVICE_FATL_ERROR;
62             break;
63         case CAMERA_DEVICE_PREEMPTED:
64             err = CameraErrorCode::DEVICE_PREEMPTED;
65             break;
66         case CAMERA_OPERATION_NOT_ALLOWED:
67             err = CameraErrorCode::OPERATION_NOT_ALLOWED;
68             break;
69         case CAMERA_DEVICE_ERROR:
70             err = CameraErrorCode::OPERATION_NOT_ALLOWED;
71             break;
72         case CAMERA_NO_PERMISSION:
73             err = CameraErrorCode::OPERATION_NOT_ALLOWED;
74             break;
75         case CAMERA_DEVICE_CONFLICT:
76             err = CameraErrorCode::OPERATION_NOT_ALLOWED;
77             break;
78         case IPC_PROXY_ERR:
79         case IPC_PROXY_DEAD_OBJECT_ERR:
80         case IPC_PROXY_NULL_INVOKER_ERR:
81         case IPC_PROXY_TRANSACTION_ERR:
82         case IPC_PROXY_INVALID_CODE_ERR:
83         case IPC_STUB_ERR:
84         case IPC_STUB_WRITE_PARCEL_ERR:
85         case IPC_STUB_INVOKE_THREAD_ERR:
86         case IPC_STUB_INVALID_DATA_ERR:
87         case IPC_STUB_CURRENT_NULL_ERR:
88         case IPC_STUB_UNKNOW_TRANS_ERR:
89         case IPC_STUB_CREATE_BUS_SERVER_ERR:
90             err = CameraErrorCode::SERVICE_FATL_ERROR;
91             break;
92         default:
93             MEDIA_ERR_LOG("ServiceToCameraError() error code from service: %{public}d", ret);
94             break;
95     }
96     return err;
97 }
98 } // namespace CameraStandard
99 } // namespace OHOS
100