2012-07-06 14:42:36 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "AlarmHalService.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace alarm {
|
|
|
|
|
|
|
|
using namespace hal;
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(AlarmHalService, nsIAlarmHalService)
|
|
|
|
|
|
|
|
void
|
|
|
|
AlarmHalService::Init()
|
|
|
|
{
|
|
|
|
mAlarmEnabled = RegisterTheOneAlarmObserver(this);
|
2012-09-12 14:15:15 +04:00
|
|
|
if (!mAlarmEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-23 11:15:43 +04:00
|
|
|
RegisterSystemTimezoneChangeObserver(this);
|
2012-07-06 14:42:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ AlarmHalService::~AlarmHalService()
|
|
|
|
{
|
|
|
|
if (mAlarmEnabled) {
|
|
|
|
UnregisterTheOneAlarmObserver();
|
2012-10-23 11:15:43 +04:00
|
|
|
UnregisterSystemTimezoneChangeObserver(this);
|
2012-07-06 14:42:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-26 23:33:45 +04:00
|
|
|
/* static */ StaticRefPtr<AlarmHalService> AlarmHalService::sSingleton;
|
2012-07-06 14:42:36 +04:00
|
|
|
|
2012-10-23 11:15:43 +04:00
|
|
|
/* static */ already_AddRefed<AlarmHalService>
|
2012-07-06 14:42:36 +04:00
|
|
|
AlarmHalService::GetInstance()
|
|
|
|
{
|
|
|
|
if (!sSingleton) {
|
|
|
|
sSingleton = new AlarmHalService();
|
|
|
|
sSingleton->Init();
|
|
|
|
ClearOnShutdown(&sSingleton);
|
|
|
|
}
|
|
|
|
|
2012-10-23 11:15:43 +04:00
|
|
|
nsRefPtr<AlarmHalService> service = sSingleton.get();
|
2012-07-06 14:42:36 +04:00
|
|
|
return service.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
AlarmHalService::SetAlarm(int32_t aSeconds, int32_t aNanoseconds, bool* aStatus)
|
2012-07-06 14:42:36 +04:00
|
|
|
{
|
|
|
|
if (!mAlarmEnabled) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool status = hal::SetAlarm(aSeconds, aNanoseconds);
|
|
|
|
if (status) {
|
|
|
|
*aStatus = status;
|
|
|
|
return NS_OK;
|
|
|
|
} else {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
AlarmHalService::SetAlarmFiredCb(nsIAlarmFiredCb* aAlarmFiredCb)
|
|
|
|
{
|
|
|
|
mAlarmFiredCb = aAlarmFiredCb;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
AlarmHalService::SetTimezoneChangedCb(nsITimezoneChangedCb* aTimeZoneChangedCb)
|
|
|
|
{
|
|
|
|
mTimezoneChangedCb = aTimeZoneChangedCb;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 11:15:43 +04:00
|
|
|
AlarmHalService::Notify(const void_t& aVoid)
|
2012-07-06 14:42:36 +04:00
|
|
|
{
|
2012-09-12 14:15:15 +04:00
|
|
|
if (!mAlarmFiredCb) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mAlarmFiredCb->OnAlarmFired();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 11:15:43 +04:00
|
|
|
AlarmHalService::Notify(
|
|
|
|
const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo)
|
2012-09-12 14:15:15 +04:00
|
|
|
{
|
2012-10-23 11:15:43 +04:00
|
|
|
if (!mTimezoneChangedCb) {
|
2012-09-12 14:15:15 +04:00
|
|
|
return;
|
2012-07-06 14:42:36 +04:00
|
|
|
}
|
2012-10-23 11:15:43 +04:00
|
|
|
mTimezoneChangedCb->OnTimezoneChanged(
|
|
|
|
aSystemTimezoneChangeInfo.newTimezoneOffsetMinutes());
|
2012-07-06 14:42:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // alarm
|
|
|
|
} // dom
|
|
|
|
} // mozilla
|