michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 "FMRadioParent.h" michael@0: #include "mozilla/unused.h" michael@0: #include "mozilla/dom/ContentParent.h" michael@0: #include "FMRadioRequestParent.h" michael@0: #include "FMRadioService.h" michael@0: michael@0: BEGIN_FMRADIO_NAMESPACE michael@0: michael@0: FMRadioParent::FMRadioParent() michael@0: { michael@0: MOZ_COUNT_CTOR(FMRadioParent); michael@0: michael@0: IFMRadioService::Singleton()->AddObserver(this); michael@0: } michael@0: michael@0: FMRadioParent::~FMRadioParent() michael@0: { michael@0: MOZ_COUNT_DTOR(FMRadioParent); michael@0: michael@0: IFMRadioService::Singleton()->RemoveObserver(this); michael@0: } michael@0: michael@0: bool michael@0: FMRadioParent::RecvGetStatusInfo(StatusInfo* aStatusInfo) michael@0: { michael@0: aStatusInfo->enabled() = IFMRadioService::Singleton()->IsEnabled(); michael@0: aStatusInfo->frequency() = IFMRadioService::Singleton()->GetFrequency(); michael@0: aStatusInfo->upperBound() = michael@0: IFMRadioService::Singleton()->GetFrequencyUpperBound(); michael@0: aStatusInfo->lowerBound() = michael@0: IFMRadioService::Singleton()->GetFrequencyLowerBound(); michael@0: aStatusInfo->channelWidth() = michael@0: IFMRadioService::Singleton()->GetChannelWidth(); michael@0: return true; michael@0: } michael@0: michael@0: PFMRadioRequestParent* michael@0: FMRadioParent::AllocPFMRadioRequestParent(const FMRadioRequestArgs& aArgs) michael@0: { michael@0: nsRefPtr requestParent = new FMRadioRequestParent(); michael@0: michael@0: switch (aArgs.type()) { michael@0: case FMRadioRequestArgs::TEnableRequestArgs: michael@0: IFMRadioService::Singleton()->Enable( michael@0: aArgs.get_EnableRequestArgs().frequency(), requestParent); michael@0: break; michael@0: case FMRadioRequestArgs::TDisableRequestArgs: michael@0: IFMRadioService::Singleton()->Disable(requestParent); michael@0: break; michael@0: case FMRadioRequestArgs::TSetFrequencyRequestArgs: michael@0: IFMRadioService::Singleton()->SetFrequency( michael@0: aArgs.get_SetFrequencyRequestArgs().frequency(), requestParent); michael@0: break; michael@0: case FMRadioRequestArgs::TSeekRequestArgs: michael@0: IFMRadioService::Singleton()->Seek( michael@0: aArgs.get_SeekRequestArgs().direction(), requestParent); michael@0: break; michael@0: case FMRadioRequestArgs::TCancelSeekRequestArgs: michael@0: IFMRadioService::Singleton()->CancelSeek(requestParent); michael@0: break; michael@0: default: michael@0: MOZ_CRASH(); michael@0: } michael@0: michael@0: // Balanced in DeallocPFMRadioRequestParent michael@0: return requestParent.forget().take(); michael@0: } michael@0: michael@0: bool michael@0: FMRadioParent::DeallocPFMRadioRequestParent(PFMRadioRequestParent* aActor) michael@0: { michael@0: FMRadioRequestParent* parent = static_cast(aActor); michael@0: NS_RELEASE(parent); michael@0: return true; michael@0: } michael@0: michael@0: void michael@0: FMRadioParent::Notify(const FMRadioEventType& aType) michael@0: { michael@0: switch (aType) { michael@0: case FrequencyChanged: michael@0: unused << SendNotifyFrequencyChanged( michael@0: IFMRadioService::Singleton()->GetFrequency()); michael@0: break; michael@0: case EnabledChanged: michael@0: unused << SendNotifyEnabledChanged( michael@0: IFMRadioService::Singleton()->IsEnabled(), michael@0: IFMRadioService::Singleton()->GetFrequency()); michael@0: break; michael@0: default: michael@0: NS_RUNTIMEABORT("not reached"); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: bool michael@0: FMRadioParent::RecvEnableAudio(const bool& aAudioEnabled) michael@0: { michael@0: IFMRadioService::Singleton()->EnableAudio(aAudioEnabled); michael@0: return true; michael@0: } michael@0: michael@0: END_FMRADIO_NAMESPACE michael@0: