1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,419 @@ 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 "base/basictypes.h" 1.11 + 1.12 +#include "BluetoothServiceChildProcess.h" 1.13 + 1.14 +#include "mozilla/Assertions.h" 1.15 +#include "mozilla/dom/ContentChild.h" 1.16 + 1.17 +#include "BluetoothChild.h" 1.18 +#include "MainThreadUtils.h" 1.19 + 1.20 +USING_BLUETOOTH_NAMESPACE 1.21 + 1.22 +namespace { 1.23 + 1.24 +BluetoothChild* sBluetoothChild; 1.25 + 1.26 +inline 1.27 +void 1.28 +SendRequest(BluetoothReplyRunnable* aRunnable, const Request& aRequest) 1.29 +{ 1.30 + MOZ_ASSERT(NS_IsMainThread()); 1.31 + MOZ_ASSERT(aRunnable); 1.32 + 1.33 + NS_WARN_IF_FALSE(sBluetoothChild, 1.34 + "Calling methods on BluetoothServiceChildProcess during " 1.35 + "shutdown!"); 1.36 + 1.37 + if (sBluetoothChild) { 1.38 + BluetoothRequestChild* actor = new BluetoothRequestChild(aRunnable); 1.39 + sBluetoothChild->SendPBluetoothRequestConstructor(actor, aRequest); 1.40 + } 1.41 +} 1.42 + 1.43 +} // anonymous namespace 1.44 + 1.45 +// static 1.46 +BluetoothServiceChildProcess* 1.47 +BluetoothServiceChildProcess::Create() 1.48 +{ 1.49 + MOZ_ASSERT(!sBluetoothChild); 1.50 + 1.51 + mozilla::dom::ContentChild* contentChild = 1.52 + mozilla::dom::ContentChild::GetSingleton(); 1.53 + MOZ_ASSERT(contentChild); 1.54 + 1.55 + BluetoothServiceChildProcess* btService = new BluetoothServiceChildProcess(); 1.56 + 1.57 + sBluetoothChild = new BluetoothChild(btService); 1.58 + contentChild->SendPBluetoothConstructor(sBluetoothChild); 1.59 + 1.60 + return btService; 1.61 +} 1.62 + 1.63 +BluetoothServiceChildProcess::BluetoothServiceChildProcess() 1.64 +{ 1.65 +} 1.66 + 1.67 +BluetoothServiceChildProcess::~BluetoothServiceChildProcess() 1.68 +{ 1.69 + sBluetoothChild = nullptr; 1.70 +} 1.71 + 1.72 +void 1.73 +BluetoothServiceChildProcess::NoteDeadActor() 1.74 +{ 1.75 + MOZ_ASSERT(sBluetoothChild); 1.76 + sBluetoothChild = nullptr; 1.77 +} 1.78 + 1.79 +void 1.80 +BluetoothServiceChildProcess::RegisterBluetoothSignalHandler( 1.81 + const nsAString& aNodeName, 1.82 + BluetoothSignalObserver* aHandler) 1.83 +{ 1.84 + if (sBluetoothChild && !IsSignalRegistered(aNodeName)) { 1.85 + sBluetoothChild->SendRegisterSignalHandler(nsString(aNodeName)); 1.86 + } 1.87 + BluetoothService::RegisterBluetoothSignalHandler(aNodeName, aHandler); 1.88 +} 1.89 + 1.90 +void 1.91 +BluetoothServiceChildProcess::UnregisterBluetoothSignalHandler( 1.92 + const nsAString& aNodeName, 1.93 + BluetoothSignalObserver* aHandler) 1.94 +{ 1.95 + BluetoothService::UnregisterBluetoothSignalHandler(aNodeName, aHandler); 1.96 + if (sBluetoothChild && !IsSignalRegistered(aNodeName)) { 1.97 + sBluetoothChild->SendUnregisterSignalHandler(nsString(aNodeName)); 1.98 + } 1.99 +} 1.100 + 1.101 +nsresult 1.102 +BluetoothServiceChildProcess::GetDefaultAdapterPathInternal( 1.103 + BluetoothReplyRunnable* aRunnable) 1.104 +{ 1.105 + SendRequest(aRunnable, DefaultAdapterPathRequest()); 1.106 + return NS_OK; 1.107 +} 1.108 + 1.109 +nsresult 1.110 +BluetoothServiceChildProcess::GetConnectedDevicePropertiesInternal( 1.111 + uint16_t aServiceUuid, 1.112 + BluetoothReplyRunnable* aRunnable) 1.113 +{ 1.114 + SendRequest(aRunnable, ConnectedDevicePropertiesRequest(aServiceUuid)); 1.115 + return NS_OK; 1.116 +} 1.117 +nsresult 1.118 +BluetoothServiceChildProcess::GetPairedDevicePropertiesInternal( 1.119 + const nsTArray<nsString>& aDeviceAddresses, 1.120 + BluetoothReplyRunnable* aRunnable) 1.121 +{ 1.122 + PairedDevicePropertiesRequest request; 1.123 + request.addresses().AppendElements(aDeviceAddresses); 1.124 + 1.125 + SendRequest(aRunnable, request); 1.126 + return NS_OK; 1.127 +} 1.128 + 1.129 +nsresult 1.130 +BluetoothServiceChildProcess::StopDiscoveryInternal( 1.131 + BluetoothReplyRunnable* aRunnable) 1.132 +{ 1.133 + SendRequest(aRunnable, StopDiscoveryRequest()); 1.134 + return NS_OK; 1.135 +} 1.136 + 1.137 +nsresult 1.138 +BluetoothServiceChildProcess::StartDiscoveryInternal( 1.139 + BluetoothReplyRunnable* aRunnable) 1.140 +{ 1.141 + SendRequest(aRunnable, StartDiscoveryRequest()); 1.142 + return NS_OK; 1.143 +} 1.144 + 1.145 +nsresult 1.146 +BluetoothServiceChildProcess::SetProperty(BluetoothObjectType aType, 1.147 + const BluetoothNamedValue& aValue, 1.148 + BluetoothReplyRunnable* aRunnable) 1.149 +{ 1.150 + SendRequest(aRunnable, SetPropertyRequest(aType, aValue)); 1.151 + return NS_OK; 1.152 +} 1.153 + 1.154 +nsresult 1.155 +BluetoothServiceChildProcess::CreatePairedDeviceInternal( 1.156 + const nsAString& aAddress, 1.157 + int aTimeout, 1.158 + BluetoothReplyRunnable* aRunnable) 1.159 +{ 1.160 + SendRequest(aRunnable, 1.161 + PairRequest(nsString(aAddress), aTimeout)); 1.162 + return NS_OK; 1.163 +} 1.164 + 1.165 +nsresult 1.166 +BluetoothServiceChildProcess::RemoveDeviceInternal( 1.167 + const nsAString& aObjectPath, 1.168 + BluetoothReplyRunnable* aRunnable) 1.169 +{ 1.170 + SendRequest(aRunnable, 1.171 + UnpairRequest(nsString(aObjectPath))); 1.172 + return NS_OK; 1.173 +} 1.174 + 1.175 +nsresult 1.176 +BluetoothServiceChildProcess::GetServiceChannel(const nsAString& aDeviceAddress, 1.177 + const nsAString& aServiceUuid, 1.178 + BluetoothProfileManagerBase* aManager) 1.179 +{ 1.180 + MOZ_CRASH("This should never be called!"); 1.181 +} 1.182 + 1.183 +bool 1.184 +BluetoothServiceChildProcess::UpdateSdpRecords(const nsAString& aDeviceAddress, 1.185 + BluetoothProfileManagerBase* aManager) 1.186 +{ 1.187 + MOZ_CRASH("This should never be called!"); 1.188 +} 1.189 + 1.190 +bool 1.191 +BluetoothServiceChildProcess::SetPinCodeInternal( 1.192 + const nsAString& aDeviceAddress, 1.193 + const nsAString& aPinCode, 1.194 + BluetoothReplyRunnable* aRunnable) 1.195 +{ 1.196 + SendRequest(aRunnable, 1.197 + SetPinCodeRequest(nsString(aDeviceAddress), nsString(aPinCode))); 1.198 + return true; 1.199 +} 1.200 + 1.201 +bool 1.202 +BluetoothServiceChildProcess::SetPasskeyInternal( 1.203 + const nsAString& aDeviceAddress, 1.204 + uint32_t aPasskey, 1.205 + BluetoothReplyRunnable* aRunnable) 1.206 +{ 1.207 + SendRequest(aRunnable, 1.208 + SetPasskeyRequest(nsString(aDeviceAddress), aPasskey)); 1.209 + return true; 1.210 +} 1.211 + 1.212 +bool 1.213 +BluetoothServiceChildProcess::SetPairingConfirmationInternal( 1.214 + const nsAString& aDeviceAddress, 1.215 + bool aConfirm, 1.216 + BluetoothReplyRunnable* aRunnable) 1.217 +{ 1.218 + if(aConfirm) { 1.219 + SendRequest(aRunnable, 1.220 + ConfirmPairingConfirmationRequest(nsString(aDeviceAddress))); 1.221 + } else { 1.222 + SendRequest(aRunnable, 1.223 + DenyPairingConfirmationRequest(nsString(aDeviceAddress))); 1.224 + } 1.225 + return true; 1.226 +} 1.227 + 1.228 +void 1.229 +BluetoothServiceChildProcess::Connect( 1.230 + const nsAString& aDeviceAddress, 1.231 + uint32_t aCod, 1.232 + uint16_t aServiceUuid, 1.233 + BluetoothReplyRunnable* aRunnable) 1.234 +{ 1.235 + SendRequest(aRunnable, 1.236 + ConnectRequest(nsString(aDeviceAddress), 1.237 + aCod, 1.238 + aServiceUuid)); 1.239 +} 1.240 + 1.241 +void 1.242 +BluetoothServiceChildProcess::Disconnect( 1.243 + const nsAString& aDeviceAddress, 1.244 + uint16_t aServiceUuid, 1.245 + BluetoothReplyRunnable* aRunnable) 1.246 +{ 1.247 + SendRequest(aRunnable, 1.248 + DisconnectRequest(nsString(aDeviceAddress), aServiceUuid)); 1.249 +} 1.250 + 1.251 +void 1.252 +BluetoothServiceChildProcess::SendFile( 1.253 + const nsAString& aDeviceAddress, 1.254 + BlobParent* aBlobParent, 1.255 + BlobChild* aBlobChild, 1.256 + BluetoothReplyRunnable* aRunnable) 1.257 +{ 1.258 + SendRequest(aRunnable, 1.259 + SendFileRequest(nsString(aDeviceAddress), nullptr, aBlobChild)); 1.260 +} 1.261 + 1.262 +void 1.263 +BluetoothServiceChildProcess::SendFile( 1.264 + const nsAString& aDeviceAddress, 1.265 + nsIDOMBlob* aBlobChild, 1.266 + BluetoothReplyRunnable* aRunnable) 1.267 +{ 1.268 + // Parent-process-only method 1.269 + MOZ_CRASH("This should never be called!"); 1.270 +} 1.271 + 1.272 +void 1.273 +BluetoothServiceChildProcess::StopSendingFile( 1.274 + const nsAString& aDeviceAddress, 1.275 + BluetoothReplyRunnable* aRunnable) 1.276 +{ 1.277 + SendRequest(aRunnable, 1.278 + StopSendingFileRequest(nsString(aDeviceAddress))); 1.279 +} 1.280 + 1.281 +void 1.282 +BluetoothServiceChildProcess::ConfirmReceivingFile( 1.283 + const nsAString& aDeviceAddress, 1.284 + bool aConfirm, 1.285 + BluetoothReplyRunnable* aRunnable) 1.286 +{ 1.287 + if(aConfirm) { 1.288 + SendRequest(aRunnable, 1.289 + ConfirmReceivingFileRequest(nsString(aDeviceAddress))); 1.290 + return; 1.291 + } 1.292 + 1.293 + SendRequest(aRunnable, 1.294 + DenyReceivingFileRequest(nsString(aDeviceAddress))); 1.295 +} 1.296 + 1.297 +void 1.298 +BluetoothServiceChildProcess::ConnectSco(BluetoothReplyRunnable* aRunnable) 1.299 +{ 1.300 + SendRequest(aRunnable, ConnectScoRequest()); 1.301 +} 1.302 + 1.303 +void 1.304 +BluetoothServiceChildProcess::DisconnectSco(BluetoothReplyRunnable* aRunnable) 1.305 +{ 1.306 + SendRequest(aRunnable, DisconnectScoRequest()); 1.307 +} 1.308 + 1.309 +void 1.310 +BluetoothServiceChildProcess::IsScoConnected(BluetoothReplyRunnable* aRunnable) 1.311 +{ 1.312 + SendRequest(aRunnable, IsScoConnectedRequest()); 1.313 +} 1.314 + 1.315 +#ifdef MOZ_B2G_RIL 1.316 +void 1.317 +BluetoothServiceChildProcess::AnswerWaitingCall( 1.318 + BluetoothReplyRunnable* aRunnable) 1.319 +{ 1.320 + SendRequest(aRunnable, AnswerWaitingCallRequest()); 1.321 +} 1.322 + 1.323 +void 1.324 +BluetoothServiceChildProcess::IgnoreWaitingCall( 1.325 + BluetoothReplyRunnable* aRunnable) 1.326 +{ 1.327 + SendRequest(aRunnable, IgnoreWaitingCallRequest()); 1.328 +} 1.329 + 1.330 +void 1.331 +BluetoothServiceChildProcess::ToggleCalls( 1.332 + BluetoothReplyRunnable* aRunnable) 1.333 +{ 1.334 + SendRequest(aRunnable, ToggleCallsRequest()); 1.335 +} 1.336 +#endif // MOZ_B2G_RIL 1.337 + 1.338 +void 1.339 +BluetoothServiceChildProcess::SendMetaData(const nsAString& aTitle, 1.340 + const nsAString& aArtist, 1.341 + const nsAString& aAlbum, 1.342 + int64_t aMediaNumber, 1.343 + int64_t aTotalMediaCount, 1.344 + int64_t aDuration, 1.345 + BluetoothReplyRunnable* aRunnable) 1.346 +{ 1.347 + SendRequest(aRunnable, 1.348 + SendMetaDataRequest(nsString(aTitle), nsString(aArtist), 1.349 + nsString(aAlbum), aMediaNumber, 1.350 + aTotalMediaCount, aDuration)); 1.351 +} 1.352 + 1.353 +void 1.354 +BluetoothServiceChildProcess::SendPlayStatus(int64_t aDuration, 1.355 + int64_t aPosition, 1.356 + const nsAString& aPlayStatus, 1.357 + BluetoothReplyRunnable* aRunnable) 1.358 +{ 1.359 + SendRequest(aRunnable, 1.360 + SendPlayStatusRequest(aDuration, aPosition, 1.361 + nsString(aPlayStatus))); 1.362 +} 1.363 + 1.364 +nsresult 1.365 +BluetoothServiceChildProcess::HandleStartup() 1.366 +{ 1.367 + // Don't need to do anything here for startup since our Create function takes 1.368 + // care of the actor machinery. 1.369 + return NS_OK; 1.370 +} 1.371 + 1.372 +nsresult 1.373 +BluetoothServiceChildProcess::HandleShutdown() 1.374 +{ 1.375 + // If this process is shutting down then we need to disconnect ourselves from 1.376 + // the parent. 1.377 + if (sBluetoothChild) { 1.378 + sBluetoothChild->BeginShutdown(); 1.379 + } 1.380 + return NS_OK; 1.381 +} 1.382 + 1.383 +nsresult 1.384 +BluetoothServiceChildProcess::StartInternal() 1.385 +{ 1.386 + MOZ_CRASH("This should never be called!"); 1.387 +} 1.388 + 1.389 +nsresult 1.390 +BluetoothServiceChildProcess::StopInternal() 1.391 +{ 1.392 + MOZ_CRASH("This should never be called!"); 1.393 +} 1.394 + 1.395 +bool 1.396 +BluetoothServiceChildProcess::IsConnected(uint16_t aServiceUuid) 1.397 +{ 1.398 + MOZ_CRASH("This should never be called!"); 1.399 +} 1.400 + 1.401 +nsresult 1.402 +BluetoothServiceChildProcess::SendSinkMessage(const nsAString& aDeviceAddresses, 1.403 + const nsAString& aMessage) 1.404 +{ 1.405 + MOZ_CRASH("This should never be called!"); 1.406 +} 1.407 + 1.408 +nsresult 1.409 +BluetoothServiceChildProcess::SendInputMessage(const nsAString& aDeviceAddresses, 1.410 + const nsAString& aMessage) 1.411 +{ 1.412 + MOZ_CRASH("This should never be called!"); 1.413 +} 1.414 + 1.415 +void 1.416 +BluetoothServiceChildProcess::UpdatePlayStatus(uint32_t aDuration, 1.417 + uint32_t aPosition, 1.418 + ControlPlayStatus aPlayStatus) 1.419 +{ 1.420 + MOZ_CRASH("This should never be called!"); 1.421 +} 1.422 +