Bug 914175 - Reply error when no profile is connected, r=echou

This commit is contained in:
Gina Yeh 2013-09-11 09:21:48 +02:00
parent 3abb9d3485
commit 9232c36f20
4 changed files with 27 additions and 5 deletions

View File

@ -21,9 +21,10 @@ BluetoothProfileController::BluetoothProfileController(
const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable,
BluetoothProfileControllerCallback aCallback)
: mDeviceAddress(aDeviceAddress)
: mCallback(aCallback)
, mDeviceAddress(aDeviceAddress)
, mRunnable(aRunnable)
, mCallback(aCallback)
, mSuccess(false)
{
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
MOZ_ASSERT(aRunnable);
@ -152,7 +153,12 @@ BluetoothProfileController::ConnectNext()
// The action has been completed, so the dom request is replied and then
// the callback is invoked
DispatchBluetoothReply(mRunnable, BluetoothValue(true), EmptyString());
if (mSuccess) {
DispatchBluetoothReply(mRunnable, BluetoothValue(true), EmptyString());
} else {
DispatchBluetoothReply(mRunnable, BluetoothValue(),
NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
}
mCallback();
}
@ -163,6 +169,8 @@ BluetoothProfileController::OnConnect(const nsAString& aErrorStr)
if (!aErrorStr.IsEmpty()) {
BT_WARNING(NS_ConvertUTF16toUTF8(aErrorStr).get());
} else {
mSuccess = true;
}
ConnectNext();
@ -203,7 +211,12 @@ BluetoothProfileController::DisconnectNext()
// The action has been completed, so the dom request is replied and then
// the callback is invoked
DispatchBluetoothReply(mRunnable, BluetoothValue(true), EmptyString());
if (mSuccess) {
DispatchBluetoothReply(mRunnable, BluetoothValue(true), EmptyString());
} else {
DispatchBluetoothReply(mRunnable, BluetoothValue(),
NS_LITERAL_STRING(ERR_DISCONNECTION_FAILED));
}
mCallback();
}
@ -214,6 +227,8 @@ BluetoothProfileController::OnDisconnect(const nsAString& aErrorStr)
if (!aErrorStr.IsEmpty()) {
BT_WARNING(NS_ConvertUTF16toUTF8(aErrorStr).get());
} else {
mSuccess = true;
}
DisconnectNext();

View File

@ -93,10 +93,11 @@ private:
int8_t mProfilesIndex;
nsTArray<BluetoothProfileManagerBase*> mProfiles;
BluetoothProfileControllerCallback mCallback;
uint32_t mCod;
nsString mDeviceAddress;
nsRefPtr<BluetoothReplyRunnable> mRunnable;
BluetoothProfileControllerCallback mCallback;
bool mSuccess;
};
END_BLUETOOTH_NAMESPACE

View File

@ -14,6 +14,8 @@
*/
#define ERR_ALREADY_CONNECTED "AlreadyConnectedError"
#define ERR_ALREADY_DISCONNECTED "AlreadyDisconnectedError"
#define ERR_CONNECTION_FAILED "ConnectionFailedError"
#define ERR_DISCONNECTION_FAILED "DisconnectionFailedError"
#define ERR_NO_AVAILABLE_RESOURCE "NoAvailableResourceError"
#define ERR_REACHED_CONNECTION_LIMIT "ReachedConnectionLimitError"
#define ERR_SERVICE_CHANNEL_NOT_FOUND "DeviceChannelRetrievalError"

View File

@ -106,6 +106,10 @@ interface BluetoothAdapter : EventTarget {
* device (CoD). If it isn't passed when calling Disconnect, all connected
* profiles are going to be closed.
*
* Reply success if the connection of any profile is successfully
* established/released; reply error if we failed to connect/disconnect all
* of the planned profiles.
*
* @param device Remote device
* @param profile 2-octets service UUID. This is optional.
*/