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 #ifndef mozilla_dom_bluetooth_bluetootheventservice_h__
8 #define mozilla_dom_bluetooth_bluetootheventservice_h__
10 #include "BluetoothCommon.h"
11 #include "BluetoothProfileManagerBase.h"
12 #include "mozilla/dom/ipc/Blob.h"
13 #include "nsAutoPtr.h"
14 #include "nsClassHashtable.h"
15 #include "nsIDOMFile.h"
16 #include "nsIObserver.h"
17 #include "nsTObserverArray.h"
18 #include "nsThreadUtils.h"
22 class UnixSocketConsumer
;
26 BEGIN_BLUETOOTH_NAMESPACE
28 class BluetoothManager
;
29 class BluetoothNamedValue
;
30 class BluetoothReplyRunnable
;
31 class BluetoothSignal
;
33 typedef mozilla::ObserverList
<BluetoothSignal
> BluetoothSignalObserverList
;
35 class BluetoothService
: public nsIObserver
38 friend class ToggleBtTask
;
41 friend class StartupTask
;
44 class ToggleBtAck
: public nsRunnable
47 ToggleBtAck(bool aEnabled
);
53 friend class ToggleBtAck
;
59 * Add a message handler object from message distribution observer.
60 * Must be called from the main thread.
62 * @param aNodeName Node name of the object
63 * @param aMsgHandler Weak pointer to the object
66 RegisterBluetoothSignalHandler(const nsAString
& aNodeName
,
67 BluetoothSignalObserver
* aMsgHandler
);
70 * Remove a message handler object from message distribution observer.
71 * Must be called from the main thread.
73 * @param aNodeName Node name of the object
74 * @param aMsgHandler Weak pointer to the object
77 UnregisterBluetoothSignalHandler(const nsAString
& aNodeName
,
78 BluetoothSignalObserver
* aMsgHandler
);
81 * Remove a message handlers for the given observer.
82 * Must be called from the main thread.
84 * @param aMsgHandler Weak pointer to the object
87 UnregisterAllSignalHandlers(BluetoothSignalObserver
* aMsgHandler
);
90 * Distribute a signal to the observer list
92 * @param aSignal Signal object to distribute
94 * @return NS_OK if signal distributed, NS_ERROR_FAILURE on error
97 DistributeSignal(const BluetoothSignal
& aEvent
);
100 * Returns the BluetoothService singleton. Only to be called from main thread.
102 * @param aService Pointer to return singleton into.
104 * @return NS_OK on proper assignment, NS_ERROR_FAILURE otherwise (if service
105 * has not yet been started, for instance)
107 static BluetoothService
*
110 static already_AddRefed
<BluetoothService
>
113 nsRefPtr
<BluetoothService
> service
= Get();
114 return service
.forget();
118 * Returns an array of each adapter's properties, implemented via a platform
121 * @return NS_OK on success, NS_ERROR_FAILURE otherwise
124 GetAdaptersInternal(BluetoothReplyRunnable
* aRunnable
) = 0;
127 * Returns the properties of paired devices, implemented via a platform
130 * @return NS_OK on success, NS_ERROR_FAILURE otherwise
133 GetPairedDevicePropertiesInternal(const nsTArray
<nsString
>& aDeviceAddresses
,
134 BluetoothReplyRunnable
* aRunnable
) = 0;
137 * Returns the properties of connected devices regarding to specific profile,
138 * implemented via a platform specific methood.
140 * @return NS_OK on success, NS_ERROR_FAILURE otherwise
143 GetConnectedDevicePropertiesInternal(uint16_t aServiceUuid
,
144 BluetoothReplyRunnable
* aRunnable
) = 0;
147 * Returns up-to-date uuids of given device address,
148 * implemented via a platform specific methood.
150 * @return NS_OK on success, NS_ERROR_FAILURE otherwise
153 FetchUuidsInternal(const nsAString
& aDeviceAddress
,
154 BluetoothReplyRunnable
* aRunnable
) = 0;
157 * Stop device discovery (platform specific implementation)
159 * @return NS_OK if discovery stopped correctly, false otherwise
162 StopDiscoveryInternal(BluetoothReplyRunnable
* aRunnable
) = 0;
165 * Start device discovery (platform specific implementation)
167 * @return NS_OK if discovery stopped correctly, false otherwise
170 StartDiscoveryInternal(BluetoothReplyRunnable
* aRunnable
) = 0;
173 * Set a property for the specified object
175 * @param aPropName Name of the property
176 * @param aValue Boolean value
177 * @param aRunnable Runnable to run on async reply
179 * @return NS_OK if property is set correctly, NS_ERROR_FAILURE otherwise
182 SetProperty(BluetoothObjectType aType
,
183 const BluetoothNamedValue
& aValue
,
184 BluetoothReplyRunnable
* aRunnable
) = 0;
187 CreatePairedDeviceInternal(const nsAString
& aAddress
,
189 BluetoothReplyRunnable
* aRunnable
) = 0;
192 RemoveDeviceInternal(const nsAString
& aObjectPath
,
193 BluetoothReplyRunnable
* aRunnable
) = 0;
196 * Get corresponding service channel of specific service on remote device.
197 * It's usually the very first step of establishing an outbound connection.
199 * @param aObjectPath Object path of remote device
200 * @param aServiceUuid UUID of the target service
201 * @param aManager Instance which has callback function OnGetServiceChannel()
203 * @return NS_OK if the task begins, NS_ERROR_FAILURE otherwise
206 GetServiceChannel(const nsAString
& aDeviceAddress
,
207 const nsAString
& aServiceUuid
,
208 BluetoothProfileManagerBase
* aManager
) = 0;
211 UpdateSdpRecords(const nsAString
& aDeviceAddress
,
212 BluetoothProfileManagerBase
* aManager
) = 0;
215 SetPinCodeInternal(const nsAString
& aDeviceAddress
, const nsAString
& aPinCode
,
216 BluetoothReplyRunnable
* aRunnable
) = 0;
219 SetPasskeyInternal(const nsAString
& aDeviceAddress
, uint32_t aPasskey
,
220 BluetoothReplyRunnable
* aRunnable
) = 0;
223 SetPairingConfirmationInternal(const nsAString
& aDeviceAddress
, bool aConfirm
,
224 BluetoothReplyRunnable
* aRunnable
) = 0;
227 Connect(const nsAString
& aDeviceAddress
, uint32_t aCod
, uint16_t aServiceUuid
,
228 BluetoothReplyRunnable
* aRunnable
) = 0;
231 Disconnect(const nsAString
& aDeviceAddress
, uint16_t aServiceUuid
,
232 BluetoothReplyRunnable
* aRunnable
) = 0;
235 IsConnected(uint16_t aServiceUuid
) = 0;
238 SendFile(const nsAString
& aDeviceAddress
,
239 BlobParent
* aBlobParent
,
240 BlobChild
* aBlobChild
,
241 BluetoothReplyRunnable
* aRunnable
) = 0;
244 SendFile(const nsAString
& aDeviceAddress
,
246 BluetoothReplyRunnable
* aRunnable
) = 0;
249 StopSendingFile(const nsAString
& aDeviceAddress
,
250 BluetoothReplyRunnable
* aRunnable
) = 0;
253 ConfirmReceivingFile(const nsAString
& aDeviceAddress
, bool aConfirm
,
254 BluetoothReplyRunnable
* aRunnable
) = 0;
257 ConnectSco(BluetoothReplyRunnable
* aRunnable
) = 0;
260 DisconnectSco(BluetoothReplyRunnable
* aRunnable
) = 0;
263 IsScoConnected(BluetoothReplyRunnable
* aRunnable
) = 0;
267 AnswerWaitingCall(BluetoothReplyRunnable
* aRunnable
) = 0;
270 IgnoreWaitingCall(BluetoothReplyRunnable
* aRunnable
) = 0;
273 ToggleCalls(BluetoothReplyRunnable
* aRunnable
) = 0;
277 SendMetaData(const nsAString
& aTitle
,
278 const nsAString
& aArtist
,
279 const nsAString
& aAlbum
,
280 int64_t aMediaNumber
,
281 int64_t aTotalMediaCount
,
283 BluetoothReplyRunnable
* aRunnable
) = 0;
286 SendPlayStatus(int64_t aDuration
,
288 const nsAString
& aPlayStatus
,
289 BluetoothReplyRunnable
* aRunnable
) = 0;
292 UpdatePlayStatus(uint32_t aDuration
,
294 ControlPlayStatus aPlayStatus
) = 0;
297 SendSinkMessage(const nsAString
& aDeviceAddresses
,
298 const nsAString
& aMessage
) = 0;
301 SendInputMessage(const nsAString
& aDeviceAddresses
,
302 const nsAString
& aMessage
) = 0;
313 void FireAdapterStateChanged(bool aEnable
);
314 nsresult
EnableDisable(bool aEnable
,
315 BluetoothReplyRunnable
* aRunnable
);
318 * Platform specific startup functions go here. Usually deals with member
319 * variables, so not static. Guaranteed to be called outside of main thread.
321 * @return NS_OK on correct startup, NS_ERROR_FAILURE otherwise
324 StartInternal(BluetoothReplyRunnable
* aRunnable
) = 0;
327 * Platform specific startup functions go here. Usually deals with member
328 * variables, so not static. Guaranteed to be called outside of main thread.
330 * @return NS_OK on correct startup, NS_ERROR_FAILURE otherwise
333 StopInternal(BluetoothReplyRunnable
* aRunnable
) = 0;
336 BluetoothService() : mEnabled(false)
339 virtual ~BluetoothService();
348 StartBluetooth(bool aIsStartup
, BluetoothReplyRunnable
* aRunnable
);
351 StopBluetooth(bool aIsStartup
, BluetoothReplyRunnable
* aRunnable
);
354 StartStopBluetooth(bool aStart
,
356 BluetoothReplyRunnable
* aRunnable
);
359 * Called when XPCOM first creates this service.
365 * Called when the startup settings check has completed.
368 HandleStartupSettingsCheck(bool aEnable
);
371 * Called when "mozsettings-changed" observer topic fires.
374 HandleSettingsChanged(const nsAString
& aData
);
377 * Called when XPCOM is shutting down.
382 // Called by ToggleBtAck.
384 SetEnabled(bool aEnabled
);
387 static BluetoothService
*
390 typedef nsClassHashtable
<nsStringHashKey
, BluetoothSignalObserverList
>
391 BluetoothSignalObserverTable
;
393 BluetoothSignalObserverTable mBluetoothSignalObserverTable
;
398 END_BLUETOOTH_NAMESPACE