91bb7ae9a992946ed3720dc21e14d375958553bc
[platform/core/csapi/tizenfx.git] / src / Tizen.Location / Tizen.Location / LocationError.cs
1 // Copyright 2016 by Samsung Electronics, Inc.,
2 //
3 // This software is the confidential and proprietary information
4 // of Samsung Electronics, Inc. ("Confidential Information"). You
5 // shall not disclose such Confidential Information and shall use
6 // it only in accordance with the terms of the license agreement
7 // you entered into with Samsung.
8
9
10 using System;
11 using Tizen.Internals.Errors;
12
13 namespace Tizen.Location
14 {
15     internal static class LocationManagerError
16     {
17         public const int Base = -0x02C00000;
18         public const int BoundsBase = -0x02C00000 | 0x20;
19     }
20
21     /// <summary>
22     /// Location Manager error codes
23     /// </summary>
24     public enum LocationError
25     {
26         None = ErrorCode.None,/**< Successful */
27         OutOfMemoryError = ErrorCode.OutOfMemory,/**< Out of memory error */
28         InvalidParameter = ErrorCode.InvalidParameter,/**< Invalid parameter */
29         AcessibilityNotallowed = ErrorCode.PermissionDenied,/**< Permission denied */
30         NotSupported = ErrorCode.NotSupported,/**< Address family not supported */
31         IncorrectMethod = LocationManagerError.Base | 0x01,/**< Location manager contains incorrect method for a given call */
32         NetworkFailed = LocationManagerError.Base | 0x02,/**< Network unavailable */
33         ServiceNotAvailable = LocationManagerError.Base | 0x03,/**< Location service is not available */
34         GPSSettingOff = LocationManagerError.Base | 0x04,/**< GPS/WPS, or MOCK setting is not enabled */
35         SecuirtyRestricted = LocationManagerError.Base | 0x05,/**< Restricted by security system policy */
36         SettingOff = GPSSettingOff/**< GPS/WPS, or MOCK setting is not enabled */
37     }
38
39     /// <summary>
40     /// Location Boundary error codes
41     /// </summary>
42     public enum LocationBoundError
43     {
44         None = ErrorCode.None,/**< Successful */
45         OutOfMemoryError = ErrorCode.OutOfMemory,/**< Out of memory error */
46         InvalidParameter = ErrorCode.InvalidParameter,/**< Invalid parameter */
47         NotSupported = ErrorCode.NotSupported,/**< Not supported */
48         IncorrectType = LocationManagerError.BoundsBase | 0x01,/**< Incorrect bounds type for a given call */
49         IsAdded = LocationManagerError.BoundsBase | 0x02/**< Cannot remove bounds handle from location manager   */
50     }
51
52     internal static class LocationErrorFactory
53     {
54         internal static Exception ThrowLocationException(int errCode)
55         {
56             LocationError error = (LocationError)errCode;
57             switch (error)
58             {
59                 case LocationError.AcessibilityNotallowed:
60                     return new InvalidOperationException("Accesibility not allowed");
61                 case LocationError.SettingOff:
62                     return new InvalidOperationException("Current locationtype setting is off");
63                 case LocationError.IncorrectMethod:
64                     return new InvalidOperationException("Incorrect method used");
65                 case LocationError.InvalidParameter:
66                     return new ArgumentException("Invalid Parameter passed");
67                 case LocationError.NetworkFailed:
68                     return new InvalidOperationException("Network failed");
69                 case LocationError.NotSupported:
70                     return new InvalidOperationException("Operation not supported");
71                 case LocationError.OutOfMemoryError:
72                     return new InvalidOperationException("Out of memory error");
73                 case LocationError.SecuirtyRestricted:
74                     return new InvalidOperationException("Security Restricted");
75                 case LocationError.ServiceNotAvailable:
76                     return new InvalidOperationException("Service not available");
77                 default:
78                     return new InvalidOperationException("Unknown Error");
79             }
80         }
81
82         internal static Exception ThrowLocationBoundaryException(int errCode)
83         {
84             LocationBoundError error = (LocationBoundError)errCode;
85             switch (error)
86             {
87                 case LocationBoundError.IncorrectType:
88                     return new InvalidOperationException("Incorrect type passed");
89                 case LocationBoundError.InvalidParameter:
90                     return new ArgumentException("Invalid parameter passed");
91                 case LocationBoundError.IsAdded:
92                     return new InvalidOperationException("Boundary is not addded");
93                 case LocationBoundError.NotSupported:
94                     return new InvalidOperationException("Operation Not supported");
95                 case LocationBoundError.OutOfMemoryError:
96                     return new InvalidOperationException("Out of memory exception");
97                 default:
98                     return new InvalidOperationException("Unknown Error");
99             }
100         }
101     }
102 }