Fix xml documentation issues (#105)
[platform/core/csapi/tizenfx.git] / src / Tizen.Location.Geofence / Tizen.Location.Geofence / FenceStatus.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
19 namespace Tizen.Location.Geofence
20 {
21     /// <summary>
22     /// The geofence status describes the current state and duration of a geofence.
23     /// <list type="bullet">
24     /// <item><description>State: The state is specified by the current state of the fence.</description></item>
25     /// <item><description>Duration: Geofence is specified by the duration of the current state.</description></item>
26     /// </list>
27     /// </summary>
28     /// <since_tizen> 3 </since_tizen>
29     public class FenceStatus : IDisposable
30     {
31         private bool _disposed = false;
32
33         internal IntPtr Handle
34         {
35             get;
36             set;
37         }
38
39         /// <summary>
40         /// Creates a new geofence status.
41         /// </summary>
42         /// <since_tizen> 3 </since_tizen>
43         /// <param name="fenceId">The geofence ID.</param>
44         /// <exception cref="ArgumentException">In case of an invalid parameter.</exception>
45         /// <exception cref="NotSupportedException">In case of geofence is not supported.</exception>
46         public FenceStatus(int fenceId)
47         {
48             IntPtr handle;
49             GeofenceError ret = (GeofenceError)Interop.GeofenceStatus.Create(fenceId, out handle);
50             if (ret != GeofenceError.None)
51             {
52                 throw GeofenceErrorFactory.CreateException(ret, "Failed to create Geofence Status instance");
53             }
54
55             Handle = handle;
56         }
57
58         /// <summary>
59         /// The destructor of the FenceStatus class.
60         /// </summary>
61         /// <since_tizen> 3 </since_tizen>
62         ~FenceStatus()
63         {
64             Dispose(false);
65         }
66
67         /// <summary>
68         /// Gets the state of geofence.
69         /// </summary>
70         /// <since_tizen> 3 </since_tizen>
71         /// <exception cref="NotSupportedException">In case the geofence is not supported.</exception>
72         public GeofenceState State
73         {
74             get
75             {
76                 GeofenceState state;
77                 GeofenceError ret = (GeofenceError)Interop.GeofenceStatus.State(Handle, out state);
78                 if (ret != GeofenceError.None)
79                 {
80                     Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get FenceState");
81                 }
82
83                 return state;
84             }
85         }
86
87         /// <summary>
88         /// Gets the amount of seconds, the geofence is in the current state.
89         /// </summary>
90         /// <since_tizen> 3 </since_tizen>
91         /// <exception cref="NotSupportedException">In case the geofence is not supported.</exception>
92         public int Duration
93         {
94             get
95             {
96                 int result = -1;
97                 GeofenceError ret = (GeofenceError)Interop.GeofenceStatus.Duration(Handle, out result);
98                 if (ret != GeofenceError.None)
99                 {
100                     Tizen.Log.Error(GeofenceErrorFactory.LogTag, "Failed to get FenceDuration");
101                 }
102
103                 return result;
104             }
105         }
106
107         /// <summary>
108         /// The overloaded Dispose API for destroying the fence handle.
109         /// </summary>
110         /// <since_tizen> 3 </since_tizen>
111         public void Dispose()
112         {
113             Dispose(true);
114             GC.SuppressFinalize(this);
115         }
116
117         /// <summary>
118         /// Dispose.
119         /// </summary>
120         /// <since_tizen> 3 </since_tizen>
121         protected virtual void Dispose(bool disposing)
122         {
123             if (_disposed)
124                 return;
125
126             if (Handle != IntPtr.Zero)
127             {
128                 Interop.GeofenceStatus.Destroy(Handle);
129                 Handle = IntPtr.Zero;
130             }
131
132             _disposed = true;
133         }
134     }
135 }