upload tizen1.0 source
[framework/system/libslp-pm.git] / pmapi.h
1 /*
2  *  libslp-pm
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 __POWER_MANAGER_LIBRARY_H__
24 #define __POWER_MANAGER_LIBRARY_H__
25
26 /**
27  * @defgroup POWER_MANAGER Power manager library 
28  * @ingroup SYSTEM_FRAMEWORK
29  * @brief Power manager control API library
30  *
31  * @open
32  * @addtogroup POWER_MANAGER
33  * @{
34  * This library provides APIs to lock/unlock the power state of the system.
35  * Power Manager controls the power state as following.
36  * @image html power-manager-fsm.bmp "Fig. 1 State Diagram of Power Manager
37  * <br> If there is no user input for a certain time, PM changes the power state 
38  *  that has lower power consumption. <br> When the user input or other system interrupt occurs,
39  *  PM rolls the state back immediately.<br> If applications or other frameworks want to stop 
40  *  enter the specific state of power manager, use pm_lock_state() and pm_unlock_state()
41  *  <br> Be careful! A caller process should unlock the power state after locking without timeout.
42  *  <br> If you want to stay the LCD normal state, you can use 
43  *  @li @c pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0)
44  *  <p><br> After finishing your job with locking, call 
45  *  @li @c pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER)
46  *  <p><br> Additionally, you can use the timeout for lock the state. 
47  *  If timeout is set, caller process doesn't need to call the unlock API. 
48  *  But the process should be alive.
49  *  If caller process is dead, lock condition would be drop by the power manager.
50  *  <p><br> Here is sample codes  
51  * @code
52
53 #include "pmapi.h"
54 int main(int argc, char** argv)
55 {
56         int result;
57
58         printf("=========================================\n");
59         printf("=  Lock / Unlock to transit a power manager state   =\n");
60         printf("=========================================\n");
61
62         result = pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW,0); //Lock on lcd-off until explicit unlock.
63         if (!result)
64                 printf("SUCCESS");
65         else
66                 printf("FAILED");
67
68         // DO something.
69
70         result = pm_unlock_state(LCD_NORMAL,PM_RESET_TIMER); //Unlock
71         if (!result)
72                 printf("SUCCESS");
73         else
74                 printf("FAILED");
75
76         result = pm_lock_state(LCD_OFF,STAY_CUR_STATE, 5000); // Lock on lcd-off during 5 seconds.
77         if (!result)
78                 printf("SUCCESS");
79         else
80                 printf("FAILED");
81
82         // DO something.
83         sleep(10);
84         
85         return 0;
86 }
87  * @endcode 
88  *
89  */
90
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
94
95 #define LCD_NORMAL      0x1   /**< NORMAL state */
96 #define LCD_DIM         0x2  /**< LCD dimming state */
97 #define LCD_OFF         0x4  /**< LCD off state */
98 #define SUSPEND         0x8  /**< Sleep state */
99 #define POWER_OFF       0x16  /**< Sleep state */
100 #define SETALL (LCD_DIM | LCD_OFF | LCD_NORMAL) /*< select all state - not supported yet */
101
102 /* parameters for pm_lock_state() */
103 #define GOTO_STATE_NOW  0x1
104 #define STAY_CUR_STATE  0x0
105
106 /* paramters for pm_unlcok_state() - details are described at 162 line */
107 #define PM_SLEEP_MARGIN 0x0     /**< keep guard time for unlock */
108 #define PM_RESET_TIMER  0x1     /**< reset timer for unlock */
109 #define PM_KEEP_TIMER   0x2     /**< keep timer for unlock */
110
111 /**
112  * @fn int pm_lock_state        (unsigned int state, 
113  *                                                       unsigned int flag, 
114  *                                                       unsigned int timeout);
115  * @brief This API is used to lock a particular power-state as the current power-state.\n
116  *              The parameter state specifies the power state which you want to lock LCD_NORMAL, LCD_DIM, LCD_OFF. \n
117  *              The second parameter Flag is set if you want to go the requested lock state directly.\n
118  *              The third parameter timeout specifies lock-timeout in milliseconds. 
119  *              If the value 0 is selected, the power state remains locked until pm_unlock_state is called.
120  * @param[in] state target power state which you want to lock - LCD_NORMAL, LCD_DIM, LCD_OFF
121  * @param[in] flag set if you want to go the lock state directly - GOTO_STATE_NOW, STAY_CUR_STATE
122  * @param[in] timeout lock-timeout in miliseconds. 
123  *                                        0 is always lock until calling pm_unlock_state
124  *                                        If you call this function with same state in duplicate, 
125  *                                        only last one will be processed and others are ignored.
126  * @return 0 on success, -1 if failed
127  * @see pm_unlock_state(), pm_change_state()
128  * @par Example
129  * @code
130  *      ...
131  *      // Lock current state as LCD_NORMAL 
132  *      result = pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, SET_TIMEOUT); 
133  *      if( result < 0 )
134  *              printf("[ERROR] return value result =%d, \n",result);
135  *      else
136  *              printf("[SUCCESS]return value result =%d \n",result);
137  *      ...
138  * @endcode 
139  */
140         int pm_lock_state(unsigned int, unsigned int, unsigned int);
141
142 /**
143  * @fn int pm_unlock_state      (unsigned int state,
144  *                                                       unsigned int flag)
145  * @brief This API is used to Unlock the power state. \n
146  *              The parameter state specifies the power state which you want to unlock .
147  *              Some examples are LCD_NORMAL, LCD_DIM, LCD_OFF.\n
148  *              The second parameter flag is set if you want to go to the requested state directly after unlocking. (NOT SUPPOERTED YET) 
149  *              This is valid only when the current state transition was blocked by the locking and this function call releases the blocking.
150  * @param[in] state target power state which you want to unlock
151  * @param[in] flag set timer which is going to the next state after unlocking
152  *              PM_SLEEP_MARGIN - If the current status is lcd off, pm reset timer to 5 second. If the current status is not lcd off, pm pm uses the existing timer.
153  *              PM_RESET_TIMER - Power-manager resets timer. (lcd normal : reset timer to predfined value which is set in setting module,  lcd dim or off : reset timer to 5 seconds)
154  *              PM_KEEP_TIMER - Power-manager uses the existing timer (if timer is already expired, pm changes the status) <br>
155  * @return 0 on success, -1 if failed
156  * @see pn_lock_state(), pm_change_state()
157  * @par Example
158  * @code
159  *      ...
160  *      //Un-lock NORMAL state so that power state change can occur with system-events 
161  *      result = pm_unlock_state(LCD_NORMAL,PM_RESET_TIMER); 
162  *      if( result < 0 ) 
163  *              printf("[ERROR] return value result =%d, \n",result);
164  *      else
165  *              printf("[SUCCESS]return value result =%d \n",result);
166  *      ...
167  * @endcode
168  */
169         int pm_unlock_state(unsigned int, unsigned int);
170
171 /**
172  * @fn int pm_change_state(unsigned int state);
173  * @brief This API is used to change the power manager state by force.
174  * @param[in] state power manager state - LCD_NORMAL, LCD_DIM, LCD_OFF
175  * @return 0 on success, -1 if failed.
176  * @see pm_lock_state(), pm_unlock_state()
177  * @pat Example
178  * @code
179  *      ...
180  *      result = pm_change_state(LCD_OFF);
181  *      if( result < 0 ) 
182  *              printf("[ERROR] return value result =%d, \n",result);
183  *      else
184  *              printf("[SUCCESS]return value result =%d \n",result);
185  *      ...
186  * @endcode
187  */
188         int pm_change_state(unsigned int);
189
190 /**
191  * @}
192  */
193
194 #ifdef __cplusplus
195 }
196 #endif
197 #endif                          /* __POWER_MANAGER_LIBRARY_H__ */