resetting manifest requested domain to floor
[platform/core/system/libslp-sysman.git] / sysman.h
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
18 #ifndef ___SYSMAN___
19 #define ___SYSMAN___
20
21 #include <stdlib.h>
22 #include <string.h>
23 #include <sys/time.h>
24 #include <sys/types.h>
25 #include "sysman_managed.h"
26
27 #ifndef DEPRECATED
28 #define DEPRECATED __attribute__((deprecated))
29 #endif
30
31 /** 
32  * @file        sysman.h
33  * @ingroup     libsysman System Manager library
34  * @brief       This library provides APIs related with memory, performance, processes, and so on.
35  * @author      SLP2.0
36  * @date        2010-01-24
37  * @version     0.1
38  */
39
40 /**
41  * @defgroup libsysman System Manager library
42  * @ingroup SYSTEM_FRAMEWORK
43  * @brief System manager library
44  *
45  * This library provides APIs related with memory, performance, processes, and so on.
46  * <br> Please use libslp-sysman-dev debian package and sysman.pc file for development.
47  * <br> And include sysman.h file at your source codes as following.
48  * @addtogroup libsysman System Manager library
49  * @{
50  */
51
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56 /**
57  * @breif Policy for low memory
58  */
59         enum mem_policy {
60                 OOM_LIKELY,     /**< For miscellaneous applications */
61                 OOM_IGNORE      /**< For daemons */
62         };
63
64 /* sysman_util */
65
66 /**
67  * @fn int sysman_get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size)
68  * @brief This API is used to get the file name of command line of the process from the proc fs.
69  *              Caller process MUST allocate enough memory for the cmdline parameter. \n
70  *              Its size should be assigned to cmdline_size. \n
71  *              Internally it reads the 1st argument of /proc/{pid}/cmdline and copies it to cmdline.
72  * @param[in] pid pid of the process that you want to get the file name of command line
73  * @param[out] cmdline command line of the process that you want to get the file name <br>
74  *                      Callers should allocate memory to this parameter before calling this function.
75  *                      The allocated memory size must be large enough to store the file name.
76  *                      The result will include the terminating null byte('\0') at the end of the string.
77  * @return 0 on success, -1 if failed. If the size of cmdline is smaller than the result,
78  *                      it will return -1 and errno will be set as EOVERFLOW.
79  */
80         int sysman_get_cmdline_name(pid_t pid, char *cmdline,
81                                     size_t cmdline_size);
82
83 /**
84  * @fn char *sysman_get_apppath(pid_t pid, char *app_path, size_t app_path_size)
85  * @brief This API is used to get the execution path of the process specified by the pid parameter.\n
86  *              Caller process MUST allocate enough memory for the app_path parameter. \n
87  *              Its size should be assigned to app_path_size. \n
88  *              Internally it reads a link of /proc/{pid}/exe and copies the path to app_path. 
89  * @param[in] pid pid of the process that you want to get the executed path
90  * @param[out] app_path the executed file path of the process <br>
91  *                      Callers should allocate memory to this parameter before calling this function.
92  *                      The allocated memory size must be large enough to store the executed file path.
93  *                      The result will include the terminating null byte('\0') at the end of the string.
94  * @param[in] app_path_size allocated memory size of char *app_path 
95  * @return 0 on success, -1 if failed. If the size of app_path is smaller than the result,
96  *                      it will return -1 and errno will be set as EOVERFLOW.
97  */
98         int sysman_get_apppath(pid_t pid, char *app_path, size_t app_path_size);
99
100 /* sysconf */
101
102 /**
103  * @fn int sysconf_set_mempolicy(enum mem_policy mempol)
104  * @brief This API is used to set the policy of the caller process when the phone has low available memory.
105  * @param[in] mempol oom adjust value which you want to set
106  * @return 0 on success, -1 if failed.
107  * @see sysconf_set_mempolicy_bypid()
108  */
109         int sysconf_set_mempolicy(enum mem_policy mempol);
110
111 /**
112  * @fn int sysconf_set_mempolicy_bypid(pid_t pid, enum mem_policy mempol)
113  * @brief This API is used to set the policy of the process when the phone has low available memory.
114  * @param[in] pid process id which you want to set
115  * @param[in] mempol oom adjust value which you want to set
116  * @return 0 on success, -1 if failed.
117  */
118         int sysconf_set_mempolicy_bypid(pid_t pid, enum mem_policy mempol);
119
120 /**
121  * @fn int sysconf_set_permanent(void)
122  * @brief This API is used to set itself as a permanent process.\n
123  *              If the permanent process is dead, system server will relaunch the process automatically.
124  * @return 0 on success, -1 if failed.
125  * @see sysconf_set_permanent_bypid()
126  * @par Example
127  * @code
128  *      ...
129  *      ret = sysconf_set_permanent();
130  *      if( ret < 0 )
131  *              printf("Fail to set a process as permanent\n");
132  *      ...
133  * @endcode
134  */
135         int sysconf_set_permanent(void);
136
137 /**
138  * @fn int sysconf_set_permanent_bypid(pid_t pid)
139  * @brief This API is used to set a process which has pid as a permanent process.\n
140  *              If the permanent process is dead, system server will relaunch the process automatically.
141  * @return 0 on success, -1 if failed.
142  * @see sysconf_set_permanent()
143  * @par Example
144  * @code
145  *      ...
146  *      ret = sysconf_set_permanent_bypid(pid);
147  *      if( ret < 0 )
148  *              printf("Fail to set a process(%d) as permanent\n",pid);
149  *      ...
150  * @endcode
151  */
152         int sysconf_set_permanent_bypid(pid_t pid);
153
154 /**
155  * @fn int sysconf_set_vip(pid_t pid)
156  * @brief This API is used to set a process which has pid as Very Important Process(VIP) .\n
157  *              If the VIP process is dead, restarter program will be run. \n
158  *              Restarter program may kill almost processes and run rc.local scripts again.
159  * @param[in] pid process id to be vip
160  * @return 0 on success, -1 if failed.
161  * @see sysconf_is_vip
162  * @par Example
163  * @code
164  *      ...
165  *      ret = sysconf_set_vip(pid);
166  *      if( ret < 0 )
167  *              printf("Fail to set a process(%d) as VIP\n",pid);
168  *      ...
169  * @endcode
170  */
171         int sysconf_set_vip(pid_t pid);
172
173 /**
174  * @fn int sysconf_is_vip(pid_t pid)
175  * @brief This API is used to verify that process which has pid is Very Important Process(VIP) or not.
176  * @param[in] pid process id to be vip
177  * @return 1 on success, 0 if failed.
178  * @see sysconf_set_vip
179  * @par Example
180  * @code
181  *      ...
182  *      ret = sysconf_is_vip(pid);
183  *      if(ret)
184  *              printf("process(%d) is Very Important Process\n",pid);
185  *      ...
186  * @endcode
187  */
188         int sysconf_is_vip(pid_t pid);
189
190         int sysman_set_timezone(char *tzpath_str);
191
192         int sysman_call_predef_action(const char *type, int num, ...);
193
194         int sysman_inform_foregrd(void);
195         int sysman_inform_backgrd(void);
196         int sysman_inform_active(pid_t pid);
197         int sysman_inform_inactive(pid_t pid);
198
199         int sysman_request_poweroff(void);
200         int sysman_request_entersleep(void);
201         int sysman_request_leavesleep(void);
202         int sysman_request_reboot(void);
203
204         int sysman_request_set_cpu_max_frequency(int val);
205         int sysman_request_set_cpu_min_frequency(int val);
206
207         int sysman_release_cpu_max_frequency(void);
208         int sysman_release_cpu_min_frequency(void);
209
210 /**
211  * @}
212  */
213
214 #ifdef __cplusplus
215 }
216 #endif
217 #endif                          /* ___SYSMAN___ */