Skip to content

Commit

Permalink
Bug 1482753 - Introduce two macros to implement HAL observers handy. …
Browse files Browse the repository at this point in the history
…r=gsvelto

If `ScreenConfiguration` were `ScreenInformation` we could integrate
notification functions into the macros too.

Differential Revision: https://phabricator.services.mozilla.com/D3182
  • Loading branch information
Hiroyuki Ikezoe committed Aug 13, 2018
1 parent 2e21aec commit dcd6231
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 93 deletions.
67 changes: 17 additions & 50 deletions hal/Hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
58 changes: 15 additions & 43 deletions hal/Hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit dcd6231

Please sign in to comment.