dom/bluetooth/bluedroid/hfp-fallback/BluetoothHfpManager.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 #include "BluetoothHfpManager.h"
michael@0 9 #include "BluetoothProfileController.h"
michael@0 10 #include "mozilla/Services.h"
michael@0 11 #include "mozilla/StaticPtr.h"
michael@0 12 #include "nsIObserverService.h"
michael@0 13 #include "nsThreadUtils.h"
michael@0 14
michael@0 15 using namespace mozilla;
michael@0 16 USING_BLUETOOTH_NAMESPACE
michael@0 17
michael@0 18 namespace {
michael@0 19 StaticRefPtr<BluetoothHfpManager> sBluetoothHfpManager;
michael@0 20 bool sInShutdown = false;
michael@0 21 } // anonymous namespace
michael@0 22
michael@0 23 /**
michael@0 24 * nsIObserver function
michael@0 25 */
michael@0 26 NS_IMETHODIMP
michael@0 27 BluetoothHfpManager::Observe(nsISupports* aSubject,
michael@0 28 const char* aTopic,
michael@0 29 const char16_t* aData)
michael@0 30 {
michael@0 31 if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
michael@0 32 HandleShutdown();
michael@0 33 } else {
michael@0 34 MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!");
michael@0 35 return NS_ERROR_UNEXPECTED;
michael@0 36 }
michael@0 37
michael@0 38 return NS_OK;
michael@0 39 }
michael@0 40
michael@0 41 /**
michael@0 42 * BluetoothProfileManagerBase functions
michael@0 43 */
michael@0 44 void
michael@0 45 BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
michael@0 46 BluetoothProfileController* aController)
michael@0 47 {
michael@0 48 MOZ_ASSERT(aController);
michael@0 49
michael@0 50 aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
michael@0 51 }
michael@0 52
michael@0 53 void
michael@0 54 BluetoothHfpManager::Disconnect(BluetoothProfileController* aController)
michael@0 55 {
michael@0 56 MOZ_ASSERT(aController);
michael@0 57
michael@0 58 aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
michael@0 59 }
michael@0 60
michael@0 61 bool
michael@0 62 BluetoothHfpManager::IsConnected()
michael@0 63 {
michael@0 64 return false;
michael@0 65 }
michael@0 66
michael@0 67 void
michael@0 68 BluetoothHfpManager::OnConnect(const nsAString& aErrorStr)
michael@0 69 {
michael@0 70 MOZ_ASSERT(false);
michael@0 71 }
michael@0 72
michael@0 73 void
michael@0 74 BluetoothHfpManager::OnDisconnect(const nsAString& aErrorStr)
michael@0 75 {
michael@0 76 MOZ_ASSERT(false);
michael@0 77 }
michael@0 78
michael@0 79 void
michael@0 80 BluetoothHfpManager::GetAddress(nsAString& aDeviceAddress)
michael@0 81 {
michael@0 82 aDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
michael@0 83 }
michael@0 84
michael@0 85 void
michael@0 86 BluetoothHfpManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
michael@0 87 const nsAString& aServiceUuid,
michael@0 88 int aChannel)
michael@0 89 {
michael@0 90 MOZ_ASSERT(false);
michael@0 91 }
michael@0 92
michael@0 93 void
michael@0 94 BluetoothHfpManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
michael@0 95 {
michael@0 96 MOZ_ASSERT(false);
michael@0 97 }
michael@0 98
michael@0 99 /**
michael@0 100 * BluetoothHfpManagerBase function
michael@0 101 */
michael@0 102 bool
michael@0 103 BluetoothHfpManager::IsScoConnected()
michael@0 104 {
michael@0 105 return false;
michael@0 106 }
michael@0 107
michael@0 108 /**
michael@0 109 * Non-inherited functions
michael@0 110 */
michael@0 111 // static
michael@0 112 BluetoothHfpManager*
michael@0 113 BluetoothHfpManager::Get()
michael@0 114 {
michael@0 115 MOZ_ASSERT(NS_IsMainThread());
michael@0 116
michael@0 117 // If sBluetoothHfpManager already exists, exit early
michael@0 118 if (sBluetoothHfpManager) {
michael@0 119 return sBluetoothHfpManager;
michael@0 120 }
michael@0 121
michael@0 122 // If we're in shutdown, don't create a new instance
michael@0 123 NS_ENSURE_FALSE(sInShutdown, nullptr);
michael@0 124
michael@0 125 // Create a new instance and return
michael@0 126 BluetoothHfpManager* manager = new BluetoothHfpManager();
michael@0 127 NS_ENSURE_TRUE(manager->Init(), nullptr);
michael@0 128
michael@0 129 sBluetoothHfpManager = manager;
michael@0 130 return sBluetoothHfpManager;
michael@0 131 }
michael@0 132
michael@0 133 bool
michael@0 134 BluetoothHfpManager::Init()
michael@0 135 {
michael@0 136 MOZ_ASSERT(NS_IsMainThread());
michael@0 137
michael@0 138 nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
michael@0 139 NS_ENSURE_TRUE(obs, false);
michael@0 140
michael@0 141 if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
michael@0 142 BT_WARNING("Failed to add observers!");
michael@0 143 return false;
michael@0 144 }
michael@0 145
michael@0 146 return true;
michael@0 147 }
michael@0 148
michael@0 149 void
michael@0 150 BluetoothHfpManager::HandleShutdown()
michael@0 151 {
michael@0 152 MOZ_ASSERT(NS_IsMainThread());
michael@0 153 sInShutdown = true;
michael@0 154 sBluetoothHfpManager = nullptr;
michael@0 155 }
michael@0 156
michael@0 157 bool
michael@0 158 BluetoothHfpManager::ConnectSco()
michael@0 159 {
michael@0 160 MOZ_ASSERT(NS_IsMainThread());
michael@0 161
michael@0 162 /**
michael@0 163 * TODO:
michael@0 164 * Implement ConnectSco() for applications that want to create SCO link
michael@0 165 * without a HFP connection (e.g., VoIP).
michael@0 166 */
michael@0 167 return false;
michael@0 168 }
michael@0 169
michael@0 170 bool
michael@0 171 BluetoothHfpManager::DisconnectSco()
michael@0 172 {
michael@0 173 MOZ_ASSERT(NS_IsMainThread());
michael@0 174
michael@0 175 /**
michael@0 176 * TODO:
michael@0 177 * Implement DisconnectSco() for applications that want to destroy SCO link
michael@0 178 * without a HFP connection (e.g., VoIP).
michael@0 179 */
michael@0 180 return false;
michael@0 181 }
michael@0 182
michael@0 183 void
michael@0 184 BluetoothHfpManager::Reset()
michael@0 185 {
michael@0 186 MOZ_ASSERT(NS_IsMainThread());
michael@0 187 }
michael@0 188
michael@0 189 NS_IMPL_ISUPPORTS(BluetoothHfpManager, nsIObserver)

mercurial