Bug 1181479: Refine StringToUuid; r=jocelyn

This commit is contained in:
Bruce Sun 2015-09-21 14:39:44 +08:00
parent 82a0a1c6a7
commit 15bb1771f3
3 changed files with 6 additions and 20 deletions

View File

@ -634,7 +634,7 @@ BluetoothGattManager::StartLeScan(const nsTArray<nsString>& aServiceUuids,
client->mStartLeScanRunnable = aRunnable;
BluetoothUuid appUuid;
StringToUuid(NS_ConvertUTF16toUTF8(appUuidStr).get(), appUuid);
StringToUuid(appUuidStr, appUuid);
// 'startLeScan' will be proceeded after client registered
sBluetoothGattInterface->RegisterClient(
@ -726,7 +726,7 @@ BluetoothGattManager::Connect(const nsAString& aAppUuid,
new ConnectResultHandler(client));
} else {
BluetoothUuid uuid;
StringToUuid(NS_ConvertUTF16toUTF8(aAppUuid).get(), uuid);
StringToUuid(aAppUuid, uuid);
// connect will be proceeded after client registered
sBluetoothGattInterface->RegisterClient(
@ -1507,7 +1507,7 @@ BluetoothGattManager::ConnectPeripheral(
new ConnectPeripheralResultHandler(server, aAddress));
} else {
BluetoothUuid uuid;
StringToUuid(NS_ConvertUTF16toUTF8(aAppUuid).get(), uuid);
StringToUuid(aAppUuid, uuid);
// connect will be proceeded after server registered
sBluetoothGattInterface->RegisterServer(

View File

@ -43,12 +43,13 @@ UuidToString(const BluetoothUuid& aUuid, nsAString& aString)
}
void
StringToUuid(const char* aString, BluetoothUuid& aUuid)
StringToUuid(const nsAString& aString, BluetoothUuid& aUuid)
{
uint32_t uuid0, uuid4;
uint16_t uuid1, uuid2, uuid3, uuid5;
sscanf(aString, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
sscanf(NS_ConvertUTF16toUTF8(aString).get(),
"%08x-%04hx-%04hx-%04hx-%08x%04hx",
&uuid0, &uuid1, &uuid2, &uuid3, &uuid4, &uuid5);
uuid0 = htonl(uuid0);
@ -66,12 +67,6 @@ StringToUuid(const char* aString, BluetoothUuid& aUuid)
memcpy(&aUuid.mUuid[14], &uuid5, sizeof(uint16_t));
}
void
StringToUuid(const nsAString& aString, BluetoothUuid& aUuid)
{
StringToUuid(NS_ConvertUTF16toUTF8(aString).get(), aUuid);
}
void
GenerateUuid(nsAString &aUuidString)
{

View File

@ -36,15 +36,6 @@ UuidToString(const BluetoothUuid& aUuid, nsAString& aString);
* string created by gecko back to BluetoothUuid representation.
*/
void
StringToUuid(const char* aString, BluetoothUuid& aUuid);
/**
* Convert xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx uuid string to BluetoothUuid object.
*
* This utility function is used by gecko internal only to convert uuid string
* created by gecko back to BluetoothUuid representation.
*/
void
StringToUuid(const nsAString& aString, BluetoothUuid& aUuid);
/**