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