Skip to content

Commit

Permalink
Bug 1220121: Convert IPDL of Bluetooth OPP API to |BluetoothAddress|,…
Browse files Browse the repository at this point in the history
… r=btian
  • Loading branch information
tdz committed Nov 12, 2015
1 parent 0b0f22b commit 62d409e
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 82 deletions.
28 changes: 7 additions & 21 deletions dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1526,27 +1526,20 @@ BluetoothServiceBluedroid::Disconnect(
}

void
BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress,
BluetoothServiceBluedroid::SendFile(const BluetoothAddress& aDeviceAddress,
BlobParent* aBlobParent,
BlobChild* aBlobChild,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());

BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(aDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}

// Currently we only support one device sending one file at a time,
// so we don't need aDeviceAddress here because the target device
// has been determined when calling 'Connect()'. Nevertheless, keep
// it for future use.

BluetoothOppManager* opp = BluetoothOppManager::Get();
if (!opp || !opp->SendFile(deviceAddress, aBlobParent)) {
if (!opp || !opp->SendFile(aDeviceAddress, aBlobParent)) {
DispatchReplyError(aRunnable, NS_LITERAL_STRING("SendFile failed"));
return;
}
Expand All @@ -1555,26 +1548,19 @@ BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress,
}

void
BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress,
BluetoothServiceBluedroid::SendFile(const BluetoothAddress& aDeviceAddress,
Blob* aBlob,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());

BluetoothAddress deviceAddress;
nsresult rv = StringToAddress(aDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}

// Currently we only support one device sending one file at a time,
// so we don't need aDeviceAddress here because the target device
// has been determined when calling 'Connect()'. Nevertheless, keep
// it for future use.

BluetoothOppManager* opp = BluetoothOppManager::Get();
if (!opp || !opp->SendFile(deviceAddress, aBlob)) {
if (!opp || !opp->SendFile(aDeviceAddress, aBlob)) {
DispatchReplyError(aRunnable, NS_LITERAL_STRING("SendFile failed"));
return;
}
Expand All @@ -1583,8 +1569,8 @@ BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress,
}

void
BluetoothServiceBluedroid::StopSendingFile(const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable)
BluetoothServiceBluedroid::StopSendingFile(
const BluetoothAddress& aDeviceAddress, BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());

Expand All @@ -1605,7 +1591,7 @@ BluetoothServiceBluedroid::StopSendingFile(const nsAString& aDeviceAddress,

void
BluetoothServiceBluedroid::ConfirmReceivingFile(
const nsAString& aDeviceAddress, bool aConfirm,
const BluetoothAddress& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
Expand Down
8 changes: 4 additions & 4 deletions dom/bluetooth/bluedroid/BluetoothServiceBluedroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,22 @@ class BluetoothServiceBluedroid : public BluetoothService
BluetoothReplyRunnable* aRunnable);

virtual void
SendFile(const nsAString& aDeviceAddress,
SendFile(const BluetoothAddress& aDeviceAddress,
BlobParent* aBlobParent,
BlobChild* aBlobChild,
BluetoothReplyRunnable* aRunnable);

virtual void
SendFile(const nsAString& aDeviceAddress,
SendFile(const BluetoothAddress& aDeviceAddress,
Blob* aBlob,
BluetoothReplyRunnable* aRunnable);

virtual void
StopSendingFile(const nsAString& aDeviceAddress,
StopSendingFile(const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable);

virtual void
ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirm,
ConfirmReceivingFile(const BluetoothAddress& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable);

virtual void
Expand Down
29 changes: 9 additions & 20 deletions dom/bluetooth/bluez/BluetoothDBusService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3778,60 +3778,48 @@ BluetoothDBusService::UpdateSdpRecords(const BluetoothAddress& aDeviceAddress,
}

void
BluetoothDBusService::SendFile(const nsAString& aDeviceAddress,
BluetoothDBusService::SendFile(const BluetoothAddress& aDeviceAddress,
BlobParent* aBlobParent,
BlobChild* aBlobChild,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());

BluetoothAddress deviceAddress;
if (NS_FAILED(StringToAddress(aDeviceAddress, deviceAddress))) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}

// Currently we only support one device sending one file at a time,
// so we don't need aDeviceAddress here because the target device
// has been determined when calling 'Connect()'. Nevertheless, keep
// it for future use.
BluetoothOppManager* opp = BluetoothOppManager::Get();
nsAutoString errorStr;
if (!opp || !opp->SendFile(deviceAddress, aBlobParent)) {
if (!opp || !opp->SendFile(aDeviceAddress, aBlobParent)) {
errorStr.AssignLiteral("Calling SendFile() failed");
}

DispatchBluetoothReply(aRunnable, BluetoothValue(true), errorStr);
}

void
BluetoothDBusService::SendFile(const nsAString& aDeviceAddress,
BluetoothDBusService::SendFile(const BluetoothAddress& aDeviceAddress,
Blob* aBlob,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());

BluetoothAddress deviceAddress;
if (NS_FAILED(StringToAddress(aDeviceAddress, deviceAddress))) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}

// Currently we only support one device sending one file at a time,
// so we don't need aDeviceAddress here because the target device
// has been determined when calling 'Connect()'. Nevertheless, keep
// it for future use.
BluetoothOppManager* opp = BluetoothOppManager::Get();
nsAutoString errorStr;
if (!opp || !opp->SendFile(deviceAddress, aBlob)) {
if (!opp || !opp->SendFile(aDeviceAddress, aBlob)) {
errorStr.AssignLiteral("Calling SendFile() failed");
}

DispatchBluetoothReply(aRunnable, BluetoothValue(true), errorStr);
}

void
BluetoothDBusService::StopSendingFile(const nsAString& aDeviceAddress,
BluetoothDBusService::StopSendingFile(const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
Expand All @@ -3850,9 +3838,10 @@ BluetoothDBusService::StopSendingFile(const nsAString& aDeviceAddress,
}

void
BluetoothDBusService::ConfirmReceivingFile(const nsAString& aDeviceAddress,
bool aConfirm,
BluetoothReplyRunnable* aRunnable)
BluetoothDBusService::ConfirmReceivingFile(
const BluetoothAddress& aDeviceAddress,
bool aConfirm,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread(), "Must be called from main thread!");

Expand Down
8 changes: 4 additions & 4 deletions dom/bluetooth/bluez/BluetoothDBusService.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,22 @@ class BluetoothDBusService : public BluetoothService
BluetoothReplyRunnable* aRunnable) override;

virtual void
SendFile(const nsAString& aDeviceAddress,
SendFile(const BluetoothAddress& aDeviceAddress,
BlobParent* aBlobParent,
BlobChild* aBlobChild,
BluetoothReplyRunnable* aRunnable) override;

virtual void
SendFile(const nsAString& aDeviceAddress,
SendFile(const BluetoothAddress& aDeviceAddress,
Blob* aBlob,
BluetoothReplyRunnable* aRunnable) override;

virtual void
StopSendingFile(const nsAString& aDeviceAddress,
StopSendingFile(const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) override;

virtual void
ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirm,
ConfirmReceivingFile(const BluetoothAddress& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable) override;

virtual void
Expand Down
8 changes: 4 additions & 4 deletions dom/bluetooth/common/BluetoothService.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,22 +286,22 @@ class BluetoothService : public nsIObserver
BluetoothReplyRunnable* aRunnable) = 0;

virtual void
SendFile(const nsAString& aDeviceAddress,
SendFile(const BluetoothAddress& aDeviceAddress,
BlobParent* aBlobParent,
BlobChild* aBlobChild,
BluetoothReplyRunnable* aRunnable) = 0;

virtual void
SendFile(const nsAString& aDeviceAddress,
SendFile(const BluetoothAddress& aDeviceAddress,
Blob* aBlob,
BluetoothReplyRunnable* aRunnable) = 0;

virtual void
StopSendingFile(const nsAString& aDeviceAddress,
StopSendingFile(const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) = 0;

virtual void
ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirm,
ConfirmReceivingFile(const BluetoothAddress& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable) = 0;

virtual void
Expand Down
29 changes: 25 additions & 4 deletions dom/bluetooth/common/webapi/BluetoothAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,13 @@ BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
RefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(request);

BluetoothAddress deviceAddress;
auto rv = StringToAddress(aDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}

BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
Expand All @@ -1756,7 +1763,7 @@ BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,

if (XRE_IsParentProcess()) {
// In-process transfer
bs->SendFile(aDeviceAddress, &aBlob, results);
bs->SendFile(deviceAddress, &aBlob, results);
} else {
ContentChild *cc = ContentChild::GetSingleton();
if (!cc) {
Expand All @@ -1770,7 +1777,7 @@ BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
return nullptr;
}

bs->SendFile(aDeviceAddress, nullptr, actor, results);
bs->SendFile(deviceAddress, nullptr, actor, results);
}

return request.forget();
Expand All @@ -1790,12 +1797,19 @@ BluetoothAdapter::StopSendingFile(
RefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(request);

BluetoothAddress deviceAddress;
auto rv = StringToAddress(aDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}

BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
bs->StopSendingFile(aDeviceAddress, results);
bs->StopSendingFile(deviceAddress, results);

return request.forget();
}
Expand All @@ -1814,12 +1828,19 @@ BluetoothAdapter::ConfirmReceivingFile(const nsAString& aDeviceAddress,
RefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(request);

BluetoothAddress deviceAddress;
auto rv = StringToAddress(aDeviceAddress, deviceAddress);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}

BluetoothService* bs = BluetoothService::Get();
if (!bs) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
bs->ConfirmReceivingFile(aDeviceAddress, aConfirmation, results);
bs->ConfirmReceivingFile(deviceAddress, aConfirmation, results);

return request.forget();
}
Expand Down
8 changes: 4 additions & 4 deletions dom/bluetooth/ipc/BluetoothParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ BluetoothRequestParent::DoRequest(const SendFileRequest& aRequest)
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TSendFileRequest);

mService->SendFile(aRequest.devicePath(),
mService->SendFile(aRequest.address(),
(BlobParent*)aRequest.blobParent(),
(BlobChild*)aRequest.blobChild(),
mReplyRunnable.get());
Expand All @@ -694,7 +694,7 @@ BluetoothRequestParent::DoRequest(const StopSendingFileRequest& aRequest)
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TStopSendingFileRequest);

mService->StopSendingFile(aRequest.devicePath(),
mService->StopSendingFile(aRequest.address(),
mReplyRunnable.get());

return true;
Expand All @@ -706,7 +706,7 @@ BluetoothRequestParent::DoRequest(const ConfirmReceivingFileRequest& aRequest)
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TConfirmReceivingFileRequest);

mService->ConfirmReceivingFile(aRequest.devicePath(),
mService->ConfirmReceivingFile(aRequest.address(),
true,
mReplyRunnable.get());
return true;
Expand All @@ -718,7 +718,7 @@ BluetoothRequestParent::DoRequest(const DenyReceivingFileRequest& aRequest)
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TDenyReceivingFileRequest);

mService->ConfirmReceivingFile(aRequest.devicePath(),
mService->ConfirmReceivingFile(aRequest.address(),
false,
mReplyRunnable.get());
return true;
Expand Down
Loading

0 comments on commit 62d409e

Please sign in to comment.