dom/fmradio/ipc/FMRadioChild.cpp

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:5145e982d8f2
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/. */
6
7 #include "FMRadioChild.h"
8 #include "mozilla/dom/ContentChild.h"
9 #include "mozilla/dom/FMRadioRequestChild.h"
10
11 using namespace mozilla::hal;
12
13 BEGIN_FMRADIO_NAMESPACE
14
15 StaticAutoPtr<FMRadioChild> FMRadioChild::sFMRadioChild;
16
17 FMRadioChild::FMRadioChild()
18 : mEnabled(false)
19 , mFrequency(0)
20 , mObserverList(FMRadioEventObserverList())
21 {
22 MOZ_COUNT_CTOR(FMRadioChild);
23
24 ContentChild::GetSingleton()->SendPFMRadioConstructor(this);
25
26 StatusInfo statusInfo;
27 SendGetStatusInfo(&statusInfo);
28
29 mEnabled = statusInfo.enabled();
30 mFrequency = statusInfo.frequency();
31 mUpperBound = statusInfo.upperBound();
32 mLowerBound= statusInfo.lowerBound();
33 mChannelWidth = statusInfo.channelWidth();
34 }
35
36 FMRadioChild::~FMRadioChild()
37 {
38 MOZ_COUNT_DTOR(FMRadioChild);
39 }
40
41 bool
42 FMRadioChild::IsEnabled() const
43 {
44 return mEnabled;
45 }
46
47 double
48 FMRadioChild::GetFrequency() const
49 {
50 return mFrequency;
51 }
52
53
54 double
55 FMRadioChild::GetFrequencyUpperBound() const
56 {
57 return mUpperBound;
58 }
59
60 double
61 FMRadioChild::GetFrequencyLowerBound() const
62 {
63 return mLowerBound;
64 }
65
66 double
67 FMRadioChild::GetChannelWidth() const
68 {
69 return mChannelWidth;
70 }
71
72 void
73 FMRadioChild::Enable(double aFrequency, FMRadioReplyRunnable* aReplyRunnable)
74 {
75 SendRequest(aReplyRunnable, EnableRequestArgs(aFrequency));
76 }
77
78 void
79 FMRadioChild::Disable(FMRadioReplyRunnable* aReplyRunnable)
80 {
81 SendRequest(aReplyRunnable, DisableRequestArgs());
82 }
83
84 void
85 FMRadioChild::SetFrequency(double aFrequency,
86 FMRadioReplyRunnable* aReplyRunnable)
87 {
88 SendRequest(aReplyRunnable, SetFrequencyRequestArgs(aFrequency));
89 }
90
91 void
92 FMRadioChild::Seek(FMRadioSeekDirection aDirection,
93 FMRadioReplyRunnable* aReplyRunnable)
94 {
95 SendRequest(aReplyRunnable, SeekRequestArgs(aDirection));
96 }
97
98 void
99 FMRadioChild::CancelSeek(FMRadioReplyRunnable* aReplyRunnable)
100 {
101 SendRequest(aReplyRunnable, CancelSeekRequestArgs());
102 }
103
104 inline void
105 FMRadioChild::NotifyFMRadioEvent(FMRadioEventType aType)
106 {
107 mObserverList.Broadcast(aType);
108 }
109
110 void
111 FMRadioChild::AddObserver(FMRadioEventObserver* aObserver)
112 {
113 mObserverList.AddObserver(aObserver);
114 }
115
116 void
117 FMRadioChild::RemoveObserver(FMRadioEventObserver* aObserver)
118 {
119 mObserverList.RemoveObserver(aObserver);
120 }
121
122 void
123 FMRadioChild::SendRequest(FMRadioReplyRunnable* aReplyRunnable,
124 FMRadioRequestArgs aArgs)
125 {
126 PFMRadioRequestChild* childRequest = new FMRadioRequestChild(aReplyRunnable);
127 SendPFMRadioRequestConstructor(childRequest, aArgs);
128 }
129
130 bool
131 FMRadioChild::RecvNotifyFrequencyChanged(const double& aFrequency)
132 {
133 mFrequency = aFrequency;
134 NotifyFMRadioEvent(FrequencyChanged);
135 return true;
136 }
137
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 }
147
148 bool
149 FMRadioChild::Recv__delete__()
150 {
151 return true;
152 }
153
154 PFMRadioRequestChild*
155 FMRadioChild::AllocPFMRadioRequestChild(const FMRadioRequestArgs& aArgs)
156 {
157 MOZ_CRASH();
158 return nullptr;
159 }
160
161 bool
162 FMRadioChild::DeallocPFMRadioRequestChild(PFMRadioRequestChild* aActor)
163 {
164 delete aActor;
165 return true;
166 }
167
168 void
169 FMRadioChild::EnableAudio(bool aAudioEnabled)
170 {
171 SendEnableAudio(aAudioEnabled);
172 }
173
174 // static
175 FMRadioChild*
176 FMRadioChild::Singleton()
177 {
178 MOZ_ASSERT(XRE_GetProcessType() != GeckoProcessType_Default);
179 MOZ_ASSERT(NS_IsMainThread());
180
181 if (!sFMRadioChild) {
182 sFMRadioChild = new FMRadioChild();
183 }
184
185 return sFMRadioChild;
186 }
187
188 END_FMRADIO_NAMESPACE
189

mercurial