Bug 834590 - Cache adapter path in BluetoothService, r=echou

This commit is contained in:
Gina Yeh 2013-03-15 15:15:47 +08:00
parent 6b8bd5e0d5
commit 418152901b
13 changed files with 275 additions and 288 deletions

View File

@ -164,7 +164,7 @@ BluetoothAdapter::BluetoothAdapter(nsPIDOMWindow* aWindow,
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
bs->RegisterBluetoothSignalHandler(mPath, this);
bs->RegisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_ADAPTER), this);
}
BluetoothAdapter::~BluetoothAdapter()
@ -172,7 +172,7 @@ BluetoothAdapter::~BluetoothAdapter()
BluetoothService* bs = BluetoothService::Get();
// We can be null on shutdown, where this might happen
NS_ENSURE_TRUE_VOID(bs);
bs->UnregisterBluetoothSignalHandler(mPath, this);
bs->UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_ADAPTER), this);
Unroot();
}
@ -301,9 +301,8 @@ BluetoothAdapter::Notify(const BluetoothSignal& aData)
NS_ASSERTION(aData.value().type() == BluetoothValue::TArrayOfBluetoothNamedValue,
"DeviceCreated: Invalid value type");
nsRefPtr<BluetoothDevice> device = BluetoothDevice::Create(GetOwner(),
GetPath(),
aData.value());
nsRefPtr<BluetoothDevice> device =
BluetoothDevice::Create(GetOwner(), GetPath(), aData.value());
nsCOMPtr<nsIDOMEvent> event;
NS_NewDOMBluetoothDeviceEvent(getter_AddRefs(event), this, nullptr, nullptr);
@ -344,9 +343,9 @@ BluetoothAdapter::StartStopDiscovery(bool aStart, nsIDOMDOMRequest** aRequest)
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
if (aStart) {
rv = bs->StartDiscoveryInternal(mPath, results);
rv = bs->StartDiscoveryInternal(results);
} else {
rv = bs->StopDiscoveryInternal(mPath, results);
rv = bs->StopDiscoveryInternal(results);
}
if(NS_FAILED(rv)) {
NS_WARNING("Start/Stop Discovery failed!");
@ -459,7 +458,7 @@ BluetoothAdapter::SetName(const nsAString& aName,
BluetoothNamedValue property(NS_LITERAL_STRING("Name"), value);
return SetProperty(GetOwner(), property, aRequest);
}
NS_IMETHODIMP
BluetoothAdapter::SetDiscoverable(const bool aDiscoverable,
nsIDOMDOMRequest** aRequest)
@ -520,18 +519,17 @@ BluetoothAdapter::PairUnpair(bool aPair,
nsRefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(req);
nsString addr;
nsAutoString addr;
aDevice->GetAddress(addr);
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
if (aPair) {
rv = bs->CreatePairedDeviceInternal(mPath,
addr,
rv = bs->CreatePairedDeviceInternal(addr,
kCreatePairedDeviceTimeout,
results);
} else {
rv = bs->RemoveDeviceInternal(mPath, addr, results);
rv = bs->RemoveDeviceInternal(addr, results);
}
if (NS_FAILED(rv)) {
@ -668,7 +666,7 @@ BluetoothAdapter::Connect(const nsAString& aDeviceAddress,
nsRefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(req);
bs->Connect(aDeviceAddress, mPath, aProfileId, results);
bs->Connect(aDeviceAddress, aProfileId, results);
req.forget(aRequest);
return NS_OK;

View File

@ -46,8 +46,10 @@ extern bool gBluetoothDebugFlag;
#define USING_BLUETOOTH_NAMESPACE \
using namespace mozilla::dom::bluetooth;
#define LOCAL_AGENT_PATH "/B2G/bluetooth/agent"
#define REMOTE_AGENT_PATH "/B2G/bluetooth/remote_device_agent"
#define KEY_LOCAL_AGENT "/B2G/bluetooth/agent"
#define KEY_REMOTE_AGENT "/B2G/bluetooth/remote_device_agent"
#define KEY_MANAGER "/B2G/bluetooth/manager"
#define KEY_ADAPTER "/B2G/bluetooth/adapter"
// Bluetooth address format: xx:xx:xx:xx:xx:xx (or xx_xx_xx_xx_xx_xx)
#define BLUETOOTH_ADDRESS_LENGTH 17

View File

@ -64,7 +64,7 @@ BluetoothDevice::BluetoothDevice(nsPIDOMWindow* aWindow,
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
bs->RegisterBluetoothSignalHandler(mPath, this);
bs->RegisterBluetoothSignalHandler(mAddress, this);
}
BluetoothDevice::~BluetoothDevice()
@ -72,7 +72,7 @@ BluetoothDevice::~BluetoothDevice()
BluetoothService* bs = BluetoothService::Get();
// bs can be null on shutdown, where destruction might happen.
NS_ENSURE_TRUE_VOID(bs);
bs->UnregisterBluetoothSignalHandler(mPath, this);
bs->UnregisterBluetoothSignalHandler(mAddress, this);
Unroot();
}

View File

@ -102,14 +102,14 @@ BluetoothManager::BluetoothManager(nsPIDOMWindow *aWindow)
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
bs->RegisterBluetoothSignalHandler(mPath, this);
bs->RegisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_MANAGER), this);
}
BluetoothManager::~BluetoothManager()
{
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE_VOID(bs);
bs->UnregisterBluetoothSignalHandler(mPath, this);
bs->UnregisterBluetoothSignalHandler(NS_LITERAL_STRING(KEY_MANAGER), this);
}
void

View File

@ -55,10 +55,10 @@ BluetoothPropertyContainer::SetProperty(nsIDOMWindow* aOwner,
}
nsRefPtr<BluetoothReplyRunnable> task = new BluetoothVoidReplyRunnable(req);
rv = bs->SetProperty(mObjectType, mPath, aProperty, task);
rv = bs->SetProperty(mObjectType, aProperty, task);
NS_ENSURE_SUCCESS(rv, rv);
req.forget(aRequest);
return NS_OK;
}

View File

@ -8,6 +8,7 @@
#include "BluetoothService.h"
#include "BluetoothCommon.h"
#include "BluetoothManager.h"
#include "BluetoothParent.h"
#include "BluetoothReplyRunnable.h"
@ -136,7 +137,7 @@ public:
} else {
signalName = NS_LITERAL_STRING("Disabled");
}
signalPath = NS_LITERAL_STRING("/");
signalPath = NS_LITERAL_STRING(KEY_MANAGER);
BluetoothSignal signal(signalName, signalPath, v);
gBluetoothService->DistributeSignal(signal);
}
@ -276,7 +277,7 @@ RemoveObserversExceptBluetoothManager
nsAutoPtr<BluetoothSignalObserverList>& value,
void* arg)
{
if (!key.EqualsLiteral("/")) {
if (!key.EqualsLiteral(KEY_MANAGER)) {
return PL_DHASH_REMOVE;
}
@ -409,10 +410,10 @@ BluetoothService::DistributeSignal(const BluetoothSignal& aSignal)
{
MOZ_ASSERT(NS_IsMainThread());
if (aSignal.path().EqualsLiteral(LOCAL_AGENT_PATH)) {
if (aSignal.path().EqualsLiteral(KEY_LOCAL_AGENT)) {
Notify(aSignal);
return;
} else if (aSignal.path().EqualsLiteral(REMOTE_AGENT_PATH)) {
} else if (aSignal.path().EqualsLiteral(KEY_REMOTE_AGENT)) {
Notify(aSignal);
return;
}

View File

@ -134,24 +134,18 @@ public:
/**
* Stop device discovery (platform specific implementation)
*
* @param aAdapterPath Adapter to stop discovery on
*
* @return NS_OK if discovery stopped correctly, false otherwise
*/
virtual nsresult
StopDiscoveryInternal(const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable) = 0;
StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable) = 0;
/**
* Start device discovery (platform specific implementation)
*
* @param aAdapterPath Adapter to start discovery on
*
* @return NS_OK if discovery stopped correctly, false otherwise
*/
virtual nsresult
StartDiscoveryInternal(const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable) = 0;
StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable) = 0;
/**
* Fetches the propertes for the specified device
@ -166,7 +160,6 @@ public:
/**
* Set a property for the specified object
*
* @param aPath Path to the object
* @param aPropName Name of the property
* @param aValue Boolean value
* @param aRunnable Runnable to run on async reply
@ -175,7 +168,6 @@ public:
*/
virtual nsresult
SetProperty(BluetoothObjectType aType,
const nsAString& aPath,
const BluetoothNamedValue& aValue,
BluetoothReplyRunnable* aRunnable) = 0;
@ -194,14 +186,12 @@ public:
nsAString& aDevicePath) = 0;
virtual nsresult
CreatePairedDeviceInternal(const nsAString& aAdapterPath,
const nsAString& aAddress,
CreatePairedDeviceInternal(const nsAString& aAddress,
int aTimeout,
BluetoothReplyRunnable* aRunnable) = 0;
virtual nsresult
RemoveDeviceInternal(const nsAString& aAdapterPath,
const nsAString& aObjectPath,
RemoveDeviceInternal(const nsAString& aObjectPath,
BluetoothReplyRunnable* aRunnable) = 0;
virtual nsresult
@ -236,11 +226,10 @@ public:
BluetoothReplyRunnable* aRunnable) = 0;
virtual nsresult
PrepareAdapterInternal(const nsAString& aPath) = 0;
PrepareAdapterInternal() = 0;
virtual void
Connect(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
uint16_t aProfileId,
BluetoothReplyRunnable* aRunnable) = 0;

View File

@ -309,7 +309,7 @@ BluetoothRequestParent::DoRequest(const SetPropertyRequest& aRequest)
MOZ_ASSERT(mRequestType == Request::TSetPropertyRequest);
nsresult rv =
mService->SetProperty(aRequest.type(), aRequest.path(), aRequest.value(),
mService->SetProperty(aRequest.type(), aRequest.value(),
mReplyRunnable.get());
NS_ENSURE_SUCCESS(rv, false);
@ -323,7 +323,7 @@ BluetoothRequestParent::DoRequest(const StartDiscoveryRequest& aRequest)
MOZ_ASSERT(mRequestType == Request::TStartDiscoveryRequest);
nsresult rv =
mService->StartDiscoveryInternal(aRequest.path(), mReplyRunnable.get());
mService->StartDiscoveryInternal(mReplyRunnable.get());
NS_ENSURE_SUCCESS(rv, false);
return true;
@ -336,7 +336,7 @@ BluetoothRequestParent::DoRequest(const StopDiscoveryRequest& aRequest)
MOZ_ASSERT(mRequestType == Request::TStopDiscoveryRequest);
nsresult rv =
mService->StopDiscoveryInternal(aRequest.path(), mReplyRunnable.get());
mService->StopDiscoveryInternal(mReplyRunnable.get());
NS_ENSURE_SUCCESS(rv, false);
return true;
@ -349,7 +349,7 @@ BluetoothRequestParent::DoRequest(const PairRequest& aRequest)
MOZ_ASSERT(mRequestType == Request::TPairRequest);
nsresult rv =
mService->CreatePairedDeviceInternal(aRequest.path(), aRequest.address(),
mService->CreatePairedDeviceInternal(aRequest.address(),
aRequest.timeoutMS(),
mReplyRunnable.get());
NS_ENSURE_SUCCESS(rv, false);
@ -364,7 +364,7 @@ BluetoothRequestParent::DoRequest(const UnpairRequest& aRequest)
MOZ_ASSERT(mRequestType == Request::TUnpairRequest);
nsresult rv =
mService->RemoveDeviceInternal(aRequest.path(), aRequest.address(),
mService->RemoveDeviceInternal(aRequest.address(),
mReplyRunnable.get());
NS_ENSURE_SUCCESS(rv, false);
@ -490,7 +490,6 @@ BluetoothRequestParent::DoRequest(const ConnectRequest& aRequest)
MOZ_ASSERT(mRequestType == Request::TConnectRequest);
mService->Connect(aRequest.address(),
aRequest.adapterPath(),
aRequest.profileId(),
mReplyRunnable.get());

View File

@ -124,29 +124,26 @@ BluetoothServiceChildProcess::GetPairedDevicePropertiesInternal(
nsresult
BluetoothServiceChildProcess::StopDiscoveryInternal(
const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, StopDiscoveryRequest(nsString(aAdapterPath)));
SendRequest(aRunnable, StopDiscoveryRequest());
return NS_OK;
}
nsresult
BluetoothServiceChildProcess::StartDiscoveryInternal(
const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, StartDiscoveryRequest(nsString(aAdapterPath)));
SendRequest(aRunnable, StartDiscoveryRequest());
return NS_OK;
}
nsresult
BluetoothServiceChildProcess::SetProperty(BluetoothObjectType aType,
const nsAString& aPath,
const BluetoothNamedValue& aValue,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, SetPropertyRequest(aType, nsString(aPath), aValue));
SendRequest(aRunnable, SetPropertyRequest(aType, aValue));
return NS_OK;
}
@ -171,24 +168,22 @@ BluetoothServiceChildProcess::GetDevicePath(const nsAString& aAdapterPath,
nsresult
BluetoothServiceChildProcess::CreatePairedDeviceInternal(
const nsAString& aAdapterPath,
const nsAString& aAddress,
int aTimeout,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
PairRequest(nsString(aAdapterPath), nsString(aAddress), aTimeout));
PairRequest(nsString(aAddress), aTimeout));
return NS_OK;
}
nsresult
BluetoothServiceChildProcess::RemoveDeviceInternal(
const nsAString& aAdapterPath,
const nsAString& aObjectPath,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
UnpairRequest(nsString(aAdapterPath), nsString(aObjectPath)));
UnpairRequest(nsString(aObjectPath)));
return NS_OK;
}
@ -285,7 +280,7 @@ BluetoothServiceChildProcess::SetAuthorizationInternal(
}
nsresult
BluetoothServiceChildProcess::PrepareAdapterInternal(const nsAString& aPath)
BluetoothServiceChildProcess::PrepareAdapterInternal()
{
MOZ_NOT_REACHED("Should never be called from child");
return NS_ERROR_NOT_IMPLEMENTED;
@ -294,13 +289,11 @@ BluetoothServiceChildProcess::PrepareAdapterInternal(const nsAString& aPath)
void
BluetoothServiceChildProcess::Connect(
const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
const uint16_t aProfileId,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
ConnectRequest(nsString(aDeviceAddress),
nsString(aAdapterPath),
aProfileId));
}

View File

@ -52,16 +52,13 @@ public:
MOZ_OVERRIDE;
virtual nsresult
StopDiscoveryInternal(const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual nsresult
StartDiscoveryInternal(const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual nsresult
SetProperty(BluetoothObjectType aType,
const nsAString& aPath,
const BluetoothNamedValue& aValue,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
@ -71,14 +68,12 @@ public:
nsAString& aDevicePath) MOZ_OVERRIDE;
virtual nsresult
CreatePairedDeviceInternal(const nsAString& aAdapterPath,
const nsAString& aAddress,
CreatePairedDeviceInternal(const nsAString& aAddress,
int aTimeout,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual nsresult
RemoveDeviceInternal(const nsAString& aAdapterPath,
const nsAString& aObjectPath,
RemoveDeviceInternal(const nsAString& aObjectPath,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual nsresult
@ -126,7 +121,6 @@ public:
virtual void
Connect(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
const uint16_t aProfileId,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
@ -182,7 +176,7 @@ private:
// This method should never be called from the child.
virtual nsresult
PrepareAdapterInternal(const nsAString& aPath) MOZ_OVERRIDE;
PrepareAdapterInternal() MOZ_OVERRIDE;
};
END_BLUETOOTH_NAMESPACE

View File

@ -28,7 +28,6 @@ struct DefaultAdapterPathRequest
struct SetPropertyRequest
{
BluetoothObjectType type;
nsString path;
BluetoothNamedValue value;
};
@ -40,24 +39,20 @@ struct GetPropertyRequest
struct StartDiscoveryRequest
{
nsString path;
};
struct StopDiscoveryRequest
{
nsString path;
};
struct PairRequest
{
nsString path;
nsString address;
uint32_t timeoutMS;
};
struct UnpairRequest
{
nsString path;
nsString address;
};
@ -101,7 +96,6 @@ struct DevicePropertiesRequest
struct ConnectRequest
{
nsString address;
nsString adapterPath;
uint16_t profileId;
};

File diff suppressed because it is too large Load Diff

View File

@ -35,18 +35,15 @@ public:
virtual nsresult GetPairedDevicePropertiesInternal(const nsTArray<nsString>& aDeviceAddresses,
BluetoothReplyRunnable* aRunnable);
virtual nsresult StartDiscoveryInternal(const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable);
virtual nsresult StartDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
virtual nsresult StopDiscoveryInternal(const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable);
virtual nsresult StopDiscoveryInternal(BluetoothReplyRunnable* aRunnable);
virtual nsresult
GetDevicePropertiesInternal(const BluetoothSignal& aSignal);
virtual nsresult
SetProperty(BluetoothObjectType aType,
const nsAString& aPath,
const BluetoothNamedValue& aValue,
BluetoothReplyRunnable* aRunnable);
@ -56,27 +53,23 @@ public:
nsAString& aDevicePath);
static bool
AddServiceRecords(const nsAString& aAdapterPath,
const char* serviceName,
AddServiceRecords(const char* serviceName,
unsigned long long uuidMsb,
unsigned long long uuidLsb,
int channel);
static bool
RemoveServiceRecords(const nsAString& aAdapterPath,
const char* serviceName,
RemoveServiceRecords(const char* serviceName,
unsigned long long uuidMsb,
unsigned long long uuidLsb,
int channel);
static bool
AddReservedServicesInternal(const nsAString& aAdapterPath,
const nsTArray<uint32_t>& aServices,
AddReservedServicesInternal(const nsTArray<uint32_t>& aServices,
nsTArray<uint32_t>& aServiceHandlesContainer);
static bool
RemoveReservedServicesInternal(const nsAString& aAdapterPath,
const nsTArray<uint32_t>& aServiceHandles);
RemoveReservedServicesInternal(const nsTArray<uint32_t>& aServiceHandles);
virtual nsresult
GetScoSocket(const nsAString& aObjectPath,
@ -101,14 +94,12 @@ public:
mozilla::ipc::UnixSocketConsumer* aConsumer);
virtual nsresult
CreatePairedDeviceInternal(const nsAString& aAdapterPath,
const nsAString& aDeviceAddress,
CreatePairedDeviceInternal(const nsAString& aDeviceAddress,
int aTimeout,
BluetoothReplyRunnable* aRunnable);
virtual nsresult
RemoveDeviceInternal(const nsAString& aAdapterPath,
const nsAString& aDeviceObjectPath,
RemoveDeviceInternal(const nsAString& aDeviceObjectPath,
BluetoothReplyRunnable* aRunnable);
virtual bool
@ -128,11 +119,10 @@ public:
BluetoothReplyRunnable* aRunnable);
virtual nsresult
PrepareAdapterInternal(const nsAString& aPath);
PrepareAdapterInternal();
virtual void
Connect(const nsAString& aDeviceAddress,
const nsAString& aAdapterPath,
const uint16_t aProfileId,
BluetoothReplyRunnable* aRunnable);
@ -161,10 +151,9 @@ private:
const char* aInterface,
void (*aCB)(DBusMessage *, void *),
BluetoothReplyRunnable* aRunnable);
nsresult SendDiscoveryMessage(const nsAString& aAdapterPath,
const char* aMessageName,
nsresult SendDiscoveryMessage(const char* aMessageName,
BluetoothReplyRunnable* aRunnable);
nsresult SendSetPropertyMessage(const nsString& aPath, const char* aInterface,
nsresult SendSetPropertyMessage(const char* aInterface,
const BluetoothNamedValue& aValue,
BluetoothReplyRunnable* aRunnable);