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