Bumping manifests a=b2g-bump
[gecko.git] / dom / bluetooth / BluetoothUuid.cpp
blob0e6b57debc82877659e3f15b7640de70c72c0152
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/. */
7 #include "BluetoothUuid.h"
9 #include "BluetoothA2dpManager.h"
10 #include "BluetoothHfpManager.h"
11 #include "BluetoothHidManager.h"
12 #include "BluetoothOppManager.h"
14 USING_BLUETOOTH_NAMESPACE
16 void
17 BluetoothUuidHelper::GetString(BluetoothServiceClass aServiceClass,
18 nsAString& aRetUuidStr)
20 aRetUuidStr.Truncate();
22 aRetUuidStr.AppendLiteral("0000");
23 aRetUuidStr.AppendInt(aServiceClass, 16);
24 aRetUuidStr.AppendLiteral("-0000-1000-8000-00805F9B34FB");
27 BluetoothServiceClass
28 BluetoothUuidHelper::GetBluetoothServiceClass(const nsAString& aUuidStr)
30 // An example of input UUID string: 0000110D-0000-1000-8000-00805F9B34FB
31 MOZ_ASSERT(aUuidStr.Length() == 36);
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.
38 BluetoothServiceClass retValue = BluetoothServiceClass::UNKNOWN;
39 nsString uuid(Substring(aUuidStr, 4, 4));
41 nsresult rv;
42 int32_t integer = uuid.ToInteger(&rv, 16);
43 NS_ENSURE_SUCCESS(rv, retValue);
45 return GetBluetoothServiceClass(integer);
48 BluetoothServiceClass
49 BluetoothUuidHelper::GetBluetoothServiceClass(uint16_t aServiceUuid)
51 BluetoothServiceClass retValue = BluetoothServiceClass::UNKNOWN;
52 switch (aServiceUuid) {
53 case BluetoothServiceClass::A2DP:
54 case BluetoothServiceClass::A2DP_SINK:
55 case BluetoothServiceClass::HANDSFREE:
56 case BluetoothServiceClass::HANDSFREE_AG:
57 case BluetoothServiceClass::HEADSET:
58 case BluetoothServiceClass::HEADSET_AG:
59 case BluetoothServiceClass::HID:
60 case BluetoothServiceClass::OBJECT_PUSH:
61 retValue = (BluetoothServiceClass)aServiceUuid;
63 return retValue;
66 BluetoothProfileManagerBase*
67 BluetoothUuidHelper::GetBluetoothProfileManager(uint16_t aServiceUuid)
69 BluetoothProfileManagerBase* profile;
70 BluetoothServiceClass serviceClass = GetBluetoothServiceClass(aServiceUuid);
71 switch (serviceClass) {
72 case BluetoothServiceClass::HANDSFREE:
73 case BluetoothServiceClass::HEADSET:
74 profile = BluetoothHfpManager::Get();
75 break;
76 case BluetoothServiceClass::HID:
77 profile = BluetoothHidManager::Get();
78 break;
79 case BluetoothServiceClass::A2DP:
80 profile = BluetoothA2dpManager::Get();
81 break;
82 case BluetoothServiceClass::OBJECT_PUSH:
83 profile = BluetoothOppManager::Get();
84 break;
85 default:
86 profile = nullptr;
88 return profile;