Bug 709585 - Part 5/6, hal code for the Power API. r=cjones
☠☠ backed out by de33a82cee1f ☠ ☠
authorKan-Ru Chen <kanru@kanru.info>
Mon, 30 Jan 2012 17:02:51 -0600
changeset 86994 6a4c4cb828a8f45133fb6a1c0dcb2c545ffd2b0d
parent 86993 656500fc5e791f1f4a68935e038671b9f946862b
child 86995 10b455909e944bad69d160653477d77e02a3b44f
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs709585
milestone12.0a1
Bug 709585 - Part 5/6, hal code for the Power API. r=cjones
config/system-headers
hal/Hal.cpp
hal/Hal.h
hal/Makefile.in
hal/android/AndroidHal.cpp
hal/fallback/FallbackHal.cpp
hal/linux/Power.cpp
hal/sandbox/PHal.ipdl
hal/sandbox/SandboxHal.cpp
js/src/config/system-headers
--- a/config/system-headers
+++ b/config/system-headers
@@ -724,16 +724,17 @@ sys/poll.h
 sys/ppc.h
 sys/prctl.h
 sys/priv.h
 sys/procfs.h
 sys/pstat.h
 sys/ptrace.h
 sys/queue.h
 sys/quota.h
+sys/reboot.h
 sys/reg.h
 sys/regset.h
 sys/resource.h
 sys/sched.h
 sys/select.h
 sys/sem.h
 sys/sendfile.h
 sys/shm.h
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -367,10 +367,22 @@ GetCurrentNetworkInformation(NetworkInfo
 
 void
 NotifyNetworkChange(const NetworkInformation& aInfo)
 {
   sNetworkObservers.CacheInformation(aInfo);
   sNetworkObservers.BroadcastCachedInformation();
 }
 
+void Reboot()
+{
+  AssertMainThread();
+  PROXY_IF_SANDBOXED(Reboot());
+}
+
+void PowerOff()
+{
+  AssertMainThread();
+  PROXY_IF_SANDBOXED(PowerOff());
+}
+
 } // namespace hal
 } // namespace mozilla
--- a/hal/Hal.h
+++ b/hal/Hal.h
@@ -187,16 +187,26 @@ void UnregisterNetworkObserver(NetworkOb
 void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo);
 
 /**
  * Notify of a change in the network state.
  * @param aNetworkInfo The new network information.
  */
 void NotifyNetworkChange(const hal::NetworkInformation& aNetworkInfo);
 
+/**
+ * Reboot the device.
+ */
+void Reboot();
+
+/**
+ * Power off the device.
+ */
+void PowerOff();
+
 } // namespace MOZ_HAL_NAMESPACE
 } // namespace mozilla
 
 #ifdef MOZ_DEFINED_HAL_NAMESPACE
 # undef MOZ_DEFINED_HAL_NAMESPACE
 # undef MOZ_HAL_NAMESPACE
 #endif
 
--- a/hal/Makefile.in
+++ b/hal/Makefile.in
@@ -67,19 +67,19 @@ CPPSRCS = \
   Hal.cpp \
   SandboxHal.cpp \
   WindowIdentifier.cpp \
   $(NULL)
 
 ifeq (android,$(MOZ_WIDGET_TOOLKIT))
 CPPSRCS += AndroidHal.cpp
 else ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
-CPPSRCS += GonkHal.cpp
+CPPSRCS += GonkHal.cpp Power.cpp
 else ifeq (Linux,$(OS_TARGET))
-CPPSRCS += LinuxHal.cpp
+CPPSRCS += LinuxHal.cpp Power.cpp
 ifdef MOZ_ENABLE_DBUS
 CPPSRCS += UPowerClient.cpp
 endif
 else ifeq (WINNT,$(OS_TARGET))
 CPPSRCS += WindowsHal.cpp WindowsBattery.cpp
 else
 CPPSRCS += FallbackHal.cpp
 endif
--- a/hal/android/AndroidHal.cpp
+++ b/hal/android/AndroidHal.cpp
@@ -168,11 +168,19 @@ GetCurrentNetworkInformation(hal::Networ
   AndroidBridge* bridge = AndroidBridge::Bridge();
   if (!bridge) {
     return;
   }
 
   bridge->GetCurrentNetworkInformation(aNetworkInfo);
 }
 
+void
+Reboot()
+{}
+
+void
+PowerOff()
+{}
+
 } // hal_impl
 } // mozilla
 
--- a/hal/fallback/FallbackHal.cpp
+++ b/hal/fallback/FallbackHal.cpp
@@ -100,10 +100,18 @@ DisableNetworkNotifications()
 
 void
 GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo)
 {
   aNetworkInfo->bandwidth() = dom::network::kDefaultBandwidth;
   aNetworkInfo->canBeMetered() = dom::network::kDefaultCanBeMetered;
 }
 
+void
+Reboot()
+{}
+
+void
+PowerOff()
+{}
+
 } // hal_impl
 } // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/hal/linux/Power.cpp
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Kan-Ru Chen <kchen@mozilla.com> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "Hal.h"
+
+#include <unistd.h>
+#include <sys/reboot.h>
+
+namespace mozilla {
+namespace hal_impl {
+
+void
+Reboot()
+{
+  reboot(RB_AUTOBOOT);
+}
+
+void
+PowerOff()
+{
+  reboot(RB_POWER_OFF);
+}
+
+} // hal_impl
+} // mozilla
--- a/hal/sandbox/PHal.ipdl
+++ b/hal/sandbox/PHal.ipdl
@@ -81,13 +81,16 @@ parent:
       returns (NetworkInformation aNetworkInfo);
 
     sync GetScreenEnabled() returns (bool enabled);
     SetScreenEnabled(bool enabled);
 
     sync GetScreenBrightness() returns (double brightness);
     SetScreenBrightness(double brightness);
 
+    Reboot();
+    PowerOff();
+
     __delete__();
 };
 
 } // namespace hal
 } // namespace mozilla
--- a/hal/sandbox/SandboxHal.cpp
+++ b/hal/sandbox/SandboxHal.cpp
@@ -147,16 +147,28 @@ GetScreenBrightness()
 }
 
 void
 SetScreenBrightness(double brightness)
 {
   Hal()->SendSetScreenBrightness(brightness);
 }
 
+void
+Reboot()
+{
+  Hal()->SendReboot();
+}
+
+void
+PowerOff()
+{
+  Hal()->SendPowerOff();
+}
+
 class HalParent : public PHalParent
                 , public BatteryObserver
                 , public NetworkObserver
 {
 public:
   NS_OVERRIDE virtual bool
   RecvVibrate(const InfallibleTArray<unsigned int>& pattern,
               const InfallibleTArray<uint64> &id,
@@ -262,16 +274,30 @@ public:
   }
 
   NS_OVERRIDE virtual bool
   RecvSetScreenBrightness(const double &brightness)
   {
     hal::SetScreenBrightness(brightness);
     return true;
   }
+
+  NS_OVERRIDE virtual bool
+  RecvReboot()
+  {
+    hal::Reboot();
+    return true;
+  }
+
+  NS_OVERRIDE virtual bool
+  RecvPowerOff()
+  {
+    hal::PowerOff();
+    return true;
+  }
 };
 
 class HalChild : public PHalChild {
 public:
   NS_OVERRIDE virtual bool
   RecvNotifyBatteryChange(const BatteryInformation& aBatteryInfo) {
     hal::NotifyBatteryChange(aBatteryInfo);
     return true;
--- a/js/src/config/system-headers
+++ b/js/src/config/system-headers
@@ -724,16 +724,17 @@ sys/poll.h
 sys/ppc.h
 sys/prctl.h
 sys/priv.h
 sys/procfs.h
 sys/pstat.h
 sys/ptrace.h
 sys/queue.h
 sys/quota.h
+sys/reboot.h
 sys/reg.h
 sys/regset.h
 sys/resource.h
 sys/sched.h
 sys/select.h
 sys/sem.h
 sys/sendfile.h
 sys/shm.h