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