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