Bug 811569 - Patch 4: Remove asynchronous function GetProperty , r=echou

This commit is contained in:
Gina Yeh 2013-01-29 14:52:58 +08:00
parent 86d8eef233
commit 9ae2cfbdcb
7 changed files with 40 additions and 139 deletions

View File

@ -314,8 +314,9 @@ BluetoothService::Cleanup()
} }
void void
BluetoothService::RegisterBluetoothSignalHandler(const nsAString& aNodeName, BluetoothService::RegisterBluetoothSignalHandler(
BluetoothSignalObserver* aHandler) const nsAString& aNodeName,
BluetoothSignalObserver* aHandler)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aHandler); MOZ_ASSERT(aHandler);
@ -331,8 +332,9 @@ BluetoothService::RegisterBluetoothSignalHandler(const nsAString& aNodeName,
} }
void void
BluetoothService::UnregisterBluetoothSignalHandler(const nsAString& aNodeName, BluetoothService::UnregisterBluetoothSignalHandler(
BluetoothSignalObserver* aHandler) const nsAString& aNodeName,
BluetoothSignalObserver* aHandler)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aHandler); MOZ_ASSERT(aHandler);

View File

@ -166,20 +166,6 @@ public:
BluetoothReplyRunnable* aRunnable) = 0; BluetoothReplyRunnable* aRunnable) = 0;
/** /**
* Fetches the propertes for the specified object
*
* @param aType Type of the object (see BluetoothObjectType in BluetoothCommon.h)
* @param aPath Path of the object
* @param aRunnable Runnable to return to after receiving callback
*
* @return NS_OK on function run, NS_ERROR_FAILURE otherwise
*/
virtual nsresult
GetProperties(BluetoothObjectType aType,
const nsAString& aPath,
BluetoothReplyRunnable* aRunnable) = 0;
/**
* Fetches the propertes for the specified device * Fetches the propertes for the specified device
* *
* @param aSignal BluetoothSignal to be distrubuted after retrieving device properties * @param aSignal BluetoothSignal to be distrubuted after retrieving device properties
@ -312,9 +298,6 @@ public:
protected: protected:
BluetoothService() BluetoothService()
: mEnabled(false) : mEnabled(false)
#ifdef DEBUG
, mLastRequestedEnable(false)
#endif
{ {
mBluetoothSignalObserverTable.Init(); mBluetoothSignalObserverTable.Init();
} }
@ -403,10 +386,6 @@ protected:
BluetoothManagerList mLiveManagers; BluetoothManagerList mLiveManagers;
bool mEnabled; bool mEnabled;
#ifdef DEBUG
bool mLastRequestedEnable;
#endif
}; };
END_BLUETOOTH_NAMESPACE END_BLUETOOTH_NAMESPACE

View File

@ -189,8 +189,6 @@ BluetoothParent::RecvPBluetoothRequestConstructor(
return actor->DoRequest(aRequest.get_DefaultAdapterPathRequest()); return actor->DoRequest(aRequest.get_DefaultAdapterPathRequest());
case Request::TSetPropertyRequest: case Request::TSetPropertyRequest:
return actor->DoRequest(aRequest.get_SetPropertyRequest()); return actor->DoRequest(aRequest.get_SetPropertyRequest());
case Request::TGetPropertyRequest:
return actor->DoRequest(aRequest.get_GetPropertyRequest());
case Request::TStartDiscoveryRequest: case Request::TStartDiscoveryRequest:
return actor->DoRequest(aRequest.get_StartDiscoveryRequest()); return actor->DoRequest(aRequest.get_StartDiscoveryRequest());
case Request::TStopDiscoveryRequest: case Request::TStopDiscoveryRequest:
@ -318,20 +316,6 @@ BluetoothRequestParent::DoRequest(const SetPropertyRequest& aRequest)
return true; return true;
} }
bool
BluetoothRequestParent::DoRequest(const GetPropertyRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TGetPropertyRequest);
nsresult rv =
mService->GetProperties(aRequest.type(), aRequest.path(),
mReplyRunnable.get());
NS_ENSURE_SUCCESS(rv, false);
return true;
}
bool bool
BluetoothRequestParent::DoRequest(const StartDiscoveryRequest& aRequest) BluetoothRequestParent::DoRequest(const StartDiscoveryRequest& aRequest)
{ {

View File

@ -140,15 +140,6 @@ BluetoothServiceChildProcess::StartDiscoveryInternal(
return NS_OK; return NS_OK;
} }
nsresult
BluetoothServiceChildProcess::GetProperties(BluetoothObjectType aType,
const nsAString& aPath,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, GetPropertyRequest(aType, nsString(aPath)));
return NS_OK;
}
nsresult nsresult
BluetoothServiceChildProcess::SetProperty(BluetoothObjectType aType, BluetoothServiceChildProcess::SetProperty(BluetoothObjectType aType,
const nsAString& aPath, const nsAString& aPath,

View File

@ -59,11 +59,6 @@ public:
StartDiscoveryInternal(const nsAString& aAdapterPath, StartDiscoveryInternal(const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE; BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual nsresult
GetProperties(BluetoothObjectType aType,
const nsAString& aPath,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual nsresult virtual nsresult
SetProperty(BluetoothObjectType aType, SetProperty(BluetoothObjectType aType,
const nsAString& aPath, const nsAString& aPath,

View File

@ -309,10 +309,7 @@ public:
// Get device properties and then send to BluetoothAdapter // Get device properties and then send to BluetoothAdapter
BluetoothService* bs = BluetoothService::Get(); BluetoothService* bs = BluetoothService::Get();
if (!bs) { NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
NS_WARNING("BluetoothService not available!");
return NS_ERROR_FAILURE;
}
// Due to the fact that we need to queue the dbus call to the command thread // Due to the fact that we need to queue the dbus call to the command thread
// inside the bluetoothservice, we have to route the call down to the main // inside the bluetoothservice, we have to route the call down to the main
@ -365,6 +362,8 @@ static void
UnpackIntMessage(DBusMessage* aMsg, DBusError* aErr, UnpackIntMessage(DBusMessage* aMsg, DBusError* aErr,
BluetoothValue& aValue, nsAString& aErrorStr) BluetoothValue& aValue, nsAString& aErrorStr)
{ {
MOZ_ASSERT(aMsg);
DBusError err; DBusError err;
dbus_error_init(&err); dbus_error_init(&err);
if (!IsDBusMessageError(aMsg, aErr, aErrorStr)) { if (!IsDBusMessageError(aMsg, aErr, aErrorStr)) {
@ -496,7 +495,7 @@ AgentEventFilter(DBusConnection *conn, DBusMessage *msg, void *data)
errorStr.AssignLiteral("Invalid arguments for RequestConfirmation() method"); errorStr.AssignLiteral("Invalid arguments for RequestConfirmation() method");
} else { } else {
parameters.AppendElement(BluetoothNamedValue( parameters.AppendElement(BluetoothNamedValue(
NS_LITERAL_STRING("address"), NS_LITERAL_STRING("path"),
NS_ConvertUTF8toUTF16(objectPath))); NS_ConvertUTF8toUTF16(objectPath)));
parameters.AppendElement(BluetoothNamedValue( parameters.AppendElement(BluetoothNamedValue(
NS_LITERAL_STRING("passkey"), NS_LITERAL_STRING("passkey"),
@ -528,7 +527,7 @@ AgentEventFilter(DBusConnection *conn, DBusMessage *msg, void *data)
errorStr.AssignLiteral("Invalid arguments for RequestPinCode() method"); errorStr.AssignLiteral("Invalid arguments for RequestPinCode() method");
} else { } else {
parameters.AppendElement(BluetoothNamedValue( parameters.AppendElement(BluetoothNamedValue(
NS_LITERAL_STRING("address"), NS_LITERAL_STRING("path"),
NS_ConvertUTF8toUTF16(objectPath))); NS_ConvertUTF8toUTF16(objectPath)));
KeepDBusPairingMessage(GetAddressFromObjectPath( KeepDBusPairingMessage(GetAddressFromObjectPath(
@ -556,7 +555,7 @@ AgentEventFilter(DBusConnection *conn, DBusMessage *msg, void *data)
errorStr.AssignLiteral("Invalid arguments for RequestPasskey() method"); errorStr.AssignLiteral("Invalid arguments for RequestPasskey() method");
} else { } else {
parameters.AppendElement(BluetoothNamedValue( parameters.AppendElement(BluetoothNamedValue(
NS_LITERAL_STRING("address"), NS_LITERAL_STRING("path"),
NS_ConvertUTF8toUTF16(objectPath))); NS_ConvertUTF8toUTF16(objectPath)));
KeepDBusPairingMessage(GetAddressFromObjectPath( KeepDBusPairingMessage(GetAddressFromObjectPath(
@ -1779,68 +1778,54 @@ public:
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
} }
~BluetoothDevicePropertiesRunnable()
{
}
NS_IMETHOD Run() NS_IMETHOD Run()
{ {
MOZ_ASSERT(!NS_IsMainThread()); MOZ_ASSERT(!NS_IsMainThread());
nsString devicePath; nsString devicePath;
BluetoothValue v = mSignal.value(); BluetoothValue v = mSignal.value();
if (v.type() == BluetoothValue::TArrayOfBluetoothNamedValue && if (v.type() != BluetoothValue::TArrayOfBluetoothNamedValue ||
v.get_ArrayOfBluetoothNamedValue().Length() ) { v.get_ArrayOfBluetoothNamedValue().Length() == 0) {
const InfallibleTArray<BluetoothNamedValue>& arr = v.get_ArrayOfBluetoothNamedValue();
NS_ASSERTION(arr[0].value().type() == BluetoothValue::TnsString, "failed to get_nsString");
devicePath = arr[0].value().get_nsString();
}
else if (v.type() == BluetoothValue::TnsString) {
devicePath = v.get_nsString();
}
else {
NS_WARNING("Invalid value type for GetDeviceProperties() method"); NS_WARNING("Invalid value type for GetDeviceProperties() method");
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
const InfallibleTArray<BluetoothNamedValue>& arr =
v.get_ArrayOfBluetoothNamedValue();
NS_ASSERTION(arr[0].name().EqualsLiteral("path"), "failed to get object path");
NS_ASSERTION(arr[0].value().type() == BluetoothValue::TnsString,
"failed to get_nsString");
devicePath = arr[0].value().get_nsString();
BluetoothValue prop; BluetoothValue prop;
if (!GetPropertiesInternal(devicePath, DBUS_DEVICE_IFACE, prop)) { if (!GetPropertiesInternal(devicePath, DBUS_DEVICE_IFACE, prop)) {
NS_WARNING("Getting properties failed!"); NS_WARNING("Getting properties failed!");
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
InfallibleTArray<BluetoothNamedValue> properties(prop.get_ArrayOfBluetoothNamedValue()); InfallibleTArray<BluetoothNamedValue>& properties =
if (v.type() == BluetoothValue::TArrayOfBluetoothNamedValue) { prop.get_ArrayOfBluetoothNamedValue();
// Return original dbus message parameters and also device name
// for agent events "RequestConfirmation", "RequestPinCode", and "RequestPasskey"
InfallibleTArray<BluetoothNamedValue> parameters(v.get_ArrayOfBluetoothNamedValue());
// For consistency, append path // Return original dbus message parameters and also device name
nsString path = parameters[0].value(); // for agent events "RequestConfirmation", "RequestPinCode", and "RequestPasskey"
BluetoothNamedValue pathprop; InfallibleTArray<BluetoothNamedValue>& parameters =
pathprop.name().AssignLiteral("Path"); v.get_ArrayOfBluetoothNamedValue();
pathprop.value() = path;
parameters.AppendElement(pathprop);
// Replace object path with device address // Replace object path with device address
nsString address = GetAddressFromObjectPath(path); nsString address = GetAddressFromObjectPath(devicePath);
parameters[0].value() = address; parameters[0].name().AssignLiteral("address");
parameters[0].value() = address;
uint8_t i; uint8_t i;
for (i = 0; i < properties.Length(); i++) { for (i = 0; i < properties.Length(); i++) {
// Append device name // Append device name
if (properties[i].name().EqualsLiteral("Name")) { if (properties[i].name().EqualsLiteral("Name")) {
properties[i].name().AssignLiteral("name"); properties[i].name().AssignLiteral("name");
parameters.AppendElement(properties[i]); parameters.AppendElement(properties[i]);
mSignal.value() = parameters; mSignal.value() = parameters;
break; break;
}
} }
NS_ASSERTION(i != properties.Length(), "failed to get device name");
} else {
// Return all device properties for event "DeviceCreated", including device path
properties.AppendElement(BluetoothNamedValue(NS_LITERAL_STRING("Path"), mSignal.value()));
mSignal.value() = properties;
} }
NS_ASSERTION(i != properties.Length(), "failed to get device name");
nsRefPtr<DistributeBluetoothSignalTask> t = nsRefPtr<DistributeBluetoothSignalTask> t =
new DistributeBluetoothSignalTask(mSignal); new DistributeBluetoothSignalTask(mSignal);
@ -1921,36 +1906,6 @@ private:
nsTArray<nsString> mDeviceAddresses; nsTArray<nsString> mDeviceAddresses;
}; };
nsresult
BluetoothDBusService::GetProperties(BluetoothObjectType aType,
const nsAString& aPath,
BluetoothReplyRunnable* aRunnable)
{
NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
MOZ_ASSERT(aType < ArrayLength(sBluetoothDBusIfaces));
MOZ_ASSERT(aType < ArrayLength(sBluetoothDBusPropCallbacks));
const char* interface = sBluetoothDBusIfaces[aType];
DBusCallback callback = sBluetoothDBusPropCallbacks[aType];
nsRefPtr<BluetoothReplyRunnable> runnable = aRunnable;
if (!dbus_func_args_async(mConnection,
1000,
callback,
(void*)aRunnable,
NS_ConvertUTF16toUTF8(aPath).get(),
interface,
"GetProperties",
DBUS_TYPE_INVALID)) {
NS_WARNING("Could not start async function!");
return NS_ERROR_FAILURE;
}
runnable.forget();
return NS_OK;
}
nsresult nsresult
BluetoothDBusService::GetDevicePropertiesInternal(const BluetoothSignal& aSignal) BluetoothDBusService::GetDevicePropertiesInternal(const BluetoothSignal& aSignal)
{ {

View File

@ -41,11 +41,6 @@ public:
virtual nsresult StopDiscoveryInternal(const nsAString& aAdapterPath, virtual nsresult StopDiscoveryInternal(const nsAString& aAdapterPath,
BluetoothReplyRunnable* aRunnable); BluetoothReplyRunnable* aRunnable);
virtual nsresult
GetProperties(BluetoothObjectType aType,
const nsAString& aPath,
BluetoothReplyRunnable* aRunnable);
virtual nsresult virtual nsresult
GetDevicePropertiesInternal(const BluetoothSignal& aSignal); GetDevicePropertiesInternal(const BluetoothSignal& aSignal);