Bug 851046 - Add BluetoothSocket* as an argument of callback functions in BluetoothSocketObserver. r=mrbkap

A Bluetooth*Manager may hold more than one BluetoothSocket at a time, therefore
we need to identify the caller (which socket calls the callback function).
This commit is contained in:
Eric Chou 2013-03-19 17:08:44 -07:00
Родитель b28ef5bbeb
Коммит 8dddfba09a
8 изменённых файлов: 54 добавлений и 29 удалений

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

@ -673,7 +673,8 @@ BluetoothHfpManager::HandleShutdown()
// Virtual function of class SocketConsumer
void
BluetoothHfpManager::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage)
BluetoothHfpManager::ReceiveSocketData(BluetoothSocket* aSocket,
nsAutoPtr<UnixSocketRawData>& aMessage)
{
MOZ_ASSERT(NS_IsMainThread());
@ -1305,8 +1306,10 @@ BluetoothHfpManager::HandleCallStateChanged(uint32_t aCallIndex,
}
void
BluetoothHfpManager::OnConnectSuccess()
BluetoothHfpManager::OnConnectSuccess(BluetoothSocket* aSocket)
{
MOZ_ASSERT(aSocket == mSocket);
nsCOMPtr<nsITelephonyProvider> provider =
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
NS_ENSURE_TRUE_VOID(provider);
@ -1330,8 +1333,10 @@ BluetoothHfpManager::OnConnectSuccess()
}
void
BluetoothHfpManager::OnConnectError()
BluetoothHfpManager::OnConnectError(BluetoothSocket* aSocket)
{
MOZ_ASSERT(aSocket == mSocket);
// For active connection request, we need to reply the DOMRequest
if (mRunnable) {
BluetoothValue v;
@ -1347,8 +1352,10 @@ BluetoothHfpManager::OnConnectError()
}
void
BluetoothHfpManager::OnDisconnect()
BluetoothHfpManager::OnDisconnect(BluetoothSocket* aSocket)
{
MOZ_ASSERT(aSocket == mSocket);
// When we close a connected socket, then restart listening again and
// notify Settings app.
if (mSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) {

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

@ -57,10 +57,11 @@ public:
~BluetoothHfpManager();
virtual void ReceiveSocketData(
BluetoothSocket* aSocket,
nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) MOZ_OVERRIDE;
virtual void OnConnectSuccess() MOZ_OVERRIDE;
virtual void OnConnectError() MOZ_OVERRIDE;
virtual void OnDisconnect() MOZ_OVERRIDE;
virtual void OnConnectSuccess(BluetoothSocket* aSocket) MOZ_OVERRIDE;
virtual void OnConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE;
virtual void OnDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE;
bool Connect(const nsAString& aDeviceObjectPath,
const bool aIsHandsfree,

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

@ -928,7 +928,8 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage)
// Virtual function of class SocketConsumer
void
BluetoothOppManager::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage)
BluetoothOppManager::ReceiveSocketData(BluetoothSocket* aSocket,
nsAutoPtr<UnixSocketRawData>& aMessage)
{
if (mLastCommand) {
ClientDataHandler(aMessage);
@ -1302,8 +1303,10 @@ BluetoothOppManager::ReceivingFileConfirmation()
}
void
BluetoothOppManager::OnConnectSuccess()
BluetoothOppManager::OnConnectSuccess(BluetoothSocket* aSocket)
{
MOZ_ASSERT(aSocket == mSocket);
if (mRunnable) {
BluetoothReply* reply = new BluetoothReply(BluetoothReplySuccess(true));
mRunnable->SetReply(reply);
@ -1320,8 +1323,10 @@ BluetoothOppManager::OnConnectSuccess()
}
void
BluetoothOppManager::OnConnectError()
BluetoothOppManager::OnConnectError(BluetoothSocket* aSocket)
{
MOZ_ASSERT(aSocket == mSocket);
if (mRunnable) {
nsString errorStr;
errorStr.AssignLiteral("Failed to connect with a bluetooth opp manager!");
@ -1339,8 +1344,10 @@ BluetoothOppManager::OnConnectError()
}
void
BluetoothOppManager::OnDisconnect()
BluetoothOppManager::OnDisconnect(BluetoothSocket* aSocket)
{
MOZ_ASSERT(aSocket == mSocket);
/**
* It is valid for a bluetooth device which is transfering file via OPP
* closing socket without sending OBEX disconnect request first. So we

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

@ -74,11 +74,12 @@ public:
bool IsTransferring();
// Implement interface BluetoothSocketObserver
void ReceiveSocketData(nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage)
MOZ_OVERRIDE;
void OnConnectSuccess() MOZ_OVERRIDE;
void OnConnectError() MOZ_OVERRIDE;
void OnDisconnect() MOZ_OVERRIDE;
void ReceiveSocketData(
BluetoothSocket* aSocket,
nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) MOZ_OVERRIDE;
void OnConnectSuccess(BluetoothSocket* aSocket) MOZ_OVERRIDE;
void OnConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE;
void OnDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE;
private:
BluetoothOppManager();

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

@ -173,7 +173,8 @@ BluetoothScoManager::Get()
// Virtual function of class SocketConsumer
void
BluetoothScoManager::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage)
BluetoothScoManager::ReceiveSocketData(BluetoothSocket* aSocket,
nsAutoPtr<UnixSocketRawData>& aMessage)
{
// SCO socket do nothing here
MOZ_NOT_REACHED("This should never be called!");
@ -255,8 +256,10 @@ BluetoothScoManager::Disconnect()
}
void
BluetoothScoManager::OnConnectSuccess()
BluetoothScoManager::OnConnectSuccess(BluetoothSocket* aSocket)
{
MOZ_ASSERT(aSocket == mSocket);
nsString address;
mSocket->GetAddress(address);
NotifyAudioManager(address);
@ -265,16 +268,20 @@ BluetoothScoManager::OnConnectSuccess()
}
void
BluetoothScoManager::OnConnectError()
BluetoothScoManager::OnConnectError(BluetoothSocket* aSocket)
{
MOZ_ASSERT(aSocket == mSocket);
mSocket->Disconnect();
mSocketStatus = mSocket->GetConnectionStatus();
Listen();
}
void
BluetoothScoManager::OnDisconnect()
BluetoothScoManager::OnDisconnect(BluetoothSocket* aSocket)
{
MOZ_ASSERT(aSocket == mSocket);
if (mSocketStatus == SocketConnectionStatus::SOCKET_CONNECTED) {
Listen();

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

@ -24,11 +24,11 @@ public:
~BluetoothScoManager();
virtual void ReceiveSocketData(
nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage)
MOZ_OVERRIDE;
virtual void OnConnectSuccess() MOZ_OVERRIDE;
virtual void OnConnectError() MOZ_OVERRIDE;
virtual void OnDisconnect() MOZ_OVERRIDE;
BluetoothSocket* aSocket,
nsAutoPtr<mozilla::ipc::UnixSocketRawData>& aMessage) MOZ_OVERRIDE;
virtual void OnConnectSuccess(BluetoothSocket* aSocket) MOZ_OVERRIDE;
virtual void OnConnectError(BluetoothSocket* aSocket) MOZ_OVERRIDE;
virtual void OnDisconnect(BluetoothSocket* aSocket) MOZ_OVERRIDE;
bool Connect(const nsAString& aDeviceObjectPath);
void Disconnect();

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

@ -69,7 +69,7 @@ BluetoothSocket::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mObserver);
mObserver->ReceiveSocketData(aMessage);
mObserver->ReceiveSocketData(this, aMessage);
}
void
@ -77,7 +77,7 @@ BluetoothSocket::OnConnectSuccess()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mObserver);
mObserver->OnConnectSuccess();
mObserver->OnConnectSuccess(this);
}
void
@ -85,7 +85,7 @@ BluetoothSocket::OnConnectError()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mObserver);
mObserver->OnConnectError();
mObserver->OnConnectError(this);
}
void
@ -93,6 +93,6 @@ BluetoothSocket::OnDisconnect()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mObserver);
mObserver->OnDisconnect();
mObserver->OnDisconnect(this);
}

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

@ -14,6 +14,8 @@ using namespace mozilla::ipc;
BEGIN_BLUETOOTH_NAMESPACE
class BluetoothSocket;
class BluetoothSocketObserver
{
public: