dom/bluetooth/BluetoothProfileController.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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_bluetoothprofilecontroller_h__
michael@0 8 #define mozilla_dom_bluetooth_bluetoothprofilecontroller_h__
michael@0 9
michael@0 10 #include "BluetoothUuid.h"
michael@0 11 #include "nsISupportsImpl.h"
michael@0 12 #include "nsAutoPtr.h"
michael@0 13 #include "nsITimer.h"
michael@0 14
michael@0 15 BEGIN_BLUETOOTH_NAMESPACE
michael@0 16
michael@0 17 /*
michael@0 18 * Class of Device(CoD): 32-bit unsigned integer
michael@0 19 *
michael@0 20 * 31 24 23 13 12 8 7 2 1 0
michael@0 21 * | | Major | Major | Minor | |
michael@0 22 * | | service | device | device | |
michael@0 23 * | | class | class | class | |
michael@0 24 * | |<- 11 ->|<- 5 ->|<- 6 ->| |
michael@0 25 *
michael@0 26 * https://www.bluetooth.org/en-us/specification/assigned-numbers/baseband
michael@0 27 */
michael@0 28
michael@0 29 // Bit 23 ~ Bit 13: Major service class
michael@0 30 #define GET_MAJOR_SERVICE_CLASS(cod) ((cod & 0xffe000) >> 13)
michael@0 31
michael@0 32 // Bit 12 ~ Bit 8: Major device class
michael@0 33 #define GET_MAJOR_DEVICE_CLASS(cod) ((cod & 0x1f00) >> 8)
michael@0 34
michael@0 35 // Bit 7 ~ Bit 2: Minor device class
michael@0 36 #define GET_MINOR_DEVICE_CLASS(cod) ((cod & 0xfc) >> 2)
michael@0 37
michael@0 38 // Audio: Major service class = 0x100 (Bit 21 is set)
michael@0 39 #define HAS_AUDIO(cod) (cod & 0x200000)
michael@0 40
michael@0 41 // Rendering: Major service class = 0x20 (Bit 18 is set)
michael@0 42 #define HAS_RENDERING(cod) (cod & 0x40000)
michael@0 43
michael@0 44 // Peripheral: Major device class = 0x5
michael@0 45 #define IS_PERIPHERAL(cod) (GET_MAJOR_DEVICE_CLASS(cod) == 0x5)
michael@0 46
michael@0 47 // Remote Control: sub-field of minor device class, Bit 5 ~ Bit 2 = 0x3
michael@0 48 #define IS_REMOTE_CONTROL(cod) ((GET_MINOR_DEVICE_CLASS(cod) & 0xf) == 0x3)
michael@0 49
michael@0 50 // Keyboard: sub-field of minor device class (Bit 6)
michael@0 51 #define IS_KEYBOARD(cod) ((GET_MINOR_DEVICE_CLASS(cod) & 0x10) >> 4)
michael@0 52
michael@0 53 // Pointing device: sub-field of minor device class (Bit 7)
michael@0 54 #define IS_POINTING_DEVICE(cod) ((GET_MINOR_DEVICE_CLASS(cod) & 0x20) >> 5)
michael@0 55
michael@0 56 class BluetoothProfileManagerBase;
michael@0 57 class BluetoothReplyRunnable;
michael@0 58 typedef void (*BluetoothProfileControllerCallback)();
michael@0 59
michael@0 60 class BluetoothProfileController MOZ_FINAL
michael@0 61 {
michael@0 62 ~BluetoothProfileController();
michael@0 63
michael@0 64 public:
michael@0 65 NS_INLINE_DECL_REFCOUNTING(BluetoothProfileController)
michael@0 66 /**
michael@0 67 * @param aConnect: If it's a connect request, the value should be set
michael@0 68 * to true. For disconnect request, set it to false.
michael@0 69 * @param aDeviceAddress: The address of remote device.
michael@0 70 * @param aRunnable: Once the controller has done, the runnable will be
michael@0 71 * replied. When all connection/disconnection attemps
michael@0 72 * have failed, an error is fired. In other words,
michael@0 73 * reply a success if any attemp successes.
michael@0 74 * @param aCallback: The callback will be invoked after the runnable is
michael@0 75 * replied.
michael@0 76 * @param aServiceUuid: Connect/Disconnect to the specified profile. Please
michael@0 77 * see enum BluetoothServiceClass for valid value.
michael@0 78 * @param aCod: If aServiceUuid is not assigned, i.e. the value is
michael@0 79 * 0, the controller connect multiple profiles based on
michael@0 80 * aCod or disconnect all connected profiles.
michael@0 81 */
michael@0 82 BluetoothProfileController(bool aConnect,
michael@0 83 const nsAString& aDeviceAddress,
michael@0 84 BluetoothReplyRunnable* aRunnable,
michael@0 85 BluetoothProfileControllerCallback aCallback,
michael@0 86 uint16_t aServiceUuid,
michael@0 87 uint32_t aCod = 0);
michael@0 88
michael@0 89 /**
michael@0 90 * The controller starts connecting/disconnecting profiles one by one
michael@0 91 * according to the order in array mProfiles.
michael@0 92 */
michael@0 93 void StartSession();
michael@0 94
michael@0 95 /**
michael@0 96 * The original DOM request would be fired in this function.
michael@0 97 */
michael@0 98 void EndSession();
michael@0 99
michael@0 100 /**
michael@0 101 * It would be invoked after connect/disconnect operation is completed.
michael@0 102 * An error string would be returned when it fails.
michael@0 103 */
michael@0 104 void NotifyCompletion(const nsAString& aErrorStr);
michael@0 105
michael@0 106 /**
michael@0 107 * It is invoked after a profile has reached timeout, reset mProfiles.
michael@0 108 */
michael@0 109 void GiveupAndContinue();
michael@0 110
michael@0 111 private:
michael@0 112 // Setup data member mProfiles
michael@0 113 void SetupProfiles(bool aAssignServiceClass);
michael@0 114
michael@0 115 // Add profiles into array with/without checking connection status
michael@0 116 void AddProfile(BluetoothProfileManagerBase* aProfile,
michael@0 117 bool aCheckConnected = false);
michael@0 118
michael@0 119 // Add specified profile into array
michael@0 120 void AddProfileWithServiceClass(BluetoothServiceClass aClass);
michael@0 121
michael@0 122 // Connect/Disconnect next profile in the array
michael@0 123 void Next();
michael@0 124
michael@0 125 const bool mConnect;
michael@0 126 nsString mDeviceAddress;
michael@0 127 nsRefPtr<BluetoothReplyRunnable> mRunnable;
michael@0 128 BluetoothProfileControllerCallback mCallback;
michael@0 129
michael@0 130 bool mCurrentProfileFinished;
michael@0 131 bool mSuccess;
michael@0 132 int8_t mProfilesIndex;
michael@0 133 nsTArray<BluetoothProfileManagerBase*> mProfiles;
michael@0 134
michael@0 135 // Either CoD or BluetoothServiceClass is assigned.
michael@0 136 union {
michael@0 137 uint32_t cod;
michael@0 138 BluetoothServiceClass service;
michael@0 139 } mTarget;
michael@0 140
michael@0 141 nsCOMPtr<nsITimer> mTimer;
michael@0 142 nsCOMPtr<nsITimerCallback> mCheckProfileStatusCallback;
michael@0 143 };
michael@0 144
michael@0 145 END_BLUETOOTH_NAMESPACE
michael@0 146
michael@0 147 #endif

mercurial