Bug 839370 - Implement function UpdateSdpRecords(), r=gyeh

This commit is contained in:
Eric Chou 2013-05-22 19:08:17 +08:00
parent 4490b3e244
commit a16b1e81ec
5 changed files with 96 additions and 12 deletions

View File

@ -222,10 +222,14 @@ public:
* @return NS_OK if the task begins, NS_ERROR_FAILURE otherwise
*/
virtual nsresult
GetServiceChannel(const nsAString& aObjectPath,
GetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
BluetoothProfileManagerBase* aManager) = 0;
virtual bool
UpdateSdpRecords(const nsAString& aDeviceAddress,
BluetoothProfileManagerBase* aManager) = 0;
virtual bool
SetPinCodeInternal(const nsAString& aDeviceAddress, const nsAString& aPinCode,
BluetoothReplyRunnable* aRunnable) = 0;

View File

@ -207,7 +207,7 @@ BluetoothServiceChildProcess::GetScoSocket(
}
nsresult
BluetoothServiceChildProcess::GetServiceChannel(const nsAString& aObjectPath,
BluetoothServiceChildProcess::GetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
BluetoothProfileManagerBase* aManager)
{
@ -215,6 +215,14 @@ BluetoothServiceChildProcess::GetServiceChannel(const nsAString& aObjectPath,
return NS_ERROR_FAILURE;
}
bool
BluetoothServiceChildProcess::UpdateSdpRecords(const nsAString& aDeviceAddress,
BluetoothProfileManagerBase* aManager)
{
MOZ_NOT_REACHED("This should never be called!");
return NS_ERROR_FAILURE;
}
bool
BluetoothServiceChildProcess::SetPinCodeInternal(
const nsAString& aDeviceAddress,

View File

@ -87,10 +87,14 @@ public:
mozilla::ipc::UnixSocketConsumer* aConsumer) MOZ_OVERRIDE;
virtual nsresult
GetServiceChannel(const nsAString& aObjectPath,
GetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
BluetoothProfileManagerBase* aManager) MOZ_OVERRIDE;
virtual bool
UpdateSdpRecords(const nsAString& aDeviceAddress,
BluetoothProfileManagerBase* aManager) MOZ_OVERRIDE;
virtual bool
SetPinCodeInternal(const nsAString& aDeviceAddress,
const nsAString& aPinCode,

View File

@ -2533,16 +2533,13 @@ BluetoothDBusService::Connect(const nsAString& aDeviceAddress,
if (aProfileId == BluetoothServiceClass::HANDSFREE) {
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->Connect(
GetObjectPathFromAddress(sAdapterPath, aDeviceAddress), true, aRunnable);
hfp->Connect(aDeviceAddress, true, aRunnable);
} else if (aProfileId == BluetoothServiceClass::HEADSET) {
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->Connect(
GetObjectPathFromAddress(sAdapterPath, aDeviceAddress), false, aRunnable);
hfp->Connect(aDeviceAddress, false, aRunnable);
} else if (aProfileId == BluetoothServiceClass::OBJECT_PUSH) {
BluetoothOppManager* opp = BluetoothOppManager::Get();
opp->Connect(
GetObjectPathFromAddress(sAdapterPath, aDeviceAddress), aRunnable);
opp->Connect(aDeviceAddress, aRunnable);
} else {
BluetoothValue v;
DispatchBluetoothReply(aRunnable, v, NS_LITERAL_STRING("UnknownProfileError"));
@ -2641,6 +2638,34 @@ private:
int mChannel;
};
class OnUpdateSdpRecordsRunnable : public nsRunnable
{
public:
OnUpdateSdpRecordsRunnable(const nsAString& aObjectPath,
BluetoothProfileManagerBase* aManager)
: mManager(aManager)
{
MOZ_ASSERT(!aObjectPath.IsEmpty());
MOZ_ASSERT(aManager);
mDeviceAddress = GetAddressFromObjectPath(aObjectPath);
}
nsresult
Run()
{
MOZ_ASSERT(NS_IsMainThread());
mManager->OnUpdateSdpRecords(mDeviceAddress);
return NS_OK;
}
private:
nsString mDeviceAddress;
BluetoothProfileManagerBase* mManager;
};
class OnGetServiceChannelRunnable : public nsRunnable
{
public:
@ -2715,14 +2740,16 @@ private:
};
nsresult
BluetoothDBusService::GetServiceChannel(const nsAString& aObjectPath,
BluetoothDBusService::GetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
BluetoothProfileManagerBase* aManager)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mBluetoothCommandThread);
nsRefPtr<nsRunnable> r(new GetServiceChannelRunnable(aObjectPath,
nsString objectPath(GetObjectPathFromAddress(sAdapterPath, aDeviceAddress));
nsRefPtr<nsRunnable> r(new GetServiceChannelRunnable(objectPath,
aServiceUuid,
aManager));
@ -2733,6 +2760,43 @@ BluetoothDBusService::GetServiceChannel(const nsAString& aObjectPath,
return NS_OK;
}
static void
DiscoverServicesCallback(DBusMessage* aMsg, void* aData)
{
MOZ_ASSERT(!NS_IsMainThread());
nsRefPtr<OnUpdateSdpRecordsRunnable> r(
static_cast<OnUpdateSdpRecordsRunnable*>(aData));
NS_DispatchToMainThread(r);
}
bool
BluetoothDBusService::UpdateSdpRecords(const nsAString& aDeviceAddress,
BluetoothProfileManagerBase* aManager)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!aDeviceAddress.IsEmpty());
MOZ_ASSERT(aManager);
MOZ_ASSERT(mConnection);
nsString objectPath(GetObjectPathFromAddress(sAdapterPath, aDeviceAddress));
// I choose to use raw pointer here because this is going to be passed as an
// argument into dbus_func_args_async() at once.
OnUpdateSdpRecordsRunnable* callbackRunnable =
new OnUpdateSdpRecordsRunnable(objectPath, aManager);
return dbus_func_args_async(mConnection,
-1,
DiscoverServicesCallback,
(void*)callbackRunnable,
NS_ConvertUTF16toUTF8(objectPath).get(),
DBUS_DEVICE_IFACE,
"DiscoverServices",
DBUS_TYPE_STRING, &EmptyCString(),
DBUS_TYPE_INVALID);
}
nsresult
BluetoothDBusService::GetScoSocket(const nsAString& aAddress,
bool aAuth,

View File

@ -85,10 +85,14 @@ public:
mozilla::ipc::UnixSocketConsumer* aConsumer);
virtual nsresult
GetServiceChannel(const nsAString& aObjectPath,
GetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
BluetoothProfileManagerBase* aManager);
virtual bool
UpdateSdpRecords(const nsAString& aDeviceAddress,
BluetoothProfileManagerBase* aManager);
virtual nsresult
CreatePairedDeviceInternal(const nsAString& aDeviceAddress,
int aTimeout,