[System.Feedback] Add internal API to support get ids
authorYunhee Seo <yuni.seo@samsung.com>
Wed, 8 Nov 2023 07:07:00 +0000 (16:07 +0900)
committerChanwoo Choi <chanwoo@kernel.org>
Tue, 14 Nov 2023 11:56:01 +0000 (20:56 +0900)
Allows getting feedback theme id array supported.

This is newly added to System.Feedback.
- public uint[] GetThemeIdsInternal(FeedbackType type)
     -> It returns the available id array defined in the conf file according to feedback type.

Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
src/Tizen.System.Feedback/Feedback/Feedback.cs
src/Tizen.System.Feedback/Interop/Interop.Feedback.cs

index fc5a8ae..6365ea0 100755 (executable)
@@ -17,6 +17,7 @@
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
+using System.Runtime.InteropServices;
 
 
 namespace Tizen.System
@@ -731,5 +732,61 @@ namespace Tizen.System
                 }
             }
         }
+
+        /// <summary>
+        /// Gets the id array of theme supported.
+        /// </summary>
+        /// <remarks>
+        /// Now this internal API works for FeedbackType.Sound only, FeedbackType.Vibration is not supported.
+        /// The theme id is positive value as defined in the conf file.
+        /// </remarks>
+        /// <since_tizen> 10 </since_tizen>
+        /// <param name="type">The feedback type.</param>
+        /// <returns>The array of theme id supported according to feedback type.</returns>
+        /// <exception cref="ArgumentException">Thrown when failed because of an invalid arguament.</exception>
+        /// <exception cref="NotSupportedException">Thrown when failed becuase the device (haptic, sound) is not supported.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when failed because of a system error.</exception>
+        /// <example>
+        /// <code>
+        /// Feedback feedback = new Feedback();
+        /// uint[] getThemeIds = feedback.GetThemeIdsInternal(FeedbackType.Sound);
+        /// </code>
+        /// </example>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public uint[] GetThemeIdsInternal(FeedbackType type)
+        {
+            uint countOfTheme = 0;
+            IntPtr getThemeIds;
+            Interop.Feedback.FeedbackError res;
+
+            res = (Interop.Feedback.FeedbackError)Interop.Feedback.GetThemeIdsInternal((Interop.Feedback.FeedbackType)type, out countOfTheme, out getThemeIds);
+            if (res != Interop.Feedback.FeedbackError.None)
+            {
+                Log.Warn(LogTag, string.Format("Failed to get ids of theme internal. err = {0}", res));
+                switch (res)
+                {
+                    case Interop.Feedback.FeedbackError.InvalidParameter:
+                        throw new ArgumentException("Invalid Arguments");
+                    case Interop.Feedback.FeedbackError.NotSupported:
+                        throw new NotSupportedException("Device is not supported");
+                    case Interop.Feedback.FeedbackError.OperationFailed:
+                    default:
+                        throw new InvalidOperationException("Failed to get ids of theme internal");
+                }
+            }
+
+            uint[] themeIds = new uint[countOfTheme];
+            unsafe {
+                uint index = 0;
+                uint* themeIdsPointer = (uint*)getThemeIds;
+
+                for (index = 0; index < countOfTheme; index++) {
+                    themeIds[index] = themeIdsPointer[index];
+                }
+            }
+            Marshal.FreeHGlobal(getThemeIds);
+
+            return themeIds;
+        }
     }
 }
index 0a4b4e8..81fbeda 100644 (file)
@@ -67,5 +67,8 @@ internal static partial class Interop
 
         [DllImport(Libraries.Feedback, EntryPoint = "feedback_stop_type_internal")]
         internal static extern int StopTypeInternal(FeedbackType type);
+
+        [DllImport(Libraries.Feedback, EntryPoint = "feedback_get_theme_ids_internal", CallingConvention = CallingConvention.Cdecl)]
+        internal static extern int GetThemeIdsInternal(FeedbackType type, out uint coundOfTheme, out IntPtr themeIds);
     }
 }