Remove initscripts and add PIDFile to service file
[platform/core/system/power-manager.git] / util.h
1 /*
2  * power-manager
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16 */
17
18
19 /**
20  * @file        util.h
21  * @version     0.1
22  * @brief       Utilities header for Power manager
23  */
24 #ifndef __DEF_UTIL_H__
25 #define __DEF_UTIL_H__
26
27 /**
28  * @addtogroup POWER_MANAGER
29  * @{
30  */
31
32 /*
33  * @brief write the pid
34  *
35  * get a pid and write it to pidpath
36  *
37  * @param[in] pidpath pid file path
38  * @return 0 (always)
39  */
40 extern int writepid(char *pidpath);
41
42 /*
43  * @brief read the pid
44  *
45  * get a pid and write it to pidpath
46  *
47  * @param[in] pidpath pid file path
48  * @return  pid : success, -1 : failed
49  */
50 extern int readpid(char *pidpath);
51
52 /*
53  * @brief daemonize function 
54  *
55  * fork the process, kill the parent process 
56  * and replace all the standard fds to /dev/null.
57  *
58  * @return 0 : success, -1 : fork() error
59  */
60 extern int daemonize(void);
61
62 /**
63  * @brief  function to run a process
64  *
65  * fork the process, and run the other process if it is child.
66  *
67  * @return new process pid on success, -1 on error
68  */
69 extern int exec_process(char *name);
70
71 /**
72  * @brief  function to get the pkg name for AUL (Application Util Library)
73  *
74  * remove the path of exepath and make the "com.samsung.<exe_file_name>" string.
75  *
76  * @return new process pid on success, -1 on error
77  */
78 extern char *get_pkgname(char *exepath);
79
80 /*
81  * @brief logging function
82  *
83  * This is log wrapper
84  *
85  * @param[in] priority log pritority
86  * @param[in] fmt format string
87  */
88 extern void pm_log(int priority, char *fmt, ...);
89
90 #if defined(ENABLE_DLOG_OUT)
91 #  include <dlog.h>
92 /*
93  * @brief LOG_INFO wrapper
94  */
95 #  define LOGINFO(fmt, arg...) pm_log(DLOG_INFO, fmt, ## arg)
96
97 /*
98  * @brief LOG_ERR wrapper
99  */
100 #  define LOGERR(fmt, arg...) pm_log(DLOG_ERROR, fmt, ## arg)
101 #else
102 #  include <syslog.h>
103 #  define LOGINFO(fmt, arg...) pm_log(LOG_INFO, fmt, ## arg)
104 #  define LOGERR(fmt, arg...) pm_log(LOG_ERR, fmt, ## arg)
105 #endif
106
107 /**
108  * @}
109  */
110 #endif