29f4d3eeed72a34aff2d1f3e5769f89104817dc8
[platform/core/csapi/tizenfx.git] / src / Tizen.System / Device / Power.cs
1 /*
2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 using System;
18
19 namespace Tizen.System
20 {
21     /// <summary>
22     /// Enumeration for power lock type.
23     /// </summary>
24     /// <remarks>
25     /// DisplayDim may be ignored if the DIM state is disabled on the platform.
26     /// </remarks>
27     /// <since_tizen> 5 </since_tizen>
28     public enum PowerLock
29     {
30         /// <summary>
31         /// CPU lock.
32         /// </summary>
33         /// <since_tizen> 5 </since_tizen>
34         Cpu = Interop.Device.PowerLock.Cpu,
35         /// <summary>
36         /// Display the normal lock.
37         /// </summary>
38         /// <since_tizen> 5 </since_tizen>
39         DisplayNormal = Interop.Device.PowerLock.DisplayNormal,
40         /// <summary>
41         /// Display the dim lock.
42         /// </summary>
43         /// <since_tizen> 5 </since_tizen>
44         DisplayDim = Interop.Device.PowerLock.DisplayDim,
45     }
46
47     /// <summary>
48     /// The Power class provides methods to control the power service.
49     /// </summary>
50     /// <remarks>
51     /// The Power API provides the way to control the power service.
52     /// It can be made to hold the specific state to avoid the CPU state internally.
53     /// </remarks>
54     /// <privilege>
55     /// http://tizen.org/privilege/display
56     /// </privilege>
57     /// <since_tizen> 3 </since_tizen>
58     public static class Power
59     {
60         /// <summary>
61         /// [Obsolete("Please do not use! this will be deprecated")]
62         /// </summary>
63         /// <remarks>
64         /// If the process dies, then every lock will be removed.
65         /// </remarks>
66         /// <since_tizen> 3 </since_tizen>
67         /// <param name="timeout">
68         /// The positive number in milliseconds or 0 for the permanent lock.
69         /// So you must release the permanent lock of the power state with ReleaseCpuLock() if timeout_ms is zero.
70         /// </param>
71         /// <exception cref="ArgumentException">When an invalid parameter value is set.</exception>
72         /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
73         /// <exception cref="InvalidOperationException">In case of any system error.</exception>
74         /// Please do not use! This will be deprecated!
75         /// Please use RequestLock instead!
76         [Obsolete("Please do not use! This will be deprecated! Please use RequestLock instead!")]
77         public static void RequestCpuLock(int timeout)
78         {
79             DeviceError res = (DeviceError)Interop.Device.DevicePowerRequestLock(Interop.Device.PowerLock.Cpu, timeout);
80             if (res != DeviceError.None)
81             {
82                 throw DeviceExceptionFactory.CreateException(res, "unable to acquire power lock.");
83             }
84         }
85         /// <summary>
86         /// [Obsolete("Please do not use! this will be deprecated")]
87         /// </summary>
88         /// <since_tizen> 3 </since_tizen>
89         /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
90         /// <exception cref="InvalidOperationException">In case of any system error.</exception>
91         /// Please do not use! This will be deprecated!
92         /// Please use ReleaseLock instead!
93         [Obsolete("Please do not use! This will be deprecated! Please use ReleaseLock instead!")]
94         public static void ReleaseCpuLock()
95         {
96             DeviceError res = (DeviceError)Interop.Device.DevicePowerReleaseLock(Interop.Device.PowerLock.Cpu);
97             if (res != DeviceError.None)
98             {
99                 throw DeviceExceptionFactory.CreateException(res, "unable to release power lock.");
100             }
101         }
102
103         /// <summary>
104         /// Locks the given lock state for a specified time.
105         /// After the given timeout (in milliseconds), unlock the given lock state automatically.
106         /// </summary>
107         /// <remarks>
108         /// If the process dies, then every lock will be removed.
109         /// </remarks>
110         /// <since_tizen> 5 </since_tizen>
111         /// <param name="type">
112         /// The power type to request lock.
113         /// </param>
114         /// <param name="timeout">
115         /// The positive number in milliseconds or 0 for the permanent lock.
116         /// So you must release the permanent lock of the power state with ReleaseLock() if timeout_ms is zero.
117         /// </param>
118         /// <exception cref="ArgumentException">When an invalid parameter value is set.</exception>
119         /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
120         /// <exception cref="InvalidOperationException">In case of any system error.</exception>
121         /// <example>
122         /// <code>
123         /// Tizen.System.Power.RequestLock(Tizen.System.Power.PowerLock.Cpu, 2000);
124         /// </code>
125         /// </example>
126         public static void RequestLock(PowerLock type, int timeout)
127         {
128             DeviceError res = (DeviceError)Interop.Device.DevicePowerRequestLock((Interop.Device.PowerLock)type, timeout);
129             if (res != DeviceError.None)
130             {
131                 throw DeviceExceptionFactory.CreateException(res, "unable to acquire power lock.");
132             }
133         }
134         /// <summary>
135         /// Releases the lock state.
136         /// </summary>
137         /// <since_tizen> 5 </since_tizen>
138         /// <param name="type">
139         /// The power type to request lock.
140         /// </param>
141         /// <exception cref="ArgumentException">When an invalid parameter value is set.</exception>
142         /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
143         /// <exception cref="InvalidOperationException">In case of any system error.</exception>
144         /// <example>
145         /// <code>
146         /// Tizen.System.Power.ReleaseLock(Tizen.System.Power.PowerLock.Cpu);
147         /// </code>
148         /// </example>
149         public static void ReleaseLock(PowerLock type)
150         {
151             DeviceError res = (DeviceError)Interop.Device.DevicePowerReleaseLock((Interop.Device.PowerLock)type);
152             if (res != DeviceError.None)
153             {
154                 throw DeviceExceptionFactory.CreateException(res, "unable to release power lock.");
155             }
156         }
157     }
158 }