Merge Tizen 2.0 dev to RSA
[framework/system/power-manager.git] / util.h
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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 /**
19  * @file        util.h
20  * @version     0.1
21  * @brief       Utilities header for Power manager
22  */
23 #ifndef __DEF_UTIL_H__
24 #define __DEF_UTIL_H__
25
26 /**
27  * @addtogroup POWER_MANAGER
28  * @{
29  */
30
31 /*
32  * @brief write the pid
33  *
34  * get a pid and write it to pidpath
35  *
36  * @param[in] pidpath pid file path
37  * @return 0 (always)
38  */
39 extern int writepid(char *pidpath);
40
41 /*
42  * @brief read the pid
43  *
44  * get a pid and write it to pidpath
45  *
46  * @param[in] pidpath pid file path
47  * @return  pid : success, -1 : failed
48  */
49 extern int readpid(char *pidpath);
50
51 /*
52  * @brief daemonize function 
53  *
54  * fork the process, kill the parent process 
55  * and replace all the standard fds to /dev/null.
56  *
57  * @return 0 : success, -1 : fork() error
58  */
59 extern int daemonize(void);
60
61 /**
62  * @brief  function to run a process
63  *
64  * fork the process, and run the other process if it is child.
65  *
66  * @return new process pid on success, -1 on error
67  */
68 extern int exec_process(char *name);
69
70 /**
71  * @brief  function to get the pkg name for AUL (Application Util Library)
72  *
73  * remove the path of exepath and make the "com.samsung.<exe_file_name>" string.
74  *
75  * @return new process pid on success, -1 on error
76  */
77 extern char *get_pkgname(char *exepath);
78
79 /*
80  * @brief logging function
81  *
82  * This is log wrapper
83  *
84  * @param[in] priority log pritority
85  * @param[in] fmt format string
86  */
87 extern void pm_log(int priority, char *fmt, ...);
88
89 #if defined(ENABLE_DLOG_OUT)
90 #  include <dlog.h>
91 /*
92  * @brief LOG_INFO wrapper
93  */
94 #  define LOGINFO(fmt, arg...) pm_log(DLOG_INFO, fmt, ## arg)
95
96 /*
97  * @brief LOG_ERR wrapper
98  */
99 #  define LOGERR(fmt, arg...) pm_log(DLOG_ERROR, fmt, ## arg)
100 #else
101 #  include <syslog.h>
102 #  define LOGINFO(fmt, arg...) pm_log(LOG_INFO, fmt, ## arg)
103 #  define LOGERR(fmt, arg...) pm_log(LOG_ERR, fmt, ## arg)
104 #endif
105
106 /**
107  * @}
108  */
109 #endif