1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/bluetooth/bluedroid/hfp-fallback/BluetoothHfpManager.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,189 @@ 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 +#include "BluetoothHfpManager.h" 1.12 +#include "BluetoothProfileController.h" 1.13 +#include "mozilla/Services.h" 1.14 +#include "mozilla/StaticPtr.h" 1.15 +#include "nsIObserverService.h" 1.16 +#include "nsThreadUtils.h" 1.17 + 1.18 +using namespace mozilla; 1.19 +USING_BLUETOOTH_NAMESPACE 1.20 + 1.21 +namespace { 1.22 + StaticRefPtr<BluetoothHfpManager> sBluetoothHfpManager; 1.23 + bool sInShutdown = false; 1.24 +} // anonymous namespace 1.25 + 1.26 +/** 1.27 + * nsIObserver function 1.28 + */ 1.29 +NS_IMETHODIMP 1.30 +BluetoothHfpManager::Observe(nsISupports* aSubject, 1.31 + const char* aTopic, 1.32 + const char16_t* aData) 1.33 +{ 1.34 + if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) { 1.35 + HandleShutdown(); 1.36 + } else { 1.37 + MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!"); 1.38 + return NS_ERROR_UNEXPECTED; 1.39 + } 1.40 + 1.41 + return NS_OK; 1.42 +} 1.43 + 1.44 +/** 1.45 + * BluetoothProfileManagerBase functions 1.46 + */ 1.47 +void 1.48 +BluetoothHfpManager::Connect(const nsAString& aDeviceAddress, 1.49 + BluetoothProfileController* aController) 1.50 +{ 1.51 + MOZ_ASSERT(aController); 1.52 + 1.53 + aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE)); 1.54 +} 1.55 + 1.56 +void 1.57 +BluetoothHfpManager::Disconnect(BluetoothProfileController* aController) 1.58 +{ 1.59 + MOZ_ASSERT(aController); 1.60 + 1.61 + aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE)); 1.62 +} 1.63 + 1.64 +bool 1.65 +BluetoothHfpManager::IsConnected() 1.66 +{ 1.67 + return false; 1.68 +} 1.69 + 1.70 +void 1.71 +BluetoothHfpManager::OnConnect(const nsAString& aErrorStr) 1.72 +{ 1.73 + MOZ_ASSERT(false); 1.74 +} 1.75 + 1.76 +void 1.77 +BluetoothHfpManager::OnDisconnect(const nsAString& aErrorStr) 1.78 +{ 1.79 + MOZ_ASSERT(false); 1.80 +} 1.81 + 1.82 +void 1.83 +BluetoothHfpManager::GetAddress(nsAString& aDeviceAddress) 1.84 +{ 1.85 + aDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE); 1.86 +} 1.87 + 1.88 +void 1.89 +BluetoothHfpManager::OnGetServiceChannel(const nsAString& aDeviceAddress, 1.90 + const nsAString& aServiceUuid, 1.91 + int aChannel) 1.92 +{ 1.93 + MOZ_ASSERT(false); 1.94 +} 1.95 + 1.96 +void 1.97 +BluetoothHfpManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress) 1.98 +{ 1.99 + MOZ_ASSERT(false); 1.100 +} 1.101 + 1.102 +/** 1.103 + * BluetoothHfpManagerBase function 1.104 + */ 1.105 +bool 1.106 +BluetoothHfpManager::IsScoConnected() 1.107 +{ 1.108 + return false; 1.109 +} 1.110 + 1.111 +/** 1.112 + * Non-inherited functions 1.113 + */ 1.114 +// static 1.115 +BluetoothHfpManager* 1.116 +BluetoothHfpManager::Get() 1.117 +{ 1.118 + MOZ_ASSERT(NS_IsMainThread()); 1.119 + 1.120 + // If sBluetoothHfpManager already exists, exit early 1.121 + if (sBluetoothHfpManager) { 1.122 + return sBluetoothHfpManager; 1.123 + } 1.124 + 1.125 + // If we're in shutdown, don't create a new instance 1.126 + NS_ENSURE_FALSE(sInShutdown, nullptr); 1.127 + 1.128 + // Create a new instance and return 1.129 + BluetoothHfpManager* manager = new BluetoothHfpManager(); 1.130 + NS_ENSURE_TRUE(manager->Init(), nullptr); 1.131 + 1.132 + sBluetoothHfpManager = manager; 1.133 + return sBluetoothHfpManager; 1.134 +} 1.135 + 1.136 +bool 1.137 +BluetoothHfpManager::Init() 1.138 +{ 1.139 + MOZ_ASSERT(NS_IsMainThread()); 1.140 + 1.141 + nsCOMPtr<nsIObserverService> obs = services::GetObserverService(); 1.142 + NS_ENSURE_TRUE(obs, false); 1.143 + 1.144 + if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) { 1.145 + BT_WARNING("Failed to add observers!"); 1.146 + return false; 1.147 + } 1.148 + 1.149 + return true; 1.150 +} 1.151 + 1.152 +void 1.153 +BluetoothHfpManager::HandleShutdown() 1.154 +{ 1.155 + MOZ_ASSERT(NS_IsMainThread()); 1.156 + sInShutdown = true; 1.157 + sBluetoothHfpManager = nullptr; 1.158 +} 1.159 + 1.160 +bool 1.161 +BluetoothHfpManager::ConnectSco() 1.162 +{ 1.163 + MOZ_ASSERT(NS_IsMainThread()); 1.164 + 1.165 + /** 1.166 + * TODO: 1.167 + * Implement ConnectSco() for applications that want to create SCO link 1.168 + * without a HFP connection (e.g., VoIP). 1.169 + */ 1.170 + return false; 1.171 +} 1.172 + 1.173 +bool 1.174 +BluetoothHfpManager::DisconnectSco() 1.175 +{ 1.176 + MOZ_ASSERT(NS_IsMainThread()); 1.177 + 1.178 + /** 1.179 + * TODO: 1.180 + * Implement DisconnectSco() for applications that want to destroy SCO link 1.181 + * without a HFP connection (e.g., VoIP). 1.182 + */ 1.183 + return false; 1.184 +} 1.185 + 1.186 +void 1.187 +BluetoothHfpManager::Reset() 1.188 +{ 1.189 + MOZ_ASSERT(NS_IsMainThread()); 1.190 +} 1.191 + 1.192 +NS_IMPL_ISUPPORTS(BluetoothHfpManager, nsIObserver)