2012-07-06 03:42:36 -07: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 03:15:15 -07:00
|
|
|
if (!mAlarmEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-23 00:15:43 -07:00
|
|
|
RegisterSystemTimezoneChangeObserver(this);
|
2012-07-06 03:42:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ AlarmHalService::~AlarmHalService()
|
|
|
|
{
|
|
|
|
if (mAlarmEnabled) {
|
|
|
|
UnregisterTheOneAlarmObserver();
|
2012-10-23 00:15:43 -07:00
|
|
|
UnregisterSystemTimezoneChangeObserver(this);
|
2012-07-06 03:42:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-26 12:33:45 -07:00
|
|
|
/* static */ StaticRefPtr<AlarmHalService> AlarmHalService::sSingleton;
|
2012-07-06 03:42:36 -07:00
|
|
|
|
2012-10-23 00:15:43 -07:00
|
|
|
/* static */ already_AddRefed<AlarmHalService>
|
2012-07-06 03:42:36 -07:00
|
|
|
AlarmHalService::GetInstance()
|
|
|
|
{
|
|
|
|
if (!sSingleton) {
|
|
|
|
sSingleton = new AlarmHalService();
|
|
|
|
sSingleton->Init();
|
|
|
|
ClearOnShutdown(&sSingleton);
|
|
|
|
}
|
|
|
|
|
2012-10-23 00:15:43 -07:00
|
|
|
nsRefPtr<AlarmHalService> service = sSingleton.get();
|
2012-07-06 03:42:36 -07:00
|
|
|
return service.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
AlarmHalService::SetAlarm(int32_t aSeconds, int32_t aNanoseconds, bool* aStatus)
|
2012-07-06 03:42:36 -07: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 00:15:43 -07:00
|
|
|
AlarmHalService::Notify(const void_t& aVoid)
|
2012-07-06 03:42:36 -07:00
|
|
|
{
|
2012-09-12 03:15:15 -07:00
|
|
|
if (!mAlarmFiredCb) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mAlarmFiredCb->OnAlarmFired();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 00:15:43 -07:00
|
|
|
AlarmHalService::Notify(
|
|
|
|
const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo)
|
2012-09-12 03:15:15 -07:00
|
|
|
{
|
2012-10-23 00:15:43 -07:00
|
|
|
if (!mTimezoneChangedCb) {
|
2012-09-12 03:15:15 -07:00
|
|
|
return;
|
2012-07-06 03:42:36 -07:00
|
|
|
}
|
2012-10-23 00:15:43 -07:00
|
|
|
mTimezoneChangedCb->OnTimezoneChanged(
|
|
|
|
aSystemTimezoneChangeInfo.newTimezoneOffsetMinutes());
|
2012-07-06 03:42:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} // alarm
|
|
|
|
} // dom
|
|
|
|
} // mozilla
|