Bug 802590 - patch 2: IPC implementation, r=qdot

This commit is contained in:
Eric Chou 2012-10-19 14:16:13 +08:00
parent bf2e07fff1
commit 99997a7a1d
11 changed files with 104 additions and 2 deletions

View File

@ -883,9 +883,10 @@ BluetoothAdapter::ConfirmReceivingFile(const nsAString& aDeviceAddress,
return NS_ERROR_FAILURE;
}
nsRefPtr<BluetoothVoidReplyRunnable> results =
nsRefPtr<BluetoothVoidReplyRunnable> result =
new BluetoothVoidReplyRunnable(req);
//bs->ConfirmReceivingFile(aDeviceAddress, aConfirmation, result);
bs->ConfirmReceivingFile(aDeviceAddress, aConfirmation, result);
req.forget(aRequest);
return NS_OK;

View File

@ -215,6 +215,13 @@ BluetoothOppManager::StopSendingFile(BluetoothReplyRunnable* aRunnable)
return true;
}
void
BluetoothOppManager::ConfirmReceivingFile(bool aConfirm,
BluetoothReplyRunnable* aRunnable)
{
// FIXME(Eric): Will implement in the third patch
}
// Virtual function of class SocketConsumer
void
BluetoothOppManager::ReceiveSocketData(UnixSocketRawData* aMessage)

View File

@ -51,6 +51,7 @@ public:
bool SendFile(BlobParent* aBlob,
BluetoothReplyRunnable* aRunnable);
bool StopSendingFile(BluetoothReplyRunnable* aRunnable);
void ConfirmReceivingFile(bool aConfirm, BluetoothReplyRunnable* aRunnable);
void SendConnectRequest();
void SendPutHeaderRequest(const nsAString& aFileName, int aFileSize);

View File

@ -290,6 +290,10 @@ public:
bool aEncrypt,
mozilla::ipc::UnixSocketConsumer* aConsumer) = 0;
virtual void
ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable) = 0;
bool
IsEnabled() const
{

View File

@ -221,6 +221,10 @@ BluetoothParent::RecvPBluetoothRequestConstructor(
return actor->DoRequest(aRequest.get_SendFileRequest());
case Request::TStopSendingFileRequest:
return actor->DoRequest(aRequest.get_StopSendingFileRequest());
case Request::TConfirmReceivingFileRequest:
return actor->DoRequest(aRequest.get_ConfirmReceivingFileRequest());
case Request::TDenyReceivingFileRequest:
return actor->DoRequest(aRequest.get_DenyReceivingFileRequest());
default:
MOZ_NOT_REACHED("Unknown type!");
return false;
@ -540,3 +544,27 @@ BluetoothRequestParent::DoRequest(const StopSendingFileRequest& aRequest)
return mService->StopSendingFile(aRequest.devicePath(),
mReplyRunnable.get());
}
bool
BluetoothRequestParent::DoRequest(const ConfirmReceivingFileRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TConfirmReceivingFileRequest);
mService->ConfirmReceivingFile(aRequest.devicePath(),
true,
mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const DenyReceivingFileRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TDenyReceivingFileRequest);
mService->ConfirmReceivingFile(aRequest.devicePath(),
false,
mReplyRunnable.get());
return true;
}

View File

@ -177,6 +177,12 @@ protected:
bool
DoRequest(const StopSendingFileRequest& aRequest);
bool
DoRequest(const ConfirmReceivingFileRequest& aRequest);
bool
DoRequest(const DenyReceivingFileRequest& aRequest);
};
END_BLUETOOTH_NAMESPACE

View File

@ -345,6 +345,22 @@ BluetoothServiceChildProcess::StopSendingFile(
return true;
}
void
BluetoothServiceChildProcess::ConfirmReceivingFile(
const nsAString& aDeviceAddress,
bool aConfirm,
BluetoothReplyRunnable* aRunnable)
{
if(aConfirm) {
SendRequest(aRunnable,
ConfirmReceivingFileRequest(nsString(aDeviceAddress)));
return;
}
SendRequest(aRunnable,
DenyReceivingFileRequest(nsString(aDeviceAddress)));
}
nsresult
BluetoothServiceChildProcess::HandleStartup()
{

View File

@ -149,6 +149,10 @@ public:
StopSendingFile(const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual void
ConfirmReceivingFile(const nsAString& aDeviceAddress,
bool aConfirm,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
protected:
BluetoothServiceChildProcess();
virtual ~BluetoothServiceChildProcess();

View File

@ -121,6 +121,16 @@ struct StopSendingFileRequest
nsString devicePath;
};
struct ConfirmReceivingFileRequest
{
nsString devicePath;
};
struct DenyReceivingFileRequest
{
nsString devicePath;
};
union Request
{
DefaultAdapterPathRequest;
@ -141,6 +151,8 @@ union Request
DisconnectRequest;
SendFileRequest;
StopSendingFileRequest;
ConfirmReceivingFileRequest;
DenyReceivingFileRequest;
};
protocol PBluetooth

View File

@ -2527,6 +2527,8 @@ BluetoothDBusService::SendFile(const nsAString& aDeviceAddress,
BlobChild* aBlobChild,
BluetoothReplyRunnable* aRunnable)
{
NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
// 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
@ -2541,6 +2543,8 @@ bool
BluetoothDBusService::StopSendingFile(const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable)
{
NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
// 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
@ -2551,6 +2555,21 @@ BluetoothDBusService::StopSendingFile(const nsAString& aDeviceAddress,
return true;
}
void
BluetoothDBusService::ConfirmReceivingFile(const nsAString& aDeviceAddress,
bool aConfirm,
BluetoothReplyRunnable* aRunnable)
{
NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
// 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();
opp->ConfirmReceivingFile(aConfirm, aRunnable);
}
nsresult
BluetoothDBusService::ListenSocketViaService(int aChannel,
BluetoothSocketType aType,

View File

@ -152,6 +152,10 @@ public:
StopSendingFile(const nsAString& aDeviceAddress,
BluetoothReplyRunnable* aRunnable);
virtual void
ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable);
private:
nsresult SendGetPropertyMessage(const nsAString& aPath,
const char* aInterface,