Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "BluetoothUuid.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "BluetoothA2dpManager.h" |
michael@0 | 10 | #include "BluetoothHfpManager.h" |
michael@0 | 11 | #include "BluetoothHidManager.h" |
michael@0 | 12 | #include "BluetoothOppManager.h" |
michael@0 | 13 | |
michael@0 | 14 | USING_BLUETOOTH_NAMESPACE |
michael@0 | 15 | |
michael@0 | 16 | void |
michael@0 | 17 | BluetoothUuidHelper::GetString(BluetoothServiceClass aServiceClass, |
michael@0 | 18 | nsAString& aRetUuidStr) |
michael@0 | 19 | { |
michael@0 | 20 | aRetUuidStr.Truncate(); |
michael@0 | 21 | |
michael@0 | 22 | aRetUuidStr.AppendLiteral("0000"); |
michael@0 | 23 | aRetUuidStr.AppendInt(aServiceClass, 16); |
michael@0 | 24 | aRetUuidStr.AppendLiteral("-0000-1000-8000-00805F9B34FB"); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | BluetoothServiceClass |
michael@0 | 28 | BluetoothUuidHelper::GetBluetoothServiceClass(const nsAString& aUuidStr) |
michael@0 | 29 | { |
michael@0 | 30 | // An example of input UUID string: 0000110D-0000-1000-8000-00805F9B34FB |
michael@0 | 31 | MOZ_ASSERT(aUuidStr.Length() == 36); |
michael@0 | 32 | |
michael@0 | 33 | /** |
michael@0 | 34 | * Extract uuid16 from input UUID string and return a value of enum |
michael@0 | 35 | * BluetoothServiceClass. If we failed to recognize the value, |
michael@0 | 36 | * BluetoothServiceClass::UNKNOWN is returned. |
michael@0 | 37 | */ |
michael@0 | 38 | BluetoothServiceClass retValue = BluetoothServiceClass::UNKNOWN; |
michael@0 | 39 | nsString uuid(Substring(aUuidStr, 4, 4)); |
michael@0 | 40 | |
michael@0 | 41 | nsresult rv; |
michael@0 | 42 | int32_t integer = uuid.ToInteger(&rv, 16); |
michael@0 | 43 | NS_ENSURE_SUCCESS(rv, retValue); |
michael@0 | 44 | |
michael@0 | 45 | return GetBluetoothServiceClass(integer); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | BluetoothServiceClass |
michael@0 | 49 | BluetoothUuidHelper::GetBluetoothServiceClass(uint16_t aServiceUuid) |
michael@0 | 50 | { |
michael@0 | 51 | BluetoothServiceClass retValue = BluetoothServiceClass::UNKNOWN; |
michael@0 | 52 | switch (aServiceUuid) { |
michael@0 | 53 | case BluetoothServiceClass::A2DP: |
michael@0 | 54 | case BluetoothServiceClass::HANDSFREE: |
michael@0 | 55 | case BluetoothServiceClass::HANDSFREE_AG: |
michael@0 | 56 | case BluetoothServiceClass::HEADSET: |
michael@0 | 57 | case BluetoothServiceClass::HEADSET_AG: |
michael@0 | 58 | case BluetoothServiceClass::HID: |
michael@0 | 59 | case BluetoothServiceClass::OBJECT_PUSH: |
michael@0 | 60 | retValue = (BluetoothServiceClass)aServiceUuid; |
michael@0 | 61 | } |
michael@0 | 62 | return retValue; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | BluetoothProfileManagerBase* |
michael@0 | 66 | BluetoothUuidHelper::GetBluetoothProfileManager(uint16_t aServiceUuid) |
michael@0 | 67 | { |
michael@0 | 68 | BluetoothProfileManagerBase* profile; |
michael@0 | 69 | BluetoothServiceClass serviceClass = GetBluetoothServiceClass(aServiceUuid); |
michael@0 | 70 | switch (serviceClass) { |
michael@0 | 71 | case BluetoothServiceClass::HANDSFREE: |
michael@0 | 72 | case BluetoothServiceClass::HEADSET: |
michael@0 | 73 | profile = BluetoothHfpManager::Get(); |
michael@0 | 74 | break; |
michael@0 | 75 | case BluetoothServiceClass::HID: |
michael@0 | 76 | profile = BluetoothHidManager::Get(); |
michael@0 | 77 | break; |
michael@0 | 78 | case BluetoothServiceClass::A2DP: |
michael@0 | 79 | profile = BluetoothA2dpManager::Get(); |
michael@0 | 80 | break; |
michael@0 | 81 | case BluetoothServiceClass::OBJECT_PUSH: |
michael@0 | 82 | profile = BluetoothOppManager::Get(); |
michael@0 | 83 | break; |
michael@0 | 84 | default: |
michael@0 | 85 | profile = nullptr; |
michael@0 | 86 | } |
michael@0 | 87 | return profile; |
michael@0 | 88 | } |