dom/bluetooth/ipc/BluetoothServiceChildProcess.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial