From 5af2a5023be6b0aad02e40612a40b3a0499bf423 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Fri, 28 Nov 2014 11:49:40 +0100 Subject: [PATCH] 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. --- dom/bluetooth/bluez/BluetoothDBusService.cpp | 31 ++++++++++++ dom/bluetooth/bluez/BluetoothHfpManager.cpp | 22 +++++++++ dom/bluetooth/bluez/BluetoothHfpManager.h | 3 ++ dom/bluetooth/bluez/BluetoothUtils.cpp | 52 -------------------- dom/bluetooth/bluez/BluetoothUtils.h | 11 ----- 5 files changed, 56 insertions(+), 63 deletions(-) diff --git a/dom/bluetooth/bluez/BluetoothDBusService.cpp b/dom/bluetooth/bluez/BluetoothDBusService.cpp index 838e62941e32..f4abdef747fc 100644 --- a/dom/bluetooth/bluez/BluetoothDBusService.cpp +++ b/dom/bluetooth/bluez/BluetoothDBusService.cpp @@ -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) { diff --git a/dom/bluetooth/bluez/BluetoothHfpManager.cpp b/dom/bluetooth/bluez/BluetoothHfpManager.cpp index e6b3e5c0fd17..9460d11b361c 100644 --- a/dom/bluetooth/bluez/BluetoothHfpManager.cpp +++ b/dom/bluetooth/bluez/BluetoothHfpManager.cpp @@ -690,6 +690,28 @@ BluetoothHfpManager::HandleShutdown() sBluetoothHfpManager = nullptr; } +void +BluetoothHfpManager::ParseAtCommand(const nsACString& aAtCommand, + const int aStart, + nsTArray& 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, diff --git a/dom/bluetooth/bluez/BluetoothHfpManager.h b/dom/bluetooth/bluez/BluetoothHfpManager.h index 2de35b57a22f..2a96fec639a7 100644 --- a/dom/bluetooth/bluez/BluetoothHfpManager.h +++ b/dom/bluetooth/bluez/BluetoothHfpManager.h @@ -132,6 +132,9 @@ public: #endif private: + void ParseAtCommand(const nsACString& aAtCommand, const int aStart, + nsTArray& aRetValues); + class CloseScoTask; class GetVolumeTask; #ifdef MOZ_B2G_RIL diff --git a/dom/bluetooth/bluez/BluetoothUtils.cpp b/dom/bluetooth/bluez/BluetoothUtils.cpp index d4120082d9ea..4440750856fd 100644 --- a/dom/bluetooth/bluez/BluetoothUtils.cpp +++ b/dom/bluetooth/bluez/BluetoothUtils.cpp @@ -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& aData) @@ -154,27 +123,6 @@ DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable, } } -void -ParseAtCommand(const nsACString& aAtCommand, const int aStart, - nsTArray& 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, diff --git a/dom/bluetooth/bluez/BluetoothUtils.h b/dom/bluetooth/bluez/BluetoothUtils.h index 2156207f1d4f..e9fd38176376 100644 --- a/dom/bluetooth/bluez/BluetoothUtils.h +++ b/dom/bluetooth/bluez/BluetoothUtils.h @@ -21,13 +21,6 @@ SetJsObject(JSContext* aContext, const BluetoothValue& aValue, JS::Handle aObj); -nsString -GetObjectPathFromAddress(const nsAString& aAdapterPath, - const nsAString& aDeviceAddress); - -nsString -GetAddressFromObjectPath(const nsAString& aObjectPath); - bool BroadcastSystemMessage(const nsAString& aType, const InfallibleTArray& aData); @@ -37,10 +30,6 @@ DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable, const BluetoothValue& aValue, const nsAString& aErrorStr); -void -ParseAtCommand(const nsACString& aAtCommand, const int aStart, - nsTArray& aRetValues); - void DispatchStatusChangedEvent(const nsAString& aType, const nsAString& aDeviceAddress,