dom/fmradio/ipc/FMRadioChild.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
     2 /* vim: set ts=2 et sw=2 tw=80: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     5  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #include "FMRadioChild.h"
     8 #include "mozilla/dom/ContentChild.h"
     9 #include "mozilla/dom/FMRadioRequestChild.h"
    11 using namespace mozilla::hal;
    13 BEGIN_FMRADIO_NAMESPACE
    15 StaticAutoPtr<FMRadioChild> FMRadioChild::sFMRadioChild;
    17 FMRadioChild::FMRadioChild()
    18   : mEnabled(false)
    19   , mFrequency(0)
    20   , mObserverList(FMRadioEventObserverList())
    21 {
    22   MOZ_COUNT_CTOR(FMRadioChild);
    24   ContentChild::GetSingleton()->SendPFMRadioConstructor(this);
    26   StatusInfo statusInfo;
    27   SendGetStatusInfo(&statusInfo);
    29   mEnabled = statusInfo.enabled();
    30   mFrequency = statusInfo.frequency();
    31   mUpperBound = statusInfo.upperBound();
    32   mLowerBound= statusInfo.lowerBound();
    33   mChannelWidth = statusInfo.channelWidth();
    34 }
    36 FMRadioChild::~FMRadioChild()
    37 {
    38   MOZ_COUNT_DTOR(FMRadioChild);
    39 }
    41 bool
    42 FMRadioChild::IsEnabled() const
    43 {
    44   return mEnabled;
    45 }
    47 double
    48 FMRadioChild::GetFrequency() const
    49 {
    50   return mFrequency;
    51 }
    54 double
    55 FMRadioChild::GetFrequencyUpperBound() const
    56 {
    57   return mUpperBound;
    58 }
    60 double
    61 FMRadioChild::GetFrequencyLowerBound() const
    62 {
    63   return mLowerBound;
    64 }
    66 double
    67 FMRadioChild::GetChannelWidth() const
    68 {
    69   return mChannelWidth;
    70 }
    72 void
    73 FMRadioChild::Enable(double aFrequency, FMRadioReplyRunnable* aReplyRunnable)
    74 {
    75   SendRequest(aReplyRunnable, EnableRequestArgs(aFrequency));
    76 }
    78 void
    79 FMRadioChild::Disable(FMRadioReplyRunnable* aReplyRunnable)
    80 {
    81   SendRequest(aReplyRunnable, DisableRequestArgs());
    82 }
    84 void
    85 FMRadioChild::SetFrequency(double aFrequency,
    86                            FMRadioReplyRunnable* aReplyRunnable)
    87 {
    88   SendRequest(aReplyRunnable, SetFrequencyRequestArgs(aFrequency));
    89 }
    91 void
    92 FMRadioChild::Seek(FMRadioSeekDirection aDirection,
    93                    FMRadioReplyRunnable* aReplyRunnable)
    94 {
    95   SendRequest(aReplyRunnable, SeekRequestArgs(aDirection));
    96 }
    98 void
    99 FMRadioChild::CancelSeek(FMRadioReplyRunnable* aReplyRunnable)
   100 {
   101   SendRequest(aReplyRunnable, CancelSeekRequestArgs());
   102 }
   104 inline void
   105 FMRadioChild::NotifyFMRadioEvent(FMRadioEventType aType)
   106 {
   107   mObserverList.Broadcast(aType);
   108 }
   110 void
   111 FMRadioChild::AddObserver(FMRadioEventObserver* aObserver)
   112 {
   113   mObserverList.AddObserver(aObserver);
   114 }
   116 void
   117 FMRadioChild::RemoveObserver(FMRadioEventObserver* aObserver)
   118 {
   119   mObserverList.RemoveObserver(aObserver);
   120 }
   122 void
   123 FMRadioChild::SendRequest(FMRadioReplyRunnable* aReplyRunnable,
   124                           FMRadioRequestArgs aArgs)
   125 {
   126   PFMRadioRequestChild* childRequest = new FMRadioRequestChild(aReplyRunnable);
   127   SendPFMRadioRequestConstructor(childRequest, aArgs);
   128 }
   130 bool
   131 FMRadioChild::RecvNotifyFrequencyChanged(const double& aFrequency)
   132 {
   133   mFrequency = aFrequency;
   134   NotifyFMRadioEvent(FrequencyChanged);
   135   return true;
   136 }
   138 bool
   139 FMRadioChild::RecvNotifyEnabledChanged(const bool& aEnabled,
   140                                        const double& aFrequency)
   141 {
   142   mEnabled = aEnabled;
   143   mFrequency = aFrequency;
   144   NotifyFMRadioEvent(EnabledChanged);
   145   return true;
   146 }
   148 bool
   149 FMRadioChild::Recv__delete__()
   150 {
   151   return true;
   152 }
   154 PFMRadioRequestChild*
   155 FMRadioChild::AllocPFMRadioRequestChild(const FMRadioRequestArgs& aArgs)
   156 {
   157   MOZ_CRASH();
   158   return nullptr;
   159 }
   161 bool
   162 FMRadioChild::DeallocPFMRadioRequestChild(PFMRadioRequestChild* aActor)
   163 {
   164   delete aActor;
   165   return true;
   166 }
   168 void
   169 FMRadioChild::EnableAudio(bool aAudioEnabled)
   170 {
   171   SendEnableAudio(aAudioEnabled);
   172 }
   174 // static
   175 FMRadioChild*
   176 FMRadioChild::Singleton()
   177 {
   178   MOZ_ASSERT(XRE_GetProcessType() != GeckoProcessType_Default);
   179   MOZ_ASSERT(NS_IsMainThread());
   181   if (!sFMRadioChild) {
   182     sFMRadioChild = new FMRadioChild();
   183   }
   185   return sFMRadioChild;
   186 }
   188 END_FMRADIO_NAMESPACE

mercurial