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