dom/bluetooth/BluetoothUuid.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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)
    19 {
    20   aRetUuidStr.Truncate();
    22   aRetUuidStr.AppendLiteral("0000");
    23   aRetUuidStr.AppendInt(aServiceClass, 16);
    24   aRetUuidStr.AppendLiteral("-0000-1000-8000-00805F9B34FB");
    25 }
    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);
    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));
    41   nsresult rv;
    42   int32_t integer = uuid.ToInteger(&rv, 16);
    43   NS_ENSURE_SUCCESS(rv, retValue);
    45   return GetBluetoothServiceClass(integer);
    46 }
    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 }
    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 }

mercurial