LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DisplayStates.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2009-2012 Hewlett-Packard Development Company, L.P.
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 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef DISPLAYSTATES_H
23 #define DISPLAYSTATES_H
24 
25 #include "Common.h"
26 
27 #include "Timer.h"
28 #include "Event.h"
29 #include "Settings.h"
30 
31 // DisplayState: Different states of the display - each associated with a specific behavior
42 };
43 
44 // DisplayEvent: Events that could trigger a change in the display state
76 };
77 
83 };
84 
85 // forward declaration needed to use display manager
86 class DisplayManager;
87 
88 // DisplayStateBase: base class of a display state
89 // specifies functions that all display states need to implement
91  protected:
93 
94  public:
96 
97  virtual DisplayState state() const = 0;
98 
99  virtual void enter (DisplayState state, DisplayEvent displayEvent, sptr<Event> event = NULL) = 0;
100  virtual void leave (DisplayState state, DisplayEvent displayEvent, sptr<Event> event = NULL) = 0;
101 
102  virtual void handleEvent (DisplayEvent displayEvent, sptr<Event> event = NULL) = 0;
103 
104  virtual bool updateBrightness (int alsRegion);
105 
106  void changeDisplayState (DisplayState state, DisplayEvent displayEvent, sptr<Event> event = NULL);
107  void updateLockState (DisplayLockState, DisplayEvent displayEvent);
108 
109  bool isDisplayUnlocked();
110  bool isUSBCharging();
111  bool isOnCall();
112  bool isSliderOpen();
113  bool isDNAST();
114  bool isOnPuck();
115  bool isProximityActivated();
116  int getCurrentAlsRegion();
117  bool isBacklightOn();
118  bool isDisplayOn();
119  bool isTouchpanelOn();
120  bool isDemo();
121 
122  int dimTimeout();
123  int offTimeout();
124  int lockedOffTimeout();
125  int lastEvent();
126 
127  void updateLastEvent();
128  virtual void stopInactivityTimer();
129  virtual void startInactivityTimer();
130 
131  void displayOn(bool als);
132  void displayDim();
133  void displayOff();
134 
135  bool proximityOff();
136  bool proximityOn();
137  bool orientationSensorOn();
138  bool orientationSensorOff();
139  void enablePainting();
140  void disablePainting();
141 
142  void emitDisplayStateChange(int);
143 
144  bool postPenCancel (int id = 0);
145 };
146 
147 
148 // DisplayOff: device on, display off
149 // This will change out of the current state for the following events
150 // change to OnLocked when power key up, phonecall in
151 // change to On usb in, slider open
152 // change to nightstand when placed on puck
153 // all other events do not cause change in state
155  public:
156  DisplayState state() const { return DisplayStateOff; }
157 
158  void enter (DisplayState, DisplayEvent, sptr<Event> = NULL);
159  void leave (DisplayState, DisplayEvent, sptr<Event> = NULL);
160 
161  void handleEvent (DisplayEvent displayEvent, sptr<Event> event = NULL);
162 
163 };
164 
165 // DisplayOffOnCall: device on, in phonecall, proximity triggered, display off
166 // This will change out of the current state for the following events
167 // change to On - proxmity triggered
168 // all other events do not cause change in state
170  public:
173 
174  void enter (DisplayState, DisplayEvent, sptr<Event> = NULL);
175  void leave (DisplayState, DisplayEvent, sptr<Event> = NULL);
176 
177  void handleEvent (DisplayEvent displayEvent, sptr<Event> event = NULL);
178 
179 };
180 
181 
182 // DisplayOn: device on, display on, unlocked
183 // This will change out of the current state for the following events
184 // change to Off when power key up, quick inactivity fired
185 // change to daystand when placed on puck
186 // change to dim on inactivity
187 // all other events do not cause change in state
188 // incoming phonecall will turn on proximity sensor
189 // if state change was due to event, start slow inactivity timer
190 // if state change was due to direct call, start quick inactivity timer
191 // any change in als will cause brightness and core navi update
192 
193 class DisplayOn : public DisplayStateBase {
194  private:
195  Timer<DisplayOn> *m_timerUser;
196  Timer<DisplayOn> *m_timerInternal;
197 
198  void startUserInactivityTimer();
199  void startInternalInactivityTimer();
200  public:
201  DisplayOn();
202 
203  DisplayState state() const { return DisplayStateOn; }
204 
205  void enter (DisplayState, DisplayEvent, sptr<Event> = NULL);
206  void leave (DisplayState, DisplayEvent, sptr<Event> = NULL);
207 
208  void handleEvent (DisplayEvent displayEvent, sptr<Event> event = NULL);
209 
210  bool updateBrightness (int alsRegion);
211  bool timeoutUser();
212  bool timeoutInternal();
213  void stopInactivityTimer();
214  void startInactivityTimer();
215 };
216 
217 
218 // DisplayOnLocked: device on, display on, locked
219 // This will change out of the current state for the following events
220 // change to Off when power key up, inactivity fired
221 // change to DockMode when placed on puck
222 // change to On when USB plugged in, slider opened
223 // all other events do not cause change in state
224 // when state is entered, start inactivity timer
225 // any change in als will cause brightness and core navi update
226 
228  private:
229  Timer<DisplayOnLocked> *m_timer;
230 
231  public:
232  DisplayOnLocked();
233 
235 
236  void enter (DisplayState, DisplayEvent, sptr<Event> = NULL);
237  void leave (DisplayState, DisplayEvent, sptr<Event> = NULL);
238 
239  void handleEvent (DisplayEvent displayEvent, sptr<Event> event = NULL);
240 
241  bool updateBrightness (int alsRegion);
242  bool timeout();
243  void stopInactivityTimer();
244  void startInactivityTimer();
245 };
246 
247 // DisplayDim: device on, display dim, unlocked
248 // This will change out of the current state for the following events
249 // change to On when usb in, incoming phonecall, slider open
250 // change to Nightstand when on puck,
251 // change to Off when slider close, inactivity
252 // all other events do not cause change in state
253 // when state is entered, start inactivity timer
254 // als events are ignored
255 
256 class DisplayDim : public DisplayStateBase {
257  private:
258  Timer<DisplayDim> *m_timer;
259 
260  public:
261  DisplayDim();
262  DisplayState state() const { return DisplayStateDim; }
263 
264  void enter (DisplayState, DisplayEvent, sptr<Event> = NULL);
265  void leave (DisplayState, DisplayEvent, sptr<Event> = NULL);
266 
267  void handleEvent (DisplayEvent displayEvent, sptr<Event> event = NULL);
268  bool timeout();
269 
270  void stopInactivityTimer();
271  void startInactivityTimer();
272 };
273 
274 
275 // DisplayOnPuck: device on, display on, on the puck
276 // This will change out of the current state for the following events
277 // change to On when off the puck
278 // change to DockMode when power key up, slider close, low als
279 // all other events do not cause change in state
280 
282  private:
283  Timer<DisplayOnPuck> *m_timer;
284 
285  public:
286  DisplayOnPuck();
288 
289  void enter (DisplayState, DisplayEvent, sptr<Event> = NULL);
290  void leave (DisplayState, DisplayEvent, sptr<Event> = NULL);
291 
292  void handleEvent (DisplayEvent displayEvent, sptr<Event> event = NULL);
293 
294  bool updateBrightness (int alsRegion);
295  bool timeout();
296 
297  void stopInactivityTimer();
298  void startInactivityTimer();
299 };
300 
301 
302 // DisplayDockMode: device on, display dim, on the puck
303 // This will change out of the current state for the following events
304 // change to On when off the puck
305 // change to OnPuck when power key up, incoming phonecall, usb in
306 // all other events do not cause change in state
307 
309  public:
310  DisplayDockMode();
312 
313  void enter (DisplayState, DisplayEvent, sptr<Event> = NULL);
314  void leave (DisplayState, DisplayEvent, sptr<Event> = NULL);
315 
316  void handleEvent (DisplayEvent displayEvent, sptr<Event> event = NULL);
317 
318  bool timeoutExit();
319 
320  private:
321  Timer<DisplayDockMode> * m_timerExit;
322 
323 };
324 
325 // DisplayOffSuspended: device off, display off
326 // This will change out of the current state for the following events
327 // powerd sends a resume call
328 // all other events do not cause change in state
330  private:
331  DisplayState m_restoreState;
332  DisplayEvent m_restoreDisplayEvent;
333  sptr<Event> m_restoreEvent;
334 
335  public:
338 
339  void enter (DisplayState, DisplayEvent, sptr<Event> = NULL);
340  void leave (DisplayState, DisplayEvent, sptr<Event> = NULL);
341 
342  void handleEvent (DisplayEvent displayEvent, sptr<Event> event = NULL);
343 
344 };
345 
346 
347 #endif // DISPLAYSTATES_H