Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "base/basictypes.h"
8 #include "BluetoothHfpManager.h"
9 #include "BluetoothProfileController.h"
10 #include "mozilla/Services.h"
11 #include "mozilla/StaticPtr.h"
12 #include "nsIObserverService.h"
13 #include "nsThreadUtils.h"
15 using namespace mozilla;
16 USING_BLUETOOTH_NAMESPACE
18 namespace {
19 StaticRefPtr<BluetoothHfpManager> sBluetoothHfpManager;
20 bool sInShutdown = false;
21 } // anonymous namespace
23 /**
24 * nsIObserver function
25 */
26 NS_IMETHODIMP
27 BluetoothHfpManager::Observe(nsISupports* aSubject,
28 const char* aTopic,
29 const char16_t* aData)
30 {
31 if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
32 HandleShutdown();
33 } else {
34 MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!");
35 return NS_ERROR_UNEXPECTED;
36 }
38 return NS_OK;
39 }
41 /**
42 * BluetoothProfileManagerBase functions
43 */
44 void
45 BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
46 BluetoothProfileController* aController)
47 {
48 MOZ_ASSERT(aController);
50 aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
51 }
53 void
54 BluetoothHfpManager::Disconnect(BluetoothProfileController* aController)
55 {
56 MOZ_ASSERT(aController);
58 aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
59 }
61 bool
62 BluetoothHfpManager::IsConnected()
63 {
64 return false;
65 }
67 void
68 BluetoothHfpManager::OnConnect(const nsAString& aErrorStr)
69 {
70 MOZ_ASSERT(false);
71 }
73 void
74 BluetoothHfpManager::OnDisconnect(const nsAString& aErrorStr)
75 {
76 MOZ_ASSERT(false);
77 }
79 void
80 BluetoothHfpManager::GetAddress(nsAString& aDeviceAddress)
81 {
82 aDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
83 }
85 void
86 BluetoothHfpManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
87 const nsAString& aServiceUuid,
88 int aChannel)
89 {
90 MOZ_ASSERT(false);
91 }
93 void
94 BluetoothHfpManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
95 {
96 MOZ_ASSERT(false);
97 }
99 /**
100 * BluetoothHfpManagerBase function
101 */
102 bool
103 BluetoothHfpManager::IsScoConnected()
104 {
105 return false;
106 }
108 /**
109 * Non-inherited functions
110 */
111 // static
112 BluetoothHfpManager*
113 BluetoothHfpManager::Get()
114 {
115 MOZ_ASSERT(NS_IsMainThread());
117 // If sBluetoothHfpManager already exists, exit early
118 if (sBluetoothHfpManager) {
119 return sBluetoothHfpManager;
120 }
122 // If we're in shutdown, don't create a new instance
123 NS_ENSURE_FALSE(sInShutdown, nullptr);
125 // Create a new instance and return
126 BluetoothHfpManager* manager = new BluetoothHfpManager();
127 NS_ENSURE_TRUE(manager->Init(), nullptr);
129 sBluetoothHfpManager = manager;
130 return sBluetoothHfpManager;
131 }
133 bool
134 BluetoothHfpManager::Init()
135 {
136 MOZ_ASSERT(NS_IsMainThread());
138 nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
139 NS_ENSURE_TRUE(obs, false);
141 if (NS_FAILED(obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false))) {
142 BT_WARNING("Failed to add observers!");
143 return false;
144 }
146 return true;
147 }
149 void
150 BluetoothHfpManager::HandleShutdown()
151 {
152 MOZ_ASSERT(NS_IsMainThread());
153 sInShutdown = true;
154 sBluetoothHfpManager = nullptr;
155 }
157 bool
158 BluetoothHfpManager::ConnectSco()
159 {
160 MOZ_ASSERT(NS_IsMainThread());
162 /**
163 * TODO:
164 * Implement ConnectSco() for applications that want to create SCO link
165 * without a HFP connection (e.g., VoIP).
166 */
167 return false;
168 }
170 bool
171 BluetoothHfpManager::DisconnectSco()
172 {
173 MOZ_ASSERT(NS_IsMainThread());
175 /**
176 * TODO:
177 * Implement DisconnectSco() for applications that want to destroy SCO link
178 * without a HFP connection (e.g., VoIP).
179 */
180 return false;
181 }
183 void
184 BluetoothHfpManager::Reset()
185 {
186 MOZ_ASSERT(NS_IsMainThread());
187 }
189 NS_IMPL_ISUPPORTS(BluetoothHfpManager, nsIObserver)