[Device] Implementation of system.device module including error handling.
[platform/core/csapi/system.git] / Tizen.System / Device / DeviceExceptionFactory.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace Tizen.System
7 {
8     internal enum DeviceError
9     {
10         None = Tizen.Internals.Errors.ErrorCode.None,
11         InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
12         PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
13         InvalidOperation = Tizen.Internals.Errors.ErrorCode.InvalidOperation,
14         AlreadyInProgress = Tizen.Internals.Errors.ErrorCode.NowInProgress,
15         NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported,
16         ResourceBusy = Tizen.Internals.Errors.ErrorCode.ResourceBusy,
17         OperationFailed = -0x01140000 | 0x01,
18         NotInitialized = -0x01140000 | 0x02
19     };
20
21     class DeviceExceptionFactory
22     {
23         internal const string LogTag = "Tizen.System.Device";
24
25         internal static Exception CreateException(DeviceError err, string msg)
26         {
27             Exception exp;
28             switch (err)
29             {
30                 case DeviceError.InvalidParameter:
31                     exp =  new ArgumentException(msg);
32                     break;
33                 case DeviceError.AlreadyInProgress:
34                     //fall through
35                 case DeviceError.NotSupported:
36                     //fall through
37                 case DeviceError.ResourceBusy:
38                     //fall through
39                 case DeviceError.OperationFailed:
40                     //fall through
41                 case DeviceError.NotInitialized:
42                     //fall through
43                 case DeviceError.PermissionDenied:
44                     //fall through
45                 case DeviceError.InvalidOperation:
46                     exp = new InvalidOperationException(msg);
47                     break;
48                 default:
49                     exp = new InvalidOperationException("Unknown error occured.");
50                     break;
51             }
52             return exp;
53         }
54     }
55 }