michael@0: /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "BluetoothUuid.h" michael@0: michael@0: #include "BluetoothA2dpManager.h" michael@0: #include "BluetoothHfpManager.h" michael@0: #include "BluetoothHidManager.h" michael@0: #include "BluetoothOppManager.h" michael@0: michael@0: USING_BLUETOOTH_NAMESPACE michael@0: michael@0: void michael@0: BluetoothUuidHelper::GetString(BluetoothServiceClass aServiceClass, michael@0: nsAString& aRetUuidStr) michael@0: { michael@0: aRetUuidStr.Truncate(); michael@0: michael@0: aRetUuidStr.AppendLiteral("0000"); michael@0: aRetUuidStr.AppendInt(aServiceClass, 16); michael@0: aRetUuidStr.AppendLiteral("-0000-1000-8000-00805F9B34FB"); michael@0: } michael@0: michael@0: BluetoothServiceClass michael@0: BluetoothUuidHelper::GetBluetoothServiceClass(const nsAString& aUuidStr) michael@0: { michael@0: // An example of input UUID string: 0000110D-0000-1000-8000-00805F9B34FB michael@0: MOZ_ASSERT(aUuidStr.Length() == 36); michael@0: michael@0: /** michael@0: * Extract uuid16 from input UUID string and return a value of enum michael@0: * BluetoothServiceClass. If we failed to recognize the value, michael@0: * BluetoothServiceClass::UNKNOWN is returned. michael@0: */ michael@0: BluetoothServiceClass retValue = BluetoothServiceClass::UNKNOWN; michael@0: nsString uuid(Substring(aUuidStr, 4, 4)); michael@0: michael@0: nsresult rv; michael@0: int32_t integer = uuid.ToInteger(&rv, 16); michael@0: NS_ENSURE_SUCCESS(rv, retValue); michael@0: michael@0: return GetBluetoothServiceClass(integer); michael@0: } michael@0: michael@0: BluetoothServiceClass michael@0: BluetoothUuidHelper::GetBluetoothServiceClass(uint16_t aServiceUuid) michael@0: { michael@0: BluetoothServiceClass retValue = BluetoothServiceClass::UNKNOWN; michael@0: switch (aServiceUuid) { michael@0: case BluetoothServiceClass::A2DP: michael@0: case BluetoothServiceClass::HANDSFREE: michael@0: case BluetoothServiceClass::HANDSFREE_AG: michael@0: case BluetoothServiceClass::HEADSET: michael@0: case BluetoothServiceClass::HEADSET_AG: michael@0: case BluetoothServiceClass::HID: michael@0: case BluetoothServiceClass::OBJECT_PUSH: michael@0: retValue = (BluetoothServiceClass)aServiceUuid; michael@0: } michael@0: return retValue; michael@0: } michael@0: michael@0: BluetoothProfileManagerBase* michael@0: BluetoothUuidHelper::GetBluetoothProfileManager(uint16_t aServiceUuid) michael@0: { michael@0: BluetoothProfileManagerBase* profile; michael@0: BluetoothServiceClass serviceClass = GetBluetoothServiceClass(aServiceUuid); michael@0: switch (serviceClass) { michael@0: case BluetoothServiceClass::HANDSFREE: michael@0: case BluetoothServiceClass::HEADSET: michael@0: profile = BluetoothHfpManager::Get(); michael@0: break; michael@0: case BluetoothServiceClass::HID: michael@0: profile = BluetoothHidManager::Get(); michael@0: break; michael@0: case BluetoothServiceClass::A2DP: michael@0: profile = BluetoothA2dpManager::Get(); michael@0: break; michael@0: case BluetoothServiceClass::OBJECT_PUSH: michael@0: profile = BluetoothOppManager::Get(); michael@0: break; michael@0: default: michael@0: profile = nullptr; michael@0: } michael@0: return profile; michael@0: }