Release 4.0.0-preview1-00051
[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     /// The Power class provides methods to control the power service.
23     /// </summary>
24     /// <remarks>
25     /// The Power API provides the way to control the power service.
26     /// It can be made to hold the specific state to avoid the CPU state internally.
27     /// </remarks>
28     /// <privilege>
29     /// http://tizen.org/privilege/display
30     /// </privilege>
31     public static class Power
32     {
33         /// <summary>
34         /// Locks the CPU for a specified time.
35         /// After the given timeout (in milliseconds), unlock the given lock state automatically.
36         /// </summary>
37         /// <remarks>
38         /// If the process dies, then every lock will be removed.
39         /// </remarks>
40         /// <since_tizen> 3 </since_tizen>
41         /// <param name="timeout">
42         /// The positive number in milliseconds or 0 for the permanent lock.
43         /// So you must release the permanent lock of the power state with ReleaseCpuLock() if timeout_ms is zero.
44         /// </param>
45         /// <exception cref="ArgumentException">When an invalid parameter value is set.</exception>
46         /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
47         /// <exception cref="InvalidOperationException">In case of any system error.</exception>
48         /// <code>
49         /// Tizen.System.Power.RequestCpuLock(2000);
50         /// </code>
51
52         public static void RequestCpuLock(int timeout)
53         {
54             DeviceError res = (DeviceError)Interop.Device.DevicePowerRequestLock(0, timeout);
55             if (res != DeviceError.None)
56             {
57                 throw DeviceExceptionFactory.CreateException(res, "unable to acquire power lock.");
58             }
59         }
60         /// <summary>
61         /// Releases the CPU lock state.
62         /// </summary>
63         /// <since_tizen> 3 </since_tizen>
64         /// <exception cref="UnauthorizedAccessException">If the privilege is not set.</exception>
65         /// <exception cref="InvalidOperationException">In case of any system error.</exception>
66         /// <code>
67         /// Tizen.System.Power.ReleaseCpuLock();
68         /// </code>
69         public static void ReleaseCpuLock()
70         {
71             DeviceError res = (DeviceError)Interop.Device.DevicePowerReleaseLock(0);
72             if (res != DeviceError.None)
73             {
74                 throw DeviceExceptionFactory.CreateException(res, "unable to release power lock.");
75             }
76         }
77     }
78 }