1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/fmradio/ipc/FMRadioParent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,109 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "FMRadioParent.h" 1.10 +#include "mozilla/unused.h" 1.11 +#include "mozilla/dom/ContentParent.h" 1.12 +#include "FMRadioRequestParent.h" 1.13 +#include "FMRadioService.h" 1.14 + 1.15 +BEGIN_FMRADIO_NAMESPACE 1.16 + 1.17 +FMRadioParent::FMRadioParent() 1.18 +{ 1.19 + MOZ_COUNT_CTOR(FMRadioParent); 1.20 + 1.21 + IFMRadioService::Singleton()->AddObserver(this); 1.22 +} 1.23 + 1.24 +FMRadioParent::~FMRadioParent() 1.25 +{ 1.26 + MOZ_COUNT_DTOR(FMRadioParent); 1.27 + 1.28 + IFMRadioService::Singleton()->RemoveObserver(this); 1.29 +} 1.30 + 1.31 +bool 1.32 +FMRadioParent::RecvGetStatusInfo(StatusInfo* aStatusInfo) 1.33 +{ 1.34 + aStatusInfo->enabled() = IFMRadioService::Singleton()->IsEnabled(); 1.35 + aStatusInfo->frequency() = IFMRadioService::Singleton()->GetFrequency(); 1.36 + aStatusInfo->upperBound() = 1.37 + IFMRadioService::Singleton()->GetFrequencyUpperBound(); 1.38 + aStatusInfo->lowerBound() = 1.39 + IFMRadioService::Singleton()->GetFrequencyLowerBound(); 1.40 + aStatusInfo->channelWidth() = 1.41 + IFMRadioService::Singleton()->GetChannelWidth(); 1.42 + return true; 1.43 +} 1.44 + 1.45 +PFMRadioRequestParent* 1.46 +FMRadioParent::AllocPFMRadioRequestParent(const FMRadioRequestArgs& aArgs) 1.47 +{ 1.48 + nsRefPtr<FMRadioRequestParent> requestParent = new FMRadioRequestParent(); 1.49 + 1.50 + switch (aArgs.type()) { 1.51 + case FMRadioRequestArgs::TEnableRequestArgs: 1.52 + IFMRadioService::Singleton()->Enable( 1.53 + aArgs.get_EnableRequestArgs().frequency(), requestParent); 1.54 + break; 1.55 + case FMRadioRequestArgs::TDisableRequestArgs: 1.56 + IFMRadioService::Singleton()->Disable(requestParent); 1.57 + break; 1.58 + case FMRadioRequestArgs::TSetFrequencyRequestArgs: 1.59 + IFMRadioService::Singleton()->SetFrequency( 1.60 + aArgs.get_SetFrequencyRequestArgs().frequency(), requestParent); 1.61 + break; 1.62 + case FMRadioRequestArgs::TSeekRequestArgs: 1.63 + IFMRadioService::Singleton()->Seek( 1.64 + aArgs.get_SeekRequestArgs().direction(), requestParent); 1.65 + break; 1.66 + case FMRadioRequestArgs::TCancelSeekRequestArgs: 1.67 + IFMRadioService::Singleton()->CancelSeek(requestParent); 1.68 + break; 1.69 + default: 1.70 + MOZ_CRASH(); 1.71 + } 1.72 + 1.73 + // Balanced in DeallocPFMRadioRequestParent 1.74 + return requestParent.forget().take(); 1.75 +} 1.76 + 1.77 +bool 1.78 +FMRadioParent::DeallocPFMRadioRequestParent(PFMRadioRequestParent* aActor) 1.79 +{ 1.80 + FMRadioRequestParent* parent = static_cast<FMRadioRequestParent*>(aActor); 1.81 + NS_RELEASE(parent); 1.82 + return true; 1.83 +} 1.84 + 1.85 +void 1.86 +FMRadioParent::Notify(const FMRadioEventType& aType) 1.87 +{ 1.88 + switch (aType) { 1.89 + case FrequencyChanged: 1.90 + unused << SendNotifyFrequencyChanged( 1.91 + IFMRadioService::Singleton()->GetFrequency()); 1.92 + break; 1.93 + case EnabledChanged: 1.94 + unused << SendNotifyEnabledChanged( 1.95 + IFMRadioService::Singleton()->IsEnabled(), 1.96 + IFMRadioService::Singleton()->GetFrequency()); 1.97 + break; 1.98 + default: 1.99 + NS_RUNTIMEABORT("not reached"); 1.100 + break; 1.101 + } 1.102 +} 1.103 + 1.104 +bool 1.105 +FMRadioParent::RecvEnableAudio(const bool& aAudioEnabled) 1.106 +{ 1.107 + IFMRadioService::Singleton()->EnableAudio(aAudioEnabled); 1.108 + return true; 1.109 +} 1.110 + 1.111 +END_FMRADIO_NAMESPACE 1.112 +