|
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 "base/basictypes.h" |
|
8 |
|
9 #include "BluetoothServiceChildProcess.h" |
|
10 |
|
11 #include "mozilla/Assertions.h" |
|
12 #include "mozilla/dom/ContentChild.h" |
|
13 |
|
14 #include "BluetoothChild.h" |
|
15 #include "MainThreadUtils.h" |
|
16 |
|
17 USING_BLUETOOTH_NAMESPACE |
|
18 |
|
19 namespace { |
|
20 |
|
21 BluetoothChild* sBluetoothChild; |
|
22 |
|
23 inline |
|
24 void |
|
25 SendRequest(BluetoothReplyRunnable* aRunnable, const Request& aRequest) |
|
26 { |
|
27 MOZ_ASSERT(NS_IsMainThread()); |
|
28 MOZ_ASSERT(aRunnable); |
|
29 |
|
30 NS_WARN_IF_FALSE(sBluetoothChild, |
|
31 "Calling methods on BluetoothServiceChildProcess during " |
|
32 "shutdown!"); |
|
33 |
|
34 if (sBluetoothChild) { |
|
35 BluetoothRequestChild* actor = new BluetoothRequestChild(aRunnable); |
|
36 sBluetoothChild->SendPBluetoothRequestConstructor(actor, aRequest); |
|
37 } |
|
38 } |
|
39 |
|
40 } // anonymous namespace |
|
41 |
|
42 // static |
|
43 BluetoothServiceChildProcess* |
|
44 BluetoothServiceChildProcess::Create() |
|
45 { |
|
46 MOZ_ASSERT(!sBluetoothChild); |
|
47 |
|
48 mozilla::dom::ContentChild* contentChild = |
|
49 mozilla::dom::ContentChild::GetSingleton(); |
|
50 MOZ_ASSERT(contentChild); |
|
51 |
|
52 BluetoothServiceChildProcess* btService = new BluetoothServiceChildProcess(); |
|
53 |
|
54 sBluetoothChild = new BluetoothChild(btService); |
|
55 contentChild->SendPBluetoothConstructor(sBluetoothChild); |
|
56 |
|
57 return btService; |
|
58 } |
|
59 |
|
60 BluetoothServiceChildProcess::BluetoothServiceChildProcess() |
|
61 { |
|
62 } |
|
63 |
|
64 BluetoothServiceChildProcess::~BluetoothServiceChildProcess() |
|
65 { |
|
66 sBluetoothChild = nullptr; |
|
67 } |
|
68 |
|
69 void |
|
70 BluetoothServiceChildProcess::NoteDeadActor() |
|
71 { |
|
72 MOZ_ASSERT(sBluetoothChild); |
|
73 sBluetoothChild = nullptr; |
|
74 } |
|
75 |
|
76 void |
|
77 BluetoothServiceChildProcess::RegisterBluetoothSignalHandler( |
|
78 const nsAString& aNodeName, |
|
79 BluetoothSignalObserver* aHandler) |
|
80 { |
|
81 if (sBluetoothChild && !IsSignalRegistered(aNodeName)) { |
|
82 sBluetoothChild->SendRegisterSignalHandler(nsString(aNodeName)); |
|
83 } |
|
84 BluetoothService::RegisterBluetoothSignalHandler(aNodeName, aHandler); |
|
85 } |
|
86 |
|
87 void |
|
88 BluetoothServiceChildProcess::UnregisterBluetoothSignalHandler( |
|
89 const nsAString& aNodeName, |
|
90 BluetoothSignalObserver* aHandler) |
|
91 { |
|
92 BluetoothService::UnregisterBluetoothSignalHandler(aNodeName, aHandler); |
|
93 if (sBluetoothChild && !IsSignalRegistered(aNodeName)) { |
|
94 sBluetoothChild->SendUnregisterSignalHandler(nsString(aNodeName)); |
|
95 } |
|
96 } |
|
97 |
|
98 nsresult |
|
99 BluetoothServiceChildProcess::GetDefaultAdapterPathInternal( |
|
100 BluetoothReplyRunnable* aRunnable) |
|
101 { |
|
102 SendRequest(aRunnable, DefaultAdapterPathRequest()); |
|
103 return NS_OK; |
|
104 } |
|
105 |
|
106 nsresult |
|
107 BluetoothServiceChildProcess::GetConnectedDevicePropertiesInternal( |
|
108 uint16_t aServiceUuid, |
|
109 BluetoothReplyRunnable* aRunnable) |
|
110 { |
|
111 SendRequest(aRunnable, ConnectedDevicePropertiesRequest(aServiceUuid)); |
|
112 return NS_OK; |
|
113 } |
|
114 nsresult |
|
115 BluetoothServiceChildProcess::GetPairedDevicePropertiesInternal( |
|
116 const nsTArray<nsString>& aDeviceAddresses, |
|
117 BluetoothReplyRunnable* aRunnable) |
|
118 { |
|
119 PairedDevicePropertiesRequest request; |
|
120 request.addresses().AppendElements(aDeviceAddresses); |
|
121 |
|
122 SendRequest(aRunnable, request); |
|
123 return NS_OK; |
|
124 } |
|
125 |
|
126 nsresult |
|
127 BluetoothServiceChildProcess::StopDiscoveryInternal( |
|
128 BluetoothReplyRunnable* aRunnable) |
|
129 { |
|
130 SendRequest(aRunnable, StopDiscoveryRequest()); |
|
131 return NS_OK; |
|
132 } |
|
133 |
|
134 nsresult |
|
135 BluetoothServiceChildProcess::StartDiscoveryInternal( |
|
136 BluetoothReplyRunnable* aRunnable) |
|
137 { |
|
138 SendRequest(aRunnable, StartDiscoveryRequest()); |
|
139 return NS_OK; |
|
140 } |
|
141 |
|
142 nsresult |
|
143 BluetoothServiceChildProcess::SetProperty(BluetoothObjectType aType, |
|
144 const BluetoothNamedValue& aValue, |
|
145 BluetoothReplyRunnable* aRunnable) |
|
146 { |
|
147 SendRequest(aRunnable, SetPropertyRequest(aType, aValue)); |
|
148 return NS_OK; |
|
149 } |
|
150 |
|
151 nsresult |
|
152 BluetoothServiceChildProcess::CreatePairedDeviceInternal( |
|
153 const nsAString& aAddress, |
|
154 int aTimeout, |
|
155 BluetoothReplyRunnable* aRunnable) |
|
156 { |
|
157 SendRequest(aRunnable, |
|
158 PairRequest(nsString(aAddress), aTimeout)); |
|
159 return NS_OK; |
|
160 } |
|
161 |
|
162 nsresult |
|
163 BluetoothServiceChildProcess::RemoveDeviceInternal( |
|
164 const nsAString& aObjectPath, |
|
165 BluetoothReplyRunnable* aRunnable) |
|
166 { |
|
167 SendRequest(aRunnable, |
|
168 UnpairRequest(nsString(aObjectPath))); |
|
169 return NS_OK; |
|
170 } |
|
171 |
|
172 nsresult |
|
173 BluetoothServiceChildProcess::GetServiceChannel(const nsAString& aDeviceAddress, |
|
174 const nsAString& aServiceUuid, |
|
175 BluetoothProfileManagerBase* aManager) |
|
176 { |
|
177 MOZ_CRASH("This should never be called!"); |
|
178 } |
|
179 |
|
180 bool |
|
181 BluetoothServiceChildProcess::UpdateSdpRecords(const nsAString& aDeviceAddress, |
|
182 BluetoothProfileManagerBase* aManager) |
|
183 { |
|
184 MOZ_CRASH("This should never be called!"); |
|
185 } |
|
186 |
|
187 bool |
|
188 BluetoothServiceChildProcess::SetPinCodeInternal( |
|
189 const nsAString& aDeviceAddress, |
|
190 const nsAString& aPinCode, |
|
191 BluetoothReplyRunnable* aRunnable) |
|
192 { |
|
193 SendRequest(aRunnable, |
|
194 SetPinCodeRequest(nsString(aDeviceAddress), nsString(aPinCode))); |
|
195 return true; |
|
196 } |
|
197 |
|
198 bool |
|
199 BluetoothServiceChildProcess::SetPasskeyInternal( |
|
200 const nsAString& aDeviceAddress, |
|
201 uint32_t aPasskey, |
|
202 BluetoothReplyRunnable* aRunnable) |
|
203 { |
|
204 SendRequest(aRunnable, |
|
205 SetPasskeyRequest(nsString(aDeviceAddress), aPasskey)); |
|
206 return true; |
|
207 } |
|
208 |
|
209 bool |
|
210 BluetoothServiceChildProcess::SetPairingConfirmationInternal( |
|
211 const nsAString& aDeviceAddress, |
|
212 bool aConfirm, |
|
213 BluetoothReplyRunnable* aRunnable) |
|
214 { |
|
215 if(aConfirm) { |
|
216 SendRequest(aRunnable, |
|
217 ConfirmPairingConfirmationRequest(nsString(aDeviceAddress))); |
|
218 } else { |
|
219 SendRequest(aRunnable, |
|
220 DenyPairingConfirmationRequest(nsString(aDeviceAddress))); |
|
221 } |
|
222 return true; |
|
223 } |
|
224 |
|
225 void |
|
226 BluetoothServiceChildProcess::Connect( |
|
227 const nsAString& aDeviceAddress, |
|
228 uint32_t aCod, |
|
229 uint16_t aServiceUuid, |
|
230 BluetoothReplyRunnable* aRunnable) |
|
231 { |
|
232 SendRequest(aRunnable, |
|
233 ConnectRequest(nsString(aDeviceAddress), |
|
234 aCod, |
|
235 aServiceUuid)); |
|
236 } |
|
237 |
|
238 void |
|
239 BluetoothServiceChildProcess::Disconnect( |
|
240 const nsAString& aDeviceAddress, |
|
241 uint16_t aServiceUuid, |
|
242 BluetoothReplyRunnable* aRunnable) |
|
243 { |
|
244 SendRequest(aRunnable, |
|
245 DisconnectRequest(nsString(aDeviceAddress), aServiceUuid)); |
|
246 } |
|
247 |
|
248 void |
|
249 BluetoothServiceChildProcess::SendFile( |
|
250 const nsAString& aDeviceAddress, |
|
251 BlobParent* aBlobParent, |
|
252 BlobChild* aBlobChild, |
|
253 BluetoothReplyRunnable* aRunnable) |
|
254 { |
|
255 SendRequest(aRunnable, |
|
256 SendFileRequest(nsString(aDeviceAddress), nullptr, aBlobChild)); |
|
257 } |
|
258 |
|
259 void |
|
260 BluetoothServiceChildProcess::SendFile( |
|
261 const nsAString& aDeviceAddress, |
|
262 nsIDOMBlob* aBlobChild, |
|
263 BluetoothReplyRunnable* aRunnable) |
|
264 { |
|
265 // Parent-process-only method |
|
266 MOZ_CRASH("This should never be called!"); |
|
267 } |
|
268 |
|
269 void |
|
270 BluetoothServiceChildProcess::StopSendingFile( |
|
271 const nsAString& aDeviceAddress, |
|
272 BluetoothReplyRunnable* aRunnable) |
|
273 { |
|
274 SendRequest(aRunnable, |
|
275 StopSendingFileRequest(nsString(aDeviceAddress))); |
|
276 } |
|
277 |
|
278 void |
|
279 BluetoothServiceChildProcess::ConfirmReceivingFile( |
|
280 const nsAString& aDeviceAddress, |
|
281 bool aConfirm, |
|
282 BluetoothReplyRunnable* aRunnable) |
|
283 { |
|
284 if(aConfirm) { |
|
285 SendRequest(aRunnable, |
|
286 ConfirmReceivingFileRequest(nsString(aDeviceAddress))); |
|
287 return; |
|
288 } |
|
289 |
|
290 SendRequest(aRunnable, |
|
291 DenyReceivingFileRequest(nsString(aDeviceAddress))); |
|
292 } |
|
293 |
|
294 void |
|
295 BluetoothServiceChildProcess::ConnectSco(BluetoothReplyRunnable* aRunnable) |
|
296 { |
|
297 SendRequest(aRunnable, ConnectScoRequest()); |
|
298 } |
|
299 |
|
300 void |
|
301 BluetoothServiceChildProcess::DisconnectSco(BluetoothReplyRunnable* aRunnable) |
|
302 { |
|
303 SendRequest(aRunnable, DisconnectScoRequest()); |
|
304 } |
|
305 |
|
306 void |
|
307 BluetoothServiceChildProcess::IsScoConnected(BluetoothReplyRunnable* aRunnable) |
|
308 { |
|
309 SendRequest(aRunnable, IsScoConnectedRequest()); |
|
310 } |
|
311 |
|
312 #ifdef MOZ_B2G_RIL |
|
313 void |
|
314 BluetoothServiceChildProcess::AnswerWaitingCall( |
|
315 BluetoothReplyRunnable* aRunnable) |
|
316 { |
|
317 SendRequest(aRunnable, AnswerWaitingCallRequest()); |
|
318 } |
|
319 |
|
320 void |
|
321 BluetoothServiceChildProcess::IgnoreWaitingCall( |
|
322 BluetoothReplyRunnable* aRunnable) |
|
323 { |
|
324 SendRequest(aRunnable, IgnoreWaitingCallRequest()); |
|
325 } |
|
326 |
|
327 void |
|
328 BluetoothServiceChildProcess::ToggleCalls( |
|
329 BluetoothReplyRunnable* aRunnable) |
|
330 { |
|
331 SendRequest(aRunnable, ToggleCallsRequest()); |
|
332 } |
|
333 #endif // MOZ_B2G_RIL |
|
334 |
|
335 void |
|
336 BluetoothServiceChildProcess::SendMetaData(const nsAString& aTitle, |
|
337 const nsAString& aArtist, |
|
338 const nsAString& aAlbum, |
|
339 int64_t aMediaNumber, |
|
340 int64_t aTotalMediaCount, |
|
341 int64_t aDuration, |
|
342 BluetoothReplyRunnable* aRunnable) |
|
343 { |
|
344 SendRequest(aRunnable, |
|
345 SendMetaDataRequest(nsString(aTitle), nsString(aArtist), |
|
346 nsString(aAlbum), aMediaNumber, |
|
347 aTotalMediaCount, aDuration)); |
|
348 } |
|
349 |
|
350 void |
|
351 BluetoothServiceChildProcess::SendPlayStatus(int64_t aDuration, |
|
352 int64_t aPosition, |
|
353 const nsAString& aPlayStatus, |
|
354 BluetoothReplyRunnable* aRunnable) |
|
355 { |
|
356 SendRequest(aRunnable, |
|
357 SendPlayStatusRequest(aDuration, aPosition, |
|
358 nsString(aPlayStatus))); |
|
359 } |
|
360 |
|
361 nsresult |
|
362 BluetoothServiceChildProcess::HandleStartup() |
|
363 { |
|
364 // Don't need to do anything here for startup since our Create function takes |
|
365 // care of the actor machinery. |
|
366 return NS_OK; |
|
367 } |
|
368 |
|
369 nsresult |
|
370 BluetoothServiceChildProcess::HandleShutdown() |
|
371 { |
|
372 // If this process is shutting down then we need to disconnect ourselves from |
|
373 // the parent. |
|
374 if (sBluetoothChild) { |
|
375 sBluetoothChild->BeginShutdown(); |
|
376 } |
|
377 return NS_OK; |
|
378 } |
|
379 |
|
380 nsresult |
|
381 BluetoothServiceChildProcess::StartInternal() |
|
382 { |
|
383 MOZ_CRASH("This should never be called!"); |
|
384 } |
|
385 |
|
386 nsresult |
|
387 BluetoothServiceChildProcess::StopInternal() |
|
388 { |
|
389 MOZ_CRASH("This should never be called!"); |
|
390 } |
|
391 |
|
392 bool |
|
393 BluetoothServiceChildProcess::IsConnected(uint16_t aServiceUuid) |
|
394 { |
|
395 MOZ_CRASH("This should never be called!"); |
|
396 } |
|
397 |
|
398 nsresult |
|
399 BluetoothServiceChildProcess::SendSinkMessage(const nsAString& aDeviceAddresses, |
|
400 const nsAString& aMessage) |
|
401 { |
|
402 MOZ_CRASH("This should never be called!"); |
|
403 } |
|
404 |
|
405 nsresult |
|
406 BluetoothServiceChildProcess::SendInputMessage(const nsAString& aDeviceAddresses, |
|
407 const nsAString& aMessage) |
|
408 { |
|
409 MOZ_CRASH("This should never be called!"); |
|
410 } |
|
411 |
|
412 void |
|
413 BluetoothServiceChildProcess::UpdatePlayStatus(uint32_t aDuration, |
|
414 uint32_t aPosition, |
|
415 ControlPlayStatus aPlayStatus) |
|
416 { |
|
417 MOZ_CRASH("This should never be called!"); |
|
418 } |
|
419 |