[Device][PerformanceController] Add PerformanceController API (#1683)
authorsanghyeok-oh <62281925+sanghyeok-oh@users.noreply.github.com>
Thu, 2 Jul 2020 06:10:27 +0000 (15:10 +0900)
committerGitHub <noreply@github.com>
Thu, 2 Jul 2020 06:10:27 +0000 (15:10 +0900)
* [Device][PmQos] Add PmQos API

Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
* remove debugging log

Change-Id: I0159e335f684cf88ccee9d7dcec4b733c566131c
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
* Fix tizen version, remove unnecessary lines

Change-Id: I5b17449630e50763307c5f555bb3e3c62e7dcc6f
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
* Fix a typo

Change-Id: I4df7053e04c0b757a47266352d00549c14d2d8a0
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
* Add PmQosType

Change-Id: Ib89b74951ba7b4a06846abb7969c37e3610d8e3a
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
* Add EditorBrowsable attribute

Change-Id: Iddbdf2787a431b6794de08121d8d35896a27e81b
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
* Add EditorBrowsable attribute for PmQosType

Change-Id: Ifdabca75ddd1efcf3d5ef4512b67ee1cb61035f2
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
* remove since tag

Change-Id: I5ffb25098e8634617430e83c9fb1ab8e80c6c0a8
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
* Change class name from PmQos to PerformanceController

Change-Id: I5c46c05a722eb110d06e3fb40fd31754c15d237f
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
* Remove since

Change-Id: Ib4c53ea3eace178db71d18904a760727483fe9e9
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
* Rename PmQosType to PerformanceControlType

Change-Id: I22a90223ce0ead6b081786d4be63edeec0ec21bf
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
* Modify summary

Change-Id: I925423dff1f2dd55e1df103e27b78bf858e9eb96
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
* Remove implicit operator

Change-Id: Idb20a8f52f26878c7aae977d2c101bb82906be7e
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
src/Tizen.System/Device/PerformanceControlType.cs [new file with mode: 0644]
src/Tizen.System/Device/PerformanceController.cs [new file with mode: 0644]
src/Tizen.System/Interop/Interop.Device.cs

diff --git a/src/Tizen.System/Device/PerformanceControlType.cs b/src/Tizen.System/Device/PerformanceControlType.cs
new file mode 100644 (file)
index 0000000..63122f7
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+
+using Tizen.Common;
+using System.ComponentModel;
+
+namespace Tizen.System
+{
+    /// <summary>
+    /// This class represents the type of event for backends. This class can be converted from the string type.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class PerformanceControlType
+    {
+        /// <summary>
+        /// Pre-defined event type "PreCreated".
+        /// </summary>
+        public static readonly PerformanceControlType AppLaunchHome = new PerformanceControlType("AppLaunchHome");
+
+        /// <summary>
+        /// Pre-defined event type "HomeScreen".
+        /// </summary>
+        public static readonly PerformanceControlType HomeScreen = new PerformanceControlType("HomeScreen");
+
+        private string _typeName;
+
+        /// <summary>
+        /// Initializes the PerformanceControlType class.
+        /// </summary>
+        /// <param name="name">The name of event type.</param>
+        private PerformanceControlType(string name) {
+            _typeName = name;
+        }
+
+        /// <summary>
+        /// Returns the name of event type.
+        /// </summary>
+        public override string ToString() {
+            return _typeName;
+        }
+
+        /// <summary>
+        /// Returns the hash code for event type string.
+        /// </summary>
+        public override int GetHashCode() {
+            if (_typeName == null) return 0;
+            return _typeName.GetHashCode();
+        }
+
+        /// <summary>
+        /// Determines whether this instance and a specified object.
+        /// </summary>
+        public override bool Equals(object obj) {
+            PerformanceControlType other = obj as PerformanceControlType;
+            return other != null && other._typeName == this._typeName;
+        }
+    }
+}
diff --git a/src/Tizen.System/Device/PerformanceController.cs b/src/Tizen.System/Device/PerformanceController.cs
new file mode 100644 (file)
index 0000000..88206eb
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+
+using Tizen.Common;
+using System.Collections.Generic;
+using System.ComponentModel;
+
+namespace Tizen.System
+{
+    /// <summary>
+    /// The PerformanceController class provides the methods to control the system resources.
+    /// </summary>
+    /// <remarks>
+    /// It supports to control cpu clock within input timeout.
+    /// </remarks>
+    /// <privilege>
+    /// </privilege>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public static class PerformanceController
+    {
+        private delegate int PerformanceControlFunc(int timeout);
+        private static readonly Dictionary<PerformanceControlType, PerformanceControlFunc> PerformanceControlFunctions = new Dictionary<PerformanceControlType, PerformanceControlFunc>
+        {
+            {PerformanceControlType.AppLaunchHome, Interop.Device.DevicePmQosAppLaunchHome},
+            {PerformanceControlType.HomeScreen, Interop.Device.DevicePmQosHomeScreen},
+            /* Add Here */
+        };
+
+        /// <summary>
+        /// Increase the cpu clock within timeout.
+        /// </summary>
+        /// <param name="type">Performance Control Type</param>
+        /// <param name="timeout">Cpu clock increasing duration in milliseconds.</param>
+        /// <exception cref="ArgumentException">When an invalid parameter value is set.</exception>
+        /// <exception cref="InvalidOperationException">In case of any system error.</exception>
+        /// <exception cref="NotSupportedException">In case the device does not support this behavior.</exception>
+        /// <example>
+        /// <code>
+        ///     try
+        ///     {
+        ///         PerformanceController.Request(PerformanceControlType.AppLaunchHome, 100);
+        ///     }
+        ///     Catch(Exception e)
+        ///     {
+        ///     }
+        /// </code>
+        /// </example>
+        public static void Request(PerformanceControlType type, int timeout) {
+            PerformanceControlFunc func = null;
+
+            if (!PerformanceControlFunctions.TryGetValue(type, out func))
+                throw new ArgumentException("Invalid Arguments");
+
+            DeviceError res = (DeviceError)func(timeout);
+
+            if (res != DeviceError.None) {
+                throw DeviceExceptionFactory.CreateException(res, "unable to transmit PmQos command.");
+            }
+        }
+    }
+}
index 740d01b..236a547 100644 (file)
@@ -113,5 +113,11 @@ internal static partial class Interop
         internal static extern int DeviceAddCallback(Tizen.System.EventType type, deviceCallback cb, IntPtr data);
         [DllImport(Libraries.Device, EntryPoint = "device_remove_callback", CallingConvention = CallingConvention.Cdecl)]
         internal static extern int DeviceRemoveCallback(Tizen.System.EventType type, deviceCallback cb);
+
+        //PmQos
+        [DllImport(Libraries.Device, EntryPoint = "device_pmqos_app_launch_home", CallingConvention = CallingConvention.Cdecl)]
+        internal static extern int DevicePmQosAppLaunchHome(int timeout);
+        [DllImport(Libraries.Device, EntryPoint = "device_pmqos_homescreen", CallingConvention = CallingConvention.Cdecl)]
+        internal static extern int DevicePmQosHomeScreen(int timeout);
     }
 }