Bumping manifests a=b2g-bump
[gecko.git] / dom / bluetooth2 / BluetoothUuid.cpp
blob9a57a06a98b0c2927f0f1ab48132fab937d5f21f
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::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;
62 return retValue;
65 BluetoothProfileManagerBase*
66 BluetoothUuidHelper::GetBluetoothProfileManager(uint16_t aServiceUuid)
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;
87 return profile;