Bug 1105308: Cleanup non-shared functions in BlueZ' BluetoothUtils.{cpp,h}, r=btian

This patch moves functions out of BlueZ' BluetoothUtils.{cpp,h} that
are specific to this backend.
This commit is contained in:
Thomas Zimmermann 2014-11-28 11:49:40 +01:00
parent cdc21a34c0
commit ecb1ee7b47
5 changed files with 56 additions and 63 deletions

View File

@ -392,6 +392,37 @@ BluetoothDBusService::~BluetoothDBusService()
sGetPropertyMonitor = nullptr;
}
static nsString
GetObjectPathFromAddress(const nsAString& aAdapterPath,
const nsAString& aDeviceAddress)
{
// The object path would be like /org/bluez/2906/hci0/dev_00_23_7F_CB_B4_F1,
// and the adapter path would be the first part of the object path, according
// to the example above, it's /org/bluez/2906/hci0.
nsString devicePath(aAdapterPath);
devicePath.AppendLiteral("/dev_");
devicePath.Append(aDeviceAddress);
devicePath.ReplaceChar(':', '_');
return devicePath;
}
static nsString
GetAddressFromObjectPath(const nsAString& aObjectPath)
{
// The object path would be like /org/bluez/2906/hci0/dev_00_23_7F_CB_B4_F1,
// and the adapter path would be the first part of the object path, according
// to the example above, it's /org/bluez/2906/hci0.
nsString address(aObjectPath);
int addressHead = address.RFind("/") + 5;
MOZ_ASSERT(addressHead + BLUETOOTH_ADDRESS_LENGTH == (int)address.Length());
address.Cut(0, addressHead);
address.ReplaceChar('_', ':');
return address;
}
static bool
GetConnectedDevicesFilter(const BluetoothValue& aValue)
{

View File

@ -690,6 +690,28 @@ BluetoothHfpManager::HandleShutdown()
sBluetoothHfpManager = nullptr;
}
void
BluetoothHfpManager::ParseAtCommand(const nsACString& aAtCommand,
const int aStart,
nsTArray<nsCString>& aRetValues)
{
int length = aAtCommand.Length();
int begin = aStart;
for (int i = aStart; i < length; ++i) {
// Use ',' as separator
if (aAtCommand[i] == ',') {
nsCString tmp(nsDependentCSubstring(aAtCommand, begin, i - begin));
aRetValues.AppendElement(tmp);
begin = i + 1;
}
}
nsCString tmp(nsDependentCSubstring(aAtCommand, begin));
aRetValues.AppendElement(tmp);
}
// Virtual function of class SocketConsumer
void
BluetoothHfpManager::ReceiveSocketData(BluetoothSocket* aSocket,

View File

@ -132,6 +132,9 @@ public:
#endif
private:
void ParseAtCommand(const nsACString& aAtCommand, const int aStart,
nsTArray<nsCString>& aRetValues);
class CloseScoTask;
class GetVolumeTask;
#ifdef MOZ_B2G_RIL

View File

@ -71,37 +71,6 @@ SetJsObject(JSContext* aContext,
return true;
}
nsString
GetObjectPathFromAddress(const nsAString& aAdapterPath,
const nsAString& aDeviceAddress)
{
// The object path would be like /org/bluez/2906/hci0/dev_00_23_7F_CB_B4_F1,
// and the adapter path would be the first part of the object path, according
// to the example above, it's /org/bluez/2906/hci0.
nsString devicePath(aAdapterPath);
devicePath.AppendLiteral("/dev_");
devicePath.Append(aDeviceAddress);
devicePath.ReplaceChar(':', '_');
return devicePath;
}
nsString
GetAddressFromObjectPath(const nsAString& aObjectPath)
{
// The object path would be like /org/bluez/2906/hci0/dev_00_23_7F_CB_B4_F1,
// and the adapter path would be the first part of the object path, according
// to the example above, it's /org/bluez/2906/hci0.
nsString address(aObjectPath);
int addressHead = address.RFind("/") + 5;
MOZ_ASSERT(addressHead + BLUETOOTH_ADDRESS_LENGTH == (int)address.Length());
address.Cut(0, addressHead);
address.ReplaceChar('_', ':');
return address;
}
bool
BroadcastSystemMessage(const nsAString& aType,
const InfallibleTArray<BluetoothNamedValue>& aData)
@ -154,27 +123,6 @@ DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable,
}
}
void
ParseAtCommand(const nsACString& aAtCommand, const int aStart,
nsTArray<nsCString>& aRetValues)
{
int length = aAtCommand.Length();
int begin = aStart;
for (int i = aStart; i < length; ++i) {
// Use ',' as separator
if (aAtCommand[i] == ',') {
nsCString tmp(nsDependentCSubstring(aAtCommand, begin, i - begin));
aRetValues.AppendElement(tmp);
begin = i + 1;
}
}
nsCString tmp(nsDependentCSubstring(aAtCommand, begin));
aRetValues.AppendElement(tmp);
}
void
DispatchStatusChangedEvent(const nsAString& aType,
const nsAString& aAddress,

View File

@ -21,13 +21,6 @@ SetJsObject(JSContext* aContext,
const BluetoothValue& aValue,
JS::Handle<JSObject*> aObj);
nsString
GetObjectPathFromAddress(const nsAString& aAdapterPath,
const nsAString& aDeviceAddress);
nsString
GetAddressFromObjectPath(const nsAString& aObjectPath);
bool
BroadcastSystemMessage(const nsAString& aType,
const InfallibleTArray<BluetoothNamedValue>& aData);
@ -37,10 +30,6 @@ DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable,
const BluetoothValue& aValue,
const nsAString& aErrorStr);
void
ParseAtCommand(const nsACString& aAtCommand, const int aStart,
nsTArray<nsCString>& aRetValues);
void
DispatchStatusChangedEvent(const nsAString& aType,
const nsAString& aDeviceAddress,