Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Location.Geofence / Tizen.Location.Geofence / GeofenceErrorFactory.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;
19
20
21 namespace Tizen.Location.Geofence
22 {
23     /// <summary>
24     /// Enum to give the type of error occured, if any.
25     /// </summary>
26     /// <since_tizen>3</since_tizen>
27     public enum GeofenceError
28     {
29         /// <summary>
30         /// Successful.
31         /// </summary>
32         /// <since_tizen>3</since_tizen>
33         None = Tizen.Internals.Errors.ErrorCode.None,
34
35         /// <summary>
36         /// Out of memory.
37         /// </summary>
38         /// <since_tizen>3</since_tizen>
39         OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
40
41         /// <summary>
42         /// Invalid parameter.
43         /// </summary>
44         /// <since_tizen>3</since_tizen>
45         InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
46
47         /// <summary>
48         /// Permission denied.
49         /// </summary>
50         /// <since_tizen>3</since_tizen>
51         PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
52
53         /// <summary>
54         /// Not Supported.
55         /// </summary>
56         /// <since_tizen>3</since_tizen>
57         NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported,
58
59         /// <summary>
60         /// Geofence Manager is not initialized.
61         /// </summary>
62         /// <since_tizen>3</since_tizen>
63         NotInitialized = -0x02C00000 | 0x100 | 0x01,
64
65         /// <summary>
66         /// Invalid geofence ID.
67         /// </summary>
68         /// <since_tizen>3</since_tizen>
69         InvalidID = -0x02C00000 | 0x100 | 0x02,
70
71         /// <summary>
72         /// Exception occurs.
73         /// </summary>
74         /// <since_tizen>3</since_tizen>
75         Exception = -0x02C00000 | 0x100 | 0x03,
76
77         /// <summary>
78         /// Geofencing is already started.
79         /// </summary>
80         /// <since_tizen>3</since_tizen>
81         AlreadyStarted = -0x02C00000 | 0x100 | 0x04,
82
83         /// <summary>
84         /// Too many geofence.
85         /// </summary>
86         /// <since_tizen>3</since_tizen>
87         TooManyGeofence = -0x02C00000 | 0x100 | 0x05,
88
89         /// <summary>
90         /// Error in GPS, Wi-Fi, or BT.
91         /// </summary>
92         /// <since_tizen>3</since_tizen>
93         IPC = -0x02C00000 | 0x100 | 0x06,
94
95         /// <summary>
96         /// DB error in the server side.
97         /// </summary>
98         /// <since_tizen>3</since_tizen>
99         DBFailed = -0x02C00000 | 0x100 | 0x07,
100
101         /// <summary>
102         /// Access to specified place is denied.
103         /// </summary>
104         /// <since_tizen>3</since_tizen>
105         PlaceAccessDenied = -0x02C00000 | 0x100 | 0x08,
106
107         /// <summary>
108         /// Access to specified geofence is denied.
109         /// </summary>
110         /// <since_tizen>3</since_tizen>
111         GeofenceAccessDenied = -0x02C00000 | 0x100 | 0x09
112     };
113
114     internal class GeofenceErrorFactory
115     {
116         internal const string LogTag = "Tizen.Location.Geofence";
117
118         internal static Exception CreateException(GeofenceError err, string msg)
119         {
120             Log.Info(LogTag, "Got Error " + err + " throwing Exception with msg " + msg);
121             Exception exp;
122             switch (err)
123             {
124                 case GeofenceError.InvalidParameter:
125                     {
126                         exp = new ArgumentException(msg + " Invalid Parameters Provided");
127                         break;
128                     }
129
130                 case GeofenceError.OutOfMemory:
131                     {
132                         exp = new OutOfMemoryException(msg + " Out Of Memory");
133                         break;
134                     }
135
136                 case GeofenceError.NotInitialized:
137                     {
138                         exp = new InvalidOperationException(msg + " Not initializded");
139                         break;
140                     }
141
142                 case GeofenceError.NotSupported:
143                     {
144                         exp = new NotSupportedException(msg + " Not supported");
145                         break;
146                     }
147
148                 case GeofenceError.PermissionDenied:
149                 // fall through
150                 case GeofenceError.GeofenceAccessDenied:
151                 //fall through
152                 case GeofenceError.PlaceAccessDenied:
153                     {
154                         exp = new UnauthorizedAccessException(msg + " Permission Denied");
155                         break;
156                     }
157
158                 case GeofenceError.DBFailed:
159                     {
160                         exp = new InvalidOperationException(msg + " DataBase Failed");
161                         break;
162                     }
163
164                 default:
165                     {
166                         exp = new InvalidOperationException(msg);
167                         break;
168                     }
169             }
170
171             return exp;
172         }
173     }
174 }