diff options
author | Praveen Gattu <gattu.p@samsung.com> | 2016-09-19 10:54:01 +0530 |
---|---|---|
committer | Praveen Gattu <gattu.p@samsung.com> | 2016-10-04 12:35:38 +0530 |
commit | c11ea22ad1e7fd0858c1cc3d7f756ed68a506b2b (patch) | |
tree | 2ca76ad981b7fc65a60ecebcb8d7630d6054006d | |
parent | d590939b4d4c9f75a4d5b3334531a577ddbb4108 (diff) | |
download | application-c11ea22ad1e7fd0858c1cc3d7f756ed68a506b2b.tar.gz application-c11ea22ad1e7fd0858c1cc3d7f756ed68a506b2b.tar.bz2 application-c11ea22ad1e7fd0858c1cc3d7f756ed68a506b2b.zip |
Alarm module implementation.Updated project files.Updated doxygen with previleges and exception.
Change-Id: I9bc7747cbf268c076d16dc1c9e89a3bf4177565f
Signed-off-by: Praveen Gattu <gattu.p@samsung.com>
-rw-r--r-- | Tizen.Applications/Interop/Interop.Alarm.cs | 79 | ||||
-rwxr-xr-x | Tizen.Applications/Interop/Interop.Libraries.cs | 1 | ||||
-rw-r--r-- | Tizen.Applications/Tizen.Applications.Net45.csproj | 6 | ||||
-rw-r--r-- | Tizen.Applications/Tizen.Applications.csproj | 6 | ||||
-rw-r--r-- | Tizen.Applications/Tizen.Applications/Alarm.cs | 174 | ||||
-rw-r--r-- | Tizen.Applications/Tizen.Applications/AlarmErrorFactory.cs | 50 | ||||
-rw-r--r-- | Tizen.Applications/Tizen.Applications/AlarmManager.cs | 284 |
7 files changed, 598 insertions, 2 deletions
diff --git a/Tizen.Applications/Interop/Interop.Alarm.cs b/Tizen.Applications/Interop/Interop.Alarm.cs new file mode 100644 index 0000000..2279028 --- /dev/null +++ b/Tizen.Applications/Interop/Interop.Alarm.cs @@ -0,0 +1,79 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; +using System.Runtime.InteropServices; + +using Tizen.Internals.Errors; +using Tizen.Applications; + +internal static partial class Interop +{ + internal static partial class Alarm + { + [StructLayout(LayoutKind.Sequential)] + internal struct DateTime + { + internal int sec; + internal int min; + internal int hour; + internal int mday; /* day of the month, range 1 to 31*/ + internal int mon; + internal int year; + internal int wday; /* day of the week, range 0 to 6*/ + internal int yday; /* day in the year, range 0 to 365*/ + internal int isdst; /* daylight saving time*/ + }; + + [DllImport(Libraries.Alarm, EntryPoint = "alarm_schedule_after_delay")] + internal static extern int CreateAlarmAfterDelay(SafeAppControlHandle appControl, int delay, int period, out int alarmId); + + [DllImport(Libraries.Alarm, EntryPoint = "alarm_schedule_once_after_delay")] + internal static extern int CreateAlarmOnceAfterDelay(SafeAppControlHandle appControl, int delay, out int alarmId); + + [DllImport(Libraries.Alarm, EntryPoint = "alarm_schedule_once_at_date")] + internal static extern int CreateAlarmOnceAtDate(SafeAppControlHandle appControl, DateTime date, out int alarmId); + + [DllImport(Libraries.Alarm, EntryPoint = "alarm_schedule_with_recurrence_week_flag")] + internal static extern int CreateAlarmRecurWeek(SafeAppControlHandle appControl, DateTime date, int week, out int alarmId); + + [DllImport(Libraries.Alarm, EntryPoint = "alarm_get_scheduled_recurrence_week_flag")] + internal static extern int GetAlarmWeekFlag(int alarmId, out int weekFlag); + + [DllImport(Libraries.Alarm, EntryPoint = "alarm_cancel")] + internal static extern int CancelAlarm(int alarmId); + + [DllImport(Libraries.Alarm, EntryPoint = "alarm_cancel_all")] + internal static extern int CancelAllAlarms(); + + [DllImport(Libraries.Alarm, EntryPoint = "alarm_get_scheduled_date")] + internal static extern int GetAlarmScheduledDate(int alarmId, out DateTime date); + + [DllImport(Libraries.Alarm, EntryPoint = "alarm_get_current_time")] + internal static extern int GetCurrentTime(out DateTime date); + + [DllImport(Libraries.Alarm, EntryPoint = "alarm_get_app_control")] + internal static extern int GetAlarmAppControl(int alarmId, out SafeAppControlHandle control); + + [DllImport(Libraries.Alarm, EntryPoint = "alarm_get_scheduled_period")] + internal static extern int GetAlarmScheduledPeriod(int alarmId, out int period); + + [DllImport(Libraries.Alarm, EntryPoint = "alarm_set_global")] + internal static extern int SetAlarmGlobalFlag(int alarmId, bool global); + + [DllImport(Libraries.Alarm, EntryPoint = "alarm_get_global")] + internal static extern int GetAlarmGlobalFlag(int alarmId, out bool global); + + [DllImport(Libraries.Alarm, EntryPoint = "alarm_foreach_registered_alarm")] + internal static extern int GetAllRegisteredAlarms(RegisteredAlarmCallback callback, IntPtr userData); + + //callback + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool RegisteredAlarmCallback(int alarmId, IntPtr userData); + } +} diff --git a/Tizen.Applications/Interop/Interop.Libraries.cs b/Tizen.Applications/Interop/Interop.Libraries.cs index c0c9ad9..a306507 100755 --- a/Tizen.Applications/Interop/Interop.Libraries.cs +++ b/Tizen.Applications/Interop/Interop.Libraries.cs @@ -22,5 +22,6 @@ internal static partial class Interop public const string Glib = "libglib-2.0.so.0"; public const string Libc = "libc.so.6"; public const string Notification = "libnotification.so.0"; + public const string Alarm = "libcapi-appfw-alarm.so.0"; } } diff --git a/Tizen.Applications/Tizen.Applications.Net45.csproj b/Tizen.Applications/Tizen.Applications.Net45.csproj index 28b8e30..e07e77d 100644 --- a/Tizen.Applications/Tizen.Applications.Net45.csproj +++ b/Tizen.Applications/Tizen.Applications.Net45.csproj @@ -61,6 +61,7 @@ <Compile Include="Interop\Interop.Package.cs" /> <Compile Include="Interop\Interop.PackageManager.cs" /> <Compile Include="Interop\Interop.Service.cs" /> + <Compile Include="Interop\Interop.Alarm.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Tizen.Applications.CoreBackend\EventType.cs" /> <Compile Include="Tizen.Applications.CoreBackend\DefaultCoreBackend.cs" /> @@ -117,6 +118,9 @@ <Compile Include="Tizen.Applications\NotificationManager.cs" /> <Compile Include="Tizen.Applications\ProgressNotification.cs" /> <Compile Include="Tizen.Applications\TizenSynchronizationContext.cs" /> + <Compile Include="Tizen.Applications\Alarm.cs" /> + <Compile Include="Tizen.Applications\AlarmErrorFactory.cs" /> + <Compile Include="Tizen.Applications\AlarmManager.cs" /> </ItemGroup> <ItemGroup> <None Include="Tizen.Applications.Net45.project.json" /> @@ -131,4 +135,4 @@ <Target Name="AfterBuild"> </Target> --> -</Project>
\ No newline at end of file +</Project> diff --git a/Tizen.Applications/Tizen.Applications.csproj b/Tizen.Applications/Tizen.Applications.csproj index da97323..c8f4ad2 100644 --- a/Tizen.Applications/Tizen.Applications.csproj +++ b/Tizen.Applications/Tizen.Applications.csproj @@ -58,6 +58,7 @@ <Compile Include="Interop\Interop.Package.cs" /> <Compile Include="Interop\Interop.PackageManager.cs" /> <Compile Include="Interop\Interop.Service.cs" /> + <Compile Include="Interop\Interop.Alarm.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Tizen.Applications.CoreBackend\EventType.cs" /> <Compile Include="Tizen.Applications.CoreBackend\DefaultCoreBackend.cs" /> @@ -114,6 +115,9 @@ <Compile Include="Tizen.Applications\NotificationManager.cs" /> <Compile Include="Tizen.Applications\ProgressNotification.cs" /> <Compile Include="Tizen.Applications\TizenSynchronizationContext.cs" /> + <Compile Include="Tizen.Applications\Alarm.cs" /> + <Compile Include="Tizen.Applications\AlarmErrorFactory.cs" /> + <Compile Include="Tizen.Applications\AlarmManager.cs" /> </ItemGroup> <ItemGroup> <None Include="Tizen.Applications.project.json" /> @@ -140,4 +144,4 @@ <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths> <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences> </PropertyGroup> -</Project>
\ No newline at end of file +</Project> diff --git a/Tizen.Applications/Tizen.Applications/Alarm.cs b/Tizen.Applications/Tizen.Applications/Alarm.cs new file mode 100644 index 0000000..c73ca42 --- /dev/null +++ b/Tizen.Applications/Tizen.Applications/Alarm.cs @@ -0,0 +1,174 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.Applications +{ + /// <summary> + /// The Alarm API allows setting an "alarm clock" for the delivery of a notification at some point in the future. + /// </summary> + /// <example> + /// <code> + /// public class AlarmExample + /// { + /// /// ... + /// IEnumerable < Alarm > alarms = AlarmManager.GetAllSceduledAlarms(); + /// alarms[0].Cancel(); + /// } + /// </code> + /// </example> + public class Alarm + { + private const string _logTag = "Tizen.Applications.Alarm"; + + /// <summary> + /// Constructor created with new AlarmId. + /// </summary> + /// <param name="id"></param> + internal Alarm(int id) + { + AlarmId = id; + } + + /// <summary> + /// The alarm ID uniquely identifies an alarm. + /// </summary> + internal int AlarmId + { + get; + set; + } + + /// <summary> + /// Gets the recurrence days of the week. + /// </summary> + /// <privilege>http://tizen.org/privilege/alarm.get</privilege> + /// <remarks> + /// week_flag may be a combination of days, like Tuesday | Friday + /// </remarks> + public AlarmWeekFlag WeekFlag + { + get + { + int week; + AlarmError ret = (AlarmError)Interop.Alarm.GetAlarmWeekFlag(AlarmId, out week); + if (ret != AlarmError.None) + { + Log.Error(_logTag, "Failed to get WeekFlag"); + } + + return (AlarmWeekFlag)week; + } + } + + /// <summary> + /// Gets the scheduled time. + /// </summary> + /// <privilege>http://tizen.org/privilege/alarm.get</privilege> + public DateTime ScheduledDate + { + get + { + Interop.Alarm.DateTime value; + AlarmError ret = (AlarmError)Interop.Alarm.GetAlarmScheduledDate(AlarmId, out value); + if (ret != AlarmError.None) + { + Log.Error(_logTag, "Failed to get WeekFlag"); + } + + DateTime time = AlarmManager.ConvertIntPtrToDateTime(value); + return time; + } + } + + /// <summary> + /// Gets the period of time between the recurrent alarms. + /// </summary> + /// <privilege>http://tizen.org/privilege/alarm.get</privilege> + public int Period + { + get + { + int period; + AlarmError ret = (AlarmError)Interop.Alarm.GetAlarmScheduledPeriod(AlarmId, out period); + if (ret != AlarmError.None) + { + Log.Error(_logTag, "Failed to get WeekFlag"); + } + + return period; + } + } + + /// <summary> + /// Gets the AppControl to be invoked when the the alarm is triggered. + /// </summary> + /// <privilege>http://tizen.org/privilege/alarm.get</privilege> + public AppControl AlarmAppControl + { + get + { + SafeAppControlHandle handle; + AlarmError ret = (AlarmError)Interop.Alarm.GetAlarmAppControl(AlarmId, out handle); + + if (ret != AlarmError.None) + { + Log.Error(_logTag, "Failed to get WeekFlag"); + } + + return new AppControl(handle); + } + } + + /// <summary> + /// Gets whether the alarm will launch global application or not. + /// </summary> + /// <privilege>http://tizen.org/privilege/alarm.set</privilege> + /// <privilege>http://tizen.org/privilege/alarm.get</privilege> + public bool Global + { + get + { + bool global; + AlarmError ret = (AlarmError)Interop.Alarm.GetAlarmGlobalFlag(AlarmId, out global); + if (ret != AlarmError.None) + { + Log.Error(_logTag, "Failed to get WeekFlag"); + } + + return global; + } + + set + { + AlarmError ret = (AlarmError)Interop.Alarm.SetAlarmGlobalFlag(AlarmId, value); + if (ret != AlarmError.None) + { + Log.Error(_logTag, "Failed to get WeekFlag"); + } + } + } + + /// <summary> + /// Cancels the the specific alarm. + /// </summary> + /// <exception cref="ArgumentException">Thrown in case of Invalid parmaeter.</exception> + /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied due to insufficient previlleges.</exception> + /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> + /// <privilege>http://tizen.org/privilege/alarm.set</privilege> + public void Cancel() + { + AlarmError ret = (AlarmError)Interop.Alarm.CancelAlarm(AlarmId); + if (ret != AlarmError.None) + { + throw AlarmErrorFactory.GetException(ret, "Failed to Cancel alarm"); + } + } + } +} diff --git a/Tizen.Applications/Tizen.Applications/AlarmErrorFactory.cs b/Tizen.Applications/Tizen.Applications/AlarmErrorFactory.cs new file mode 100644 index 0000000..32e6331 --- /dev/null +++ b/Tizen.Applications/Tizen.Applications/AlarmErrorFactory.cs @@ -0,0 +1,50 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.Applications +{ + internal enum AlarmError + { + None = Tizen.Internals.Errors.ErrorCode.None, + InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter, + InvalidTime = -0x01100000 | 0x05, + InvalidDate = -0x01100000 | 0x06, + ConnectionFail = -0x01100000 | 0x07, + NotPermittedApp = -0x01100000 | 0x08, + OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory, + PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied + } + internal static class AlarmErrorFactory + { + private const string _logTag = "Tizen.Applications.Alarm"; + + internal static Exception GetException(AlarmError ret, string msg) + { + switch (ret) + { + case AlarmError.InvalidParameter: + //fall through + case AlarmError.InvalidTime: + //fall through + case AlarmError.InvalidDate: + Log.Error(_logTag, msg); + return new ArgumentException(ret + " error occurred."); + case AlarmError.NotPermittedApp: + //fall through + case AlarmError.PermissionDenied: + Log.Error(_logTag, msg); + return new UnauthorizedAccessException(ret + "error occured."); + default: + Log.Error(_logTag, msg); + return new InvalidOperationException(ret + " error occurred."); + } + } + } +} diff --git a/Tizen.Applications/Tizen.Applications/AlarmManager.cs b/Tizen.Applications/Tizen.Applications/AlarmManager.cs new file mode 100644 index 0000000..5e99356 --- /dev/null +++ b/Tizen.Applications/Tizen.Applications/AlarmManager.cs @@ -0,0 +1,284 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; + +namespace Tizen.Applications +{ + /// <summary> + /// Enumeration for Alarm Week Flag, the days of the week. + /// </summary> + [Flags] + public enum AlarmWeekFlag + { + /// <summary> + /// Identifier for Sunday. + /// </summary> + Sunday = 0x01, + + /// <summary> + /// Identifier for Monday. + /// </summary> + Monday = 0x02, + + /// <summary> + /// Identifier for Tuesday. + /// </summary> + Tuesday = 0x04, + + /// <summary> + /// Identifier for Wednesday. + /// </summary> + Wednesday = 0x08, + + /// <summary> + /// Identifier for Thursday. + /// </summary> + Thursday = 0x10, + + /// <summary> + /// Identifier for Friday. + /// </summary> + Friday = 0x20, + + /// <summary> + /// Identifier for Saturday. + /// </summary> + Saturday = 0x40, + + /// <summary> + /// All Days of the Week. + /// </summary> + AllDays = Sunday |Monday|Tuesday|Wednesday|Thursday|Friday|Saturday, + + /// <summary> + /// Only Weekdays + /// </summary> + WeekDays = Monday | Tuesday | Wednesday | Thursday | Friday + } + + /// <summary> + /// Mobile devices typically give constant access to information from various sources.Some of this information is best delivered through alarms - + /// the most obvious case is a calendar scheduling application which lets you know when a meeting is about to start.Alarms are certainly better than actively waiting in a loop. + /// They are also better than putting an interface to sleep because they do not block your main UI thread. + /// Use of alarms helps build smooth user experiences and implements unattended data synchronization tasks. + /// If an application is installed after setting the alarm, your alarm is cancelled automatically. + /// </summary> + /// <example> + /// <code> + /// public class AlarmManagerExample + /// { + /// /// ... + /// Alarm alarm = AlarmManager.CreateAlarm(24000,1000,null); + /// AlarmManager.CancelAll(); + /// } + /// </code> + /// </example> + + public static class AlarmManager + { + private const string LogTag = "Tizen.Applications.Alarm"; + + private static Interop.Alarm.DateTime ConvertDateTimeToStruct(DateTime value) + { + Interop.Alarm.DateTime time = new Interop.Alarm.DateTime(); + time.sec = value.Second; + time.min = value.Minute; + time.hour = value.Hour; + time.mday = value.Day; + time.mon = value.Month - 1; + time.year = value.Year - 1900; + time.wday = (int)value.DayOfWeek; + time.yday = value.DayOfYear; + time.isdst = 0; + return time; + } + + internal static DateTime ConvertIntPtrToDateTime(Interop.Alarm.DateTime time) + { + DateTime value = new DateTime(1900 + time.year, 1 + time.mon, time.mday, time.hour, time.min, time.sec, DateTimeKind.Utc); + return value; + } + + /// <summary> + /// Sets an alarm to be triggered after a specific time. + /// The alarm will first go off delay seconds later and then will go off every certain amount of time defined using period seconds. + /// </summary> + /// <param name="delay">The amount of time before the first execution (in seconds).</param> + /// <param name="period"> The amount of time between subsequent alarms (in seconds). This value does not guarantee the accuracy. + /// The actual interval is calculated by the OS. The minimum value is 600sec</param> + /// <param name="appControl"> The destination AppControl to perform a specific task when the alarm is triggered </param> + /// <returns>Alarm Instance created with the set param values.</returns> + /// <exception cref="ArgumentException">Thrown in case of Invalid parmaeter.</exception> + /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception> + /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> + /// <privilege>http://tizen.org/privilege/alarm.set</privilege> + public static Alarm CreateAlarm(int delay, int period, AppControl appControl) + { + Alarm alarm = null; + int alarmId; + SafeAppControlHandle handle = (appControl == null) ? null : appControl.SafeAppControlHandle; + AlarmError ret = (AlarmError)Interop.Alarm.CreateAlarmAfterDelay(handle, delay, period, out alarmId); + alarm = new Alarm(alarmId); + if (ret != AlarmError.None) + { + throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm"); + } + + return alarm; + } + + /// <summary> + /// Sets an alarm to be triggered after a specific time. + /// The alarm will go off delay seconds later. + /// </summary> + /// <param name="delay"> The amount of time before the execution (in seconds) </param> + /// <param name="appControl"> The destination AppControl to perform a specific task when the alarm is triggered </param> + /// <returns> Alarm Instance created with the set param values.</returns> + /// <exception cref="ArgumentException">Thrown in case of Invalid parmaeter.</exception> + /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception> + /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> + /// <privilege>http://tizen.org/privilege/alarm.set</privilege> + public static Alarm CreateAlarm(int delay, AppControl appControl) + { + Alarm alarm = null; + int alarmId; + AlarmError ret = (AlarmError)Interop.Alarm.CreateAlarmOnceAfterDelay(appControl.SafeAppControlHandle, delay, out alarmId); + alarm = new Alarm(alarmId); + if (ret != AlarmError.None) + { + throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm"); + } + + return alarm; + } + + /// <summary> + /// Sets an alarm to be triggered at a specific time. + /// The date describes the time of the first occurrence. + /// </summary> + /// <param name="value"> The first active alarm time </param> + /// <param name="appControl"> The destination AppControl to perform specific work when the alarm is triggered </param> + /// <returns> Alarm Instance created with the set param values.</returns> + /// <remarks>This operation is permitted wit UI application appcontrol only.</remarks> + /// <exception cref="ArgumentException">Thrown in case of Invalid parmaeter.</exception> + /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception> + /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> + /// <privilege>http://tizen.org/privilege/alarm.set</privilege> + public static Alarm CreateAlarm(DateTime value, AppControl appControl) + { + Alarm alarm = null; + int alarmId; + Interop.Alarm.DateTime time = ConvertDateTimeToStruct(value); + AlarmError ret = (AlarmError)Interop.Alarm.CreateAlarmOnceAtDate(appControl.SafeAppControlHandle, time, out alarmId); + alarm = new Alarm(alarmId); + if (ret != AlarmError.None) + { + throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm"); + } + + return alarm; + } + + /// <summary> + /// Sets an alarm to be triggered periodically, starting at a specific time. + /// The date describes the time of the first occurrence. + /// weekFlag is the repeat value of the days of the week. + /// If weekFlag is AlarmWeekFlag.Tuesday, the alarm will repeat every Tuesday at a specific time. + /// </summary> + /// <remarks>This operation is permitted wit UI application appcontrol only.</remarks> + /// <param name="value"> The first active alarm time </param> + /// <param name="weekFlag"> The day of the week, AlarmWeekFlag may be a combination of days, like AlarmWeekFlag.Sunday | AlarmWeekFlag.Monday</param> + /// <param name="appControl"> The destination AppControl to perform specific work when the alarm is triggered </param> + /// <returns> Alarm Instance created with the set param values.</returns> + /// <exception cref="ArgumentException">Thrown in case of Invalid parmaeter.</exception> + /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception> + /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> + /// <privilege>http://tizen.org/privilege/alarm.set</privilege> + public static Alarm CreateAlarm(DateTime value, AlarmWeekFlag weekFlag, AppControl appControl) + { + Alarm alarm = null; + int alarmId; + Interop.Alarm.DateTime time = ConvertDateTimeToStruct(value); + AlarmError ret = (AlarmError)Interop.Alarm.CreateAlarmRecurWeek(appControl.SafeAppControlHandle, time, (int)weekFlag, out alarmId); + alarm = new Alarm(alarmId); + if (ret != AlarmError.None) + { + throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm"); + } + + return alarm; + } + + /// <summary> + /// Cancels all scheduled alarms that are registered by the application that calls this API. + /// </summary> + /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception> + /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> + /// <privilege>http://tizen.org/privilege/alarm.set</privilege> + public static void CancelAll() + { + AlarmError ret = (AlarmError)Interop.Alarm.CancelAllAlarms(); + if (ret != AlarmError.None) + { + throw AlarmErrorFactory.GetException(ret, "Failed to cancel Alarms"); + } + } + + /// <summary> + /// Retrieves all registered alarms. + /// </summary> + /// <returns>List of all Alarm instances.</returns> + /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception> + /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> + /// <privilege>http://tizen.org/privilege/alarm.get</privilege> + public static IEnumerable<Alarm> GetAllSceduledAlarms() + { + List<Alarm> alarms = new List<Alarm>(); + Interop.Alarm.RegisteredAlarmCallback callback = (int alarmId, IntPtr userData) => + { + alarms.Add(new Alarm(alarmId)); + return true; + }; + + AlarmError ret = (AlarmError)Interop.Alarm.GetAllRegisteredAlarms(callback, IntPtr.Zero); + if (ret != AlarmError.None) + { + throw AlarmErrorFactory.GetException(ret, "Failed to get Alarms"); + } + + return alarms; + } + + /// <summary> + /// Gets the current system time. + /// </summary> + /// <returns>The current system time</returns> + /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception> + public static DateTime GetCurrentTime() + { + DateTime time; + Interop.Alarm.DateTime value; + AlarmError ret = (AlarmError)Interop.Alarm.GetCurrentTime(out value); + if (ret != AlarmError.None) + { + throw AlarmErrorFactory.GetException(ret, "Failed to get Currenttime"); + } + else + { + + time = ConvertIntPtrToDateTime(value); + } + + return time; + } + + } +} |