Wed, 31 Dec 2014 06:09:35 +0100
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 | #ifndef mozilla_dom_bluetooth_bluetootheventservice_h__ |
michael@0 | 8 | #define mozilla_dom_bluetooth_bluetootheventservice_h__ |
michael@0 | 9 | |
michael@0 | 10 | #include "BluetoothCommon.h" |
michael@0 | 11 | #include "BluetoothProfileManagerBase.h" |
michael@0 | 12 | #include "mozilla/dom/ipc/Blob.h" |
michael@0 | 13 | #include "nsAutoPtr.h" |
michael@0 | 14 | #include "nsClassHashtable.h" |
michael@0 | 15 | #include "nsIDOMFile.h" |
michael@0 | 16 | #include "nsIObserver.h" |
michael@0 | 17 | #include "nsTObserverArray.h" |
michael@0 | 18 | #include "nsThreadUtils.h" |
michael@0 | 19 | |
michael@0 | 20 | namespace mozilla { |
michael@0 | 21 | namespace ipc { |
michael@0 | 22 | class UnixSocketConsumer; |
michael@0 | 23 | } |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | BEGIN_BLUETOOTH_NAMESPACE |
michael@0 | 27 | |
michael@0 | 28 | class BluetoothManager; |
michael@0 | 29 | class BluetoothNamedValue; |
michael@0 | 30 | class BluetoothReplyRunnable; |
michael@0 | 31 | class BluetoothSignal; |
michael@0 | 32 | |
michael@0 | 33 | typedef mozilla::ObserverList<BluetoothSignal> BluetoothSignalObserverList; |
michael@0 | 34 | |
michael@0 | 35 | class BluetoothService : public nsIObserver |
michael@0 | 36 | , public BluetoothSignalObserver |
michael@0 | 37 | { |
michael@0 | 38 | class ToggleBtTask; |
michael@0 | 39 | friend class ToggleBtTask; |
michael@0 | 40 | |
michael@0 | 41 | class StartupTask; |
michael@0 | 42 | friend class StartupTask; |
michael@0 | 43 | |
michael@0 | 44 | public: |
michael@0 | 45 | class ToggleBtAck : public nsRunnable |
michael@0 | 46 | { |
michael@0 | 47 | public: |
michael@0 | 48 | ToggleBtAck(bool aEnabled); |
michael@0 | 49 | NS_IMETHOD Run(); |
michael@0 | 50 | |
michael@0 | 51 | private: |
michael@0 | 52 | bool mEnabled; |
michael@0 | 53 | }; |
michael@0 | 54 | friend class ToggleBtAck; |
michael@0 | 55 | |
michael@0 | 56 | NS_DECL_ISUPPORTS |
michael@0 | 57 | NS_DECL_NSIOBSERVER |
michael@0 | 58 | |
michael@0 | 59 | /** |
michael@0 | 60 | * Add a message handler object from message distribution observer. |
michael@0 | 61 | * Must be called from the main thread. |
michael@0 | 62 | * |
michael@0 | 63 | * @param aNodeName Node name of the object |
michael@0 | 64 | * @param aMsgHandler Weak pointer to the object |
michael@0 | 65 | */ |
michael@0 | 66 | virtual void |
michael@0 | 67 | RegisterBluetoothSignalHandler(const nsAString& aNodeName, |
michael@0 | 68 | BluetoothSignalObserver* aMsgHandler); |
michael@0 | 69 | |
michael@0 | 70 | /** |
michael@0 | 71 | * Remove a message handler object from message distribution observer. |
michael@0 | 72 | * Must be called from the main thread. |
michael@0 | 73 | * |
michael@0 | 74 | * @param aNodeName Node name of the object |
michael@0 | 75 | * @param aMsgHandler Weak pointer to the object |
michael@0 | 76 | */ |
michael@0 | 77 | virtual void |
michael@0 | 78 | UnregisterBluetoothSignalHandler(const nsAString& aNodeName, |
michael@0 | 79 | BluetoothSignalObserver* aMsgHandler); |
michael@0 | 80 | |
michael@0 | 81 | /** |
michael@0 | 82 | * Remove a message handlers for the given observer. |
michael@0 | 83 | * Must be called from the main thread. |
michael@0 | 84 | * |
michael@0 | 85 | * @param aMsgHandler Weak pointer to the object |
michael@0 | 86 | */ |
michael@0 | 87 | void |
michael@0 | 88 | UnregisterAllSignalHandlers(BluetoothSignalObserver* aMsgHandler); |
michael@0 | 89 | |
michael@0 | 90 | /** |
michael@0 | 91 | * Distribute a signal to the observer list |
michael@0 | 92 | * |
michael@0 | 93 | * @param aSignal Signal object to distribute |
michael@0 | 94 | * |
michael@0 | 95 | * @return NS_OK if signal distributed, NS_ERROR_FAILURE on error |
michael@0 | 96 | */ |
michael@0 | 97 | void |
michael@0 | 98 | DistributeSignal(const BluetoothSignal& aEvent); |
michael@0 | 99 | |
michael@0 | 100 | /** |
michael@0 | 101 | * Called when get a Bluetooth Signal from BluetoothDBusService |
michael@0 | 102 | * |
michael@0 | 103 | */ |
michael@0 | 104 | void |
michael@0 | 105 | Notify(const BluetoothSignal& aParam); |
michael@0 | 106 | |
michael@0 | 107 | /** |
michael@0 | 108 | * Returns the BluetoothService singleton. Only to be called from main thread. |
michael@0 | 109 | * |
michael@0 | 110 | * @param aService Pointer to return singleton into. |
michael@0 | 111 | * |
michael@0 | 112 | * @return NS_OK on proper assignment, NS_ERROR_FAILURE otherwise (if service |
michael@0 | 113 | * has not yet been started, for instance) |
michael@0 | 114 | */ |
michael@0 | 115 | static BluetoothService* |
michael@0 | 116 | Get(); |
michael@0 | 117 | |
michael@0 | 118 | static already_AddRefed<BluetoothService> |
michael@0 | 119 | FactoryCreate() |
michael@0 | 120 | { |
michael@0 | 121 | nsRefPtr<BluetoothService> service = Get(); |
michael@0 | 122 | return service.forget(); |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | /** |
michael@0 | 126 | * Returns the path of the default adapter, implemented via a platform |
michael@0 | 127 | * specific method. |
michael@0 | 128 | * |
michael@0 | 129 | * @return NS_OK on success, NS_ERROR_FAILURE otherwise |
michael@0 | 130 | */ |
michael@0 | 131 | virtual nsresult |
michael@0 | 132 | GetDefaultAdapterPathInternal(BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 133 | |
michael@0 | 134 | /** |
michael@0 | 135 | * Returns the properties of paired devices, implemented via a platform |
michael@0 | 136 | * specific method. |
michael@0 | 137 | * |
michael@0 | 138 | * @return NS_OK on success, NS_ERROR_FAILURE otherwise |
michael@0 | 139 | */ |
michael@0 | 140 | virtual nsresult |
michael@0 | 141 | GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddresses, |
michael@0 | 142 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 143 | |
michael@0 | 144 | /** |
michael@0 | 145 | * Returns the properties of connected devices regarding to specific profile, |
michael@0 | 146 | * implemented via a platform specific methood. |
michael@0 | 147 | * |
michael@0 | 148 | * @return NS_OK on success, NS_ERROR_FAILURE otherwise |
michael@0 | 149 | */ |
michael@0 | 150 | virtual nsresult |
michael@0 | 151 | GetConnectedDevicePropertiesInternal(uint16_t aServiceUuid, |
michael@0 | 152 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 153 | |
michael@0 | 154 | /** |
michael@0 | 155 | * Stop device discovery (platform specific implementation) |
michael@0 | 156 | * |
michael@0 | 157 | * @return NS_OK if discovery stopped correctly, false otherwise |
michael@0 | 158 | */ |
michael@0 | 159 | virtual nsresult |
michael@0 | 160 | StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 161 | |
michael@0 | 162 | /** |
michael@0 | 163 | * Start device discovery (platform specific implementation) |
michael@0 | 164 | * |
michael@0 | 165 | * @return NS_OK if discovery stopped correctly, false otherwise |
michael@0 | 166 | */ |
michael@0 | 167 | virtual nsresult |
michael@0 | 168 | StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 169 | |
michael@0 | 170 | /** |
michael@0 | 171 | * Set a property for the specified object |
michael@0 | 172 | * |
michael@0 | 173 | * @param aPropName Name of the property |
michael@0 | 174 | * @param aValue Boolean value |
michael@0 | 175 | * @param aRunnable Runnable to run on async reply |
michael@0 | 176 | * |
michael@0 | 177 | * @return NS_OK if property is set correctly, NS_ERROR_FAILURE otherwise |
michael@0 | 178 | */ |
michael@0 | 179 | virtual nsresult |
michael@0 | 180 | SetProperty(BluetoothObjectType aType, |
michael@0 | 181 | const BluetoothNamedValue& aValue, |
michael@0 | 182 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 183 | |
michael@0 | 184 | virtual nsresult |
michael@0 | 185 | CreatePairedDeviceInternal(const nsAString& aAddress, |
michael@0 | 186 | int aTimeout, |
michael@0 | 187 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 188 | |
michael@0 | 189 | virtual nsresult |
michael@0 | 190 | RemoveDeviceInternal(const nsAString& aObjectPath, |
michael@0 | 191 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 192 | |
michael@0 | 193 | /** |
michael@0 | 194 | * Get corresponding service channel of specific service on remote device. |
michael@0 | 195 | * It's usually the very first step of establishing an outbound connection. |
michael@0 | 196 | * |
michael@0 | 197 | * @param aObjectPath Object path of remote device |
michael@0 | 198 | * @param aServiceUuid UUID of the target service |
michael@0 | 199 | * @param aManager Instance which has callback function OnGetServiceChannel() |
michael@0 | 200 | * |
michael@0 | 201 | * @return NS_OK if the task begins, NS_ERROR_FAILURE otherwise |
michael@0 | 202 | */ |
michael@0 | 203 | virtual nsresult |
michael@0 | 204 | GetServiceChannel(const nsAString& aDeviceAddress, |
michael@0 | 205 | const nsAString& aServiceUuid, |
michael@0 | 206 | BluetoothProfileManagerBase* aManager) = 0; |
michael@0 | 207 | |
michael@0 | 208 | virtual bool |
michael@0 | 209 | UpdateSdpRecords(const nsAString& aDeviceAddress, |
michael@0 | 210 | BluetoothProfileManagerBase* aManager) = 0; |
michael@0 | 211 | |
michael@0 | 212 | virtual bool |
michael@0 | 213 | SetPinCodeInternal(const nsAString& aDeviceAddress, const nsAString& aPinCode, |
michael@0 | 214 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 215 | |
michael@0 | 216 | virtual bool |
michael@0 | 217 | SetPasskeyInternal(const nsAString& aDeviceAddress, uint32_t aPasskey, |
michael@0 | 218 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 219 | |
michael@0 | 220 | virtual bool |
michael@0 | 221 | SetPairingConfirmationInternal(const nsAString& aDeviceAddress, bool aConfirm, |
michael@0 | 222 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 223 | |
michael@0 | 224 | virtual void |
michael@0 | 225 | Connect(const nsAString& aDeviceAddress, uint32_t aCod, uint16_t aServiceUuid, |
michael@0 | 226 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 227 | |
michael@0 | 228 | virtual void |
michael@0 | 229 | Disconnect(const nsAString& aDeviceAddress, uint16_t aServiceUuid, |
michael@0 | 230 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 231 | |
michael@0 | 232 | virtual bool |
michael@0 | 233 | IsConnected(uint16_t aServiceUuid) = 0; |
michael@0 | 234 | |
michael@0 | 235 | virtual void |
michael@0 | 236 | SendFile(const nsAString& aDeviceAddress, |
michael@0 | 237 | BlobParent* aBlobParent, |
michael@0 | 238 | BlobChild* aBlobChild, |
michael@0 | 239 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 240 | |
michael@0 | 241 | virtual void |
michael@0 | 242 | SendFile(const nsAString& aDeviceAddress, |
michael@0 | 243 | nsIDOMBlob* aBlob, |
michael@0 | 244 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 245 | |
michael@0 | 246 | virtual void |
michael@0 | 247 | StopSendingFile(const nsAString& aDeviceAddress, |
michael@0 | 248 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 249 | |
michael@0 | 250 | virtual void |
michael@0 | 251 | ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirm, |
michael@0 | 252 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 253 | |
michael@0 | 254 | virtual void |
michael@0 | 255 | ConnectSco(BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 256 | |
michael@0 | 257 | virtual void |
michael@0 | 258 | DisconnectSco(BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 259 | |
michael@0 | 260 | virtual void |
michael@0 | 261 | IsScoConnected(BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 262 | |
michael@0 | 263 | #ifdef MOZ_B2G_RIL |
michael@0 | 264 | virtual void |
michael@0 | 265 | AnswerWaitingCall(BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 266 | |
michael@0 | 267 | virtual void |
michael@0 | 268 | IgnoreWaitingCall(BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 269 | |
michael@0 | 270 | virtual void |
michael@0 | 271 | ToggleCalls(BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 272 | #endif |
michael@0 | 273 | |
michael@0 | 274 | virtual void |
michael@0 | 275 | SendMetaData(const nsAString& aTitle, |
michael@0 | 276 | const nsAString& aArtist, |
michael@0 | 277 | const nsAString& aAlbum, |
michael@0 | 278 | int64_t aMediaNumber, |
michael@0 | 279 | int64_t aTotalMediaCount, |
michael@0 | 280 | int64_t aDuration, |
michael@0 | 281 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 282 | |
michael@0 | 283 | virtual void |
michael@0 | 284 | SendPlayStatus(int64_t aDuration, |
michael@0 | 285 | int64_t aPosition, |
michael@0 | 286 | const nsAString& aPlayStatus, |
michael@0 | 287 | BluetoothReplyRunnable* aRunnable) = 0; |
michael@0 | 288 | |
michael@0 | 289 | virtual void |
michael@0 | 290 | UpdatePlayStatus(uint32_t aDuration, |
michael@0 | 291 | uint32_t aPosition, |
michael@0 | 292 | ControlPlayStatus aPlayStatus) = 0; |
michael@0 | 293 | |
michael@0 | 294 | virtual nsresult |
michael@0 | 295 | SendSinkMessage(const nsAString& aDeviceAddresses, |
michael@0 | 296 | const nsAString& aMessage) = 0; |
michael@0 | 297 | |
michael@0 | 298 | virtual nsresult |
michael@0 | 299 | SendInputMessage(const nsAString& aDeviceAddresses, |
michael@0 | 300 | const nsAString& aMessage) = 0; |
michael@0 | 301 | |
michael@0 | 302 | bool |
michael@0 | 303 | IsEnabled() const |
michael@0 | 304 | { |
michael@0 | 305 | return mEnabled; |
michael@0 | 306 | } |
michael@0 | 307 | |
michael@0 | 308 | bool |
michael@0 | 309 | IsToggling() const; |
michael@0 | 310 | |
michael@0 | 311 | void |
michael@0 | 312 | RemoveObserverFromTable(const nsAString& key); |
michael@0 | 313 | |
michael@0 | 314 | /** |
michael@0 | 315 | * Below 2 function/variable are used for ensuring event 'AdapterAdded' will |
michael@0 | 316 | * be fired after event 'Enabled'. |
michael@0 | 317 | */ |
michael@0 | 318 | void TryFiringAdapterAdded(); |
michael@0 | 319 | void AdapterAddedReceived(); |
michael@0 | 320 | |
michael@0 | 321 | protected: |
michael@0 | 322 | BluetoothService() : mEnabled(false) |
michael@0 | 323 | , mAdapterAddedReceived(false) |
michael@0 | 324 | { |
michael@0 | 325 | } |
michael@0 | 326 | |
michael@0 | 327 | virtual ~BluetoothService(); |
michael@0 | 328 | |
michael@0 | 329 | bool |
michael@0 | 330 | Init(); |
michael@0 | 331 | |
michael@0 | 332 | void |
michael@0 | 333 | Cleanup(); |
michael@0 | 334 | |
michael@0 | 335 | nsresult |
michael@0 | 336 | StartBluetooth(bool aIsStartup); |
michael@0 | 337 | |
michael@0 | 338 | nsresult |
michael@0 | 339 | StopBluetooth(bool aIsStartup); |
michael@0 | 340 | |
michael@0 | 341 | nsresult |
michael@0 | 342 | StartStopBluetooth(bool aStart, bool aIsStartup); |
michael@0 | 343 | |
michael@0 | 344 | /** |
michael@0 | 345 | * Platform specific startup functions go here. Usually deals with member |
michael@0 | 346 | * variables, so not static. Guaranteed to be called outside of main thread. |
michael@0 | 347 | * |
michael@0 | 348 | * @return NS_OK on correct startup, NS_ERROR_FAILURE otherwise |
michael@0 | 349 | */ |
michael@0 | 350 | virtual nsresult |
michael@0 | 351 | StartInternal() = 0; |
michael@0 | 352 | |
michael@0 | 353 | /** |
michael@0 | 354 | * Platform specific startup functions go here. Usually deals with member |
michael@0 | 355 | * variables, so not static. Guaranteed to be called outside of main thread. |
michael@0 | 356 | * |
michael@0 | 357 | * @return NS_OK on correct startup, NS_ERROR_FAILURE otherwise |
michael@0 | 358 | */ |
michael@0 | 359 | virtual nsresult |
michael@0 | 360 | StopInternal() = 0; |
michael@0 | 361 | |
michael@0 | 362 | /** |
michael@0 | 363 | * Called when XPCOM first creates this service. |
michael@0 | 364 | */ |
michael@0 | 365 | virtual nsresult |
michael@0 | 366 | HandleStartup(); |
michael@0 | 367 | |
michael@0 | 368 | /** |
michael@0 | 369 | * Called when the startup settings check has completed. |
michael@0 | 370 | */ |
michael@0 | 371 | nsresult |
michael@0 | 372 | HandleStartupSettingsCheck(bool aEnable); |
michael@0 | 373 | |
michael@0 | 374 | /** |
michael@0 | 375 | * Called when "mozsettings-changed" observer topic fires. |
michael@0 | 376 | */ |
michael@0 | 377 | nsresult |
michael@0 | 378 | HandleSettingsChanged(const nsAString& aData); |
michael@0 | 379 | |
michael@0 | 380 | /** |
michael@0 | 381 | * Called when XPCOM is shutting down. |
michael@0 | 382 | */ |
michael@0 | 383 | virtual nsresult |
michael@0 | 384 | HandleShutdown(); |
michael@0 | 385 | |
michael@0 | 386 | // Called by ToggleBtAck. |
michael@0 | 387 | void |
michael@0 | 388 | SetEnabled(bool aEnabled); |
michael@0 | 389 | |
michael@0 | 390 | // Called by Get(). |
michael@0 | 391 | static BluetoothService* |
michael@0 | 392 | Create(); |
michael@0 | 393 | |
michael@0 | 394 | typedef nsClassHashtable<nsStringHashKey, BluetoothSignalObserverList > |
michael@0 | 395 | BluetoothSignalObserverTable; |
michael@0 | 396 | |
michael@0 | 397 | BluetoothSignalObserverTable mBluetoothSignalObserverTable; |
michael@0 | 398 | |
michael@0 | 399 | bool mEnabled; |
michael@0 | 400 | |
michael@0 | 401 | private: |
michael@0 | 402 | bool mAdapterAddedReceived; |
michael@0 | 403 | }; |
michael@0 | 404 | |
michael@0 | 405 | END_BLUETOOTH_NAMESPACE |
michael@0 | 406 | |
michael@0 | 407 | #endif |