Add new apis for alarm notification
authorinkyun.kil <inkyun.kil@samsung.com>
Mon, 24 Apr 2017 10:23:24 +0000 (19:23 +0900)
committerJiwoong Im <jiwoong.im@samsung.com>
Fri, 28 Apr 2017 05:17:42 +0000 (05:17 +0000)
Signed-off-by: inkyun.kil <inkyun.kil@samsung.com>
Change-Id: I79a85c9d104fe5d445e04abe9ac5b38b6e94546a

src/Tizen.Applications.Alarm/Interop/Interop.Alarm.cs
src/Tizen.Applications.Alarm/Tizen.Applications.Alarm.csproj
src/Tizen.Applications.Alarm/Tizen.Applications/AlarmManager.cs

index f3e9ccd..bb4bbf9 100755 (executable)
@@ -19,6 +19,7 @@ using System.Runtime.InteropServices;
 
 using Tizen.Internals.Errors;
 using Tizen.Applications;
+using Tizen.Applications.Notifications;
 
 internal static partial class Interop
 {
@@ -82,6 +83,18 @@ internal static partial class Interop
         [DllImport(Libraries.Alarm, EntryPoint = "alarm_foreach_registered_alarm")]
         internal static extern int GetAllRegisteredAlarms(RegisteredAlarmCallback callback, IntPtr userData);
 
+        [DllImport(Libraries.Alarm, EntryPoint = "alarm_schedule_noti_once_at_date")]
+        internal static extern AlarmError CreateAlarmNotiOnceAtDate(NotificationSafeHandle noti, ref DateTime date, out int alarmId);
+
+        [DllImport(Libraries.Alarm, EntryPoint = "alarm_schedule_noti_after_delay")]
+        internal static extern AlarmError CreateAlarmNotiAfterDelay(NotificationSafeHandle noti, int delay, int period, out int alarmId);
+
+        [DllImport(Libraries.Alarm, EntryPoint = "alarm_schedule_noti_once_after_delay")]
+        internal static extern AlarmError CreateAlarmNotiOnceAfterDelay(NotificationSafeHandle noti, int delay, out int alarmId);
+
+        [DllImport(Libraries.Alarm, EntryPoint = "alarm_schedule_noti_with_recurrence_week_flag")]
+        internal static extern AlarmError CreateAlarmNotiRecurWeek(NotificationSafeHandle noti, ref DateTime date, int week, out int alarmId);
+
         //callback
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         internal delegate bool RegisteredAlarmCallback(int alarmId, IntPtr userData);
index 5bcb6f8..c2dc0fb 100755 (executable)
       <Project>{663c5a3d-e631-4987-aee7-f498c56a40fc}</Project>
       <Name>Tizen.Applications.Common</Name>
     </ProjectReference>
+    <ProjectReference Include="..\Tizen.Applications.Notification\Tizen.Applications.Notification.csproj">
+      <Project>{36C346B4-5ABC-45C7-808B-04178B76FA0D}</Project>
+      <Name>Tizen.Applications.Notification</Name>
+    </ProjectReference>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
index 01f5a8a..266052e 100755 (executable)
  * limitations under the License.
  */
 
-using System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-
 namespace Tizen.Applications
 {
+    using System;
+    using System.Collections.Generic;
+    using System.Runtime.InteropServices;
+    using Tizen.Applications.Notifications;
+
     /// <summary>
     /// Enumeration for Alarm Week Flag, the days of the week.
     /// </summary>
@@ -226,6 +227,123 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Sets an alarm to be triggered periodically, starting at a specific time.
+        /// The date describes the time of the first occurrence.
+        /// </summary>
+        /// <param name="dateTime"> The first active alarm time </param>
+        /// <param name="notification"> The notification to be posted 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>
+        /// <privilege>http://tizen.org/privilege/notification</privilege>
+        public static Alarm CreateAlarm(DateTime dateTime, Notification notification)
+        {
+            Alarm alarm = null;
+            int alarmId;
+            NotificationSafeHandle safeHandle = NotificationManager.MakeNotificationSafeHandle(notification);
+            Interop.Alarm.DateTime time = ConvertDateTimeToStruct(dateTime);
+            AlarmError ret = Interop.Alarm.CreateAlarmNotiOnceAtDate(safeHandle, ref time, out alarmId);
+            if (ret != AlarmError.None)
+            {
+                throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm");
+            }
+
+            alarm = new Alarm(alarmId);
+
+            return alarm;
+        }
+
+        /// <summary>
+        /// Sets an alarm to be triggered periodically, starting at a specific time.
+        /// The date describes the time of the first occurrence.
+        /// </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.
+        /// <param name="notification"> The notification to be posted 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>
+        /// <privilege>http://tizen.org/privilege/notification</privilege>
+        public static Alarm CreateAlarm(int delay, int period, Notification notification)
+        {
+            Alarm alarm = null;
+            int alarmId;
+            NotificationSafeHandle safeHandle = NotificationManager.MakeNotificationSafeHandle(notification);
+            AlarmError ret = Interop.Alarm.CreateAlarmNotiAfterDelay(safeHandle, delay, period, out alarmId);
+            if (ret != AlarmError.None)
+            {
+                throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm");
+            }
+
+            alarm = new Alarm(alarmId);
+
+            return alarm;
+        }
+
+        /// <summary>
+        /// Sets an alarm to be triggered periodically, starting at a specific time.
+        /// The date describes the time of the first occurrence.
+        /// </summary
+        /// <param name="dateTime"> 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="notification"> The notification to be posted 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>
+        /// <privilege>http://tizen.org/privilege/notification</privilege>
+        public static Alarm CreateAlarm(DateTime dateTime, AlarmWeekFlag weekFlag, Notification notification)
+        {
+            Alarm alarm = null;
+            int alarmId;
+            NotificationSafeHandle safeHandle = NotificationManager.MakeNotificationSafeHandle(notification);
+            Interop.Alarm.DateTime time = ConvertDateTimeToStruct(dateTime);
+            AlarmError ret = Interop.Alarm.CreateAlarmNotiRecurWeek(safeHandle, ref time, (int)weekFlag, out alarmId);
+            if (ret != AlarmError.None)
+            {
+                throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm");
+            }
+
+            alarm = new Alarm(alarmId);
+
+            return alarm;
+        }
+
+        /// <summary>
+        /// Sets an alarm to be triggered periodically, starting at a specific time.
+        /// The date describes the time of the first occurrence.
+        /// </summary>
+        /// <param name="delay">The amount of time before the first execution (in seconds).</param>
+        /// <param name="notification"> The notification to be posted 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>
+        /// <privilege>http://tizen.org/privilege/notification</privilege>
+        public static Alarm CreateAlarm(int delay, Notification notification)
+        {
+            Alarm alarm = null;
+            int alarmId;
+            NotificationSafeHandle safeHandle = NotificationManager.MakeNotificationSafeHandle(notification);
+            AlarmError ret = Interop.Alarm.CreateAlarmNotiOnceAfterDelay(safeHandle, delay, out alarmId);
+            if (ret != AlarmError.None)
+            {
+                throw AlarmErrorFactory.GetException(ret, "Failed to create Alarm");
+            }
+
+            alarm = new Alarm(alarmId);
+
+            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>