Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Recorder / Recorder / RecorderErrorFactory.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 RecorderError
24     {
25         TizenErrorRecorder = -0x01950000,
26         RecorderErrorClass = TizenErrorRecorder | 0x10,
27         None = ErrorCode.None,
28         InvalidParameter = ErrorCode.InvalidParameter,
29         InvalidState = RecorderErrorClass | 0x02,
30         OutOfMemory = ErrorCode.OutOfMemory,
31         DeviceError = RecorderErrorClass | 0x04,
32         InvalidOperation = ErrorCode.InvalidOperation,
33         SecurityRestricted = RecorderErrorClass | 0x07,
34         Esd = RecorderErrorClass | 0x0a,
35         OutOfStorage = RecorderErrorClass | 0x0b,
36         PermissionDenied = ErrorCode.PermissionDenied,
37         NotSupported = ErrorCode.NotSupported,
38         ResourceConflict = RecorderErrorClass | 0x0c,
39         ServiceDisconnected = RecorderErrorClass | 0x0d
40     }
41
42     internal static class RecorderErrorFactory
43     {
44         internal static void ThrowIfError(RecorderError errorCode, string errorMessage = null,
45             [CallerMemberName] string caller = null, [CallerLineNumber] int line = 0)
46         {
47             if (errorCode == RecorderError.None)
48             {
49                 return;
50             }
51
52             Log.Info(RecorderLog.Tag, "errorCode : " + errorCode.ToString() + ", Caller : " + caller + ", line " + line.ToString());
53
54             switch (errorCode)
55             {
56                 case RecorderError.InvalidParameter:
57                     throw new ArgumentException(errorMessage);
58
59                 case RecorderError.OutOfMemory:
60                     throw new OutOfMemoryException(errorMessage);
61
62                 case RecorderError.DeviceError:
63                 case RecorderError.Esd:
64                 case RecorderError.SecurityRestricted:
65                 case RecorderError.PermissionDenied:
66                     throw new UnauthorizedAccessException(errorMessage);
67
68                 case RecorderError.NotSupported:
69                     throw new NotSupportedException(errorMessage);
70
71                 case RecorderError.InvalidState:
72                 case RecorderError.InvalidOperation:
73                 case RecorderError.ResourceConflict:
74                 case RecorderError.ServiceDisconnected:
75                 case RecorderError.OutOfStorage: //TODO need to alloc new proper exception class
76                     throw new InvalidOperationException(errorMessage);
77
78                 default:
79                     throw new Exception("Unknown error : " + errorCode.ToString());
80             }
81         }
82     }
83 }