Bug 783551 - Get tooltool running on the b2g on OS X builds. r=respindola
[gecko.git] / hal / Hal.h
blob84d96241a456e2136830e14376f9aacc25d1a29d
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et ft=cpp : */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_Hal_h
8 #define mozilla_Hal_h
10 #include "mozilla/hal_sandbox/PHal.h"
11 #include "base/basictypes.h"
12 #include "mozilla/Types.h"
13 #include "nsTArray.h"
14 #include "prlog.h"
15 #include "mozilla/dom/battery/Types.h"
16 #include "mozilla/dom/network/Types.h"
17 #include "mozilla/dom/power/Types.h"
18 #include "mozilla/hal_sandbox/PHal.h"
19 #include "mozilla/dom/ScreenOrientation.h"
22 * Hal.h contains the public Hal API.
24 * By default, this file defines its functions in the hal namespace, but if
25 * MOZ_HAL_NAMESPACE is defined, we'll define our functions in that namespace.
27 * This is used by HalImpl.h and HalSandbox.h, which define copies of all the
28 * functions here in the hal_impl and hal_sandbox namespaces.
31 class nsIDOMWindow;
33 #ifndef MOZ_HAL_NAMESPACE
34 # define MOZ_HAL_NAMESPACE hal
35 # define MOZ_DEFINED_HAL_NAMESPACE 1
36 #endif
38 namespace mozilla {
40 template <class T>
41 class Observer;
43 namespace hal {
45 typedef Observer<void_t> AlarmObserver;
46 typedef Observer<ScreenConfiguration> ScreenConfigurationObserver;
48 class WindowIdentifier;
50 extern PRLogModuleInfo *sHalLog;
51 #define HAL_LOG(msg) PR_LOG(mozilla::hal::sHalLog, PR_LOG_DEBUG, msg)
53 } // namespace hal
55 namespace MOZ_HAL_NAMESPACE {
57 /**
58 * Turn the default vibrator device on/off per the pattern specified
59 * by |pattern|. Each element in the pattern is the number of
60 * milliseconds to turn the vibrator on or off. The first element in
61 * |pattern| is an "on" element, the next is "off", and so on.
63 * If |pattern| is empty, any in-progress vibration is canceled.
65 * Only an active window within an active tab may call Vibrate; calls
66 * from inactive windows and windows on inactive tabs do nothing.
68 * If you're calling hal::Vibrate from the outside world, pass an
69 * nsIDOMWindow* in place of the WindowIdentifier parameter.
70 * The method with WindowIdentifier will be called automatically.
72 void Vibrate(const nsTArray<uint32_t>& pattern,
73 nsIDOMWindow* aWindow);
74 void Vibrate(const nsTArray<uint32_t>& pattern,
75 const hal::WindowIdentifier &id);
77 /**
78 * Cancel a vibration started by the content window identified by
79 * WindowIdentifier.
81 * If the window was the last window to start a vibration, the
82 * cancellation request will go through even if the window is not
83 * active.
85 * As with hal::Vibrate(), if you're calling hal::CancelVibrate from the outside
86 * world, pass an nsIDOMWindow*. The method with WindowIdentifier will be called
87 * automatically.
89 void CancelVibrate(nsIDOMWindow* aWindow);
90 void CancelVibrate(const hal::WindowIdentifier &id);
92 /**
93 * Inform the battery backend there is a new battery observer.
94 * @param aBatteryObserver The observer that should be added.
96 void RegisterBatteryObserver(BatteryObserver* aBatteryObserver);
98 /**
99 * Inform the battery backend a battery observer unregistered.
100 * @param aBatteryObserver The observer that should be removed.
102 void UnregisterBatteryObserver(BatteryObserver* aBatteryObserver);
105 * Returns the current battery information.
107 void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo);
110 * Notify of a change in the battery state.
111 * @param aBatteryInfo The new battery information.
113 void NotifyBatteryChange(const hal::BatteryInformation& aBatteryInfo);
116 * Determine whether the device's screen is currently enabled.
118 bool GetScreenEnabled();
121 * Enable or disable the device's screen.
123 * Note that it may take a few seconds for the screen to turn on or off.
125 void SetScreenEnabled(bool enabled);
128 * Get the brightness of the device's screen's backlight, on a scale from 0
129 * (very dim) to 1 (full blast).
131 * If the display is currently disabled, this returns the brightness the
132 * backlight will have when the display is re-enabled.
134 double GetScreenBrightness();
137 * Set the brightness of the device's screen's backlight, on a scale from 0
138 * (very dimm) to 1 (full blast). Values larger than 1 are treated like 1, and
139 * values smaller than 0 are treated like 0.
141 * Note that we may reduce the resolution of the given brightness value before
142 * sending it to the screen. Therefore if you call SetScreenBrightness(x)
143 * followed by GetScreenBrightness(), the value returned by
144 * GetScreenBrightness() may not be exactly x.
146 void SetScreenBrightness(double brightness);
149 * Determine whether the device is allowed to sleep.
151 bool GetCpuSleepAllowed();
154 * Set whether the device is allowed to suspend automatically after
155 * the screen is disabled.
157 void SetCpuSleepAllowed(bool allowed);
160 * Set the value of a light to a particular color, with a specific flash pattern.
161 * light specifices which light. See Hal.idl for the list of constants
162 * mode specifies user set or based on ambient light sensor
163 * flash specifies whether or how to flash the light
164 * flashOnMS and flashOffMS specify the pattern for XXX flash mode
165 * color specifies the color. If the light doesn't support color, the given color is
166 * transformed into a brightness, or just an on/off if that is all the light is capable of.
167 * returns true if successful and false if failed.
169 bool SetLight(hal::LightType light, const hal::LightConfiguration& aConfig);
171 * GET the value of a light returning a particular color, with a specific flash pattern.
172 * returns true if successful and false if failed.
174 bool GetLight(hal::LightType light, hal::LightConfiguration* aConfig);
178 * Register an observer for the sensor of given type.
180 * The observer will receive data whenever the data generated by the
181 * sensor is avaiable.
183 void RegisterSensorObserver(hal::SensorType aSensor,
184 hal::ISensorObserver *aObserver);
187 * Unregister an observer for the sensor of given type.
189 void UnregisterSensorObserver(hal::SensorType aSensor,
190 hal::ISensorObserver *aObserver);
193 * Post a value generated by a sensor.
195 * This API is internal to hal; clients shouldn't call it directly.
197 void NotifySensorChange(const hal::SensorData &aSensorData);
200 * Enable sensor notifications from the backend
202 * This method is only visible from implementation of sensor manager.
203 * Rest of the system should not try this.
205 void EnableSensorNotifications(hal::SensorType aSensor);
208 * Disable sensor notifications from the backend
210 * This method is only visible from implementation of sensor manager.
211 * Rest of the system should not try this.
213 void DisableSensorNotifications(hal::SensorType aSensor);
217 * Inform the network backend there is a new network observer.
218 * @param aNetworkObserver The observer that should be added.
220 void RegisterNetworkObserver(NetworkObserver* aNetworkObserver);
223 * Inform the network backend a network observer unregistered.
224 * @param aNetworkObserver The observer that should be removed.
226 void UnregisterNetworkObserver(NetworkObserver* aNetworkObserver);
229 * Returns the current network information.
231 void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo);
234 * Notify of a change in the network state.
235 * @param aNetworkInfo The new network information.
237 void NotifyNetworkChange(const hal::NetworkInformation& aNetworkInfo);
240 * Adjusting system clock.
241 * @param aDeltaMilliseconds The difference compared with current system clock.
243 void AdjustSystemClock(int32_t aDeltaMilliseconds);
246 * Set timezone
247 * @param aTimezoneSpec The definition can be found in
248 * http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
250 void SetTimezone(const nsCString& aTimezoneSpec);
253 * Reboot the device.
255 void Reboot();
258 * Power off the device.
260 void PowerOff();
263 * Enable wake lock notifications from the backend.
265 * This method is only used by WakeLockObserversManager.
267 void EnableWakeLockNotifications();
270 * Disable wake lock notifications from the backend.
272 * This method is only used by WakeLockObserversManager.
274 void DisableWakeLockNotifications();
277 * Inform the wake lock backend there is a new wake lock observer.
278 * @param aWakeLockObserver The observer that should be added.
280 void RegisterWakeLockObserver(WakeLockObserver* aObserver);
283 * Inform the wake lock backend a wake lock observer unregistered.
284 * @param aWakeLockObserver The observer that should be removed.
286 void UnregisterWakeLockObserver(WakeLockObserver* aObserver);
289 * Adjust the internal wake lock counts.
290 * @param aTopic lock topic
291 * @param aLockAdjust to increase or decrease active locks
292 * @param aHiddenAdjust to increase or decrease hidden locks
294 void ModifyWakeLock(const nsAString &aTopic,
295 hal::WakeLockControl aLockAdjust,
296 hal::WakeLockControl aHiddenAdjust);
299 * Query the wake lock numbers of aTopic.
300 * @param aTopic lock topic
301 * @param aWakeLockInfo wake lock numbers
303 void GetWakeLockInfo(const nsAString &aTopic, hal::WakeLockInformation *aWakeLockInfo);
306 * Notify of a change in the wake lock state.
307 * @param aWakeLockInfo The new wake lock information.
309 void NotifyWakeLockChange(const hal::WakeLockInformation& aWakeLockInfo);
312 * Inform the backend there is a new screen configuration observer.
313 * @param aScreenConfigurationObserver The observer that should be added.
315 void RegisterScreenConfigurationObserver(hal::ScreenConfigurationObserver* aScreenConfigurationObserver);
318 * Inform the backend a screen configuration observer unregistered.
319 * @param aScreenConfigurationObserver The observer that should be removed.
321 void UnregisterScreenConfigurationObserver(hal::ScreenConfigurationObserver* aScreenConfigurationObserver);
324 * Returns the current screen configuration.
326 void GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration);
329 * Notify of a change in the screen configuration.
330 * @param aScreenConfiguration The new screen orientation.
332 void NotifyScreenConfigurationChange(const hal::ScreenConfiguration& aScreenConfiguration);
335 * Lock the screen orientation to the specific orientation.
336 * @return Whether the lock has been accepted.
338 bool LockScreenOrientation(const dom::ScreenOrientation& aOrientation);
341 * Unlock the screen orientation.
343 void UnlockScreenOrientation();
346 * Register an observer for the switch of given SwitchDevice.
348 * The observer will receive data whenever the data generated by the
349 * given switch.
351 void RegisterSwitchObserver(hal::SwitchDevice aDevice, hal::SwitchObserver *aSwitchObserver);
354 * Unregister an observer for the switch of given SwitchDevice.
356 void UnregisterSwitchObserver(hal::SwitchDevice aDevice, hal::SwitchObserver *aSwitchObserver);
359 * Notify the state of the switch.
361 * This API is internal to hal; clients shouldn't call it directly.
363 void NotifySwitchChange(const hal::SwitchEvent& aEvent);
366 * Get current switch information.
368 hal::SwitchState GetCurrentSwitchState(hal::SwitchDevice aDevice);
371 * Register an observer that is notified when a programmed alarm
372 * expires.
374 * Currently, there can only be 0 or 1 alarm observers.
376 bool RegisterTheOneAlarmObserver(hal::AlarmObserver* aObserver);
379 * Unregister the alarm observer. Doing so will implicitly cancel any
380 * programmed alarm.
382 void UnregisterTheOneAlarmObserver();
385 * Notify that the programmed alarm has expired.
387 * This API is internal to hal; clients shouldn't call it directly.
389 void NotifyAlarmFired();
392 * Program the real-time clock to expire at the time |aSeconds|,
393 * |aNanoseconds|. These specify a point in real time relative to the
394 * UNIX epoch. The alarm will fire at this time point even if the
395 * real-time clock is changed; that is, this alarm respects changes to
396 * the real-time clock. Return true iff the alarm was programmed.
398 * The alarm can be reprogrammed at any time.
400 * This API is currently only allowed to be used from non-sandboxed
401 * contexts.
403 bool SetAlarm(PRInt32 aSeconds, PRInt32 aNanoseconds);
406 * Set the priority of the given process.
408 * Exactly what this does will vary between platforms. On *nix we might give
409 * background processes higher nice values. On other platforms, we might
410 * ignore this call entirely.
412 void SetProcessPriority(int aPid, hal::ProcessPriority aPriority);
414 } // namespace MOZ_HAL_NAMESPACE
415 } // namespace mozilla
417 #ifdef MOZ_DEFINED_HAL_NAMESPACE
418 # undef MOZ_DEFINED_HAL_NAMESPACE
419 # undef MOZ_HAL_NAMESPACE
420 #endif
422 #endif // mozilla_Hal_h