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