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/. */
10 #include "base/basictypes.h"
11 #include "base/platform_thread.h"
13 #include "mozilla/hal_sandbox/PHal.h"
14 #include "mozilla/HalBatteryInformation.h"
15 #include "mozilla/HalNetworkInformation.h"
16 #include "mozilla/HalScreenConfiguration.h"
17 #include "mozilla/HalWakeLockInformation.h"
18 #include "mozilla/HalTypes.h"
19 #include "mozilla/Types.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 nsPIDOMWindowInner
;
33 #ifndef MOZ_HAL_NAMESPACE
34 # define MOZ_HAL_NAMESPACE hal
35 # define MOZ_DEFINED_HAL_NAMESPACE 1
42 class WindowIdentifier
;
46 namespace MOZ_HAL_NAMESPACE
{
49 * Initializes the HAL. This must be called before any other HAL function.
54 * Shuts down the HAL. Besides freeing all the used resources this will check
55 * that all observers have been properly deregistered and assert if not.
60 * Turn the default vibrator device on/off per the pattern specified
61 * by |pattern|. Each element in the pattern is the number of
62 * milliseconds to turn the vibrator on or off. The first element in
63 * |pattern| is an "on" element, the next is "off", and so on.
65 * If |pattern| is empty, any in-progress vibration is canceled.
67 * Only an active window within an active tab may call Vibrate; calls
68 * from inactive windows and windows on inactive tabs do nothing.
70 * If you're calling hal::Vibrate from the outside world, pass an
71 * nsIDOMWindow* in place of the WindowIdentifier parameter.
72 * The method with WindowIdentifier will be called automatically.
74 void Vibrate(const nsTArray
<uint32_t>& pattern
, nsPIDOMWindowInner
* aWindow
);
75 void Vibrate(const nsTArray
<uint32_t>& pattern
, hal::WindowIdentifier
&& id
);
78 * Cancel a vibration started by the content window identified by
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
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
89 void CancelVibrate(nsPIDOMWindowInner
* aWindow
);
90 void CancelVibrate(hal::WindowIdentifier
&& id
);
92 #define MOZ_DEFINE_HAL_OBSERVER(name_) \
94 * Inform the backend there is a new |name_| observer. \
95 * @param aObserver The observer that should be added. \
97 void Register##name_##Observer(hal::name_##Observer* aObserver); \
99 * Inform the backend a |name_| observer unregistered. \
100 * @param aObserver The observer that should be removed. \
102 void Unregister##name_##Observer(hal::name_##Observer* aObserver);
104 MOZ_DEFINE_HAL_OBSERVER(Battery
);
107 * Returns the current battery information.
109 void GetCurrentBatteryInformation(hal::BatteryInformation
* aBatteryInfo
);
112 * Notify of a change in the battery state.
113 * @param aBatteryInfo The new battery information.
115 void NotifyBatteryChange(const hal::BatteryInformation
& aBatteryInfo
);
118 * Register an observer for the sensor of given type.
120 * The observer will receive data whenever the data generated by the
121 * sensor is avaiable.
123 void RegisterSensorObserver(hal::SensorType aSensor
,
124 hal::ISensorObserver
* aObserver
);
127 * Unregister an observer for the sensor of given type.
129 void UnregisterSensorObserver(hal::SensorType aSensor
,
130 hal::ISensorObserver
* aObserver
);
133 * Post a value generated by a sensor.
135 * This API is internal to hal; clients shouldn't call it directly.
137 void NotifySensorChange(const hal::SensorData
& aSensorData
);
140 * Enable sensor notifications from the backend
142 * This method is only visible from implementation of sensor manager.
143 * Rest of the system should not try this.
145 void EnableSensorNotifications(hal::SensorType aSensor
);
148 * Disable sensor notifications from the backend
150 * This method is only visible from implementation of sensor manager.
151 * Rest of the system should not try this.
153 void DisableSensorNotifications(hal::SensorType aSensor
);
155 MOZ_DEFINE_HAL_OBSERVER(Network
);
158 * Returns the current network information.
160 void GetCurrentNetworkInformation(hal::NetworkInformation
* aNetworkInfo
);
163 * Notify of a change in the network state.
164 * @param aNetworkInfo The new network information.
166 void NotifyNetworkChange(const hal::NetworkInformation
& aNetworkInfo
);
169 * Enable wake lock notifications from the backend.
171 * This method is only used by WakeLockObserversManager.
173 void EnableWakeLockNotifications();
176 * Disable wake lock notifications from the backend.
178 * This method is only used by WakeLockObserversManager.
180 void DisableWakeLockNotifications();
182 MOZ_DEFINE_HAL_OBSERVER(WakeLock
);
185 * Adjust a wake lock's counts on behalf of a given process.
187 * In most cases, you shouldn't need to pass the aProcessID argument; the
188 * default of CONTENT_PROCESS_ID_UNKNOWN is probably what you want.
190 * @param aTopic lock topic
191 * @param aLockAdjust to increase or decrease active locks
192 * @param aHiddenAdjust to increase or decrease hidden locks
193 * @param aProcessID indicates which process we're modifying the wake lock
194 * on behalf of. It is interpreted as
196 * CONTENT_PROCESS_ID_UNKNOWN: The current process
197 * CONTENT_PROCESS_ID_MAIN: The root process
198 * X: The process with ContentChild::GetID() == X
200 void ModifyWakeLock(const nsAString
& aTopic
, hal::WakeLockControl aLockAdjust
,
201 hal::WakeLockControl aHiddenAdjust
,
202 uint64_t aProcessID
= hal::CONTENT_PROCESS_ID_UNKNOWN
);
205 * Query the wake lock numbers of aTopic.
206 * @param aTopic lock topic
207 * @param aWakeLockInfo wake lock numbers
209 void GetWakeLockInfo(const nsAString
& aTopic
,
210 hal::WakeLockInformation
* aWakeLockInfo
);
213 * Notify of a change in the wake lock state.
214 * @param aWakeLockInfo The new wake lock information.
216 void NotifyWakeLockChange(const hal::WakeLockInformation
& aWakeLockInfo
);
218 MOZ_DEFINE_HAL_OBSERVER(ScreenConfiguration
);
221 * Returns the current screen configuration.
223 void GetCurrentScreenConfiguration(
224 hal::ScreenConfiguration
* aScreenConfiguration
);
227 * Notify of a change in the screen configuration.
228 * @param aScreenConfiguration The new screen orientation.
230 void NotifyScreenConfigurationChange(
231 const hal::ScreenConfiguration
& aScreenConfiguration
);
234 * Lock the screen orientation to the specific orientation.
235 * @return Whether the lock has been accepted.
237 [[nodiscard
]] bool LockScreenOrientation(
238 const hal::ScreenOrientation
& aOrientation
);
241 * Unlock the screen orientation.
243 void UnlockScreenOrientation();
246 * Set the priority of the given process.
248 * Exactly what this does will vary between platforms. On *nix we might give
249 * background processes higher nice values. On other platforms, we might
250 * ignore this call entirely.
252 void SetProcessPriority(int aPid
, hal::ProcessPriority aPriority
);
254 } // namespace MOZ_HAL_NAMESPACE
255 } // namespace mozilla
257 #ifdef MOZ_DEFINED_HAL_NAMESPACE
258 # undef MOZ_DEFINED_HAL_NAMESPACE
259 # undef MOZ_HAL_NAMESPACE
262 #endif // mozilla_Hal_h