Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 709585 - Part 5/6, hal code for the Power API. r=cjones
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Jan 30, 2012
1 parent 0bfb33f commit 6d426d8
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/system-headers
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ sys/pstat.h
sys/ptrace.h
sys/queue.h
sys/quota.h
sys/reboot.h
sys/reg.h
sys/regset.h
sys/resource.h
Expand Down
12 changes: 12 additions & 0 deletions hal/Hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,5 +372,17 @@ NotifyNetworkChange(const NetworkInformation& aInfo)
sNetworkObservers.BroadcastCachedInformation();
}

void Reboot()
{
AssertMainThread();
PROXY_IF_SANDBOXED(Reboot());
}

void PowerOff()
{
AssertMainThread();
PROXY_IF_SANDBOXED(PowerOff());
}

} // namespace hal
} // namespace mozilla
10 changes: 10 additions & 0 deletions hal/Hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo);
*/
void NotifyNetworkChange(const hal::NetworkInformation& aNetworkInfo);

/**
* Reboot the device.
*/
void Reboot();

/**
* Power off the device.
*/
void PowerOff();

} // namespace MOZ_HAL_NAMESPACE
} // namespace mozilla

Expand Down
4 changes: 2 additions & 2 deletions hal/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ CPPSRCS = \
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
Expand Down
8 changes: 8 additions & 0 deletions hal/android/AndroidHal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo)
bridge->GetCurrentNetworkInformation(aNetworkInfo);
}

void
Reboot()
{}

void
PowerOff()
{}

} // hal_impl
} // mozilla

8 changes: 8 additions & 0 deletions hal/fallback/FallbackHal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,13 @@ GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo)
aNetworkInfo->canBeMetered() = dom::network::kDefaultCanBeMetered;
}

void
Reboot()
{}

void
PowerOff()
{}

} // hal_impl
} // namespace mozilla
59 changes: 59 additions & 0 deletions hal/linux/Power.cpp
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions hal/sandbox/PHal.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ parent:
sync GetScreenBrightness() returns (double brightness);
SetScreenBrightness(double brightness);

Reboot();
PowerOff();

__delete__();
};

Expand Down
26 changes: 26 additions & 0 deletions hal/sandbox/SandboxHal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ SetScreenBrightness(double brightness)
Hal()->SendSetScreenBrightness(brightness);
}

void
Reboot()
{
Hal()->SendReboot();
}

void
PowerOff()
{
Hal()->SendPowerOff();
}

class HalParent : public PHalParent
, public BatteryObserver
, public NetworkObserver
Expand Down Expand Up @@ -267,6 +279,20 @@ class HalParent : public PHalParent
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 {
Expand Down
1 change: 1 addition & 0 deletions js/src/config/system-headers
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ sys/pstat.h
sys/ptrace.h
sys/queue.h
sys/quota.h
sys/reboot.h
sys/reg.h
sys/regset.h
sys/resource.h
Expand Down

0 comments on commit 6d426d8

Please sign in to comment.