Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Sensor / Tizen.Sensor / SensorErrorFactory.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 Tizen.Internals.Errors;
19
20 namespace Tizen.Sensor
21 {
22     internal enum SensorError
23     {
24         None = ErrorCode.None,
25         IOError = ErrorCode.IoError,
26         InvalidParameter = ErrorCode.InvalidParameter,
27         NotSupported = ErrorCode.NotSupported,
28         PermissionDenied = ErrorCode.PermissionDenied,
29         OutOfMemory = ErrorCode.OutOfMemory,
30         NotNeedCalibration = -0x02440000 | 0x03,
31         OperationFailed = -0x02440000 | 0x06
32     }
33
34     internal static class SensorErrorFactory
35     {
36         static internal Exception CheckAndThrowException(int error, string msg)
37         {
38             SensorError e = (SensorError)error;
39             switch (e)
40             {
41                 case SensorError.None:
42                     return null;
43                 case SensorError.IOError:
44                     return new InvalidOperationException("I/O Error: " + msg);
45                 case SensorError.InvalidParameter:
46                     return new ArgumentException("Invalid Parameter: " + msg);
47                 case SensorError.NotSupported:
48                     return new NotSupportedException("Not Supported: " + msg);
49                 case SensorError.PermissionDenied:
50                     return new UnauthorizedAccessException("Permission Denied: " + msg);
51                 case SensorError.OutOfMemory:
52                     return new InvalidOperationException("Out of Memory: " + msg);
53                 case SensorError.NotNeedCalibration:
54                     return new InvalidOperationException("Sensor doesn't need calibration: " + msg);
55                 case SensorError.OperationFailed:
56                     return new InvalidOperationException("Operation Failed: " + msg);
57                 default:
58                     return new InvalidOperationException("Unknown Error Code: " + msg);
59             }
60         }
61     }
62 }