6ae6c72aedc9dfdb930fe032e7ee4337ea45b17c
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / WatchTime.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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  
18 namespace Tizen.NUI
19 {
20     /// <summary>
21     /// The WatchTime class is used to get time for the WatchApplication.<br/>
22     /// A WatchTime has a time handle from watch application framework.<br/>
23     /// You can get time(hour, minute, second, millisecond) and date(year, month, day)<br/>
24     /// on receiving timeTick signal.
25     /// </summary>
26     /// <since_tizen> 4 </since_tizen>
27     public class WatchTime : global::System.IDisposable
28     {
29         /// <summary>
30         /// swigCMemOwn.
31         /// </summary>
32         /// <since_tizen> 4 </since_tizen>
33         protected bool swigCMemOwn;
34
35         /// <summary>
36         /// A Flat to check if it is already disposed.
37         /// </summary>
38         /// <since_tizen> 4 </since_tizen>
39         protected bool disposed = false;
40
41         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
42         //A Flag to check who called Dispose(). (By User or DisposeQueue)
43         private bool isDisposeQueued = false;
44
45         /// <summary>
46         /// Constructor.
47         /// </summary>
48         /// <since_tizen> 4 </since_tizen>
49         public WatchTime() : this(Interop.Watch.new_WatchTime(), true)
50         {
51             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
52         }
53
54         internal WatchTime(global::System.IntPtr cPtr, bool cMemoryOwn)
55         {
56             swigCMemOwn = cMemoryOwn;
57             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
58         }
59
60         /// <summary>
61         /// Distructor.
62         /// </summary>
63         ~WatchTime()
64         {
65             if (!isDisposeQueued)
66             {
67                 isDisposeQueued = true;
68                 DisposeQueue.Instance.Add(this);
69             }
70         }
71
72         /// <summary>
73         /// Get the current hour.
74         /// </summary>
75         /// <remarks>The return value is always positive.The WatchTime needs to be initialized.</remarks>
76         /// <since_tizen> 4 </since_tizen>
77         public int Hour
78         {
79             get
80             {
81                 return GetHour();
82             }
83         }
84
85         /// <summary>
86         /// Get the current hour24.
87         /// </summary>
88         /// <remarks>The return value is always positive.The WatchTime needs to be initialized.</remarks>
89         /// <since_tizen> 4 </since_tizen>
90         public int Hour24
91         {
92             get
93             {
94                 return GetHour24();
95             }
96         }
97
98         /// <summary>
99         /// Get the current minute.
100         /// </summary>
101         /// <remarks>The return value is always positive.The WatchTime needs to be initialized.</remarks>
102         /// <since_tizen> 4 </since_tizen>
103         public int Minute
104         {
105             get
106             {
107                 return GetMinute();
108             }
109         }
110
111         /// <summary>
112         /// Get the current second.
113         /// </summary>
114         /// <remarks>The return value is always positive.The WatchTime needs to be initialized.</remarks>
115         /// <since_tizen> 4 </since_tizen>
116         public int Second
117         {
118             get
119             {
120                 return GetSecond();
121             }
122         }
123
124         /// <summary>
125         /// Get the current millisecond.
126         /// </summary>
127         /// <remarks>The return value is always positive.The WatchTime needs to be initialized.</remarks>
128         /// <since_tizen> 4 </since_tizen>
129         public int Millisecond
130         {
131             get
132             {
133                 return GetMillisecond();
134             }
135         }
136
137         /// <summary>
138         /// Get the current year.
139         /// </summary>
140         /// <remarks>The return value is always positive.The WatchTime needs to be initialized.</remarks>
141         /// <since_tizen> 4 </since_tizen>
142         public int Year
143         {
144             get
145             {
146                 return GetYear();
147             }
148         }
149
150         /// <summary>
151         /// Get the current month.
152         /// </summary>
153         /// <remarks>The return value is always positive.The WatchTime needs to be initialized.</remarks>
154         /// <since_tizen> 4 </since_tizen>
155         public int Month
156         {
157             get
158             {
159                 return GetMonth();
160             }
161         }
162
163         /// <summary>
164         /// Get the current day.
165         /// </summary>
166         /// <remarks>The return value is always positive.The WatchTime needs to be initialized.</remarks>
167         /// <since_tizen> 4 </since_tizen>
168         public int Day
169         {
170             get
171             {
172                 return GetDay();
173             }
174         }
175
176         /// <summary>
177         /// Get the current week.
178         /// </summary>
179         /// <remarks>The return value is always positive.The WatchTime needs to be initialized.</remarks>
180         /// <since_tizen> 4 </since_tizen>
181         public int DayOfWeek
182         {
183             get
184             {
185                 return GetDayOfWeek();
186             }
187         }
188
189         /// <summary>
190         /// Get the ID of timezone.
191         /// </summary>
192         /// <remarks>
193         /// The WatchTime needs to be initialized.<br/>
194         /// The timezone ID, according to the IANA(Internet Assigned Numbers Authority)<br/>
195         /// If you want to see more information, please refer to the site :<br/>
196         /// https://en.wikipedia.org/wiki/List_of_tz_database_time_zones/
197         /// </remarks>
198         /// <since_tizen> 4 </since_tizen>
199         public string TimeZone
200         {
201             get
202             {
203                 return GetTimeZone();
204             }
205         }
206
207         /// <summary>
208         /// Get the daylight saving time status.
209         /// </summary>
210         /// <remarks>The WatchTime needs to be initialized.</remarks>
211         /// <since_tizen> 4 </since_tizen>
212         public bool DaylightSavingTimeStatus
213         {
214             get
215             {
216                 return GetDaylightSavingTimeStatus();
217             }
218         }
219
220         /// <summary>
221         /// To make watch time instance be disposed.
222         /// </summary>
223         /// <since_tizen> 4 </since_tizen>
224         public void Dispose()
225         {
226             //Throw excpetion if Dispose() is called in separate thread.
227             if (!Window.IsInstalled())
228             {
229                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
230             }
231
232             if (isDisposeQueued)
233             {
234                 Dispose(DisposeTypes.Implicit);
235             }
236             else
237             {
238                 Dispose(DisposeTypes.Explicit);
239                 System.GC.SuppressFinalize(this);
240             }
241         }
242
243         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WatchTime obj)
244         {
245             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
246         }
247
248         internal static WatchTime GetWatchTimeFromPtr(global::System.IntPtr cPtr)
249         {
250             WatchTime ret = new WatchTime(cPtr, false);
251             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252             return ret;
253         }
254
255         internal int GetDayOfWeek()
256         {
257             int ret = Interop.Watch.WatchTime_GetDayOfWeek(swigCPtr);
258             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259             return ret;
260         }
261
262         internal SWIGTYPE_p_tm GetUtcTime()
263         {
264             SWIGTYPE_p_tm ret = new SWIGTYPE_p_tm(Interop.Watch.WatchTime_GetUtcTime(swigCPtr), true);
265             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266             return ret;
267         }
268
269         internal SWIGTYPE_p_time_t GetUtcTimeStamp()
270         {
271             SWIGTYPE_p_time_t ret = new SWIGTYPE_p_time_t(Interop.Watch.WatchTime_GetUtcTimeStamp(swigCPtr), true);
272             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273             return ret;
274         }
275
276         internal string GetTimeZone()
277         {
278             string ret = Interop.Watch.WatchTime_GetTimeZone(swigCPtr);
279             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280             return ret;
281         }
282
283         internal bool GetDaylightSavingTimeStatus()
284         {
285             bool ret = Interop.Watch.WatchTime_GetDaylightSavingTimeStatus(swigCPtr);
286             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
287             return ret;
288         }
289
290         internal int GetHour()
291         {
292             int ret = Interop.Watch.WatchTime_GetHour(swigCPtr);
293             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294             return ret;
295         }
296
297         internal int GetHour24()
298         {
299             int ret = Interop.Watch.WatchTime_GetHour24(swigCPtr);
300             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301             return ret;
302         }
303
304         internal int GetMinute()
305         {
306             int ret = Interop.Watch.WatchTime_GetMinute(swigCPtr);
307             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308             return ret;
309         }
310
311         internal int GetSecond()
312         {
313             int ret = Interop.Watch.WatchTime_GetSecond(swigCPtr);
314             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315             return ret;
316         }
317
318         internal int GetMillisecond()
319         {
320             int ret = Interop.Watch.WatchTime_GetMillisecond(swigCPtr);
321             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322             return ret;
323         }
324
325         internal int GetYear()
326         {
327             int ret = Interop.Watch.WatchTime_GetYear(swigCPtr);
328             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329             return ret;
330         }
331
332         internal int GetMonth()
333         {
334             int ret = Interop.Watch.WatchTime_GetMonth(swigCPtr);
335             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
336             return ret;
337         }
338
339         internal int GetDay()
340         {
341             int ret = Interop.Watch.WatchTime_GetDay(swigCPtr);
342             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
343             return ret;
344         }
345
346         /// <summary>
347         /// you can override it to clean-up your own resources.
348         /// </summary>
349         /// <param name="type">DisposeTypes</param>
350         /// <since_tizen> 4 </since_tizen>
351         protected virtual void Dispose(DisposeTypes type)
352         {
353             if (disposed)
354             {
355                 return;
356             }
357
358             if (type == DisposeTypes.Explicit)
359             {
360                 //Called by User
361                 //Release your own managed resources here.
362                 //You should release all of your own disposable objects here.
363
364             }
365
366             //Release your own unmanaged resources here.
367             //You should not access any managed member here except static instance.
368             //because the execution order of Finalizes is non-deterministic.
369
370             if (swigCPtr.Handle != global::System.IntPtr.Zero)
371             {
372                 if (swigCMemOwn)
373                 {
374                     swigCMemOwn = false;
375                     Interop.Watch.delete_WatchTime(swigCPtr);
376                 }
377                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
378             }
379
380             disposed = true;
381         }
382
383     }
384
385 }