Bug 1050174: Cleanup interface of |BluetoothSocket| (under bluetoth2/), r=btian

This patch cleans up the interface of Bluedroid's |BluetoothScoket|
to look more similar the interface of |UnixSocketConsumer|, from
which it descends.
This commit is contained in:
Thomas Zimmermann 2014-08-21 09:30:37 +02:00
Родитель 1c0c5f8df9
Коммит fa45e97710
3 изменённых файлов: 35 добавлений и 49 удалений

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

@ -165,7 +165,7 @@ public:
void Run() MOZ_OVERRIDE
{
MOZ_ASSERT(NS_IsMainThread());
mSocket->CloseDroidSocket();
mSocket->CloseSocket();
}
private:
@ -255,7 +255,7 @@ BluetoothOppManager::ConnectInternal(const nsAString& aDeviceAddress)
// Stop listening because currently we only support one connection at a time.
if (mServerSocket) {
mServerSocket->Disconnect();
mServerSocket->CloseSocket();
mServerSocket = nullptr;
}
@ -269,7 +269,7 @@ BluetoothOppManager::ConnectInternal(const nsAString& aDeviceAddress)
mSocket =
new BluetoothSocket(this, BluetoothSocketType::RFCOMM, false, true);
mSocket->Connect(aDeviceAddress, -1);
mSocket->ConnectSocket(aDeviceAddress, -1);
}
void
@ -297,14 +297,14 @@ BluetoothOppManager::Listen()
* BT restarts.
*/
if (mServerSocket) {
mServerSocket->Disconnect();
mServerSocket->CloseSocket();
mServerSocket = nullptr;
}
mServerSocket =
new BluetoothSocket(this, BluetoothSocketType::RFCOMM, false, true);
if (!mServerSocket->Listen(BluetoothReservedChannels::CHANNEL_OPUSH)) {
if (!mServerSocket->ListenSocket(BluetoothReservedChannels::CHANNEL_OPUSH)) {
BT_WARNING("[OPP] Can't listen on RFCOMM socket!");
mServerSocket = nullptr;
return false;
@ -1255,7 +1255,7 @@ BluetoothOppManager::SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize)
UnixSocketRawData* s = new UnixSocketRawData(aSize);
memcpy(s->mData, aData, s->mSize);
mSocket->SendDroidSocketData(s);
mSocket->SendSocketData(s);
}
void
@ -1427,7 +1427,7 @@ void
BluetoothOppManager::Disconnect(BluetoothProfileController* aController)
{
if (mSocket) {
mSocket->Disconnect();
mSocket->CloseSocket();
} else {
BT_WARNING("%s: No ongoing file transfer to stop", __FUNCTION__);
}

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

@ -483,26 +483,6 @@ BluetoothSocket::BluetoothSocket(BluetoothSocketObserver* aObserver,
mDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE);
}
void
BluetoothSocket::CloseDroidSocket()
{
MOZ_ASSERT(NS_IsMainThread());
if (!mImpl) {
return;
}
// From this point on, we consider mImpl as being deleted.
// We sever the relationship here so any future calls to listen or connect
// will create a new implementation.
mImpl->ShutdownOnMainThread();
XRE_GetIOMessageLoop()->PostTask(
FROM_HERE, new SocketIOShutdownTask<DroidSocketImpl>(mImpl));
mImpl = nullptr;
NotifyDisconnect();
}
class ConnectSocketResultHandler MOZ_FINAL : public BluetoothSocketResultHandler
{
public:
@ -535,7 +515,7 @@ private:
};
bool
BluetoothSocket::Connect(const nsAString& aDeviceAddress, int aChannel)
BluetoothSocket::ConnectSocket(const nsAString& aDeviceAddress, int aChannel)
{
MOZ_ASSERT(NS_IsMainThread());
NS_ENSURE_FALSE(mImpl, false);
@ -584,7 +564,7 @@ private:
};
bool
BluetoothSocket::Listen(int aChannel)
BluetoothSocket::ListenSocket(int aChannel)
{
MOZ_ASSERT(NS_IsMainThread());
NS_ENSURE_FALSE(mImpl, false);
@ -603,8 +583,28 @@ BluetoothSocket::Listen(int aChannel)
return true;
}
void
BluetoothSocket::CloseSocket()
{
MOZ_ASSERT(NS_IsMainThread());
if (!mImpl) {
return;
}
// From this point on, we consider mImpl as being deleted.
// We sever the relationship here so any future calls to listen or connect
// will create a new implementation.
mImpl->ShutdownOnMainThread();
XRE_GetIOMessageLoop()->PostTask(
FROM_HERE, new SocketIOShutdownTask<DroidSocketImpl>(mImpl));
mImpl = nullptr;
NotifyDisconnect();
}
bool
BluetoothSocket::SendDroidSocketData(UnixSocketRawData* aData)
BluetoothSocket::SendSocketData(UnixSocketRawData* aData)
{
MOZ_ASSERT(NS_IsMainThread());
NS_ENSURE_TRUE(mImpl, false);

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

@ -23,14 +23,13 @@ public:
bool aAuth,
bool aEncrypt);
bool Connect(const nsAString& aDeviceAddress, int aChannel);
bool ConnectSocket(const nsAString& aDeviceAddress, int aChannel);
bool Listen(int aChannel);
bool ListenSocket(int aChannel);
inline void Disconnect()
{
CloseDroidSocket();
}
void CloseSocket();
bool SendSocketData(mozilla::ipc::UnixSocketRawData* aData);
virtual void OnConnectSuccess() MOZ_OVERRIDE;
virtual void OnConnectError() MOZ_OVERRIDE;
@ -48,19 +47,6 @@ public:
mDeviceAddress = aDeviceAddress;
}
void CloseDroidSocket();
bool SendDroidSocketData(mozilla::ipc::UnixSocketRawData* aData);
void CloseSocket() MOZ_OVERRIDE
{
CloseDroidSocket();
}
bool SendSocketData(mozilla::ipc::UnixSocketRawData* aMessage) MOZ_OVERRIDE
{
return SendDroidSocketData(aMessage);
}
private:
BluetoothSocketObserver* mObserver;
DroidSocketImpl* mImpl;