Blame hal/Hal.h

Packit f0b94e
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
Packit f0b94e
/* vim: set sw=2 ts=8 et ft=cpp : */
Packit f0b94e
/* This Source Code Form is subject to the terms of the Mozilla Public
Packit f0b94e
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
Packit f0b94e
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
Packit f0b94e
Packit f0b94e
#ifndef mozilla_Hal_h
Packit f0b94e
#define mozilla_Hal_h
Packit f0b94e
Packit f0b94e
#include "base/basictypes.h"
Packit f0b94e
#include "base/platform_thread.h"
Packit f0b94e
#include "nsTArray.h"
Packit f0b94e
#include "mozilla/dom/battery/Types.h"
Packit f0b94e
#include "mozilla/dom/network/Types.h"
Packit f0b94e
#include "mozilla/dom/power/Types.h"
Packit f0b94e
#include "mozilla/dom/ScreenOrientation.h"
Packit f0b94e
#include "mozilla/hal_sandbox/PHal.h"
Packit f0b94e
#include "mozilla/HalScreenConfiguration.h"
Packit f0b94e
#include "mozilla/HalTypes.h"
Packit f0b94e
#include "mozilla/Types.h"
Packit f0b94e
Packit f0b94e
/*
Packit f0b94e
 * Hal.h contains the public Hal API.
Packit f0b94e
 *
Packit f0b94e
 * By default, this file defines its functions in the hal namespace, but if
Packit f0b94e
 * MOZ_HAL_NAMESPACE is defined, we'll define our functions in that namespace.
Packit f0b94e
 *
Packit f0b94e
 * This is used by HalImpl.h and HalSandbox.h, which define copies of all the
Packit f0b94e
 * functions here in the hal_impl and hal_sandbox namespaces.
Packit f0b94e
 */
Packit f0b94e
Packit f0b94e
class nsPIDOMWindowInner;
Packit f0b94e
Packit f0b94e
#ifndef MOZ_HAL_NAMESPACE
Packit f0b94e
#define MOZ_HAL_NAMESPACE hal
Packit f0b94e
#define MOZ_DEFINED_HAL_NAMESPACE 1
Packit f0b94e
#endif
Packit f0b94e
Packit f0b94e
namespace mozilla {
Packit f0b94e
Packit f0b94e
namespace hal {
Packit f0b94e
Packit f0b94e
class WindowIdentifier;
Packit f0b94e
Packit f0b94e
typedef Observer<int64_t> SystemClockChangeObserver;
Packit f0b94e
typedef Observer<SystemTimezoneChangeInformation> SystemTimezoneChangeObserver;
Packit f0b94e
Packit f0b94e
}  // namespace hal
Packit f0b94e
Packit f0b94e
namespace MOZ_HAL_NAMESPACE {
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Turn the default vibrator device on/off per the pattern specified
Packit f0b94e
 * by |pattern|.  Each element in the pattern is the number of
Packit f0b94e
 * milliseconds to turn the vibrator on or off.  The first element in
Packit f0b94e
 * |pattern| is an "on" element, the next is "off", and so on.
Packit f0b94e
 *
Packit f0b94e
 * If |pattern| is empty, any in-progress vibration is canceled.
Packit f0b94e
 *
Packit f0b94e
 * Only an active window within an active tab may call Vibrate; calls
Packit f0b94e
 * from inactive windows and windows on inactive tabs do nothing.
Packit f0b94e
 *
Packit f0b94e
 * If you're calling hal::Vibrate from the outside world, pass an
Packit f0b94e
 * nsIDOMWindow* in place of the WindowIdentifier parameter.
Packit f0b94e
 * The method with WindowIdentifier will be called automatically.
Packit f0b94e
 */
Packit f0b94e
void Vibrate(const nsTArray<uint32_t>& pattern, nsPIDOMWindowInner* aWindow);
Packit f0b94e
void Vibrate(const nsTArray<uint32_t>& pattern,
Packit f0b94e
             const hal::WindowIdentifier& id);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Cancel a vibration started by the content window identified by
Packit f0b94e
 * WindowIdentifier.
Packit f0b94e
 *
Packit f0b94e
 * If the window was the last window to start a vibration, the
Packit f0b94e
 * cancellation request will go through even if the window is not
Packit f0b94e
 * active.
Packit f0b94e
 *
Packit f0b94e
 * As with hal::Vibrate(), if you're calling hal::CancelVibrate from the outside
Packit f0b94e
 * world, pass an nsIDOMWindow*. The method with WindowIdentifier will be called
Packit f0b94e
 * automatically.
Packit f0b94e
 */
Packit f0b94e
void CancelVibrate(nsPIDOMWindowInner* aWindow);
Packit f0b94e
void CancelVibrate(const hal::WindowIdentifier& id);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Inform the battery backend there is a new battery observer.
Packit f0b94e
 * @param aBatteryObserver The observer that should be added.
Packit f0b94e
 */
Packit f0b94e
void RegisterBatteryObserver(BatteryObserver* aBatteryObserver);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Inform the battery backend a battery observer unregistered.
Packit f0b94e
 * @param aBatteryObserver The observer that should be removed.
Packit f0b94e
 */
Packit f0b94e
void UnregisterBatteryObserver(BatteryObserver* aBatteryObserver);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Returns the current battery information.
Packit f0b94e
 */
Packit f0b94e
void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Notify of a change in the battery state.
Packit f0b94e
 * @param aBatteryInfo The new battery information.
Packit f0b94e
 */
Packit f0b94e
void NotifyBatteryChange(const hal::BatteryInformation& aBatteryInfo);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Register an observer for the sensor of given type.
Packit f0b94e
 *
Packit f0b94e
 * The observer will receive data whenever the data generated by the
Packit f0b94e
 * sensor is avaiable.
Packit f0b94e
 */
Packit f0b94e
void RegisterSensorObserver(hal::SensorType aSensor,
Packit f0b94e
                            hal::ISensorObserver* aObserver);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Unregister an observer for the sensor of given type.
Packit f0b94e
 */
Packit f0b94e
void UnregisterSensorObserver(hal::SensorType aSensor,
Packit f0b94e
                              hal::ISensorObserver* aObserver);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Post a value generated by a sensor.
Packit f0b94e
 *
Packit f0b94e
 * This API is internal to hal; clients shouldn't call it directly.
Packit f0b94e
 */
Packit f0b94e
void NotifySensorChange(const hal::SensorData& aSensorData);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Enable sensor notifications from the backend
Packit f0b94e
 *
Packit f0b94e
 * This method is only visible from implementation of sensor manager.
Packit f0b94e
 * Rest of the system should not try this.
Packit f0b94e
 */
Packit f0b94e
void EnableSensorNotifications(hal::SensorType aSensor);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Disable sensor notifications from the backend
Packit f0b94e
 *
Packit f0b94e
 * This method is only visible from implementation of sensor manager.
Packit f0b94e
 * Rest of the system should not try this.
Packit f0b94e
 */
Packit f0b94e
void DisableSensorNotifications(hal::SensorType aSensor);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Inform the network backend there is a new network observer.
Packit f0b94e
 * @param aNetworkObserver The observer that should be added.
Packit f0b94e
 */
Packit f0b94e
void RegisterNetworkObserver(NetworkObserver* aNetworkObserver);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Inform the network backend a network observer unregistered.
Packit f0b94e
 * @param aNetworkObserver The observer that should be removed.
Packit f0b94e
 */
Packit f0b94e
void UnregisterNetworkObserver(NetworkObserver* aNetworkObserver);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Returns the current network information.
Packit f0b94e
 */
Packit f0b94e
void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Notify of a change in the network state.
Packit f0b94e
 * @param aNetworkInfo The new network information.
Packit f0b94e
 */
Packit f0b94e
void NotifyNetworkChange(const hal::NetworkInformation& aNetworkInfo);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Adjusting system clock.
Packit f0b94e
 * @param aDeltaMilliseconds The difference compared with current system clock.
Packit f0b94e
 */
Packit f0b94e
void AdjustSystemClock(int64_t aDeltaMilliseconds);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Register observer for system clock changed notification.
Packit f0b94e
 * @param aObserver The observer that should be added.
Packit f0b94e
 */
Packit f0b94e
void RegisterSystemClockChangeObserver(
Packit f0b94e
    hal::SystemClockChangeObserver* aObserver);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Unregister the observer for system clock changed.
Packit f0b94e
 * @param aObserver The observer that should be removed.
Packit f0b94e
 */
Packit f0b94e
void UnregisterSystemClockChangeObserver(
Packit f0b94e
    hal::SystemClockChangeObserver* aObserver);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Notify of a change in the system clock.
Packit f0b94e
 * @param aClockDeltaMS
Packit f0b94e
 */
Packit f0b94e
void NotifySystemClockChange(const int64_t& aClockDeltaMS);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Register observer for system timezone changed notification.
Packit f0b94e
 * @param aObserver The observer that should be added.
Packit f0b94e
 */
Packit f0b94e
void RegisterSystemTimezoneChangeObserver(
Packit f0b94e
    hal::SystemTimezoneChangeObserver* aObserver);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Unregister the observer for system timezone changed.
Packit f0b94e
 * @param aObserver The observer that should be removed.
Packit f0b94e
 */
Packit f0b94e
void UnregisterSystemTimezoneChangeObserver(
Packit f0b94e
    hal::SystemTimezoneChangeObserver* aObserver);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Notify of a change in the system timezone.
Packit f0b94e
 * @param aSystemTimezoneChangeInfo
Packit f0b94e
 */
Packit f0b94e
void NotifySystemTimezoneChange(
Packit f0b94e
    const hal::SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Enable wake lock notifications from the backend.
Packit f0b94e
 *
Packit f0b94e
 * This method is only used by WakeLockObserversManager.
Packit f0b94e
 */
Packit f0b94e
void EnableWakeLockNotifications();
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Disable wake lock notifications from the backend.
Packit f0b94e
 *
Packit f0b94e
 * This method is only used by WakeLockObserversManager.
Packit f0b94e
 */
Packit f0b94e
void DisableWakeLockNotifications();
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Inform the wake lock backend there is a new wake lock observer.
Packit f0b94e
 * @param aWakeLockObserver The observer that should be added.
Packit f0b94e
 */
Packit f0b94e
void RegisterWakeLockObserver(WakeLockObserver* aObserver);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Inform the wake lock backend a wake lock observer unregistered.
Packit f0b94e
 * @param aWakeLockObserver The observer that should be removed.
Packit f0b94e
 */
Packit f0b94e
void UnregisterWakeLockObserver(WakeLockObserver* aObserver);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Adjust a wake lock's counts on behalf of a given process.
Packit f0b94e
 *
Packit f0b94e
 * In most cases, you shouldn't need to pass the aProcessID argument; the
Packit f0b94e
 * default of CONTENT_PROCESS_ID_UNKNOWN is probably what you want.
Packit f0b94e
 *
Packit f0b94e
 * @param aTopic        lock topic
Packit f0b94e
 * @param aLockAdjust   to increase or decrease active locks
Packit f0b94e
 * @param aHiddenAdjust to increase or decrease hidden locks
Packit f0b94e
 * @param aProcessID    indicates which process we're modifying the wake lock
Packit f0b94e
 *                      on behalf of.  It is interpreted as
Packit f0b94e
 *
Packit f0b94e
 *                      CONTENT_PROCESS_ID_UNKNOWN: The current process
Packit f0b94e
 *                      CONTENT_PROCESS_ID_MAIN: The root process
Packit f0b94e
 *                      X: The process with ContentChild::GetID() == X
Packit f0b94e
 */
Packit f0b94e
void ModifyWakeLock(const nsAString& aTopic, hal::WakeLockControl aLockAdjust,
Packit f0b94e
                    hal::WakeLockControl aHiddenAdjust,
Packit f0b94e
                    uint64_t aProcessID = hal::CONTENT_PROCESS_ID_UNKNOWN);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Query the wake lock numbers of aTopic.
Packit f0b94e
 * @param aTopic        lock topic
Packit f0b94e
 * @param aWakeLockInfo wake lock numbers
Packit f0b94e
 */
Packit f0b94e
void GetWakeLockInfo(const nsAString& aTopic,
Packit f0b94e
                     hal::WakeLockInformation* aWakeLockInfo);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Notify of a change in the wake lock state.
Packit f0b94e
 * @param aWakeLockInfo The new wake lock information.
Packit f0b94e
 */
Packit f0b94e
void NotifyWakeLockChange(const hal::WakeLockInformation& aWakeLockInfo);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Inform the backend there is a new screen configuration observer.
Packit f0b94e
 * @param aScreenConfigurationObserver The observer that should be added.
Packit f0b94e
 */
Packit f0b94e
void RegisterScreenConfigurationObserver(
Packit f0b94e
    hal::ScreenConfigurationObserver* aScreenConfigurationObserver);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Inform the backend a screen configuration observer unregistered.
Packit f0b94e
 * @param aScreenConfigurationObserver The observer that should be removed.
Packit f0b94e
 */
Packit f0b94e
void UnregisterScreenConfigurationObserver(
Packit f0b94e
    hal::ScreenConfigurationObserver* aScreenConfigurationObserver);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Returns the current screen configuration.
Packit f0b94e
 */
Packit f0b94e
void GetCurrentScreenConfiguration(
Packit f0b94e
    hal::ScreenConfiguration* aScreenConfiguration);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Notify of a change in the screen configuration.
Packit f0b94e
 * @param aScreenConfiguration The new screen orientation.
Packit f0b94e
 */
Packit f0b94e
void NotifyScreenConfigurationChange(
Packit f0b94e
    const hal::ScreenConfiguration& aScreenConfiguration);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Lock the screen orientation to the specific orientation.
Packit f0b94e
 * @return Whether the lock has been accepted.
Packit f0b94e
 */
Packit f0b94e
MOZ_MUST_USE bool LockScreenOrientation(
Packit f0b94e
    const dom::ScreenOrientationInternal& aOrientation);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Unlock the screen orientation.
Packit f0b94e
 */
Packit f0b94e
void UnlockScreenOrientation();
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Return true if the current platform supports the setting of process
Packit f0b94e
 * priority.
Packit f0b94e
 */
Packit f0b94e
bool SetProcessPrioritySupported();
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Set the priority of the given process.
Packit f0b94e
 *
Packit f0b94e
 * Exactly what this does will vary between platforms.  On *nix we might give
Packit f0b94e
 * background processes higher nice values.  On other platforms, we might
Packit f0b94e
 * ignore this call entirely.
Packit f0b94e
 */
Packit f0b94e
void SetProcessPriority(int aPid, hal::ProcessPriority aPriority);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Set the current thread's priority to appropriate platform-specific value for
Packit f0b94e
 * given functionality. Instead of providing arbitrary priority numbers you
Packit f0b94e
 * must specify a type of function like THREAD_PRIORITY_COMPOSITOR.
Packit f0b94e
 */
Packit f0b94e
void SetCurrentThreadPriority(hal::ThreadPriority aThreadPriority);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Set a thread priority to appropriate platform-specific value for
Packit f0b94e
 * given functionality. Instead of providing arbitrary priority numbers you
Packit f0b94e
 * must specify a type of function like THREAD_PRIORITY_COMPOSITOR.
Packit f0b94e
 */
Packit f0b94e
void SetThreadPriority(PlatformThreadId aThreadId,
Packit f0b94e
                       hal::ThreadPriority aThreadPriority);
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Start monitoring disk space for low space situations.
Packit f0b94e
 *
Packit f0b94e
 * This API is currently only allowed to be used from the main process.
Packit f0b94e
 */
Packit f0b94e
void StartDiskSpaceWatcher();
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Stop monitoring disk space for low space situations.
Packit f0b94e
 *
Packit f0b94e
 * This API is currently only allowed to be used from the main process.
Packit f0b94e
 */
Packit f0b94e
void StopDiskSpaceWatcher();
Packit f0b94e
Packit f0b94e
}  // namespace MOZ_HAL_NAMESPACE
Packit f0b94e
}  // namespace mozilla
Packit f0b94e
Packit f0b94e
#ifdef MOZ_DEFINED_HAL_NAMESPACE
Packit f0b94e
#undef MOZ_DEFINED_HAL_NAMESPACE
Packit f0b94e
#undef MOZ_HAL_NAMESPACE
Packit f0b94e
#endif
Packit f0b94e
Packit f0b94e
#endif  // mozilla_Hal_h