0471e5466181fd1bb39dc02501488519c155dbe5
[platform/core/csapi/tizenfx.git] / src / Tizen.Location / Tizen.Location / LocationError.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.Location
21 {
22     internal static class LocationManagerError
23     {
24         public const int Base = -0x02C00000;
25         public const int BoundsBase = -0x02C00000 | 0x20;
26     }
27
28     /// <summary>
29     /// Location Manager error codes.
30     /// </summary>
31     public enum LocationError
32     {
33         None = ErrorCode.None,/**< Successful */
34         OutOfMemory = ErrorCode.OutOfMemory,/**< Out of memory error */
35         InvalidParameter = ErrorCode.InvalidParameter,/**< Invalid parameter */
36         AcessibilityNotallowed = ErrorCode.PermissionDenied,/**< Permission denied */
37         NotSupported = ErrorCode.NotSupported,/**< Address family not supported */
38         IncorrectMethod = LocationManagerError.Base | 0x01,/**< Location manager contains incorrect method for a given call */
39         NetworkFailed = LocationManagerError.Base | 0x02,/**< Network unavailable */
40         ServiceNotAvailable = LocationManagerError.Base | 0x03,/**< Location service is not available */
41         SettingOff = LocationManagerError.Base | 0x04,/**< GPS/WPS, or MOCK setting is not enabled */
42         SecuirtyRestricted = LocationManagerError.Base | 0x05,/**< Restricted by security system policy */
43     }
44
45     /// <summary>
46     /// Location Boundary error codes.
47     /// </summary>
48     public enum LocationBoundError
49     {
50         None = ErrorCode.None,/**< Successful */
51         OutOfMemory = ErrorCode.OutOfMemory,/**< Out of memory error */
52         InvalidParameter = ErrorCode.InvalidParameter,/**< Invalid parameter */
53         NotSupported = ErrorCode.NotSupported,/**< Not supported */
54         IncorrectType = LocationManagerError.BoundsBase | 0x01,/**< Incorrect bounds type for a given call */
55         IsAdded = LocationManagerError.BoundsBase | 0x02/**< Cannot remove bounds handle from location manager   */
56     }
57
58     internal static class LocationErrorFactory
59     {
60         internal static Exception ThrowLocationException(int errCode)
61         {
62             Log.Error(Globals.LogTag, "Throw Location Exception : " + errCode);
63             LocationError error = (LocationError)errCode;
64             switch (error)
65             {
66                 case LocationError.OutOfMemory:
67                     return new InvalidOperationException("Out of memory");
68                 case LocationError.InvalidParameter:
69                     return new ArgumentException("Invalid Parameter passed");
70                 case LocationError.AcessibilityNotallowed:
71                     return new UnauthorizedAccessException("Accesibility not allowed");
72                 case LocationError.NotSupported:
73                     return new NotSupportedException("Not supported");
74                 case LocationError.IncorrectMethod:
75                     return new InvalidOperationException("Incorrect method used");
76                 case LocationError.NetworkFailed:
77                     return new InvalidOperationException("Network failed");
78                 case LocationError.ServiceNotAvailable:
79                     return new InvalidOperationException("Service not available");
80                 case LocationError.SettingOff:
81                     return new InvalidOperationException("Current locationtype setting is off");
82                 case LocationError.SecuirtyRestricted:
83                     return new InvalidOperationException("Security Restricted");
84                 default:
85                     return new InvalidOperationException("Unknown Error");
86             }
87         }
88
89         internal static Exception ThrowLocationBoundaryException(int errCode)
90         {
91             LocationBoundError error = (LocationBoundError)errCode;
92             switch (error)
93             {
94                 case LocationBoundError.OutOfMemory:
95                     return new InvalidOperationException("Out of memory exception");
96                 case LocationBoundError.InvalidParameter:
97                     return new ArgumentException("Invalid parameter passed");
98                 case LocationBoundError.NotSupported:
99                     return new NotSupportedException("Not supported");
100                 case LocationBoundError.IncorrectType:
101                     return new InvalidOperationException("Incorrect type passed");
102                 case LocationBoundError.IsAdded:
103                     return new InvalidOperationException("Boundary is not addded");
104                 default:
105                     return new InvalidOperationException("Unknown Error");
106             }
107         }
108     }
109 }