dom/fmradio/ipc/FMRadioChild.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/fmradio/ipc/FMRadioChild.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,189 @@
     1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "FMRadioChild.h"
    1.11 +#include "mozilla/dom/ContentChild.h"
    1.12 +#include "mozilla/dom/FMRadioRequestChild.h"
    1.13 +
    1.14 +using namespace mozilla::hal;
    1.15 +
    1.16 +BEGIN_FMRADIO_NAMESPACE
    1.17 +
    1.18 +StaticAutoPtr<FMRadioChild> FMRadioChild::sFMRadioChild;
    1.19 +
    1.20 +FMRadioChild::FMRadioChild()
    1.21 +  : mEnabled(false)
    1.22 +  , mFrequency(0)
    1.23 +  , mObserverList(FMRadioEventObserverList())
    1.24 +{
    1.25 +  MOZ_COUNT_CTOR(FMRadioChild);
    1.26 +
    1.27 +  ContentChild::GetSingleton()->SendPFMRadioConstructor(this);
    1.28 +
    1.29 +  StatusInfo statusInfo;
    1.30 +  SendGetStatusInfo(&statusInfo);
    1.31 +
    1.32 +  mEnabled = statusInfo.enabled();
    1.33 +  mFrequency = statusInfo.frequency();
    1.34 +  mUpperBound = statusInfo.upperBound();
    1.35 +  mLowerBound= statusInfo.lowerBound();
    1.36 +  mChannelWidth = statusInfo.channelWidth();
    1.37 +}
    1.38 +
    1.39 +FMRadioChild::~FMRadioChild()
    1.40 +{
    1.41 +  MOZ_COUNT_DTOR(FMRadioChild);
    1.42 +}
    1.43 +
    1.44 +bool
    1.45 +FMRadioChild::IsEnabled() const
    1.46 +{
    1.47 +  return mEnabled;
    1.48 +}
    1.49 +
    1.50 +double
    1.51 +FMRadioChild::GetFrequency() const
    1.52 +{
    1.53 +  return mFrequency;
    1.54 +}
    1.55 +
    1.56 +
    1.57 +double
    1.58 +FMRadioChild::GetFrequencyUpperBound() const
    1.59 +{
    1.60 +  return mUpperBound;
    1.61 +}
    1.62 +
    1.63 +double
    1.64 +FMRadioChild::GetFrequencyLowerBound() const
    1.65 +{
    1.66 +  return mLowerBound;
    1.67 +}
    1.68 +
    1.69 +double
    1.70 +FMRadioChild::GetChannelWidth() const
    1.71 +{
    1.72 +  return mChannelWidth;
    1.73 +}
    1.74 +
    1.75 +void
    1.76 +FMRadioChild::Enable(double aFrequency, FMRadioReplyRunnable* aReplyRunnable)
    1.77 +{
    1.78 +  SendRequest(aReplyRunnable, EnableRequestArgs(aFrequency));
    1.79 +}
    1.80 +
    1.81 +void
    1.82 +FMRadioChild::Disable(FMRadioReplyRunnable* aReplyRunnable)
    1.83 +{
    1.84 +  SendRequest(aReplyRunnable, DisableRequestArgs());
    1.85 +}
    1.86 +
    1.87 +void
    1.88 +FMRadioChild::SetFrequency(double aFrequency,
    1.89 +                           FMRadioReplyRunnable* aReplyRunnable)
    1.90 +{
    1.91 +  SendRequest(aReplyRunnable, SetFrequencyRequestArgs(aFrequency));
    1.92 +}
    1.93 +
    1.94 +void
    1.95 +FMRadioChild::Seek(FMRadioSeekDirection aDirection,
    1.96 +                   FMRadioReplyRunnable* aReplyRunnable)
    1.97 +{
    1.98 +  SendRequest(aReplyRunnable, SeekRequestArgs(aDirection));
    1.99 +}
   1.100 +
   1.101 +void
   1.102 +FMRadioChild::CancelSeek(FMRadioReplyRunnable* aReplyRunnable)
   1.103 +{
   1.104 +  SendRequest(aReplyRunnable, CancelSeekRequestArgs());
   1.105 +}
   1.106 +
   1.107 +inline void
   1.108 +FMRadioChild::NotifyFMRadioEvent(FMRadioEventType aType)
   1.109 +{
   1.110 +  mObserverList.Broadcast(aType);
   1.111 +}
   1.112 +
   1.113 +void
   1.114 +FMRadioChild::AddObserver(FMRadioEventObserver* aObserver)
   1.115 +{
   1.116 +  mObserverList.AddObserver(aObserver);
   1.117 +}
   1.118 +
   1.119 +void
   1.120 +FMRadioChild::RemoveObserver(FMRadioEventObserver* aObserver)
   1.121 +{
   1.122 +  mObserverList.RemoveObserver(aObserver);
   1.123 +}
   1.124 +
   1.125 +void
   1.126 +FMRadioChild::SendRequest(FMRadioReplyRunnable* aReplyRunnable,
   1.127 +                          FMRadioRequestArgs aArgs)
   1.128 +{
   1.129 +  PFMRadioRequestChild* childRequest = new FMRadioRequestChild(aReplyRunnable);
   1.130 +  SendPFMRadioRequestConstructor(childRequest, aArgs);
   1.131 +}
   1.132 +
   1.133 +bool
   1.134 +FMRadioChild::RecvNotifyFrequencyChanged(const double& aFrequency)
   1.135 +{
   1.136 +  mFrequency = aFrequency;
   1.137 +  NotifyFMRadioEvent(FrequencyChanged);
   1.138 +  return true;
   1.139 +}
   1.140 +
   1.141 +bool
   1.142 +FMRadioChild::RecvNotifyEnabledChanged(const bool& aEnabled,
   1.143 +                                       const double& aFrequency)
   1.144 +{
   1.145 +  mEnabled = aEnabled;
   1.146 +  mFrequency = aFrequency;
   1.147 +  NotifyFMRadioEvent(EnabledChanged);
   1.148 +  return true;
   1.149 +}
   1.150 +
   1.151 +bool
   1.152 +FMRadioChild::Recv__delete__()
   1.153 +{
   1.154 +  return true;
   1.155 +}
   1.156 +
   1.157 +PFMRadioRequestChild*
   1.158 +FMRadioChild::AllocPFMRadioRequestChild(const FMRadioRequestArgs& aArgs)
   1.159 +{
   1.160 +  MOZ_CRASH();
   1.161 +  return nullptr;
   1.162 +}
   1.163 +
   1.164 +bool
   1.165 +FMRadioChild::DeallocPFMRadioRequestChild(PFMRadioRequestChild* aActor)
   1.166 +{
   1.167 +  delete aActor;
   1.168 +  return true;
   1.169 +}
   1.170 +
   1.171 +void
   1.172 +FMRadioChild::EnableAudio(bool aAudioEnabled)
   1.173 +{
   1.174 +  SendEnableAudio(aAudioEnabled);
   1.175 +}
   1.176 +
   1.177 +// static
   1.178 +FMRadioChild*
   1.179 +FMRadioChild::Singleton()
   1.180 +{
   1.181 +  MOZ_ASSERT(XRE_GetProcessType() != GeckoProcessType_Default);
   1.182 +  MOZ_ASSERT(NS_IsMainThread());
   1.183 +
   1.184 +  if (!sFMRadioChild) {
   1.185 +    sFMRadioChild = new FMRadioChild();
   1.186 +  }
   1.187 +
   1.188 +  return sFMRadioChild;
   1.189 +}
   1.190 +
   1.191 +END_FMRADIO_NAMESPACE
   1.192 +

mercurial