michael@0: /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "base/basictypes.h" michael@0: michael@0: #include "BluetoothServiceChildProcess.h" michael@0: michael@0: #include "mozilla/Assertions.h" michael@0: #include "mozilla/dom/ContentChild.h" michael@0: michael@0: #include "BluetoothChild.h" michael@0: #include "MainThreadUtils.h" michael@0: michael@0: USING_BLUETOOTH_NAMESPACE michael@0: michael@0: namespace { michael@0: michael@0: BluetoothChild* sBluetoothChild; michael@0: michael@0: inline michael@0: void michael@0: SendRequest(BluetoothReplyRunnable* aRunnable, const Request& aRequest) michael@0: { michael@0: MOZ_ASSERT(NS_IsMainThread()); michael@0: MOZ_ASSERT(aRunnable); michael@0: michael@0: NS_WARN_IF_FALSE(sBluetoothChild, michael@0: "Calling methods on BluetoothServiceChildProcess during " michael@0: "shutdown!"); michael@0: michael@0: if (sBluetoothChild) { michael@0: BluetoothRequestChild* actor = new BluetoothRequestChild(aRunnable); michael@0: sBluetoothChild->SendPBluetoothRequestConstructor(actor, aRequest); michael@0: } michael@0: } michael@0: michael@0: } // anonymous namespace michael@0: michael@0: // static michael@0: BluetoothServiceChildProcess* michael@0: BluetoothServiceChildProcess::Create() michael@0: { michael@0: MOZ_ASSERT(!sBluetoothChild); michael@0: michael@0: mozilla::dom::ContentChild* contentChild = michael@0: mozilla::dom::ContentChild::GetSingleton(); michael@0: MOZ_ASSERT(contentChild); michael@0: michael@0: BluetoothServiceChildProcess* btService = new BluetoothServiceChildProcess(); michael@0: michael@0: sBluetoothChild = new BluetoothChild(btService); michael@0: contentChild->SendPBluetoothConstructor(sBluetoothChild); michael@0: michael@0: return btService; michael@0: } michael@0: michael@0: BluetoothServiceChildProcess::BluetoothServiceChildProcess() michael@0: { michael@0: } michael@0: michael@0: BluetoothServiceChildProcess::~BluetoothServiceChildProcess() michael@0: { michael@0: sBluetoothChild = nullptr; michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::NoteDeadActor() michael@0: { michael@0: MOZ_ASSERT(sBluetoothChild); michael@0: sBluetoothChild = nullptr; michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::RegisterBluetoothSignalHandler( michael@0: const nsAString& aNodeName, michael@0: BluetoothSignalObserver* aHandler) michael@0: { michael@0: if (sBluetoothChild && !IsSignalRegistered(aNodeName)) { michael@0: sBluetoothChild->SendRegisterSignalHandler(nsString(aNodeName)); michael@0: } michael@0: BluetoothService::RegisterBluetoothSignalHandler(aNodeName, aHandler); michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::UnregisterBluetoothSignalHandler( michael@0: const nsAString& aNodeName, michael@0: BluetoothSignalObserver* aHandler) michael@0: { michael@0: BluetoothService::UnregisterBluetoothSignalHandler(aNodeName, aHandler); michael@0: if (sBluetoothChild && !IsSignalRegistered(aNodeName)) { michael@0: sBluetoothChild->SendUnregisterSignalHandler(nsString(aNodeName)); michael@0: } michael@0: } michael@0: michael@0: nsresult michael@0: BluetoothServiceChildProcess::GetDefaultAdapterPathInternal( michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, DefaultAdapterPathRequest()); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: BluetoothServiceChildProcess::GetConnectedDevicePropertiesInternal( michael@0: uint16_t aServiceUuid, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, ConnectedDevicePropertiesRequest(aServiceUuid)); michael@0: return NS_OK; michael@0: } michael@0: nsresult michael@0: BluetoothServiceChildProcess::GetPairedDevicePropertiesInternal( michael@0: const nsTArray& aDeviceAddresses, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: PairedDevicePropertiesRequest request; michael@0: request.addresses().AppendElements(aDeviceAddresses); michael@0: michael@0: SendRequest(aRunnable, request); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: BluetoothServiceChildProcess::StopDiscoveryInternal( michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, StopDiscoveryRequest()); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: BluetoothServiceChildProcess::StartDiscoveryInternal( michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, StartDiscoveryRequest()); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: BluetoothServiceChildProcess::SetProperty(BluetoothObjectType aType, michael@0: const BluetoothNamedValue& aValue, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, SetPropertyRequest(aType, aValue)); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: BluetoothServiceChildProcess::CreatePairedDeviceInternal( michael@0: const nsAString& aAddress, michael@0: int aTimeout, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, michael@0: PairRequest(nsString(aAddress), aTimeout)); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: BluetoothServiceChildProcess::RemoveDeviceInternal( michael@0: const nsAString& aObjectPath, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, michael@0: UnpairRequest(nsString(aObjectPath))); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: BluetoothServiceChildProcess::GetServiceChannel(const nsAString& aDeviceAddress, michael@0: const nsAString& aServiceUuid, michael@0: BluetoothProfileManagerBase* aManager) michael@0: { michael@0: MOZ_CRASH("This should never be called!"); michael@0: } michael@0: michael@0: bool michael@0: BluetoothServiceChildProcess::UpdateSdpRecords(const nsAString& aDeviceAddress, michael@0: BluetoothProfileManagerBase* aManager) michael@0: { michael@0: MOZ_CRASH("This should never be called!"); michael@0: } michael@0: michael@0: bool michael@0: BluetoothServiceChildProcess::SetPinCodeInternal( michael@0: const nsAString& aDeviceAddress, michael@0: const nsAString& aPinCode, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, michael@0: SetPinCodeRequest(nsString(aDeviceAddress), nsString(aPinCode))); michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: BluetoothServiceChildProcess::SetPasskeyInternal( michael@0: const nsAString& aDeviceAddress, michael@0: uint32_t aPasskey, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, michael@0: SetPasskeyRequest(nsString(aDeviceAddress), aPasskey)); michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: BluetoothServiceChildProcess::SetPairingConfirmationInternal( michael@0: const nsAString& aDeviceAddress, michael@0: bool aConfirm, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: if(aConfirm) { michael@0: SendRequest(aRunnable, michael@0: ConfirmPairingConfirmationRequest(nsString(aDeviceAddress))); michael@0: } else { michael@0: SendRequest(aRunnable, michael@0: DenyPairingConfirmationRequest(nsString(aDeviceAddress))); michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::Connect( michael@0: const nsAString& aDeviceAddress, michael@0: uint32_t aCod, michael@0: uint16_t aServiceUuid, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, michael@0: ConnectRequest(nsString(aDeviceAddress), michael@0: aCod, michael@0: aServiceUuid)); michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::Disconnect( michael@0: const nsAString& aDeviceAddress, michael@0: uint16_t aServiceUuid, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, michael@0: DisconnectRequest(nsString(aDeviceAddress), aServiceUuid)); michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::SendFile( michael@0: const nsAString& aDeviceAddress, michael@0: BlobParent* aBlobParent, michael@0: BlobChild* aBlobChild, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, michael@0: SendFileRequest(nsString(aDeviceAddress), nullptr, aBlobChild)); michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::SendFile( michael@0: const nsAString& aDeviceAddress, michael@0: nsIDOMBlob* aBlobChild, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: // Parent-process-only method michael@0: MOZ_CRASH("This should never be called!"); michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::StopSendingFile( michael@0: const nsAString& aDeviceAddress, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, michael@0: StopSendingFileRequest(nsString(aDeviceAddress))); michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::ConfirmReceivingFile( michael@0: const nsAString& aDeviceAddress, michael@0: bool aConfirm, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: if(aConfirm) { michael@0: SendRequest(aRunnable, michael@0: ConfirmReceivingFileRequest(nsString(aDeviceAddress))); michael@0: return; michael@0: } michael@0: michael@0: SendRequest(aRunnable, michael@0: DenyReceivingFileRequest(nsString(aDeviceAddress))); michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::ConnectSco(BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, ConnectScoRequest()); michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::DisconnectSco(BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, DisconnectScoRequest()); michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::IsScoConnected(BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, IsScoConnectedRequest()); michael@0: } michael@0: michael@0: #ifdef MOZ_B2G_RIL michael@0: void michael@0: BluetoothServiceChildProcess::AnswerWaitingCall( michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, AnswerWaitingCallRequest()); michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::IgnoreWaitingCall( michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, IgnoreWaitingCallRequest()); michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::ToggleCalls( michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, ToggleCallsRequest()); michael@0: } michael@0: #endif // MOZ_B2G_RIL michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::SendMetaData(const nsAString& aTitle, michael@0: const nsAString& aArtist, michael@0: const nsAString& aAlbum, michael@0: int64_t aMediaNumber, michael@0: int64_t aTotalMediaCount, michael@0: int64_t aDuration, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, michael@0: SendMetaDataRequest(nsString(aTitle), nsString(aArtist), michael@0: nsString(aAlbum), aMediaNumber, michael@0: aTotalMediaCount, aDuration)); michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::SendPlayStatus(int64_t aDuration, michael@0: int64_t aPosition, michael@0: const nsAString& aPlayStatus, michael@0: BluetoothReplyRunnable* aRunnable) michael@0: { michael@0: SendRequest(aRunnable, michael@0: SendPlayStatusRequest(aDuration, aPosition, michael@0: nsString(aPlayStatus))); michael@0: } michael@0: michael@0: nsresult michael@0: BluetoothServiceChildProcess::HandleStartup() michael@0: { michael@0: // Don't need to do anything here for startup since our Create function takes michael@0: // care of the actor machinery. michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: BluetoothServiceChildProcess::HandleShutdown() michael@0: { michael@0: // If this process is shutting down then we need to disconnect ourselves from michael@0: // the parent. michael@0: if (sBluetoothChild) { michael@0: sBluetoothChild->BeginShutdown(); michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: BluetoothServiceChildProcess::StartInternal() michael@0: { michael@0: MOZ_CRASH("This should never be called!"); michael@0: } michael@0: michael@0: nsresult michael@0: BluetoothServiceChildProcess::StopInternal() michael@0: { michael@0: MOZ_CRASH("This should never be called!"); michael@0: } michael@0: michael@0: bool michael@0: BluetoothServiceChildProcess::IsConnected(uint16_t aServiceUuid) michael@0: { michael@0: MOZ_CRASH("This should never be called!"); michael@0: } michael@0: michael@0: nsresult michael@0: BluetoothServiceChildProcess::SendSinkMessage(const nsAString& aDeviceAddresses, michael@0: const nsAString& aMessage) michael@0: { michael@0: MOZ_CRASH("This should never be called!"); michael@0: } michael@0: michael@0: nsresult michael@0: BluetoothServiceChildProcess::SendInputMessage(const nsAString& aDeviceAddresses, michael@0: const nsAString& aMessage) michael@0: { michael@0: MOZ_CRASH("This should never be called!"); michael@0: } michael@0: michael@0: void michael@0: BluetoothServiceChildProcess::UpdatePlayStatus(uint32_t aDuration, michael@0: uint32_t aPosition, michael@0: ControlPlayStatus aPlayStatus) michael@0: { michael@0: MOZ_CRASH("This should never be called!"); michael@0: } michael@0: