Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "FMRadioParent.h" |
michael@0 | 7 | #include "mozilla/unused.h" |
michael@0 | 8 | #include "mozilla/dom/ContentParent.h" |
michael@0 | 9 | #include "FMRadioRequestParent.h" |
michael@0 | 10 | #include "FMRadioService.h" |
michael@0 | 11 | |
michael@0 | 12 | BEGIN_FMRADIO_NAMESPACE |
michael@0 | 13 | |
michael@0 | 14 | FMRadioParent::FMRadioParent() |
michael@0 | 15 | { |
michael@0 | 16 | MOZ_COUNT_CTOR(FMRadioParent); |
michael@0 | 17 | |
michael@0 | 18 | IFMRadioService::Singleton()->AddObserver(this); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | FMRadioParent::~FMRadioParent() |
michael@0 | 22 | { |
michael@0 | 23 | MOZ_COUNT_DTOR(FMRadioParent); |
michael@0 | 24 | |
michael@0 | 25 | IFMRadioService::Singleton()->RemoveObserver(this); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | bool |
michael@0 | 29 | FMRadioParent::RecvGetStatusInfo(StatusInfo* aStatusInfo) |
michael@0 | 30 | { |
michael@0 | 31 | aStatusInfo->enabled() = IFMRadioService::Singleton()->IsEnabled(); |
michael@0 | 32 | aStatusInfo->frequency() = IFMRadioService::Singleton()->GetFrequency(); |
michael@0 | 33 | aStatusInfo->upperBound() = |
michael@0 | 34 | IFMRadioService::Singleton()->GetFrequencyUpperBound(); |
michael@0 | 35 | aStatusInfo->lowerBound() = |
michael@0 | 36 | IFMRadioService::Singleton()->GetFrequencyLowerBound(); |
michael@0 | 37 | aStatusInfo->channelWidth() = |
michael@0 | 38 | IFMRadioService::Singleton()->GetChannelWidth(); |
michael@0 | 39 | return true; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | PFMRadioRequestParent* |
michael@0 | 43 | FMRadioParent::AllocPFMRadioRequestParent(const FMRadioRequestArgs& aArgs) |
michael@0 | 44 | { |
michael@0 | 45 | nsRefPtr<FMRadioRequestParent> requestParent = new FMRadioRequestParent(); |
michael@0 | 46 | |
michael@0 | 47 | switch (aArgs.type()) { |
michael@0 | 48 | case FMRadioRequestArgs::TEnableRequestArgs: |
michael@0 | 49 | IFMRadioService::Singleton()->Enable( |
michael@0 | 50 | aArgs.get_EnableRequestArgs().frequency(), requestParent); |
michael@0 | 51 | break; |
michael@0 | 52 | case FMRadioRequestArgs::TDisableRequestArgs: |
michael@0 | 53 | IFMRadioService::Singleton()->Disable(requestParent); |
michael@0 | 54 | break; |
michael@0 | 55 | case FMRadioRequestArgs::TSetFrequencyRequestArgs: |
michael@0 | 56 | IFMRadioService::Singleton()->SetFrequency( |
michael@0 | 57 | aArgs.get_SetFrequencyRequestArgs().frequency(), requestParent); |
michael@0 | 58 | break; |
michael@0 | 59 | case FMRadioRequestArgs::TSeekRequestArgs: |
michael@0 | 60 | IFMRadioService::Singleton()->Seek( |
michael@0 | 61 | aArgs.get_SeekRequestArgs().direction(), requestParent); |
michael@0 | 62 | break; |
michael@0 | 63 | case FMRadioRequestArgs::TCancelSeekRequestArgs: |
michael@0 | 64 | IFMRadioService::Singleton()->CancelSeek(requestParent); |
michael@0 | 65 | break; |
michael@0 | 66 | default: |
michael@0 | 67 | MOZ_CRASH(); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | // Balanced in DeallocPFMRadioRequestParent |
michael@0 | 71 | return requestParent.forget().take(); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | bool |
michael@0 | 75 | FMRadioParent::DeallocPFMRadioRequestParent(PFMRadioRequestParent* aActor) |
michael@0 | 76 | { |
michael@0 | 77 | FMRadioRequestParent* parent = static_cast<FMRadioRequestParent*>(aActor); |
michael@0 | 78 | NS_RELEASE(parent); |
michael@0 | 79 | return true; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | void |
michael@0 | 83 | FMRadioParent::Notify(const FMRadioEventType& aType) |
michael@0 | 84 | { |
michael@0 | 85 | switch (aType) { |
michael@0 | 86 | case FrequencyChanged: |
michael@0 | 87 | unused << SendNotifyFrequencyChanged( |
michael@0 | 88 | IFMRadioService::Singleton()->GetFrequency()); |
michael@0 | 89 | break; |
michael@0 | 90 | case EnabledChanged: |
michael@0 | 91 | unused << SendNotifyEnabledChanged( |
michael@0 | 92 | IFMRadioService::Singleton()->IsEnabled(), |
michael@0 | 93 | IFMRadioService::Singleton()->GetFrequency()); |
michael@0 | 94 | break; |
michael@0 | 95 | default: |
michael@0 | 96 | NS_RUNTIMEABORT("not reached"); |
michael@0 | 97 | break; |
michael@0 | 98 | } |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | bool |
michael@0 | 102 | FMRadioParent::RecvEnableAudio(const bool& aAudioEnabled) |
michael@0 | 103 | { |
michael@0 | 104 | IFMRadioService::Singleton()->EnableAudio(aAudioEnabled); |
michael@0 | 105 | return true; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | END_FMRADIO_NAMESPACE |
michael@0 | 109 |