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