mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 749551 - Alarm API (AlarmHalService). r=cjones
This commit is contained in:
parent
6c4a2306fe
commit
f5a54ba399
98
dom/alarm/AlarmHalService.cpp
Normal file
98
dom/alarm/AlarmHalService.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* virtual */ AlarmHalService::~AlarmHalService()
|
||||
{
|
||||
if (mAlarmEnabled) {
|
||||
UnregisterTheOneAlarmObserver();
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ nsRefPtr<AlarmHalService> AlarmHalService::sSingleton;
|
||||
|
||||
/* static */ already_AddRefed<nsIAlarmHalService>
|
||||
AlarmHalService::GetInstance()
|
||||
{
|
||||
if (!sSingleton) {
|
||||
sSingleton = new AlarmHalService();
|
||||
sSingleton->Init();
|
||||
ClearOnShutdown(&sSingleton);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIAlarmHalService> service(do_QueryInterface(sSingleton));
|
||||
return service.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AlarmHalService::SetAlarm(PRInt32 aSeconds, PRInt32 aNanoseconds, bool* aStatus)
|
||||
{
|
||||
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
|
||||
AlarmHalService::Notify(const mozilla::void_t& aVoid)
|
||||
{
|
||||
if (mAlarmFiredCb) {
|
||||
mAlarmFiredCb->OnAlarmFired();
|
||||
}
|
||||
}
|
||||
|
||||
PRInt32
|
||||
AlarmHalService::GetTimezoneOffset(bool aIgnoreDST)
|
||||
{
|
||||
PRExplodedTime prTime;
|
||||
PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &prTime);
|
||||
|
||||
PRInt32 offset = prTime.tm_params.tp_gmt_offset;
|
||||
if (!aIgnoreDST) {
|
||||
offset += prTime.tm_params.tp_dst_offset;
|
||||
}
|
||||
|
||||
return -(offset / 60);
|
||||
}
|
||||
|
||||
} // alarm
|
||||
} // dom
|
||||
} // mozilla
|
56
dom/alarm/AlarmHalService.h
Normal file
56
dom/alarm/AlarmHalService.h
Normal file
@ -0,0 +1,56 @@
|
||||
/* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_alarm_AlarmHalService_h
|
||||
#define mozilla_dom_alarm_AlarmHalService_h
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/Hal.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "nsIAlarmHalService.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "prtime.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace alarm {
|
||||
|
||||
class AlarmHalService : public nsIAlarmHalService,
|
||||
mozilla::hal::AlarmObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIALARMHALSERVICE
|
||||
|
||||
void Init();
|
||||
virtual ~AlarmHalService();
|
||||
|
||||
static nsRefPtr<AlarmHalService> sSingleton;
|
||||
static already_AddRefed<nsIAlarmHalService> GetInstance();
|
||||
|
||||
// Implementing hal::AlarmObserver
|
||||
void Notify(const mozilla::void_t& aVoid);
|
||||
|
||||
private:
|
||||
bool mAlarmEnabled;
|
||||
nsCOMPtr<nsIAlarmFiredCb> mAlarmFiredCb;
|
||||
|
||||
// TODO The mTimezoneChangedCb would be called
|
||||
// when a timezone-changed event is detected
|
||||
// at run-time. To do so, we can register a
|
||||
// timezone-changed observer, see bug 714358.
|
||||
// We need to adjust the alarm time respect to
|
||||
// the correct timezone where user is located.
|
||||
nsCOMPtr<nsITimezoneChangedCb> mTimezoneChangedCb;
|
||||
|
||||
PRInt32 GetTimezoneOffset(bool aIgnoreDST);
|
||||
};
|
||||
|
||||
} // namespace alarm
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_alarm_AlarmHalService_h
|
@ -13,9 +13,13 @@ MODULE = dom
|
||||
XPIDL_MODULE = dom_alarm
|
||||
LIBRARY_NAME = domalarm_s
|
||||
LIBXUL_LIBRARY = 1
|
||||
FORCE_STATIC_LIB = 1
|
||||
GRE_MODULE = 1
|
||||
|
||||
include $(topsrcdir)/dom/dom-config.mk
|
||||
|
||||
EXPORTS_NAMESPACES = mozilla/dom/alarm
|
||||
|
||||
EXTRA_COMPONENTS = \
|
||||
AlarmsManager.js \
|
||||
AlarmsManager.manifest \
|
||||
@ -23,6 +27,15 @@ EXTRA_COMPONENTS = \
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIDOMAlarmsManager.idl \
|
||||
nsIAlarmHalService.idl \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS_mozilla/dom/alarm = \
|
||||
AlarmHalService.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
AlarmHalService.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
@ -30,4 +43,5 @@ DIRS += test
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
include $(topsrcdir)/ipc/chromium/chromium-config.mk
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
33
dom/alarm/nsIAlarmHalService.idl
Normal file
33
dom/alarm/nsIAlarmHalService.idl
Normal file
@ -0,0 +1,33 @@
|
||||
/* 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 "nsISupports.idl"
|
||||
|
||||
[scriptable, function, uuid(9f3ed2c0-aed9-11e1-8c3d-5310bd393466)]
|
||||
interface nsIAlarmFiredCb : nsISupports
|
||||
{
|
||||
void onAlarmFired();
|
||||
};
|
||||
|
||||
[scriptable, function, uuid(0ca52e84-ba8f-11e1-87e8-63235527db9e)]
|
||||
interface nsITimezoneChangedCb : nsISupports
|
||||
{
|
||||
void onTimezoneChanged(in long aTimezoneOffset);
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_ALARMHALSERVICE_CID { 0x7dafea4c, 0x7163, 0x4b70, { 0x95, 0x4e, 0x5a, 0xd4, 0x09, 0x94, 0x83, 0xd7 } }
|
||||
#define ALARMHALSERVICE_CONTRACTID "@mozilla.org/alarmHalService;1"
|
||||
%}
|
||||
|
||||
[scriptable, builtinclass, uuid(057b1ee4-f696-486d-bd55-205e21e88fab)]
|
||||
interface nsIAlarmHalService : nsISupports
|
||||
{
|
||||
bool setAlarm(in long aSeconds, in long aNanoseconds);
|
||||
void setAlarmFiredCb(in nsIAlarmFiredCb aAlarmFiredCb);
|
||||
void setTimezoneChangedCb(in nsITimezoneChangedCb aTimezoneChangedCb);
|
||||
};
|
||||
|
||||
|
||||
|
@ -218,6 +218,7 @@ static void Shutdown();
|
||||
#include "mozilla/dom/sms/SmsRequestManager.h"
|
||||
#include "mozilla/dom/sms/SmsServicesFactory.h"
|
||||
#include "nsIPowerManagerService.h"
|
||||
#include "nsIAlarmHalService.h"
|
||||
|
||||
using namespace mozilla::dom::sms;
|
||||
|
||||
@ -225,6 +226,10 @@ using namespace mozilla::dom::sms;
|
||||
|
||||
using mozilla::dom::power::PowerManagerService;
|
||||
|
||||
#include "mozilla/dom/alarm/AlarmHalService.h"
|
||||
|
||||
using mozilla::dom::alarm::AlarmHalService;
|
||||
|
||||
// Transformiix
|
||||
/* 5d5d92cd-6bf8-11d9-bf4a-000a95dc234c */
|
||||
#define TRANSFORMIIX_NODESET_CID \
|
||||
@ -274,6 +279,8 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsISmsDatabaseService, SmsServicesFacto
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIPowerManagerService,
|
||||
PowerManagerService::GetInstance)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(SmsRequestManager)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIAlarmHalService,
|
||||
AlarmHalService::GetInstance)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@ -775,6 +782,7 @@ NS_DEFINE_NAMED_CID(SMS_DATABASE_SERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(SMS_REQUEST_MANAGER_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_POWERMANAGERSERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(OSFILECONSTANTSSERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_ALARMHALSERVICE_CID);
|
||||
|
||||
static nsresult
|
||||
CreateWindowCommandTableConstructor(nsISupports *aOuter,
|
||||
@ -1043,6 +1051,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
|
||||
{ &kSMS_REQUEST_MANAGER_CID, false, NULL, SmsRequestManagerConstructor },
|
||||
{ &kNS_POWERMANAGERSERVICE_CID, false, NULL, nsIPowerManagerServiceConstructor },
|
||||
{ &kOSFILECONSTANTSSERVICE_CID, true, NULL, OSFileConstantsServiceConstructor },
|
||||
{ &kNS_ALARMHALSERVICE_CID, false, NULL, nsIAlarmHalServiceConstructor },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
@ -1176,6 +1185,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
|
||||
{ SMS_REQUEST_MANAGER_CONTRACTID, &kSMS_REQUEST_MANAGER_CID },
|
||||
{ POWERMANAGERSERVICE_CONTRACTID, &kNS_POWERMANAGERSERVICE_CID },
|
||||
{ OSFILECONSTANTSSERVICE_CONTRACTID, &kOSFILECONSTANTSSERVICE_CID },
|
||||
{ ALARMHALSERVICE_CONTRACTID, &kNS_ALARMHALSERVICE_CID },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user