Implementation of libfeedback
authorpr.jung <pr.jung@samsung.com>
Thu, 11 Aug 2016 06:15:49 +0000 (15:15 +0900)
committerpr.jung <pr.jung@samsung.com>
Mon, 29 Aug 2016 09:26:33 +0000 (18:26 +0900)
Change-Id: I8f52c22bb550d5bb7c302899d37dbee4b88bca6c
Signed-off-by: pr.jung <pr.jung@samsung.com>
Tizen.System/Feedback/Feedback.cs [new file with mode: 0644]
Tizen.System/Feedback/FeedbackPattern.cs [new file with mode: 0644]
Tizen.System/Feedback/FeedbackType.cs [new file with mode: 0644]
Tizen.System/Interop/Interop.Feedback.cs [new file with mode: 0644]
Tizen.System/Interop/Interop.Libraries.cs
Tizen.System/Tizen.System.csproj
packaging/csapi-system.spec [changed mode: 0755->0644]

diff --git a/Tizen.System/Feedback/Feedback.cs b/Tizen.System/Feedback/Feedback.cs
new file mode 100644 (file)
index 0000000..b9f73e1
--- /dev/null
@@ -0,0 +1,353 @@
+using System;
+using System.Collections.Generic;
+
+
+namespace Tizen.System.Feedback
+{
+    /// <summary>
+    /// Class for constants
+    /// </summary>
+    internal static class Constants
+    {
+        internal const int NumberOfPattern = 39;
+    }
+
+    /// <summary>
+    /// The Feedback API provides functions to control haptic and sound.
+    /// The Feedback API provides the way to play and stop feedback and get the information whether specific pattern is supported.
+    /// Below is supported pattern string.
+    /// Tap
+    /// SoftInputPanel
+    /// Key0
+    /// Key1
+    /// Key2
+    /// Key3
+    /// Key4
+    /// Key5
+    /// Key6
+    /// Key7
+    /// Key8
+    /// Key9
+    /// KeyStar
+    /// KeySharp
+    /// KeyBack
+    /// Hold
+    /// HardwareKeyPressed
+    /// HardwareKeyHold
+    /// Message
+    /// Email
+    /// WakeUp
+    /// Schedule
+    /// Timer
+    /// General
+    /// PowerOn
+    /// PowerOff
+    /// ChargerConnected
+    /// ChargingError
+    /// FullyCharged
+    /// LowBattery
+    /// Lock
+    /// UnLock
+    /// VibrationModeAbled
+    /// SilentModeDisabled
+    /// BluetoothDeviceConnected
+    /// BluetoothDeviceDisconnected
+    /// ListReorder
+    /// ListSlider
+    /// VolumeKeyPressed
+    /// </summary>
+    /// <privilege>
+    /// For controlling haptic device:
+    /// http://tizen.org/privilege/haptic
+    /// For controlling sound, previlege is not needed.
+    /// </privilege>
+    /// <code>
+    /// Tizen.System.Feedback.Feedback feedback = new Tizen.System.Feedback.Feedback();
+    /// bool res = feedback.IsSupportedPattern(FeedbackType.Vibration, "Tap");
+    /// </code>
+    public class Feedback
+    {
+        private const string LogTag = "Tizen.System.Feedback";
+
+        private readonly FeedbackPattern[] Pattern = new FeedbackPattern[39];
+        public Feedback()
+        {
+            Pattern[0].PatternNumber = 0;
+            Pattern[0].PatternString = "Tap";
+            Pattern[1].PatternNumber = 1;
+            Pattern[1].PatternString = "SoftInputPanel";
+            Pattern[2].PatternNumber = 6;
+            Pattern[2].PatternString = "Key0";
+            Pattern[3].PatternNumber = 7;
+            Pattern[3].PatternString = "Key1";
+            Pattern[4].PatternNumber = 8;
+            Pattern[4].PatternString = "Key2";
+            Pattern[5].PatternNumber = 9;
+            Pattern[5].PatternString = "Key3";
+            Pattern[6].PatternNumber = 10;
+            Pattern[6].PatternString = "Key4";
+            Pattern[7].PatternNumber = 11;
+            Pattern[7].PatternString = "Key5";
+            Pattern[8].PatternNumber = 12;
+            Pattern[8].PatternString = "Key6";
+            Pattern[9].PatternNumber = 13;
+            Pattern[9].PatternString = "Key7";
+            Pattern[10].PatternNumber = 14;
+            Pattern[10].PatternString = "Key8";
+            Pattern[11].PatternNumber = 15;
+            Pattern[11].PatternString = "Key9";
+            Pattern[12].PatternNumber = 16;
+            Pattern[12].PatternString = "KeyStar";
+            Pattern[13].PatternNumber = 17;
+            Pattern[13].PatternString = "KeySharp";
+            Pattern[14].PatternNumber = 18;
+            Pattern[14].PatternString = "KeyBack";
+            Pattern[15].PatternNumber = 19;
+            Pattern[15].PatternString = "Hold";
+            Pattern[16].PatternNumber = 21;
+            Pattern[16].PatternString = "HardwareKeyPressed";
+            Pattern[17].PatternNumber = 22;
+            Pattern[17].PatternString = "HardwareKeyHold";
+            Pattern[18].PatternNumber = 23;
+            Pattern[18].PatternString = "Message";
+            Pattern[19].PatternNumber = 25;
+            Pattern[19].PatternString = "Email";
+            Pattern[20].PatternNumber = 27;
+            Pattern[20].PatternString = "WakeUp";
+            Pattern[21].PatternNumber = 29;
+            Pattern[21].PatternString = "Schedule";
+            Pattern[22].PatternNumber = 31;
+            Pattern[22].PatternString = "Timer";
+            Pattern[23].PatternNumber = 33;
+            Pattern[23].PatternString = "General";
+            Pattern[24].PatternNumber = 36;
+            Pattern[24].PatternString = "PowerOn";
+            Pattern[25].PatternNumber = 37;
+            Pattern[25].PatternString = "PowerOff";
+            Pattern[26].PatternNumber = 38;
+            Pattern[26].PatternString = "ChargerConnected";
+            Pattern[27].PatternNumber = 40;
+            Pattern[27].PatternString = "ChargingError";
+            Pattern[28].PatternNumber = 42;
+            Pattern[28].PatternString = "FullyCharged";
+            Pattern[29].PatternNumber = 44;
+            Pattern[29].PatternString = "LowBattery";
+            Pattern[30].PatternNumber = 46;
+            Pattern[30].PatternString = "Lock";
+            Pattern[31].PatternNumber = 47;
+            Pattern[31].PatternString = "UnLock";
+            Pattern[32].PatternNumber = 55;
+            Pattern[32].PatternString = "VibrationModeAbled";
+            Pattern[33].PatternNumber = 56;
+            Pattern[33].PatternString = "SilentModeDisabled";
+            Pattern[34].PatternNumber = 57;
+            Pattern[34].PatternString = "BluetoothDeviceConnected";
+            Pattern[35].PatternNumber = 58;
+            Pattern[35].PatternString = "BluetoothDeviceDisconnected";
+            Pattern[36].PatternNumber = 62;
+            Pattern[36].PatternString = "ListReorder";
+            Pattern[37].PatternNumber = 63;
+            Pattern[37].PatternString = "ListSlider";
+            Pattern[38].PatternNumber = 64;
+            Pattern[38].PatternString = "VolumeKeyPressed";
+
+            Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Initialize();
+            if (res != Interop.Feedback.FeedbackError.None)
+            {
+                Log.Warn(LogTag, string.Format("Failed to initialize feedback. err = {0}", res));
+                switch (res)
+                {
+                    case Interop.Feedback.FeedbackError.NotSupported:
+                        throw new NotSupportedException("Device is not supported");
+                    default:
+                        throw new InvalidOperationException("Failed to initialize");
+                }
+            }
+        }
+
+        ~Feedback()
+        {
+            Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Deinitialize();
+            if (res != Interop.Feedback.FeedbackError.None)
+            {
+                Log.Warn(LogTag, string.Format("Failed to initialize feedback. err = {0}", res));
+                switch (res)
+                {
+                    case Interop.Feedback.FeedbackError.NotInitialized:
+                        throw new Exception("Not initialized");
+                    default:
+                        throw new InvalidOperationException("Failed to initialize");
+                }
+            }
+        }
+
+        /// <summary>
+        /// Get supported information about specific type and pattern
+        /// </summary>
+        /// <remarks>
+        /// To get supported information for Vibration type, app should have http://tizen.org/privilege/haptic privilege.
+        /// </remarks>
+        /// <param name="type">Feedback type</param>
+        /// <param name="pattern">Feedback pattern string</param>
+        /// <returns>Information whether pattern is supported</returns>
+        /// <exception cref="Exception">Thrown when failed because feedback is not initialized</exception>
+        /// <exception cref="ArgumentException">Thrown when failed because of a invalid arguament</exception>
+        /// <exception cref="NotSupportedException">Thrown when failed becuase device(haptic, sound) is not supported</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when failed because access is not granted(No privilege)</exception>
+        /// <exception cref="InvalidOperationException">Thrown when failed because of system error</exception>
+        /// <privilege>http://tizen.org/privilege/haptic</privilege>
+        /// <example>
+        /// <code>
+       /// Tizen.System.Feedback.Feedback feedback = new Tizen.System.Feedback.Feedback();
+        /// bool res = feedback.IsSupportedPattern(FeedbackType.Vibration, "Tap");
+        /// </code>
+        /// </example>
+        public bool IsSupportedPattern(FeedbackType type, String pattern)
+        {
+            bool supported = false;
+            bool found = false;
+            int i = 0;
+            Interop.Feedback.FeedbackError res;
+
+            for (i = 0; i < Constants.NumberOfPattern; i++)
+            {
+                if (String.Compare(pattern, Pattern[i].PatternString) == 0)
+                {
+                    found = true;
+                    break;
+                }
+            }
+
+            if (!found)
+                throw new ArgumentException("Invalid Arguments");
+
+            res = (Interop.Feedback.FeedbackError)Interop.Feedback.IsSupportedPattern((Interop.Feedback.FeedbackType)type, Pattern[i].PatternNumber, out supported);
+
+
+            if (res != Interop.Feedback.FeedbackError.None)
+            {
+                Log.Warn(LogTag, string.Format("Failed to get supported information. err = {0}", res));
+                switch (res)
+                {
+                    case Interop.Feedback.FeedbackError.NotInitialized:
+                        throw new Exception("Not initialized");
+                    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.PermissionDenied:
+                        throw new UnauthorizedAccessException("Access is not granted");
+                    case Interop.Feedback.FeedbackError.OperationFailed:
+                    default:
+                        throw new InvalidOperationException("Failed to get supported information");
+                }
+            }
+            return supported;
+        }
+
+        /// <summary>
+        /// Play specific feedback pattern
+        /// </summary>
+        /// <remarks>
+        /// To play Vibration type, app should have http://tizen.org/privilege/haptic privilege.
+        /// </remarks>
+        /// <param name="type">Feedback type</param>
+        /// <param name="pattern">Feedback pattern string</param>
+        /// <exception cref="Exception">Thrown when failed because feedback is not initialized</exception>
+        /// <exception cref="ArgumentException">Thrown when failed because of a invalid arguament</exception>
+        /// <exception cref="NotSupportedException">Thrown when failed because device(haptic, sound) or specific pattern is not supported</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when failed because access is not granted(No privilege)</exception>
+        /// <exception cref="InvalidOperationException">Thrown when failed because of system error</exception>
+        /// <privilege>http://tizen.org/privilege/haptic</privilege>
+        /// <example>
+        /// <code>
+       /// Tizen.System.Feedback.Feedback feedback = new Tizen.System.Feedback.Feedback();
+        /// feedback.Play(FeedbackType.All, "Tap");
+        /// </code>
+        /// </example>
+        public void Play(FeedbackType type, String pattern)
+        {
+            bool found = false;
+            int i = 0;
+            Interop.Feedback.FeedbackError res;
+
+            for (i = 0; i < Constants.NumberOfPattern; i++)
+            {
+                if (String.Compare(pattern, Pattern[i].PatternString) == 0)
+                {
+                    found = true;
+                    break;
+                }
+            }
+
+            if (!found)
+                throw new ArgumentException("Invalid Arguments");
+
+            if (type == FeedbackType.All)
+                res = (Interop.Feedback.FeedbackError)Interop.Feedback.Play(Pattern[i].PatternNumber);
+            else
+                res = (Interop.Feedback.FeedbackError)Interop.Feedback.PlayType((Interop.Feedback.FeedbackType)type, Pattern[i].PatternNumber);
+
+            if (res != Interop.Feedback.FeedbackError.None)
+            {
+                Log.Warn(LogTag, string.Format("Failed to play feedback. err = {0}", res));
+                switch (res)
+                {
+                    case Interop.Feedback.FeedbackError.NotInitialized:
+                        throw new Exception("Not initialized");
+                    case Interop.Feedback.FeedbackError.InvalidParameter:
+                        throw new ArgumentException("Invalid Arguments");
+                    case Interop.Feedback.FeedbackError.NotSupported:
+                        throw new NotSupportedException("Not supported");
+                    case Interop.Feedback.FeedbackError.PermissionDenied:
+                        throw new UnauthorizedAccessException("Access is not granted");
+                    case Interop.Feedback.FeedbackError.OperationFailed:
+                    default:
+                        throw new InvalidOperationException("Failed to play pattern");
+                }
+            }
+        }
+
+        /// <summary>
+        /// Stop to play feedback
+        /// </summary>
+        /// <remarks>
+        /// To stop vibration, app should have http://tizen.org/privilege/haptic privilege.
+        /// </remarks>
+        /// <exception cref="Exception">Thrown when failed because feedback is not initialized</exception>
+        /// <exception cref="ArgumentException">Thrown when failed because of a invalid arguament</exception>
+        /// <exception cref="NotSupportedException">Thrown when failed because device(haptic, sound) or specific pattern is not supported</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when failed because access is not granted(No privilege)</exception>
+        /// <exception cref="InvalidOperationException">Thrown when failed because of system error</exception>
+        /// <privilege>http://tizen.org/privilege/haptic</privilege>
+        /// <example>
+        /// <code>
+        /// Feedback Feedback1 = new Feedback();
+        /// Feedback1.Stop();
+        /// </code>
+        /// </example>
+        public void Stop()
+        {
+            Interop.Feedback.FeedbackError res = (Interop.Feedback.FeedbackError)Interop.Feedback.Stop();
+
+            if (res != Interop.Feedback.FeedbackError.None)
+            {
+                Log.Warn(LogTag, string.Format("Failed to stop feedback. err = {0}", res));
+                switch (res)
+                {
+                    case Interop.Feedback.FeedbackError.NotInitialized:
+                        throw new Exception("Not initialized");
+                    case Interop.Feedback.FeedbackError.InvalidParameter:
+                        throw new ArgumentException("Invalid Arguments");
+                    case Interop.Feedback.FeedbackError.NotSupported:
+                        throw new NotSupportedException("Not supported");
+                    case Interop.Feedback.FeedbackError.PermissionDenied:
+                        throw new UnauthorizedAccessException("Access is not granted");
+                    case Interop.Feedback.FeedbackError.OperationFailed:
+                    default:
+                        throw new InvalidOperationException("Failed to play pattern");
+                }
+            }
+        }
+    }
+}
diff --git a/Tizen.System/Feedback/FeedbackPattern.cs b/Tizen.System/Feedback/FeedbackPattern.cs
new file mode 100644 (file)
index 0000000..12ac6fd
--- /dev/null
@@ -0,0 +1,25 @@
+// 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.
+
+namespace Tizen.System.Feedback
+{
+    /// <summary>
+    /// String and Enumeration for feedback patterns.
+    /// </summary>
+    internal struct FeedbackPattern
+    {
+        internal int PatternNumber;
+        internal string PatternString;
+
+        internal FeedbackPattern(int n, string s)
+        {
+            PatternNumber = n;
+            PatternString = s;
+        }
+    }
+}
diff --git a/Tizen.System/Feedback/FeedbackType.cs b/Tizen.System/Feedback/FeedbackType.cs
new file mode 100644 (file)
index 0000000..346bb25
--- /dev/null
@@ -0,0 +1,29 @@
+// 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.
+
+namespace Tizen.System.Feedback
+{
+    /// <summary>
+    /// Enumeration for feedback device types.
+    /// </summary>
+    public enum FeedbackType
+    {
+        /// <summary>
+        ///  Sound and Vibration
+        /// </summary>
+        All = 0,
+        /// <summary>
+        /// Sound feedback
+        /// </summary>
+        Sound = Interop.Feedback.FeedbackType.Sound,
+        /// <summary>
+        /// Vibration
+        /// /// </summary>
+        Vibration = Interop.Feedback.FeedbackType.Vibration,
+    }
+}
diff --git a/Tizen.System/Interop/Interop.Feedback.cs b/Tizen.System/Interop/Interop.Feedback.cs
new file mode 100644 (file)
index 0000000..7e87c6d
--- /dev/null
@@ -0,0 +1,51 @@
+// 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;
+
+internal static partial class Interop
+{
+    internal static partial class Feedback
+    {
+        internal enum FeedbackError
+        {
+            None = Tizen.Internals.Errors.ErrorCode.None,
+            OperationFailed = Tizen.Internals.Errors.ErrorCode.NotPermitted,
+            InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
+            NotSupported = Tizen.Internals.Errors.ErrorCode.NoSuchDevice,
+            PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
+            NotInitialized = -0x00020000 | 0x12,
+        }
+
+        // Any change here might require changes in Tizen.System.FeedbackType enum
+        internal enum FeedbackType
+        {
+            Sound = 1,
+            Vibration = 2,
+        }
+
+        [DllImport(Libraries.Feedback, EntryPoint = "feedback_initialize")]
+        internal static extern int Initialize();
+
+        [DllImport(Libraries.Feedback, EntryPoint = "feedback_deinitialize")]
+        internal static extern int Deinitialize();
+
+        [DllImport(Libraries.Feedback, EntryPoint = "feedback_play")]
+        internal static extern int Play(int pattern);
+
+        [DllImport(Libraries.Feedback, EntryPoint = "feedback_play_type")]
+        internal static extern int PlayType(FeedbackType type, int pattern);
+
+        [DllImport(Libraries.Feedback, EntryPoint = "feedback_stop")]
+        internal static extern int Stop();
+
+        [DllImport(Libraries.Feedback, EntryPoint = "feedback_is_supported_pattern")]
+        internal static extern int IsSupportedPattern(FeedbackType type, int pattern, out bool supported);
+    }
+}
index ab50290..6e4e26f 100644 (file)
@@ -13,5 +13,6 @@ internal static partial class Interop
         internal const string RuntimeInfo = "libcapi-system-runtime-info.so.0";
         internal const string Storage = "libstorage.so.0.1";
         internal const string SystemInfo = "libcapi-system-info.so.0";
+        internal const string Feedback = "libfeedback.so.0";
     }
 }
index 4383969..175a75f 100644 (file)
     <Compile Include="Device\Power.cs" />
     <Compile Include="Device\IR.cs" />
     <Compile Include="Device\DeviceEventArgs.cs" />
+    <Compile Include="Feedback\Feedback.cs" />
+    <Compile Include="Feedback\FeedbackPattern.cs" />
+    <Compile Include="Feedback\FeedbackType.cs" />
+    <Compile Include="Interop\Interop.Feedback.cs" />
     <Compile Include="Interop\Interop.Device.cs" />
     <Compile Include="Interop\Interop.RuntimeInfo.cs" />
     <Compile Include="Interop\Interop.Libraries.cs" />
old mode 100755 (executable)
new mode 100644 (file)