[System] Add power internal APIs
[platform/core/csapi/tizenfx.git] / src / Tizen.System.Resource / Resource / Resource.cs
1 /*
2  * Copyright (c) 2022 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 using System.ComponentModel;
19
20 namespace Tizen.System
21 {
22         /// <summary>
23         /// Provides methods to support CPU boosting and CPU inheritance.
24         /// </summary>
25         [EditorBrowsable(EditorBrowsableState.Never)]
26         public class Resource
27         {
28         /// <summary>
29                 /// Set cpu boosting for the target process (pid/tids).
30         /// </summary>
31                 /// <privilege>
32                 /// http://tizen.org/privilege/internal/default/partner
33                 /// </privilege>
34                 /// <param name="pid">The target process pid/tids.</param>
35                 /// <param name="level">The cpu boosting level</param>
36                 /// <param name="flags">The cpu boosting flag bits</param>
37                 /// <param name="timeoutMsec">The timeout in milliseconds</param>
38                 [EditorBrowsable(EditorBrowsableState.Never)]
39                 public static void ResourceSetCpuBoosting (ResourcePidInfo pid, CpuBoostingLevel level, CpuBoostingFlag flags, int timeoutMsec)
40                 {
41                         ResourceError ret = Interop.Resource.ResourceSetCpuBoosting(pid, level, flags, timeoutMsec);
42                         if (ret != ResourceError.None) {
43                                 Log.Error(ResourceErrorFactory.LogTag, "Interop failed to set cpu boosting");
44                                 ResourceErrorFactory.ThrowException(ret);
45                         }
46                 }
47
48                 /// <summary>
49                 /// Clear cpu boosting for the boosted process (pid/tids).
50         /// </summary>
51                 /// <privilege>
52                 /// http://tizen.org/privilege/internal/default/partner
53                 /// </privilege>
54                 /// <param name="pid">The target process pid/tids.</param>
55                 [EditorBrowsable(EditorBrowsableState.Never)]
56                 public static void ResourceClearCpuBoosting (ResourcePidInfo pid)
57                 {
58                         ResourceError ret = Interop.Resource.ResourceClearCpuBoosting(pid);
59                         if (ret != ResourceError.None) {
60                                 Log.Error(ResourceErrorFactory.LogTag, "Interop failed to clear cpu boosting");
61                                 ResourceErrorFactory.ThrowException(ret);
62                         }
63                 }
64
65                 /// <summary>
66                 /// Get the cpu boosting level for the target process (pid/tids).
67         /// </summary>
68                 /// <privilege>
69                 /// http://tizen.org/privilege/internal/default/partner
70                 /// </privilege>
71                 /// <param name="pid">The target process pid/tids.</param>
72                 /// <param name="level">The boosting level for the target process (pid/tids).</param>
73                 [EditorBrowsable(EditorBrowsableState.Never)]
74                 public static void ResourceGetCpuBoostingLevel (ResourcePidInfo pid, out CpuBoostingLevelInfo level)
75                 {
76                         ResourceError ret = Interop.Resource.ResourceGetCpuBoostingLevel(pid, out level);
77                         if (ret != ResourceError.None) {
78                                 Log.Error(ResourceErrorFactory.LogTag, "Interop failed to get cpu boosting");
79                                 ResourceErrorFactory.ThrowException(ret);
80                         }
81
82                         if (level.TidLevel == IntPtr.Zero) {
83                                 Log.Error(ResourceErrorFactory.LogTag, "TidLevel cannot be zero");
84                                 ResourceErrorFactory.ThrowException(ResourceError.InvalidParameter);
85                         }
86                 }
87
88                 /// <summary>
89                 /// Set cpu resource inheritance from the source tid to the destination process (pid/tids).
90         /// </summary>
91                 /// <privilege>
92                 /// http://tizen.org/privilege/internal/default/partner
93                 /// </privilege>
94                 /// <param name="sourceTid">The caller thread tid.</param>
95                 /// <param name="destProcess">The name of destination process.</param>
96                 /// <param name="timeoutMsec">The timeout in milliceconds.</param>
97                 [EditorBrowsable(EditorBrowsableState.Never)]
98                 public static void ResourceSetCpuInheritance (int sourceTid, string destProcess, int timeoutMsec)
99                 {
100                         ResourceError ret = Interop.Resource.ResourceSetCpuInheritance(sourceTid, destProcess, timeoutMsec);
101                         if (ret != ResourceError.None) {
102                                 Log.Error(ResourceErrorFactory.LogTag, "Interop failed to set inheritance");
103                                 ResourceErrorFactory.ThrowException(ret);
104                         }
105                 }
106
107                 /// <summary>
108                 /// Clear cpu resource inheritance from the source tid to the destination process (pid/tids).
109         /// </summary>
110                 /// <privilege>
111                 /// http://tizen.org/privilege/internal/default/partner
112                 /// </privilege>
113                 /// <param name="sourceTid">The caller thread tid.</param>
114                 /// <param name="destProcess">The name of destination process.</param>
115                 [EditorBrowsable(EditorBrowsableState.Never)]
116                 public static void ResourceClearCpuInheritance (int sourceTid, string destProcess)
117                 {
118                         ResourceError ret = Interop.Resource.ResourceClearCpuInheritance(sourceTid, destProcess);
119                         if (ret != ResourceError.None) {
120                                 Log.Error(ResourceErrorFactory.LogTag, "Interop failed to clear inheritance");
121                                 ResourceErrorFactory.ThrowException(ret);
122                         }
123                 }
124
125                 /// <summary>
126                 /// Register a destination process (pid/tids) for cpu resource inheritance.
127         /// </summary>
128                 /// <privilege>
129                 /// http://tizen.org/privilege/internal/default/partner
130                 /// </privilege>
131                 /// <param name="destProcess">The name of destination process.</param>
132                 /// <param name="pid">The destination process pid/tids.</param>
133                 [EditorBrowsable(EditorBrowsableState.Never)]
134                 public static void ResourceRegisterCpuInheritanceDestination (string destProcess, ResourcePidInfo pid)
135                 {
136                         ResourceError ret = Interop.Resource.ResourceRegisterCpuInheritanceDestination(destProcess, pid);
137                         if (ret != ResourceError.None) {
138                                 Log.Error(ResourceErrorFactory.LogTag, "Interop failed to register destination");
139                                 ResourceErrorFactory.ThrowException(ret);
140                         }
141                 }
142
143                 /// <summary>
144                 /// Unregister a destination process (pid/tids) for cpu resource inheritance.
145         /// </summary>
146                 /// <privilege>
147                 /// http://tizen.org/privilege/internal/default/partner
148                 /// </privilege>
149                 /// <param name="destProcess">The name of destination process.</param>
150                 [EditorBrowsable(EditorBrowsableState.Never)]
151                 public static void ResourceUnregisterCpuInheritanceDestination (string destProcess)
152                 {
153                         ResourceError ret = Interop.Resource.ResourceUnregisterCpuInheritanceDestination(destProcess);
154                         if (ret != ResourceError.None) {
155                                 Log.Error(ResourceErrorFactory.LogTag, "Interop failed to unregister destination");
156                                 ResourceErrorFactory.ThrowException(ret);
157                         }
158                 }
159         }
160 }