Initialize Tizen 2.3
[framework/system/deviced.git] / src / deviced / dd-deviced.h
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
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 #ifndef __DD_DEVICED__
21 #define __DD_DEVICED__
22
23 #include <stdlib.h>
24 #include <string.h>
25 #include <sys/time.h>
26 #include <sys/types.h>
27 #include "dd-deviced-managed.h"
28
29 /**
30  * @file        dd-deviced.h
31  * @defgroup    CAPI_SYSTEM_DEVICED_UTIL_MODULE Util
32  * @ingroup     CAPI_SYSTEM_DEVICED
33  * @section CAPI_SYSTEM_DEVICED_UTIL_MODULE_HEADER Required Header
34  *   \#include <dd-deviced.h>
35  */
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 /**
42  * @addtogroup CAPI_SYSTEM_DEVICED_UTIL_MODULE
43  * @{
44  */
45
46 /**
47  * @brief Policy for low memory
48  */
49 enum mem_policy {
50         OOM_LIKELY,     /**< For miscellaneous applications */
51         OOM_IGNORE      /**< For daemons */
52 };
53
54 #define CRASH_TICKET_PATH               "/opt/usr/share/crash/ticket"
55 #define FORCED_DUMP_DIR_PATH            "/opt/usr/media/SLP_debug"
56 #define FORCED_DUMP_ZIP_PATH            "/opt/usr/media/SLP_debug/zip"
57
58 /**
59  * @brief Logs dump type
60  */
61 enum dump_log_type {
62         AP_DUMP = 0,    /**< Application logs dump */
63         CP_DUMP = 1,    /**< Modem logs dump */
64         ALL_DUMP = 2    /**< All logs dump - application and modem */
65 };
66
67 /* deviced_util */
68
69 /**
70  * @fn int deviced_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  * @param[in] cmdline_size
81  * @return 0 on success, -1 if failed.\n
82  *         If the size of cmdline is smaller than the result, it will return -1 and  \n
83  *         errno will be set as EOVERFLOW. \n
84  *         If the function cannot open /proc/%d/cmdline file then it will return -1 and \n
85  *         errno will be set as ESRCH.
86  */
87 int deviced_get_cmdline_name(pid_t pid, char *cmdline,
88                                     size_t cmdline_size);
89
90 /**
91  * @fn int deviced_get_apppath(pid_t pid, char *app_path, size_t app_path_size)
92  * @brief This API is used to get the execution path of the process specified by the pid parameter.\n
93  *              Caller process MUST allocate enough memory for the app_path parameter. \n
94  *              Its size should be assigned to app_path_size. \n
95  *              Internally it reads a link of /proc/{pid}/exe and copies the path to app_path.
96  * @param[in] pid pid of the process that you want to get the executed path
97  * @param[out] app_path the executed file path of the process <br>
98  *                      Callers should allocate memory to this parameter before calling this function.
99  *                      The allocated memory size must be large enough to store the executed file path.
100  *                      The result will include the terminating null byte('\0') at the end of the string.
101  * @param[in] app_path_size allocated memory size of char *app_path
102  * @return 0 on success, -1 if failed. \n
103  *         If the size of app_path is smaller than the result, it will return -1 and \n
104  *         errno will be set as EOVERFLOW.
105  */
106 int deviced_get_apppath(pid_t pid, char *app_path, size_t app_path_size);
107
108 /* sysconf */
109
110 /**
111  * @fn int deviced_conf_set_mempolicy(enum mem_policy mempol)
112  * @brief This API is used to set the policy of the current process when the phone has low available memory.
113  * @param[in] mempol oom adjust value which you want to set
114  * @return 0 on success, -1 if failed.
115  * @see deviced_conf_set_mempolicy_bypid()
116  * @retval -1 operation error
117  * @retval -EBADMSG - dbus error (in case of any error on the bus)
118  * @retval -EINVAL no mandatory parameters
119  * @retval -ESRCH incorrect sender process id
120  */
121 int deviced_conf_set_mempolicy(enum mem_policy mempol);
122
123 /**
124  * @fn int deviced_conf_set_mempolicy_bypid(pid_t pid, enum mem_policy mempol)
125  * @brief This API is used to set the policy of the given process when the phone has low available memory.
126  * @param[in] pid process id which you want to set
127  * @param[in] mempol oom adjust value which you want to set
128  * @return 0 on success, -1 if failed.
129  * @retval -1 operation error
130  * @retval -EBADMSG - dbus error (in case of any error on the bus)
131  * @retval -EINVAL no mandatory parameters
132  * @retval -ESRCH incorrect sender process id
133  */
134 int deviced_conf_set_mempolicy_bypid(pid_t pid, enum mem_policy mempol);
135
136 /**
137  * @fn int deviced_conf_set_permanent(void)
138  * @brief This API is used to set itself as a permanent process.\n
139  *              If the permanent process is dead, system server will relaunch the process automatically.
140  * @return 0 on success, -1 if failed.
141  * @see deviced_conf_set_permanent_bypid()
142  * @par Example
143  * @code
144  *  ...
145  *  ret = deviced_conf_set_permanent();
146  *  if( ret < 0 )
147  *      printf("Fail to set a process as permanent\n");
148  *  ...
149  * @endcode
150  */
151 int deviced_conf_set_permanent(void);
152
153 /**
154  * @fn int deviced_conf_set_permanent_bypid(pid_t pid)
155  * @brief This API is used to set a given process as permanent.\n
156  *       If the permanent process is dead, system server will relaunch the process automatically.
157  * @param[in] pid proces id
158  * @return 0 on success, -1 if failed.
159  * @see deviced_set_permanent()
160  * @par Example
161  * @code
162  *  ...
163  *  ret = deviced_conf_set_permanent_bypid(pid);
164  *  if( ret < 0 )
165  *      printf("Fail to set a process(%d) as permanent\n",pid);
166  *  ...
167  * @endcode
168  */
169 int deviced_conf_set_permanent_bypid(pid_t pid);
170
171 /**
172  * @fn int deviced_conf_set_vip(pid_t pid)
173  * @brief This API is used to set a process which has pid as Very Important Process(VIP) .\n
174  *              If the VIP process is dead, restarter program will be run. \n
175  *              Restarter program may kill almost processes and run rc.local scripts again.
176  * @param[in] pid process id to be vip
177  * @return 0 on success, -1 if failed.
178  * @see sysconf_is_vip
179  * @par Example
180  * @code
181  *      ...
182  *      ret = deviced_conf_set_vip(pid);
183  *      if( ret < 0 )
184  *              printf("Fail to set a process(%d) as VIP\n",pid);
185  *      ...
186  * @endcode
187  */
188 int deviced_conf_set_vip(pid_t pid);
189
190 /**
191  * @fn int deviced_conf_is_vip(pid_t pid)
192  * @brief This API is used to verify that process which has pid is Very Important Process(VIP) or not.
193  * @param[in] pid process id to be vip
194  * @return 1 if given process if vip process, otherwise 0 is returned.
195  * @see deviced_conf_set_vip
196  * @par Example
197  * @code
198  *      ...
199  *      ret = deviced_conf_is_vip(pid);
200  *      if(ret)
201  *              printf("process(%d) is Very Important Process\n",pid);
202  *      ...
203  * @endcode
204  */
205 int deviced_conf_is_vip(pid_t pid);
206
207 /**
208  * @fn int deviced_set_timezone(char *tzpath_str)
209  * @brief This API sets system timezone.
210  * @param[in] tzpath_str path to timezone definition file
211  * @return 0 on success, negative value if failed.
212  * @retval -1 operation error
213  * @retval -EBADMSG dbus error (in case of any error on the bus)
214  * @retval -EINVAL no mandatory parameters
215  * @retval -ESRCH incorrect sender process id
216  */
217 int deviced_set_timezone(char *tzpath_str);
218
219 /**
220  * @fn int deviced_call_predef_action(const char *type, int num, ...)
221  * @brief This API calls predefined systemd action.
222  *              Internally it send message through SYSTEM_NOTI_SOCKET_PATH (/tmp/sn) UNIX socket to systemd.
223  * @param[in] type systemd action type name
224  * @param[in] num input parameters count. num cannot exceed SYSTEM_NOTI_MAXARG (16).
225  * @param[in] ... action input parameters. List of the parameters depends on action type.
226  * @return 0 on success, -1 if failed.
227  *         If the action type is not set (is blank) or num > SYSTEM_NOTI_MAXARG it will return -1
228  *         and errno will be set as EINVAL.
229  */
230 int deviced_call_predef_action(const char *type, int num, ...);
231
232 /**
233  * @fn int deviced_inform_foregrd(void)
234  * @brief This API call notifies that current process is running in foreground.
235  * @return 0 or positive value on success and negative value if failed.
236  * @retval -1 operation error
237  * @retval -EBADMSG dbus error (in case of any error on the bus)
238  * @retval -EINVAL no mandatory parameters
239  * @retval -ESRCH incorrect sender process id
240  */
241 int deviced_inform_foregrd(void);
242
243 /**
244  * @fn int deviced_inform_backgrd(void)
245  * @brief This API call notifies that current process is running in background.
246  * @return 0 or positive value on success and negative value if failed.
247  * @retval -1 operation error
248  * @retval -EBADMSG dbus error (in case of any error on the bus)
249  * @retval -EINVAL no mandatory parameters
250  * @retval -ESRCH incorrect sender process id
251  */
252 int deviced_inform_backgrd(void);
253
254 /**
255  * @fn int deviced_inform_active(pid_t pid)
256  * @brief This API call notifies deviced daemon that given process (pid) is active.
257  * @param[in] pid process pid
258  * @return 0 or positive value on success and negative value if failed.
259  * @retval -1 operation error
260  * @retval -EBADMSG dbus error (in case of any error on the bus)
261  * @retval -EINVAL no mandatory parameters
262  * @retval -ESRCH incorrect sender process id
263  */
264 int deviced_inform_active(pid_t pid);
265
266 /**
267  * @fn int deviced_inform_active(pid_t pid)
268  * @brief This API call notifies deviced daemon that given process (pid) is inactive.
269  * @param[in] pid process pid
270  * @return 0 or positive value on success and negative value if failed.
271  * @retval -1 operation error
272  * @retval -EBADMSG dbus error (in case of any error on the bus)
273  * @retval -EINVAL no mandatory parameters
274  * @retval -ESRCH incorrect sender process id
275  */
276 int deviced_inform_inactive(pid_t pid);
277
278 /**
279  * @fn int deviced_request_poweroff(void)
280  * @brief This API call requests deviced daemon to launch "system poweroff popup".
281  * @return 0 or positive value on success and negative value if failed.
282  * @retval -1 operation error
283  * @retval -EBADMSG dbus error (in case of any error on the bus)
284  * @retval -EINVAL no mandatory parameters
285  * @retval -ESRCH incorrect sender process id
286  */
287 int deviced_request_poweroff(void);
288
289 /**
290  * @fn deviced_request_entersleep(void)
291  * @brief This API call requests deviced daemon to enter system into sleep mode.
292  * @return 0 or positive value on success and negative value if failed.
293  * @retval -EBADMSG dbus error (in case of any error on the bus)
294  * @retval -EINVAL no mandatory parameters
295  * @retval -ESRCH incorrect sender process id
296  */
297 int deviced_request_entersleep(void);
298
299 /**
300  * @fn int deviced_request_leavesleep(void)
301  * @brief This API calls requests deviced daemon to leave by system "sleep" mode and enter into "normal" mode.
302  * @return 0 or positive value on success and negative value if failed.
303  * @retval -EBADMSG dbus error (in case of any error on the bus)
304  * @retval -EINVAL no mandatory parameters
305  * @retval -ESRCH incorrect sender process id
306  */
307 int deviced_request_leavesleep(void);
308
309 /**
310  * @fn int deviced_request_reboot(void)
311  * @brief This API call requests deviced daemon to initiate system reboot.
312  * @return 0 on success and negative value if failed.
313  * @retval -EBADMSG dbus error (in case of any error on the bus)
314  * @retval -EINVAL no mandatory parameters
315  * @retval -ESRCH incorrect sender process id
316  */
317 int deviced_request_reboot(void);
318
319 /**
320  * @fn int deviced_request_set_cpu_max_frequency(int val)
321  * @brief This API call requests deviced daemon to set maximum CPU frequency.
322  * @param[in] val maximum CPU frequency to be set.
323  * @return 0 or positive value on success and negative value if failed.
324  * @retval -1 operation error
325  * @retval -EBADMSG - dbus error (in case of any error on the bus)
326  */
327 int deviced_request_set_cpu_max_frequency(int val);
328
329 /**
330  * @fn int deviced_request_set_cpu_min_frequency(int val)
331  * @brief This API call requests deviced daemon to set minimum CPU frequency.
332  * @param[in] val minimum CPU frequency to be set
333  * @return 0 or positive value on success and negative value if failed.
334  * @retval -1 operation error
335  * @retval -EBADMSG dbus error (in case of any error on the bus)
336  */
337 int deviced_request_set_cpu_min_frequency(int val);
338
339 /**
340  * @fn int deviced_release_cpu_max_frequency(void)
341  * @brief This API call releases limit of maximum CPU frequency set by deviced_request_set_cpu_max_frequency() API.
342  * @return 0 or positive value on success and negative value if failed.
343  * @retval -1 operation error
344  * @retval -EBADMSG dbus error (in case of any error on the bus)
345  */
346 int deviced_release_cpu_max_frequency(void);
347
348 /**
349  * @fn int deviced_release_cpu_min_frequency(void)
350  * @brief This API calls releases limit of minimum CPU frequency set by deviced_request_set_cpu_min_frequency() API.
351  * @return 0 or positive value on success and negative value if failed.
352  * @retval -1 operation error
353  * @retval -EBADMSG dbus error (in case of any error on the bus)
354  */
355 int deviced_release_cpu_min_frequency(void);
356
357 /**
358  * @fn int deviced_request_set_factory_mode(int val)
359  * @brief This API call requests systemd daemon to enter system into factory mode.
360  * @param[in] val factory mode level.\n
361  *        0 - "off" factory mode\n
362  *        1 - "on" factory mode.
363  * @return 0 or positive value on success and negative value if failed.
364  * @retval -1 operation error
365  * @retval -EBADMSG dbus error (in case of any error on the bus)
366  * @retval -EINVAL no mandatory parameters
367  * @retval -ESRCH incorrect sender process id
368  */
369 int deviced_request_set_factory_mode(int val);
370
371 /**
372  * @fn int deviced_request_dump_log(int type)
373  * @brief This API call force dumps all application, modem or application + modem logs.
374  *   - if type is equal AP_DUMP application log dump will be created.
375  *   - if type is equal CP_DUMP modem logs dump  will be created
376  *   - if dump type is equal ALL_DUMP application and modem logs dump  will be created
377  * @param[in] type dump type.
378  * @return 0 or positive value on success and negative value if failed.
379  * @retval -1 operation error
380  * @retval -EBADMSG dbus error (in case of any error on the bus)
381  * @see dump_log_type
382  */
383 int deviced_request_dump_log(int type);
384
385 /**
386  * @fn int deviced_request_delete_dump(char *ticket)
387  * @brief This API call removes all dump data for given ticket from /opt/usr/share/crash/ticket directory.
388  * @param[in] ticket ticket name.
389  * @return 1 on success and negative value if failed.
390  * @retval -1 operation error
391  * @retval -EBADMSG dbus error (in case of any error on the bus)
392  */
393 int deviced_request_delete_dump(char *ticket);
394
395 /**
396  * @}
397  */
398
399 #ifdef __cplusplus
400 }
401 #endif
402 #endif                          /* __DD_DEVICED__ */