michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "AlarmHalService.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: namespace alarm { michael@0: michael@0: using namespace hal; michael@0: michael@0: NS_IMPL_ISUPPORTS(AlarmHalService, nsIAlarmHalService) michael@0: michael@0: void michael@0: AlarmHalService::Init() michael@0: { michael@0: mAlarmEnabled = RegisterTheOneAlarmObserver(this); michael@0: if (!mAlarmEnabled) { michael@0: return; michael@0: } michael@0: RegisterSystemTimezoneChangeObserver(this); michael@0: } michael@0: michael@0: /* virtual */ AlarmHalService::~AlarmHalService() michael@0: { michael@0: if (mAlarmEnabled) { michael@0: UnregisterTheOneAlarmObserver(); michael@0: UnregisterSystemTimezoneChangeObserver(this); michael@0: } michael@0: } michael@0: michael@0: /* static */ StaticRefPtr AlarmHalService::sSingleton; michael@0: michael@0: /* static */ already_AddRefed michael@0: AlarmHalService::GetInstance() michael@0: { michael@0: if (!sSingleton) { michael@0: sSingleton = new AlarmHalService(); michael@0: sSingleton->Init(); michael@0: ClearOnShutdown(&sSingleton); michael@0: } michael@0: michael@0: nsRefPtr service = sSingleton.get(); michael@0: return service.forget(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: AlarmHalService::SetAlarm(int32_t aSeconds, int32_t aNanoseconds, bool* aStatus) michael@0: { michael@0: if (!mAlarmEnabled) { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: bool status = hal::SetAlarm(aSeconds, aNanoseconds); michael@0: if (status) { michael@0: *aStatus = status; michael@0: return NS_OK; michael@0: } else { michael@0: return NS_ERROR_FAILURE; michael@0: } michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: AlarmHalService::SetAlarmFiredCb(nsIAlarmFiredCb* aAlarmFiredCb) michael@0: { michael@0: mAlarmFiredCb = aAlarmFiredCb; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: AlarmHalService::SetTimezoneChangedCb(nsITimezoneChangedCb* aTimeZoneChangedCb) michael@0: { michael@0: mTimezoneChangedCb = aTimeZoneChangedCb; michael@0: return NS_OK; michael@0: } michael@0: michael@0: void michael@0: AlarmHalService::Notify(const void_t& aVoid) michael@0: { michael@0: if (!mAlarmFiredCb) { michael@0: return; michael@0: } michael@0: mAlarmFiredCb->OnAlarmFired(); michael@0: } michael@0: michael@0: void michael@0: AlarmHalService::Notify( michael@0: const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo) michael@0: { michael@0: if (!mTimezoneChangedCb) { michael@0: return; michael@0: } michael@0: mTimezoneChangedCb->OnTimezoneChanged( michael@0: aSystemTimezoneChangeInfo.newTimezoneOffsetMinutes()); michael@0: } michael@0: michael@0: } // alarm michael@0: } // dom michael@0: } // mozilla