зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1482753 - Introduce two macros to implement HAL observers handy. r=gsvelto
If `ScreenConfiguration` were `ScreenInformation` we could integrate notification functions into the macros too. Differential Revision: https://phabricator.services.mozilla.com/D3182
This commit is contained in:
Родитель
2e21aec705
Коммит
dcd6231961
67
hal/Hal.cpp
67
hal/Hal.cpp
|
@ -355,19 +355,22 @@ ScreenConfigurationObservers()
|
|||
return sScreenConfigurationObservers;
|
||||
}
|
||||
|
||||
void
|
||||
RegisterBatteryObserver(BatteryObserver* aObserver)
|
||||
{
|
||||
AssertMainThread();
|
||||
BatteryObservers().AddObserver(aObserver);
|
||||
#define MOZ_IMPL_HAL_OBSERVER(name_) \
|
||||
void \
|
||||
Register##name_##Observer(name_##Observer* aObserver) \
|
||||
{ \
|
||||
AssertMainThread(); \
|
||||
name_##Observers().AddObserver(aObserver); \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
Unregister##name_##Observer(name_##Observer* aObserver) \
|
||||
{ \
|
||||
AssertMainThread(); \
|
||||
name_##Observers().RemoveObserver(aObserver); \
|
||||
}
|
||||
|
||||
void
|
||||
UnregisterBatteryObserver(BatteryObserver* aObserver)
|
||||
{
|
||||
AssertMainThread();
|
||||
BatteryObservers().RemoveObserver(aObserver);
|
||||
}
|
||||
MOZ_IMPL_HAL_OBSERVER(Battery)
|
||||
|
||||
void
|
||||
GetCurrentBatteryInformation(BatteryInformation* aInfo)
|
||||
|
@ -470,19 +473,7 @@ NotifySensorChange(const SensorData &aSensorData) {
|
|||
observers.Broadcast(aSensorData);
|
||||
}
|
||||
|
||||
void
|
||||
RegisterNetworkObserver(NetworkObserver* aObserver)
|
||||
{
|
||||
AssertMainThread();
|
||||
NetworkObservers().AddObserver(aObserver);
|
||||
}
|
||||
|
||||
void
|
||||
UnregisterNetworkObserver(NetworkObserver* aObserver)
|
||||
{
|
||||
AssertMainThread();
|
||||
NetworkObservers().RemoveObserver(aObserver);
|
||||
}
|
||||
MOZ_IMPL_HAL_OBSERVER(Network)
|
||||
|
||||
void
|
||||
GetCurrentNetworkInformation(NetworkInformation* aInfo)
|
||||
|
@ -498,19 +489,7 @@ NotifyNetworkChange(const NetworkInformation& aInfo)
|
|||
NetworkObservers().BroadcastCachedInformation();
|
||||
}
|
||||
|
||||
void
|
||||
RegisterWakeLockObserver(WakeLockObserver* aObserver)
|
||||
{
|
||||
AssertMainThread();
|
||||
WakeLockObservers().AddObserver(aObserver);
|
||||
}
|
||||
|
||||
void
|
||||
UnregisterWakeLockObserver(WakeLockObserver* aObserver)
|
||||
{
|
||||
AssertMainThread();
|
||||
WakeLockObservers().RemoveObserver(aObserver);
|
||||
}
|
||||
MOZ_IMPL_HAL_OBSERVER(WakeLock)
|
||||
|
||||
void
|
||||
ModifyWakeLock(const nsAString& aTopic,
|
||||
|
@ -543,19 +522,7 @@ NotifyWakeLockChange(const WakeLockInformation& aInfo)
|
|||
WakeLockObservers().BroadcastInformation(aInfo);
|
||||
}
|
||||
|
||||
void
|
||||
RegisterScreenConfigurationObserver(ScreenConfigurationObserver* aObserver)
|
||||
{
|
||||
AssertMainThread();
|
||||
ScreenConfigurationObservers().AddObserver(aObserver);
|
||||
}
|
||||
|
||||
void
|
||||
UnregisterScreenConfigurationObserver(ScreenConfigurationObserver* aObserver)
|
||||
{
|
||||
AssertMainThread();
|
||||
ScreenConfigurationObservers().RemoveObserver(aObserver);
|
||||
}
|
||||
MOZ_IMPL_HAL_OBSERVER(ScreenConfiguration)
|
||||
|
||||
void
|
||||
GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
|
||||
|
|
58
hal/Hal.h
58
hal/Hal.h
|
@ -81,17 +81,19 @@ void Vibrate(const nsTArray<uint32_t>& pattern,
|
|||
void CancelVibrate(nsPIDOMWindowInner* aWindow);
|
||||
void CancelVibrate(const hal::WindowIdentifier &id);
|
||||
|
||||
/**
|
||||
* Inform the battery backend there is a new battery observer.
|
||||
* @param aBatteryObserver The observer that should be added.
|
||||
*/
|
||||
void RegisterBatteryObserver(hal::BatteryObserver* aBatteryObserver);
|
||||
#define MOZ_DEFINE_HAL_OBSERVER(name_) \
|
||||
/** \
|
||||
* Inform the backend there is a new |name_| observer. \
|
||||
* @param aObserver The observer that should be added. \
|
||||
*/ \
|
||||
void Register##name_##Observer(hal::name_##Observer* aObserver); \
|
||||
/** \
|
||||
* Inform the backend a |name_| observer unregistered. \
|
||||
* @param aObserver The observer that should be removed. \
|
||||
*/ \
|
||||
void Unregister##name_##Observer(hal::name_##Observer* aObserver);
|
||||
|
||||
/**
|
||||
* Inform the battery backend a battery observer unregistered.
|
||||
* @param aBatteryObserver The observer that should be removed.
|
||||
*/
|
||||
void UnregisterBatteryObserver(hal::BatteryObserver* aBatteryObserver);
|
||||
MOZ_DEFINE_HAL_OBSERVER(Battery);
|
||||
|
||||
/**
|
||||
* Returns the current battery information.
|
||||
|
@ -143,17 +145,7 @@ void EnableSensorNotifications(hal::SensorType aSensor);
|
|||
void DisableSensorNotifications(hal::SensorType aSensor);
|
||||
|
||||
|
||||
/**
|
||||
* Inform the network backend there is a new network observer.
|
||||
* @param aNetworkObserver The observer that should be added.
|
||||
*/
|
||||
void RegisterNetworkObserver(hal::NetworkObserver* aNetworkObserver);
|
||||
|
||||
/**
|
||||
* Inform the network backend a network observer unregistered.
|
||||
* @param aNetworkObserver The observer that should be removed.
|
||||
*/
|
||||
void UnregisterNetworkObserver(hal::NetworkObserver* aNetworkObserver);
|
||||
MOZ_DEFINE_HAL_OBSERVER(Network);
|
||||
|
||||
/**
|
||||
* Returns the current network information.
|
||||
|
@ -180,17 +172,7 @@ void EnableWakeLockNotifications();
|
|||
*/
|
||||
void DisableWakeLockNotifications();
|
||||
|
||||
/**
|
||||
* Inform the wake lock backend there is a new wake lock observer.
|
||||
* @param aWakeLockObserver The observer that should be added.
|
||||
*/
|
||||
void RegisterWakeLockObserver(hal::WakeLockObserver* aObserver);
|
||||
|
||||
/**
|
||||
* Inform the wake lock backend a wake lock observer unregistered.
|
||||
* @param aWakeLockObserver The observer that should be removed.
|
||||
*/
|
||||
void UnregisterWakeLockObserver(hal::WakeLockObserver* aObserver);
|
||||
MOZ_DEFINE_HAL_OBSERVER(WakeLock);
|
||||
|
||||
/**
|
||||
* Adjust a wake lock's counts on behalf of a given process.
|
||||
|
@ -226,17 +208,7 @@ void GetWakeLockInfo(const nsAString &aTopic, hal::WakeLockInformation *aWakeLoc
|
|||
*/
|
||||
void NotifyWakeLockChange(const hal::WakeLockInformation& aWakeLockInfo);
|
||||
|
||||
/**
|
||||
* Inform the backend there is a new screen configuration observer.
|
||||
* @param aScreenConfigurationObserver The observer that should be added.
|
||||
*/
|
||||
void RegisterScreenConfigurationObserver(hal::ScreenConfigurationObserver* aScreenConfigurationObserver);
|
||||
|
||||
/**
|
||||
* Inform the backend a screen configuration observer unregistered.
|
||||
* @param aScreenConfigurationObserver The observer that should be removed.
|
||||
*/
|
||||
void UnregisterScreenConfigurationObserver(hal::ScreenConfigurationObserver* aScreenConfigurationObserver);
|
||||
MOZ_DEFINE_HAL_OBSERVER(ScreenConfiguration);
|
||||
|
||||
/**
|
||||
* Returns the current screen configuration.
|
||||
|
|
Загрузка…
Ссылка в новой задаче