Bug 797810 - Patch 2: Cleanup for profile connect function, r=qdot

This commit is contained in:
Gina Yeh 2012-10-05 18:48:05 +08:00
Родитель b8946a2bd3
Коммит 196a8f9079
11 изменённых файлов: 84 добавлений и 174 удалений

Просмотреть файл

@ -747,18 +747,8 @@ BluetoothAdapter::Connect(const nsAString& aDeviceAddress,
nsRefPtr<BluetoothVoidReplyRunnable> result = new BluetoothVoidReplyRunnable(req);
if (aProfileId == (uint16_t)(BluetoothServiceUuid::Handsfree >> 32)) {
if (!bs->ConnectHeadset(aDeviceAddress, mPath, result)) {
NS_WARNING("Creating RFCOMM socket failed.");
return NS_ERROR_FAILURE;
}
} else if (aProfileId == (uint16_t)(BluetoothServiceUuid::ObjectPush >> 32)) {
if (!bs->ConnectObjectPush(aDeviceAddress, mPath, result)) {
NS_WARNING("Creating RFCOMM socket failed");
return NS_ERROR_FAILURE;
}
} else {
NS_WARNING("Unknown profile");
if (!bs->Connect(aDeviceAddress, mPath, aProfileId, result)) {
NS_WARNING("Creating RFCOMM socket failed or unknown profile.");
return NS_ERROR_FAILURE;
}
@ -792,14 +782,7 @@ BluetoothAdapter::Disconnect(uint16_t aProfileId,
nsRefPtr<BluetoothVoidReplyRunnable> result = new BluetoothVoidReplyRunnable(req);
if (aProfileId == (uint16_t)(BluetoothServiceUuid::Handsfree >> 32)) {
bs->DisconnectHeadset(result);
} else if (aProfileId == (uint16_t)(BluetoothServiceUuid::ObjectPush >> 32)) {
bs->DisconnectObjectPush(result);
} else {
NS_WARNING("Unknown profile");
return NS_ERROR_FAILURE;
}
bs->Disconnect(aProfileId, result);
req.forget(aRequest);

Просмотреть файл

@ -27,6 +27,7 @@ public:
static BluetoothHfpManager* Get();
void ReceiveSocketData(mozilla::ipc::UnixSocketRawData* aMessage);
bool Connect(const nsAString& aDeviceObjectPath,
const bool aIsHandsfree,
BluetoothReplyRunnable* aRunnable);
void Disconnect();
bool SendLine(const char* aMessage);

Просмотреть файл

@ -21,7 +21,6 @@
#include "nsISystemMessagesInternal.h"
#include "nsVariant.h"
USING_BLUETOOTH_NAMESPACE
using namespace mozilla;
using namespace mozilla::ipc;
USING_BLUETOOTH_NAMESPACE

Просмотреть файл

@ -265,20 +265,13 @@ public:
PrepareAdapterInternal(const nsAString& aPath) = 0;
virtual bool
ConnectHeadset(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable) = 0;
Connect(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
uint16_t aProfileId,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void
DisconnectHeadset(BluetoothReplyRunnable* aRunnable) = 0;
virtual bool
ConnectObjectPush(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void
DisconnectObjectPush(BluetoothReplyRunnable* aRunnable) = 0;
Disconnect(uint16_t aProfileId, BluetoothReplyRunnable* aRunnable) = 0;
virtual bool
SendFile(const nsAString& aDeviceAddress,

Просмотреть файл

@ -213,14 +213,10 @@ BluetoothParent::RecvPBluetoothRequestConstructor(
return actor->DoRequest(aRequest.get_DenyPairingConfirmationRequest());
case Request::TDenyAuthorizationRequest:
return actor->DoRequest(aRequest.get_DenyAuthorizationRequest());
case Request::TConnectHeadsetRequest:
return actor->DoRequest(aRequest.get_ConnectHeadsetRequest());
case Request::TConnectObjectPushRequest:
return actor->DoRequest(aRequest.get_ConnectObjectPushRequest());
case Request::TDisconnectHeadsetRequest:
return actor->DoRequest(aRequest.get_DisconnectHeadsetRequest());
case Request::TDisconnectObjectPushRequest:
return actor->DoRequest(aRequest.get_DisconnectObjectPushRequest());
case Request::TConnectRequest:
return actor->DoRequest(aRequest.get_ConnectRequest());
case Request::TDisconnectRequest:
return actor->DoRequest(aRequest.get_DisconnectRequest());
case Request::TSendFileRequest:
return actor->DoRequest(aRequest.get_SendFileRequest());
case Request::TStopSendingFileRequest:
@ -500,45 +496,25 @@ BluetoothRequestParent::DoRequest(const DenyAuthorizationRequest& aRequest)
}
bool
BluetoothRequestParent::DoRequest(const ConnectHeadsetRequest& aRequest)
BluetoothRequestParent::DoRequest(const ConnectRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TConnectHeadsetRequest);
MOZ_ASSERT(mRequestType == Request::TConnectRequest);
return mService->ConnectHeadset(aRequest.address(),
aRequest.adapterPath(),
mReplyRunnable.get());
return mService->Connect(aRequest.address(),
aRequest.adapterPath(),
aRequest.profileId(),
mReplyRunnable.get());
}
bool
BluetoothRequestParent::DoRequest(const ConnectObjectPushRequest& aRequest)
BluetoothRequestParent::DoRequest(const DisconnectRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TConnectObjectPushRequest);
MOZ_ASSERT(mRequestType == Request::TDisconnectRequest);
return mService->ConnectObjectPush(aRequest.address(),
aRequest.adapterPath(),
mReplyRunnable.get());
}
bool
BluetoothRequestParent::DoRequest(const DisconnectHeadsetRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TDisconnectHeadsetRequest);
mService->DisconnectHeadset(mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const DisconnectObjectPushRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TDenyAuthorizationRequest);
mService->DisconnectObjectPush(mReplyRunnable.get());
mService->Disconnect(aRequest.profileId(),
mReplyRunnable.get());
return true;
}

Просмотреть файл

@ -167,16 +167,10 @@ protected:
DoRequest(const DenyAuthorizationRequest& aRequest);
bool
DoRequest(const ConnectHeadsetRequest& aRequest);
DoRequest(const ConnectRequest& aRequest);
bool
DoRequest(const ConnectObjectPushRequest& aRequest);
bool
DoRequest(const DisconnectHeadsetRequest& aRequest);
bool
DoRequest(const DisconnectObjectPushRequest& aRequest);
DoRequest(const DisconnectRequest& aRequest);
bool
DoRequest(const SendFileRequest& aRequest);

Просмотреть файл

@ -301,42 +301,26 @@ BluetoothServiceChildProcess::PrepareAdapterInternal(const nsAString& aPath)
}
bool
BluetoothServiceChildProcess::ConnectHeadset(
BluetoothServiceChildProcess::Connect(
const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
const uint16_t aProfileId,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
ConnectHeadsetRequest(nsString(aDeviceAddress),
nsString(aAdapterPath)));
ConnectRequest(nsString(aDeviceAddress),
nsString(aAdapterPath),
aProfileId));
return true;
}
void
BluetoothServiceChildProcess::DisconnectHeadset(
BluetoothServiceChildProcess::Disconnect(
const uint16_t aProfileId,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, DisconnectHeadsetRequest());
}
bool
BluetoothServiceChildProcess::ConnectObjectPush(
const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
ConnectObjectPushRequest(nsString(aDeviceAddress),
nsString(aAdapterPath)));
return true;
}
void
BluetoothServiceChildProcess::DisconnectObjectPush(
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, DisconnectObjectPushRequest());
SendRequest(aRunnable, DisconnectRequest(aProfileId));
}
bool

Просмотреть файл

@ -130,20 +130,14 @@ public:
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual bool
ConnectHeadset(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
Connect(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
const uint16_t aProfileId,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual void
DisconnectHeadset(BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual bool
ConnectObjectPush(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual void
DisconnectObjectPush(BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
Disconnect(const uint16_t aProfileId,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual bool
SendFile(const nsAString& aDeviceAddress,

Просмотреть файл

@ -98,24 +98,18 @@ struct DevicePropertiesRequest
nsString[] addresses;
};
struct ConnectHeadsetRequest
struct ConnectRequest
{
nsString address;
nsString adapterPath;
uint16_t profileId;
};
struct ConnectObjectPushRequest
struct DisconnectRequest
{
nsString address;
nsString adapterPath;
uint16_t profileId;
};
struct DisconnectHeadsetRequest
{};
struct DisconnectObjectPushRequest
{};
struct SendFileRequest
{
nsString devicePath;
@ -143,10 +137,8 @@ union Request
ConfirmAuthorizationRequest;
DenyAuthorizationRequest;
DevicePropertiesRequest;
ConnectHeadsetRequest;
ConnectObjectPushRequest;
DisconnectHeadsetRequest;
DisconnectObjectPushRequest;
ConnectRequest;
DisconnectRequest;
SendFileRequest;
StopSendingFileRequest;
};

Просмотреть файл

@ -2210,20 +2210,45 @@ BluetoothDBusService::PrepareAdapterInternal(const nsAString& aPath)
}
bool
BluetoothDBusService::ConnectHeadset(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable)
BluetoothDBusService::Connect(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
const uint16_t aProfileId,
BluetoothReplyRunnable* aRunnable)
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
return hfp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress),
aRunnable);
NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
if (aProfileId == (uint16_t)(BluetoothServiceUuid::Handsfree >> 32)) {
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
return hfp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress), true,
aRunnable);
} else if (aProfileId == (uint16_t)(BluetoothServiceUuid::Headset >> 32)) {
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
return hfp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress), false,
aRunnable);
} else if (aProfileId == (uint16_t)(BluetoothServiceUuid::ObjectPush >> 32)) {
BluetoothOppManager* opp = BluetoothOppManager::Get();
return opp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress),
aRunnable);
}
NS_WARNING("Unknow Profile");
return false;
}
void
BluetoothDBusService::DisconnectHeadset(BluetoothReplyRunnable* aRunnable)
BluetoothDBusService::Disconnect(const uint16_t aProfileId,
BluetoothReplyRunnable* aRunnable)
{
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->Disconnect();
if (aProfileId == (uint16_t)(BluetoothServiceUuid::Handsfree >> 32)) {
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->Disconnect();
} else if (aProfileId == (uint16_t)(BluetoothServiceUuid::ObjectPush >> 32)) {
BluetoothOppManager* opp = BluetoothOppManager::Get();
opp->Disconnect();
} else {
NS_WARNING("Unknown profile");
return;
}
// Currently, just fire success because Disconnect() doesn't fail,
// but we still make aRunnable pass into this function for future
@ -2232,30 +2257,6 @@ BluetoothDBusService::DisconnectHeadset(BluetoothReplyRunnable* aRunnable)
BluetoothValue v = true;
DispatchBluetoothReply(aRunnable, v, replyError);
}
bool
BluetoothDBusService::ConnectObjectPush(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable)
{
BluetoothOppManager* opp = BluetoothOppManager::Get();
return opp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress),
aRunnable);
}
void
BluetoothDBusService::DisconnectObjectPush(BluetoothReplyRunnable* aRunnable)
{
BluetoothOppManager* opp = BluetoothOppManager::Get();
opp->Disconnect();
// Currently, just fire success because Disconnect() doesn't fail,
// but we still make aRunnable pass into this function for future
// once Disconnect will fail.
nsString replyError;
BluetoothValue v = true;
DispatchBluetoothReply(aRunnable, v, replyError);
}
class CreateBluetoothScoSocket : public nsRunnable
{
public:

Просмотреть файл

@ -134,20 +134,13 @@ public:
PrepareAdapterInternal(const nsAString& aPath);
virtual bool
ConnectHeadset(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable);
Connect(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
const uint16_t aProfileId,
BluetoothReplyRunnable* aRunnable);
virtual void
DisconnectHeadset(BluetoothReplyRunnable* aRunnable);
virtual bool
ConnectObjectPush(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable);
virtual void
DisconnectObjectPush(BluetoothReplyRunnable* aRunnable);
Disconnect(const uint16_t aProfileId, BluetoothReplyRunnable* aRunnable);
virtual bool
SendFile(const nsAString& aDeviceAddress,