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.

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

mercurial