Bug 811946 - remove annoying compiler warnings and define a more structured interface for Bluetooth uuid, r=qdot

This commit is contained in:
Eric Chou 2012-11-27 14:12:19 +08:00
Родитель 557949bf7e
Коммит 96d61874a4
10 изменённых файлов: 118 добавлений и 90 удалений

Просмотреть файл

@ -10,7 +10,6 @@
#include "BluetoothPropertyEvent.h"
#include "BluetoothReplyRunnable.h"
#include "BluetoothService.h"
#include "BluetoothServiceUuid.h"
#include "BluetoothUtils.h"
#include "GeneratedEvents.h"

Просмотреть файл

@ -10,7 +10,6 @@
#include "BluetoothReplyRunnable.h"
#include "BluetoothService.h"
#include "BluetoothUtils.h"
#include "BluetoothServiceUuid.h"
#include "nsIDOMDOMRequest.h"
#include "nsDOMClassInfo.h"

Просмотреть файл

@ -11,8 +11,8 @@
#include "BluetoothReplyRunnable.h"
#include "BluetoothScoManager.h"
#include "BluetoothService.h"
#include "BluetoothServiceUuid.h"
#include "BluetoothUtils.h"
#include "BluetoothUuid.h"
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "mozilla/Services.h"
@ -27,8 +27,6 @@
#define MOZSETTINGS_CHANGED_ID "mozsettings-changed"
#define AUDIO_VOLUME_BT_SCO "audio.volume.bt_sco"
#define HANDSFREE_UUID mozilla::dom::bluetooth::BluetoothServiceUuidStr::Handsfree
#define HEADSET_UUID mozilla::dom::bluetooth::BluetoothServiceUuidStr::Headset
using namespace mozilla;
using namespace mozilla::ipc;
@ -623,17 +621,17 @@ BluetoothHfpManager::Connect(const nsAString& aDevicePath,
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE(bs, false);
nsString serviceUuidStr;
nsString uuid;
if (aIsHandsfree) {
serviceUuidStr = NS_ConvertUTF8toUTF16(HANDSFREE_UUID);
BluetoothUuidHelper::GetString(BluetoothServiceClass::HANDSFREE, uuid);
} else {
serviceUuidStr = NS_ConvertUTF8toUTF16(HEADSET_UUID);
BluetoothUuidHelper::GetString(BluetoothServiceClass::HEADSET, uuid);
}
mRunnable = aRunnable;
nsresult rv = bs->GetSocketViaService(aDevicePath,
serviceUuidStr,
uuid,
BluetoothSocketType::RFCOMM,
true,
true,
@ -658,11 +656,12 @@ BluetoothHfpManager::Listen()
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE(bs, false);
nsresult rv = bs->ListenSocketViaService(BluetoothReservedChannels::HANDSFREE_AG,
BluetoothSocketType::RFCOMM,
true,
true,
this);
nsresult rv =
bs->ListenSocketViaService(BluetoothReservedChannels::CHANNEL_HANDSFREE_AG,
BluetoothSocketType::RFCOMM,
true,
true,
this);
mSocketStatus = GetConnectionStatus();

Просмотреть файл

@ -9,8 +9,8 @@
#include "BluetoothReplyRunnable.h"
#include "BluetoothService.h"
#include "BluetoothServiceUuid.h"
#include "BluetoothUtils.h"
#include "BluetoothUuid.h"
#include "ObexBase.h"
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
@ -207,13 +207,13 @@ BluetoothOppManager::Connect(const nsAString& aDeviceObjectPath,
return false;
}
nsString serviceUuidStr =
NS_ConvertUTF8toUTF16(BluetoothServiceUuidStr::ObjectPush);
nsString uuid;
BluetoothUuidHelper::GetString(BluetoothServiceClass::OBJECT_PUSH, uuid);
mRunnable = aRunnable;
nsresult rv = bs->GetSocketViaService(aDeviceObjectPath,
serviceUuidStr,
uuid,
BluetoothSocketType::RFCOMM,
true,
true,
@ -257,11 +257,12 @@ BluetoothOppManager::Listen()
return false;
}
nsresult rv = bs->ListenSocketViaService(BluetoothReservedChannels::OPUSH,
BluetoothSocketType::RFCOMM,
true,
true,
this);
nsresult rv =
bs->ListenSocketViaService(BluetoothReservedChannels::CHANNEL_OPUSH,
BluetoothSocketType::RFCOMM,
true,
true,
this);
mSocketStatus = GetConnectionStatus();
return NS_FAILED(rv) ? false : true;

Просмотреть файл

@ -10,7 +10,6 @@
#include "BluetoothReplyRunnable.h"
#include "BluetoothService.h"
#include "BluetoothServiceUuid.h"
#include "BluetoothUtils.h"
#include "mozilla/Services.h"

Просмотреть файл

@ -1,53 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_dom_bluetooth_bluetoothuuid_h__
#define mozilla_dom_bluetooth_bluetoothuuid_h__
namespace mozilla {
namespace dom {
namespace bluetooth {
namespace BluetoothServiceUuid {
static unsigned long long Headset = 0x0000110800000000;
static unsigned long long HeadsetAG = 0x0000111200000000;
static unsigned long long Handsfree = 0x0000111E00000000;
static unsigned long long HandsfreeAG = 0x0000111F00000000;
static unsigned long long ObjectPush = 0x0000110500000000;
static unsigned long long BaseMSB = 0x0000000000001000;
static unsigned long long BaseLSB = 0x800000805F9B34FB;
}
namespace BluetoothServiceUuidStr {
static const char* Headset = "00001108-0000-1000-8000-00805F9B34FB";
static const char* HeadsetAG = "00001112-0000-1000-8000-00805F9B34FB";
static const char* Handsfree = "0000111E-0000-1000-8000-00805F9B34FB";
static const char* HandsfreeAG = "0000111F-0000-1000-8000-00805F9B34FB";
static const char* ObjectPush = "00001105-0000-1000-8000-00805F9B34FB";
}
// TODO/qdot: Move these back into gonk and make the service handler deal with
// it there.
//
// Gotten from reading the "u8" values in B2G/external/bluez/src/adapter.c
// These were hardcoded into android
enum BluetoothReservedChannels {
DIALUP_NETWORK = 1,
HANDSFREE_AG = 10,
HEADSET_AG = 11,
OPUSH = 12,
SIM_ACCESS = 15,
PBAP_PSE = 19,
FTP = 20,
};
}
}
}
#endif

Просмотреть файл

@ -0,0 +1,20 @@
/* -*- 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"
USING_BLUETOOTH_NAMESPACE
void
BluetoothUuidHelper::GetString(BluetoothServiceClass aServiceClassUuid,
nsAString& aRetUuidStr)
{
aRetUuidStr.Truncate();
aRetUuidStr.AppendLiteral("0000");
aRetUuidStr.AppendInt(aServiceClassUuid, 16);
aRetUuidStr.AppendLiteral("-0000-1000-8000-00805F9B34FB");
}

Просмотреть файл

@ -0,0 +1,63 @@
/* -*- 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/. */
#ifndef mozilla_dom_bluetooth_bluetoothuuid_h__
#define mozilla_dom_bluetooth_bluetoothuuid_h__
#include "BluetoothCommon.h"
BEGIN_BLUETOOTH_NAMESPACE
/*
* Service classes and Profile Identifiers
*
* Supported Bluetooth services for v1 are listed as below.
*
* The value of each service class is defined in "AssignedNumbers/Service
* Discovery Protocol (SDP)/Service classes and Profile Identifiers" in the
* Bluetooth Core Specification.
*/
enum BluetoothServiceClass
{
HEADSET = 0x1108,
HEADSET_AG = 0x1112,
HANDSFREE = 0x111E,
HANDSFREE_AG = 0x111F,
OBJECT_PUSH = 0x1105
};
class BluetoothUuidHelper
{
public:
/**
* Get a 128-bit uuid string calculated from a 16-bit service class UUID and
* BASE_UUID
*
* @param aServiceClassUuid 16-bit service class UUID
* @param aRetUuidStr out parameter, 128-bit uuid string
*/
static void
GetString(BluetoothServiceClass aServiceClassUuid, nsAString& aRetUuidStr);
};
// TODO/qdot: Move these back into gonk and make the service handler deal with
// it there.
//
// Gotten from reading the "u8" values in B2G/external/bluez/src/adapter.c
// These were hardcoded into android
enum BluetoothReservedChannels {
CHANNEL_DIALUP_NETWORK = 1,
CHANNEL_HANDSFREE_AG = 10,
CHANNEL_HEADSET_AG = 11,
CHANNEL_OPUSH = 12,
CHANNEL_SIM_ACCESS = 15,
CHANNEL_PBAP_PSE = 19,
CHANNEL_FTP = 20,
};
END_BLUETOOTH_NAMESPACE
#endif

Просмотреть файл

@ -56,6 +56,7 @@ CPPSRCS += \
BluetoothOppManager.cpp \
ObexBase.cpp \
BluetoothScoManager.cpp \
BluetoothUuid.cpp \
$(NULL)
ifdef MOZ_B2G_RIL

Просмотреть файл

@ -22,9 +22,9 @@
#include "BluetoothOppManager.h"
#include "BluetoothReplyRunnable.h"
#include "BluetoothScoManager.h"
#include "BluetoothServiceUuid.h"
#include "BluetoothUnixSocketConnector.h"
#include "BluetoothUtils.h"
#include "BluetoothUuid.h"
#include <cstdio>
#include <dbus/dbus.h>
@ -766,9 +766,9 @@ public:
nsTArray<uint32_t> uuids;
uuids.AppendElement((uint32_t)(BluetoothServiceUuid::HandsfreeAG >> 32));
uuids.AppendElement((uint32_t)(BluetoothServiceUuid::HeadsetAG >> 32));
uuids.AppendElement((uint32_t)(BluetoothServiceUuid::ObjectPush >> 32));
uuids.AppendElement(BluetoothServiceClass::HANDSFREE_AG);
uuids.AppendElement(BluetoothServiceClass::HEADSET_AG);
uuids.AppendElement(BluetoothServiceClass::OBJECT_PUSH);
// TODO/qdot: This needs to be held for the life of the bluetooth connection
// so we could clean it up. For right now though, we can throw it away.
@ -2313,21 +2313,21 @@ BluetoothDBusService::Connect(const nsAString& aDeviceAddress,
BluetoothValue v;
nsString errorStr;
if (aProfileId == (uint16_t)(BluetoothServiceUuid::Handsfree >> 32)) {
if (aProfileId == BluetoothServiceClass::HANDSFREE) {
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
if (!hfp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress),
true, aRunnable)) {
errorStr.AssignLiteral("BluetoothHfpManager has connected/is connecting to a headset!");
DispatchBluetoothReply(aRunnable, v, errorStr);
}
} else if (aProfileId == (uint16_t)(BluetoothServiceUuid::Headset >> 32)) {
} else if (aProfileId == BluetoothServiceClass::HEADSET) {
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
if (!hfp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress),
false, aRunnable)) {
errorStr.AssignLiteral("BluetoothHfpManager has connected/is connecting to a headset!");
DispatchBluetoothReply(aRunnable, v, errorStr);
}
} else if (aProfileId == (uint16_t)(BluetoothServiceUuid::ObjectPush >> 32)) {
} else if (aProfileId == BluetoothServiceClass::OBJECT_PUSH) {
BluetoothOppManager* opp = BluetoothOppManager::Get();
if (!opp->Connect(GetObjectPathFromAddress(aAdapterPath, aDeviceAddress),
aRunnable)) {
@ -2345,11 +2345,11 @@ void
BluetoothDBusService::Disconnect(const uint16_t aProfileId,
BluetoothReplyRunnable* aRunnable)
{
if (aProfileId == (uint16_t)(BluetoothServiceUuid::Handsfree >> 32) ||
aProfileId == (uint16_t)(BluetoothServiceUuid::Headset >> 32)) {
if (aProfileId == BluetoothServiceClass::HANDSFREE ||
aProfileId == BluetoothServiceClass::HEADSET) {
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
hfp->Disconnect();
} else if (aProfileId == (uint16_t)(BluetoothServiceUuid::ObjectPush >> 32)) {
} else if (aProfileId == BluetoothServiceClass::OBJECT_PUSH) {
BluetoothOppManager* opp = BluetoothOppManager::Get();
opp->Disconnect();
} else {
@ -2370,11 +2370,11 @@ BluetoothDBusService::IsConnected(const uint16_t aProfileId)
{
NS_ASSERTION(NS_IsMainThread(), "Must be called from main thread!");
if (aProfileId == (uint16_t)(BluetoothServiceUuid::Handsfree >> 32)
|| aProfileId == (uint16_t)(BluetoothServiceUuid::Headset >> 32)) {
if (aProfileId == BluetoothServiceClass::HANDSFREE ||
aProfileId == BluetoothServiceClass::HEADSET) {
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
return hfp->GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED;
} else if (aProfileId == (uint16_t)(BluetoothServiceUuid::ObjectPush >> 32)) {
} else if (aProfileId == BluetoothServiceClass::OBJECT_PUSH) {
BluetoothOppManager* opp = BluetoothOppManager::Get();
return opp->GetConnectionStatus() == SocketConnectionStatus::SOCKET_CONNECTED;
}