Bug 802590 - Patch 3: Implemented the logic, r=qdot

This commit is contained in:
Eric Chou 2012-10-19 14:16:13 +08:00
parent 9e7732996a
commit 38f083e7e5
2 changed files with 42 additions and 12 deletions

View File

@ -100,6 +100,7 @@ BluetoothOppManager::BluetoothOppManager() : mConnected(false)
, mPacketLeftLength(0)
, mReceiving(false)
, mPutFinal(false)
, mWaitingForConfirmationFlag(false)
{
// FIXME / Bug 800249:
// mConnectedDeviceAddress is Bluetooth address of connected device,
@ -219,7 +220,22 @@ void
BluetoothOppManager::ConfirmReceivingFile(bool aConfirm,
BluetoothReplyRunnable* aRunnable)
{
// FIXME(Eric): Will implement in the third patch
if (!mWaitingForConfirmationFlag) {
NS_WARNING("We are not waiting for a confirmation now.");
return;
}
NS_ASSERTION(mPacketLeftLength == 0,
"Should not be in the middle of receiving a PUT packet.");
mWaitingForConfirmationFlag = false;
ReplyToPut(mPutFinal, aConfirm);
if (mPutFinal || !aConfirm) {
mReceiving = false;
FileTransferComplete(mConnectedDeviceAddress, aConfirm, true, sFileName,
sSentFileLength, sContentType);
}
}
// Virtual function of class SocketConsumer
@ -372,8 +388,8 @@ BluetoothOppManager::ReceiveSocketData(UnixSocketRawData* aMessage)
pktHeaders.GetContentType(sContentType);
pktHeaders.GetLength(&sFileLength);
ReceivingFileConfirmation(mConnectedDeviceAddress, sFileName, sFileLength, sContentType);
mReceiving = true;
mWaitingForConfirmationFlag = true;
}
/*
@ -395,12 +411,17 @@ BluetoothOppManager::ReceiveSocketData(UnixSocketRawData* aMessage)
}
if (mPacketLeftLength == 0) {
ReplyToPut(mPutFinal);
if (mWaitingForConfirmationFlag) {
ReceivingFileConfirmation(mConnectedDeviceAddress, sFileName,
sFileLength, sContentType);
} else {
ReplyToPut(mPutFinal, true);
if (mPutFinal) {
mReceiving = false;
FileTransferComplete(mConnectedDeviceAddress, true, true, sFileName,
sSentFileLength, sContentType);
if (mPutFinal) {
mReceiving = false;
FileTransferComplete(mConnectedDeviceAddress, true, true, sFileName,
sSentFileLength, sContentType);
}
}
}
}
@ -576,7 +597,7 @@ BluetoothOppManager::ReplyToDisconnect()
}
void
BluetoothOppManager::ReplyToPut(bool aFinal)
BluetoothOppManager::ReplyToPut(bool aFinal, bool aContinue)
{
if (!mConnected) return;
@ -585,10 +606,18 @@ BluetoothOppManager::ReplyToPut(bool aFinal)
uint8_t req[255];
int index = 3;
if (aFinal) {
SetObexPacketInfo(req, ObexResponseCode::Success, index);
if (aContinue) {
if (aFinal) {
SetObexPacketInfo(req, ObexResponseCode::Success, index);
} else {
SetObexPacketInfo(req, ObexResponseCode::Continue, index);
}
} else {
SetObexPacketInfo(req, ObexResponseCode::Continue, index);
if (aFinal) {
SetObexPacketInfo(req, ObexResponseCode::Unauthorized, index);
} else {
SetObexPacketInfo(req, ObexResponseCode::Unauthorized & (~FINAL_BIT), index);
}
}
UnixSocketRawData* s = new UnixSocketRawData(index);

View File

@ -83,7 +83,7 @@ private:
const nsString& aContentType);
void ReplyToConnect();
void ReplyToDisconnect();
void ReplyToPut(bool aFinal);
void ReplyToPut(bool aFinal, bool aContinue);
virtual void OnConnectSuccess() MOZ_OVERRIDE;
virtual void OnConnectError() MOZ_OVERRIDE;
virtual void OnDisconnect() MOZ_OVERRIDE;
@ -99,6 +99,7 @@ private:
nsString mConnectedDeviceAddress;
bool mReceiving;
bool mPutFinal;
bool mWaitingForConfirmationFlag;
nsCOMPtr<nsIDOMBlob> mBlob;
nsCOMPtr<nsIThread> mReadFileThread;