Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Camera / Camera / CameraErrorFactory.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Runtime.CompilerServices;
19 using Tizen.Internals.Errors;
20
21 namespace Tizen.Multimedia
22 {
23     internal enum CameraError
24     {
25         TizenErrorCamera = -0x01910000,
26         CameraErrorClass = TizenErrorCamera,
27         None = ErrorCode.None,
28         InvalidParameter = ErrorCode.InvalidParameter,
29         InvalidState = CameraErrorClass | 0x02,
30         OutOfMemory = ErrorCode.OutOfMemory,
31         DeviceError = CameraErrorClass | 0x04,
32         InvalidOperation = ErrorCode.InvalidOperation,
33         SecurityRestricted = CameraErrorClass | 0x07,
34         DeviceBusy = CameraErrorClass | 0x08,
35         DeviceNotFound = CameraErrorClass | 0x09,
36         Esd = CameraErrorClass | 0x0c,
37         PermissionDenied = ErrorCode.PermissionDenied,
38         NotSupported = ErrorCode.NotSupported,
39         ResourceConflict = CameraErrorClass | 0x0d,
40         ServiceDisconnected = CameraErrorClass | 0x0e
41     }
42
43     internal static class CameraErrorFactory
44     {
45         internal static void ThrowIfError(CameraError errorCode, string errorMessage = null,
46             [CallerMemberName] string caller = null, [CallerLineNumber] int line = 0)
47         {
48             if (errorCode == CameraError.None)
49             {
50                 return;
51             }
52
53             Log.Info(CameraLog.Tag, "errorCode : " + errorCode.ToString() + ", Caller : " + caller + ", line " + line.ToString());
54
55             switch (errorCode)
56             {
57                 case CameraError.InvalidParameter:
58                     throw new ArgumentException(errorMessage);
59
60                 case CameraError.OutOfMemory:
61                     throw new OutOfMemoryException(errorMessage);
62
63                 case CameraError.DeviceError:
64                 case CameraError.DeviceBusy:
65                 case CameraError.Esd:
66                     throw new CameraDeviceException(errorMessage);
67
68                 case CameraError.DeviceNotFound:
69                     throw new CameraDeviceNotFoundException(errorMessage);
70
71                 case CameraError.SecurityRestricted:
72                 case CameraError.PermissionDenied:
73                     throw new UnauthorizedAccessException(errorMessage);
74
75                 case CameraError.NotSupported:
76                     throw new NotSupportedException(errorMessage);
77
78                 case CameraError.InvalidState:
79                 case CameraError.InvalidOperation:
80                 case CameraError.ResourceConflict:
81                 case CameraError.ServiceDisconnected:
82                     throw new InvalidOperationException(errorMessage);
83
84                 default:
85                     throw new Exception("Unknown error : " + errorCode);
86             }
87         }
88     }
89 }