Bug 1482753 - Introduce two macros to implement HAL observers handy. r=gsvelto
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Mon, 13 Aug 2018 10:57:50 +0900
changeset 486321 c9c1a36c4f414593ba6587b746889e9e4d3ba870
parent 486320 8741c8f1eaa615a12d50db8d62a21eb2dbecd585
child 486322 6296ed36532a887f88dfe4c6299f34811e694220
child 486344 ec59471499f174cd05086b572f759f67cdfa4476
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgsvelto
bugs1482753
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
hal/Hal.cpp
hal/Hal.h
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -350,29 +350,32 @@ protected:
 static ScreenConfigurationObserversManager&
 ScreenConfigurationObservers()
 {
   AssertMainThread();
   static ScreenConfigurationObserversManager sScreenConfigurationObservers;
   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)
 {
   AssertMainThread();
   *aInfo = BatteryObservers().GetCurrentInformation();
 }
 
@@ -465,57 +468,33 @@ void
 NotifySensorChange(const SensorData &aSensorData) {
   SensorObserverList &observers = GetSensorObservers(aSensorData.sensor());
 
   AssertMainThread();
 
   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)
 {
   AssertMainThread();
   *aInfo = NetworkObservers().GetCurrentInformation();
 }
 
 void
 NotifyNetworkChange(const NetworkInformation& aInfo)
 {
   NetworkObservers().CacheInformation(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,
                WakeLockControl aLockAdjust,
                WakeLockControl aHiddenAdjust,
                uint64_t aProcessID /* = CONTENT_PROCESS_ID_UNKNOWN */)
 {
   AssertMainThread();
@@ -538,29 +517,17 @@ GetWakeLockInfo(const nsAString& aTopic,
 
 void
 NotifyWakeLockChange(const WakeLockInformation& aInfo)
 {
   AssertMainThread();
   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)
 {
   AssertMainThread();
   *aScreenConfiguration = ScreenConfigurationObservers().GetCurrentInformation();
 }
 
--- a/hal/Hal.h
+++ b/hal/Hal.h
@@ -76,27 +76,29 @@ void Vibrate(const nsTArray<uint32_t>& p
  *
  * As with hal::Vibrate(), if you're calling hal::CancelVibrate from the outside
  * world, pass an nsIDOMWindow*. The method with WindowIdentifier will be called
  * automatically.
  */
 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.
  */
 void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo);
 
 /**
  * Notify of a change in the battery state.
@@ -138,27 +140,17 @@ void EnableSensorNotifications(hal::Sens
  * Disable sensor notifications from the backend
  *
  * This method is only visible from implementation of sensor manager.
  * Rest of the system should not try this.
  */
 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.
  */
 void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo);
 
 /**
  * Notify of a change in the network state.
@@ -175,27 +167,17 @@ void EnableWakeLockNotifications();
 
 /**
  * Disable wake lock notifications from the backend.
  *
  * This method is only used by WakeLockObserversManager.
  */
 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.
  *
  * In most cases, you shouldn't need to pass the aProcessID argument; the
  * default of CONTENT_PROCESS_ID_UNKNOWN is probably what you want.
  *
  * @param aTopic        lock topic
@@ -221,27 +203,17 @@ void ModifyWakeLock(const nsAString &aTo
 void GetWakeLockInfo(const nsAString &aTopic, hal::WakeLockInformation *aWakeLockInfo);
 
 /**
  * Notify of a change in the wake lock state.
  * @param aWakeLockInfo The new wake lock information.
  */
 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.
  */
 void GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration);
 
 /**
  * Notify of a change in the screen configuration.