michael@0: /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ 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 "FMRadioChild.h" michael@0: #include "mozilla/dom/ContentChild.h" michael@0: #include "mozilla/dom/FMRadioRequestChild.h" michael@0: michael@0: using namespace mozilla::hal; michael@0: michael@0: BEGIN_FMRADIO_NAMESPACE michael@0: michael@0: StaticAutoPtr FMRadioChild::sFMRadioChild; michael@0: michael@0: FMRadioChild::FMRadioChild() michael@0: : mEnabled(false) michael@0: , mFrequency(0) michael@0: , mObserverList(FMRadioEventObserverList()) michael@0: { michael@0: MOZ_COUNT_CTOR(FMRadioChild); michael@0: michael@0: ContentChild::GetSingleton()->SendPFMRadioConstructor(this); michael@0: michael@0: StatusInfo statusInfo; michael@0: SendGetStatusInfo(&statusInfo); michael@0: michael@0: mEnabled = statusInfo.enabled(); michael@0: mFrequency = statusInfo.frequency(); michael@0: mUpperBound = statusInfo.upperBound(); michael@0: mLowerBound= statusInfo.lowerBound(); michael@0: mChannelWidth = statusInfo.channelWidth(); michael@0: } michael@0: michael@0: FMRadioChild::~FMRadioChild() michael@0: { michael@0: MOZ_COUNT_DTOR(FMRadioChild); michael@0: } michael@0: michael@0: bool michael@0: FMRadioChild::IsEnabled() const michael@0: { michael@0: return mEnabled; michael@0: } michael@0: michael@0: double michael@0: FMRadioChild::GetFrequency() const michael@0: { michael@0: return mFrequency; michael@0: } michael@0: michael@0: michael@0: double michael@0: FMRadioChild::GetFrequencyUpperBound() const michael@0: { michael@0: return mUpperBound; michael@0: } michael@0: michael@0: double michael@0: FMRadioChild::GetFrequencyLowerBound() const michael@0: { michael@0: return mLowerBound; michael@0: } michael@0: michael@0: double michael@0: FMRadioChild::GetChannelWidth() const michael@0: { michael@0: return mChannelWidth; michael@0: } michael@0: michael@0: void michael@0: FMRadioChild::Enable(double aFrequency, FMRadioReplyRunnable* aReplyRunnable) michael@0: { michael@0: SendRequest(aReplyRunnable, EnableRequestArgs(aFrequency)); michael@0: } michael@0: michael@0: void michael@0: FMRadioChild::Disable(FMRadioReplyRunnable* aReplyRunnable) michael@0: { michael@0: SendRequest(aReplyRunnable, DisableRequestArgs()); michael@0: } michael@0: michael@0: void michael@0: FMRadioChild::SetFrequency(double aFrequency, michael@0: FMRadioReplyRunnable* aReplyRunnable) michael@0: { michael@0: SendRequest(aReplyRunnable, SetFrequencyRequestArgs(aFrequency)); michael@0: } michael@0: michael@0: void michael@0: FMRadioChild::Seek(FMRadioSeekDirection aDirection, michael@0: FMRadioReplyRunnable* aReplyRunnable) michael@0: { michael@0: SendRequest(aReplyRunnable, SeekRequestArgs(aDirection)); michael@0: } michael@0: michael@0: void michael@0: FMRadioChild::CancelSeek(FMRadioReplyRunnable* aReplyRunnable) michael@0: { michael@0: SendRequest(aReplyRunnable, CancelSeekRequestArgs()); michael@0: } michael@0: michael@0: inline void michael@0: FMRadioChild::NotifyFMRadioEvent(FMRadioEventType aType) michael@0: { michael@0: mObserverList.Broadcast(aType); michael@0: } michael@0: michael@0: void michael@0: FMRadioChild::AddObserver(FMRadioEventObserver* aObserver) michael@0: { michael@0: mObserverList.AddObserver(aObserver); michael@0: } michael@0: michael@0: void michael@0: FMRadioChild::RemoveObserver(FMRadioEventObserver* aObserver) michael@0: { michael@0: mObserverList.RemoveObserver(aObserver); michael@0: } michael@0: michael@0: void michael@0: FMRadioChild::SendRequest(FMRadioReplyRunnable* aReplyRunnable, michael@0: FMRadioRequestArgs aArgs) michael@0: { michael@0: PFMRadioRequestChild* childRequest = new FMRadioRequestChild(aReplyRunnable); michael@0: SendPFMRadioRequestConstructor(childRequest, aArgs); michael@0: } michael@0: michael@0: bool michael@0: FMRadioChild::RecvNotifyFrequencyChanged(const double& aFrequency) michael@0: { michael@0: mFrequency = aFrequency; michael@0: NotifyFMRadioEvent(FrequencyChanged); michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: FMRadioChild::RecvNotifyEnabledChanged(const bool& aEnabled, michael@0: const double& aFrequency) michael@0: { michael@0: mEnabled = aEnabled; michael@0: mFrequency = aFrequency; michael@0: NotifyFMRadioEvent(EnabledChanged); michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: FMRadioChild::Recv__delete__() michael@0: { michael@0: return true; michael@0: } michael@0: michael@0: PFMRadioRequestChild* michael@0: FMRadioChild::AllocPFMRadioRequestChild(const FMRadioRequestArgs& aArgs) michael@0: { michael@0: MOZ_CRASH(); michael@0: return nullptr; michael@0: } michael@0: michael@0: bool michael@0: FMRadioChild::DeallocPFMRadioRequestChild(PFMRadioRequestChild* aActor) michael@0: { michael@0: delete aActor; michael@0: return true; michael@0: } michael@0: michael@0: void michael@0: FMRadioChild::EnableAudio(bool aAudioEnabled) michael@0: { michael@0: SendEnableAudio(aAudioEnabled); michael@0: } michael@0: michael@0: // static michael@0: FMRadioChild* michael@0: FMRadioChild::Singleton() michael@0: { michael@0: MOZ_ASSERT(XRE_GetProcessType() != GeckoProcessType_Default); michael@0: MOZ_ASSERT(NS_IsMainThread()); michael@0: michael@0: if (!sFMRadioChild) { michael@0: sFMRadioChild = new FMRadioChild(); michael@0: } michael@0: michael@0: return sFMRadioChild; michael@0: } michael@0: michael@0: END_FMRADIO_NAMESPACE michael@0: