[Applications.Common] Add internal API to toggle watchdog
authornewb1e-kim <jihoi.kim@samsung.com>
Wed, 9 Apr 2025 04:54:09 +0000 (13:54 +0900)
committerGitHub <noreply@github.com>
Wed, 9 Apr 2025 04:54:09 +0000 (13:54 +0900)
Add internal APIs to handling watchdog timer
Implement WatchdogTimer, for application to request related operation

src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs
src/Tizen.Applications.Common/Tizen.Applications/WatchdogTimer.cs [new file with mode: 0644]

index c620853a872bb38b0640ea8b3384e38b46989908..5b86d6ab46a091031117439a7055d2d109dad95c 100644 (file)
@@ -113,6 +113,15 @@ internal static partial class Interop
 
         [DllImport(Libraries.AppCommon, EntryPoint = "app_event_get_time_zone")]
         internal static extern ErrorCode AppEventGetTimeZone(IntPtr handle, out string timeZone, out string timeZoneId);
+        
+        [DllImport(Libraries.AppCommon, EntryPoint = "app_watchdog_timer_enable")]
+        internal static extern AppCommonErrorCode AppWatchdogTimerEnable();
+
+        [DllImport(Libraries.AppCommon, EntryPoint = "app_watchdog_timer_disable")]
+        internal static extern AppCommonErrorCode AppWatchdogTimerDisable();
+
+        [DllImport(Libraries.AppCommon, EntryPoint = "app_watchdog_timer_kick")]
+        internal static extern AppCommonErrorCode AppWatchdogTimerKick();
     }
 }
 
diff --git a/src/Tizen.Applications.Common/Tizen.Applications/WatchdogTimer.cs b/src/Tizen.Applications.Common/Tizen.Applications/WatchdogTimer.cs
new file mode 100644 (file)
index 0000000..50d84ab
--- /dev/null
@@ -0,0 +1,72 @@
+using System;
+using System.ComponentModel;
+
+namespace Tizen.Applications
+{
+    /// <summary>
+    /// A class to send request about watchdog timer.
+    /// </summary>
+    /// <remarks>
+    /// This class provides functionality for managing watchdog timer of caller.
+    /// An application can toggle watchdog timer of itself.
+    /// </remarks>
+    /// <since_tizen> 13 </since_tizen>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public static class WatchdogTimer
+    {
+        /// <summary>
+        /// Sends a disable request to deactivate the watchdog timer.
+        /// </summary>
+        /// <remarks>
+        /// After this function is called, the system doesn't detect a timeout error.
+        /// If the running application has to process a lot of operations, the application should disable or reset the watchdog timer.
+        /// Trying to disable watchdog timer already disabled will generate error.
+        /// </remarks>
+        /// <exception cref="InvalidOperationException">Invalid watchdog context</exception>
+        /// <since_tizen> 13 </since_tizen>
+        public static void Disable()
+        {
+            Interop.AppCommon.AppCommonErrorCode err = Interop.AppCommon.AppWatchdogTimerDisable();
+            if (err == Interop.AppCommon.AppCommonErrorCode.InvalidContext)
+            {
+                throw new InvalidOperationException("Invalid watchdog context");
+            }
+            return;
+        }
+
+        /// <summary>
+        /// Sends an enable request to activate the watchdog timer.
+        /// </summary>
+        /// <remarks>
+        /// After this function is called, the system detects a timeout error.
+        /// If, due to a program error as ANR (Application Not Responding), the system fails to reset the watchdog,
+        /// the timer will elapse and generate a signal to terminate the running application.
+        /// </remarks>
+        /// <exception cref="InvalidOperationException">Invalid watchdog context</exception>
+        /// <since_tizen> 13 </since_tizen>
+        public static void Enable()
+        {
+            Interop.AppCommon.AppCommonErrorCode err = Interop.AppCommon.AppWatchdogTimerEnable();
+            if (err == Interop.AppCommon.AppCommonErrorCode.InvalidContext)
+            {
+                throw new InvalidOperationException("Invalid watchdog context");
+            }
+            return;
+        }
+
+        /// <summary>
+        /// Sends a kick request to the watchdog timer.
+        /// </summary>
+        /// <exception cref="InvalidOperationException">Invalid watchdog context</exception>
+        /// <since_tizen> 13 </since_tizen>
+        public static void Kick()
+        {
+            Interop.AppCommon.AppCommonErrorCode err = Interop.AppCommon.AppWatchdogTimerKick();
+            if (err == Interop.AppCommon.AppCommonErrorCode.InvalidContext)
+            {
+                throw new InvalidOperationException("Invalid watchdog context");
+            }
+            return;
+        }
+    }
+}