Bumping manifests a=b2g-bump
[gecko.git] / dom / bluetooth2 / BluetoothService.h
blob0588d15e76c305efe29d0fda902b4e9ccf4c6098
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"
20 namespace mozilla {
21 namespace ipc {
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
37 class ToggleBtTask;
38 friend class ToggleBtTask;
40 class StartupTask;
41 friend class StartupTask;
43 public:
44 class ToggleBtAck : public nsRunnable
46 public:
47 ToggleBtAck(bool aEnabled);
48 NS_IMETHOD Run();
50 private:
51 bool mEnabled;
53 friend class ToggleBtAck;
55 NS_DECL_ISUPPORTS
56 NS_DECL_NSIOBSERVER
58 /**
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
65 virtual void
66 RegisterBluetoothSignalHandler(const nsAString& aNodeName,
67 BluetoothSignalObserver* aMsgHandler);
69 /**
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
76 virtual void
77 UnregisterBluetoothSignalHandler(const nsAString& aNodeName,
78 BluetoothSignalObserver* aMsgHandler);
80 /**
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
86 void
87 UnregisterAllSignalHandlers(BluetoothSignalObserver* aMsgHandler);
89 /**
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
96 void
97 DistributeSignal(const BluetoothSignal& aEvent);
99 /**
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*
108 Get();
110 static already_AddRefed<BluetoothService>
111 FactoryCreate()
113 nsRefPtr<BluetoothService> service = Get();
114 return service.forget();
118 * Returns an array of each adapter's properties, implemented via a platform
119 * specific method.
121 * @return NS_OK on success, NS_ERROR_FAILURE otherwise
123 virtual nsresult
124 GetAdaptersInternal(BluetoothReplyRunnable* aRunnable) = 0;
127 * Returns the properties of paired devices, implemented via a platform
128 * specific method.
130 * @return NS_OK on success, NS_ERROR_FAILURE otherwise
132 virtual nsresult
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
142 virtual nsresult
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
152 virtual nsresult
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
161 virtual nsresult
162 StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable) = 0;
165 * Start device discovery (platform specific implementation)
167 * @return NS_OK if discovery stopped correctly, false otherwise
169 virtual nsresult
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
181 virtual nsresult
182 SetProperty(BluetoothObjectType aType,
183 const BluetoothNamedValue& aValue,
184 BluetoothReplyRunnable* aRunnable) = 0;
186 virtual nsresult
187 CreatePairedDeviceInternal(const nsAString& aAddress,
188 int aTimeout,
189 BluetoothReplyRunnable* aRunnable) = 0;
191 virtual nsresult
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
205 virtual nsresult
206 GetServiceChannel(const nsAString& aDeviceAddress,
207 const nsAString& aServiceUuid,
208 BluetoothProfileManagerBase* aManager) = 0;
210 virtual bool
211 UpdateSdpRecords(const nsAString& aDeviceAddress,
212 BluetoothProfileManagerBase* aManager) = 0;
214 virtual void
215 SetPinCodeInternal(const nsAString& aDeviceAddress, const nsAString& aPinCode,
216 BluetoothReplyRunnable* aRunnable) = 0;
218 virtual void
219 SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey,
220 BluetoothReplyRunnable* aRunnable) = 0;
222 virtual void
223 SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm,
224 BluetoothReplyRunnable* aRunnable) = 0;
226 virtual void
227 Connect(const nsAString& aDeviceAddress, uint32_t aCod, uint16_t aServiceUuid,
228 BluetoothReplyRunnable* aRunnable) = 0;
230 virtual void
231 Disconnect(const nsAString& aDeviceAddress, uint16_t aServiceUuid,
232 BluetoothReplyRunnable* aRunnable) = 0;
234 virtual bool
235 IsConnected(uint16_t aServiceUuid) = 0;
237 virtual void
238 SendFile(const nsAString& aDeviceAddress,
239 BlobParent* aBlobParent,
240 BlobChild* aBlobChild,
241 BluetoothReplyRunnable* aRunnable) = 0;
243 virtual void
244 SendFile(const nsAString& aDeviceAddress,
245 nsIDOMBlob* aBlob,
246 BluetoothReplyRunnable* aRunnable) = 0;
248 virtual void
249 StopSendingFile(const nsAString& aDeviceAddress,
250 BluetoothReplyRunnable* aRunnable) = 0;
252 virtual void
253 ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirm,
254 BluetoothReplyRunnable* aRunnable) = 0;
256 virtual void
257 ConnectSco(BluetoothReplyRunnable* aRunnable) = 0;
259 virtual void
260 DisconnectSco(BluetoothReplyRunnable* aRunnable) = 0;
262 virtual void
263 IsScoConnected(BluetoothReplyRunnable* aRunnable) = 0;
265 #ifdef MOZ_B2G_RIL
266 virtual void
267 AnswerWaitingCall(BluetoothReplyRunnable* aRunnable) = 0;
269 virtual void
270 IgnoreWaitingCall(BluetoothReplyRunnable* aRunnable) = 0;
272 virtual void
273 ToggleCalls(BluetoothReplyRunnable* aRunnable) = 0;
274 #endif
276 virtual void
277 SendMetaData(const nsAString& aTitle,
278 const nsAString& aArtist,
279 const nsAString& aAlbum,
280 int64_t aMediaNumber,
281 int64_t aTotalMediaCount,
282 int64_t aDuration,
283 BluetoothReplyRunnable* aRunnable) = 0;
285 virtual void
286 SendPlayStatus(int64_t aDuration,
287 int64_t aPosition,
288 const nsAString& aPlayStatus,
289 BluetoothReplyRunnable* aRunnable) = 0;
291 virtual void
292 UpdatePlayStatus(uint32_t aDuration,
293 uint32_t aPosition,
294 ControlPlayStatus aPlayStatus) = 0;
296 virtual nsresult
297 SendSinkMessage(const nsAString& aDeviceAddresses,
298 const nsAString& aMessage) = 0;
300 virtual nsresult
301 SendInputMessage(const nsAString& aDeviceAddresses,
302 const nsAString& aMessage) = 0;
304 bool
305 IsEnabled() const
307 return mEnabled;
310 bool
311 IsToggling() const;
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
323 virtual nsresult
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
332 virtual nsresult
333 StopInternal(BluetoothReplyRunnable* aRunnable) = 0;
335 protected:
336 BluetoothService() : mEnabled(false)
339 virtual ~BluetoothService();
341 bool
342 Init();
344 void
345 Cleanup();
347 nsresult
348 StartBluetooth(bool aIsStartup, BluetoothReplyRunnable* aRunnable);
350 nsresult
351 StopBluetooth(bool aIsStartup, BluetoothReplyRunnable* aRunnable);
353 nsresult
354 StartStopBluetooth(bool aStart,
355 bool aIsStartup,
356 BluetoothReplyRunnable* aRunnable);
359 * Called when XPCOM first creates this service.
361 virtual nsresult
362 HandleStartup();
365 * Called when the startup settings check has completed.
367 nsresult
368 HandleStartupSettingsCheck(bool aEnable);
371 * Called when "mozsettings-changed" observer topic fires.
373 nsresult
374 HandleSettingsChanged(const nsAString& aData);
377 * Called when XPCOM is shutting down.
379 virtual nsresult
380 HandleShutdown();
382 // Called by ToggleBtAck.
383 void
384 SetEnabled(bool aEnabled);
386 // Called by Get().
387 static BluetoothService*
388 Create();
390 typedef nsClassHashtable<nsStringHashKey, BluetoothSignalObserverList >
391 BluetoothSignalObserverTable;
393 BluetoothSignalObserverTable mBluetoothSignalObserverTable;
395 bool mEnabled;
398 END_BLUETOOTH_NAMESPACE
400 #endif