From b75b4537a5f0e1234109713d3008fe42b9a1bf85 Mon Sep 17 00:00:00 2001 From: Jocelyn Liu Date: Fri, 6 Mar 2015 17:21:00 +0800 Subject: [PATCH] Bug 1139298: Replace type int with BluetoothGattStatus enum for GATT client callbacks. r=btian --- dom/bluetooth2/BluetoothCommon.h | 5 ++ dom/bluetooth2/BluetoothInterface.h | 30 +++++----- .../bluedroid/BluetoothGattHALInterface.cpp | 57 ++++++++++--------- .../bluedroid/BluetoothGattManager.cpp | 42 ++++++++------ .../bluedroid/BluetoothGattManager.h | 33 ++++++----- .../bluedroid/BluetoothHALHelpers.h | 17 ++++++ 6 files changed, 109 insertions(+), 75 deletions(-) diff --git a/dom/bluetooth2/BluetoothCommon.h b/dom/bluetooth2/BluetoothCommon.h index 8439caaf0a0..d2945b3579e 100644 --- a/dom/bluetooth2/BluetoothCommon.h +++ b/dom/bluetooth2/BluetoothCommon.h @@ -534,6 +534,11 @@ struct BluetoothAvrcpPlayerSettings { uint8_t mValues[256]; }; +enum BluetoothGattStatus { + GATT_STATUS_SUCCESS, + GATT_STATUS_ERROR +}; + struct BluetoothGattAdvData { uint8_t mAdvData[62]; }; diff --git a/dom/bluetooth2/BluetoothInterface.h b/dom/bluetooth2/BluetoothInterface.h index 88537b14f5b..84b4f11369a 100644 --- a/dom/bluetooth2/BluetoothInterface.h +++ b/dom/bluetooth2/BluetoothInterface.h @@ -463,7 +463,7 @@ public: virtual ~BluetoothGattClientNotificationHandler(); virtual void - RegisterClientNotification(int aStatus, + RegisterClientNotification(BluetoothGattStatus aStatus, int aClientIf, const BluetoothUuid& aAppUuid) { } @@ -476,20 +476,20 @@ public: virtual void ConnectNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, int aClientIf, const nsAString& aBdAddr) { } virtual void DisconnectNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, int aClientIf, const nsAString& aBdAddr) { } virtual void - SearchCompleteNotification(int aConnId, int aStatus) { } + SearchCompleteNotification(int aConnId, BluetoothGattStatus aStatus) { } virtual void SearchResultNotification(int aConnId, const BluetoothGattServiceId& aServiceId) @@ -497,7 +497,7 @@ public: virtual void GetCharacteristicNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, const BluetoothGattServiceId& aServiceId, const BluetoothGattId& aCharId, int aCharProperty) @@ -505,7 +505,7 @@ public: virtual void GetDescriptorNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, const BluetoothGattServiceId& aServiceId, const BluetoothGattId& aCharId, const BluetoothGattId& aDescriptorId) @@ -513,7 +513,7 @@ public: virtual void GetIncludedServiceNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, const BluetoothGattServiceId& aServiceId, const BluetoothGattServiceId& aIncludedServId) { } @@ -521,7 +521,7 @@ public: virtual void RegisterNotificationNotification(int aConnId, int aIsRegister, - int aStatus, + BluetoothGattStatus aStatus, const BluetoothGattServiceId& aServiceId, const BluetoothGattId& aCharId) { } @@ -532,40 +532,40 @@ public: virtual void ReadCharacteristicNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, const BluetoothGattReadParam& aReadParam) { } virtual void WriteCharacteristicNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, const BluetoothGattWriteParam& aWriteParam) { } virtual void ReadDescriptorNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, const BluetoothGattReadParam& aReadParam) { } virtual void WriteDescriptorNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, const BluetoothGattWriteParam& aWriteParam) { } virtual void - ExecuteWriteNotification(int aConnId, int aStatus) { } + ExecuteWriteNotification(int aConnId, BluetoothGattStatus aStatus) { } virtual void ReadRemoteRssiNotification(int aClientIf, const nsAString& aBdAddr, int aRssi, - int aStatus) + BluetoothGattStatus aStatus) { } virtual void - ListenNotification(int aStatus, int aServerIf) { } + ListenNotification(BluetoothGattStatus aStatus, int aServerIf) { } protected: BluetoothGattClientNotificationHandler() diff --git a/dom/bluetooth2/bluedroid/BluetoothGattHALInterface.cpp b/dom/bluetooth2/bluedroid/BluetoothGattHALInterface.cpp index f6442566597..0adc7878feb 100644 --- a/dom/bluetooth2/bluedroid/BluetoothGattHALInterface.cpp +++ b/dom/bluetooth2/bluedroid/BluetoothGattHALInterface.cpp @@ -98,8 +98,8 @@ struct BluetoothGattClientCallback // GATT Client Notification typedef BluetoothNotificationHALRunnable3< GattClientNotificationHandlerWrapper, void, - int, int, BluetoothUuid, - int, int, const BluetoothUuid&> + BluetoothGattStatus, int, BluetoothUuid, + BluetoothGattStatus, int, const BluetoothUuid&> RegisterClientNotification; typedef BluetoothNotificationHALRunnable3< @@ -110,19 +110,19 @@ struct BluetoothGattClientCallback typedef BluetoothNotificationHALRunnable4< GattClientNotificationHandlerWrapper, void, - int, int, int, nsString, - int, int, int, const nsAString&> + int, BluetoothGattStatus, int, nsString, + int, BluetoothGattStatus, int, const nsAString&> ConnectNotification; typedef BluetoothNotificationHALRunnable4< GattClientNotificationHandlerWrapper, void, - int, int, int, nsString, - int, int, int, const nsAString&> + int, BluetoothGattStatus, int, nsString, + int, BluetoothGattStatus, int, const nsAString&> DisconnectNotification; typedef BluetoothNotificationHALRunnable2< GattClientNotificationHandlerWrapper, void, - int, int> + int, BluetoothGattStatus> SearchCompleteNotification; typedef BluetoothNotificationHALRunnable2< @@ -133,29 +133,32 @@ struct BluetoothGattClientCallback typedef BluetoothNotificationHALRunnable5< GattClientNotificationHandlerWrapper, void, - int, int, BluetoothGattServiceId, BluetoothGattId, int, - int, int, const BluetoothGattServiceId&, const BluetoothGattId&> + int, BluetoothGattStatus, BluetoothGattServiceId, + BluetoothGattId, int, + int, BluetoothGattStatus, const BluetoothGattServiceId&, + const BluetoothGattId&> GetCharacteristicNotification; typedef BluetoothNotificationHALRunnable5< GattClientNotificationHandlerWrapper, void, - int, int, BluetoothGattServiceId, + int, BluetoothGattStatus, BluetoothGattServiceId, BluetoothGattId, BluetoothGattId, - int, int, const BluetoothGattServiceId&, + int, BluetoothGattStatus, const BluetoothGattServiceId&, const BluetoothGattId&, const BluetoothGattId&> GetDescriptorNotification; typedef BluetoothNotificationHALRunnable4< GattClientNotificationHandlerWrapper, void, - int, int, BluetoothGattServiceId, BluetoothGattServiceId, - int, int, const BluetoothGattServiceId&, const BluetoothGattServiceId&> + int, BluetoothGattStatus, BluetoothGattServiceId, BluetoothGattServiceId, + int, BluetoothGattStatus, const BluetoothGattServiceId&, + const BluetoothGattServiceId&> GetIncludedServiceNotification; typedef BluetoothNotificationHALRunnable5< GattClientNotificationHandlerWrapper, void, - int, int, int, + int, int, BluetoothGattStatus, BluetoothGattServiceId, BluetoothGattId, - int, int, int, + int, int, BluetoothGattStatus, const BluetoothGattServiceId&, const BluetoothGattId&> RegisterNotificationNotification; @@ -167,42 +170,42 @@ struct BluetoothGattClientCallback typedef BluetoothNotificationHALRunnable3< GattClientNotificationHandlerWrapper, void, - int, int, BluetoothGattReadParam, - int, int, const BluetoothGattReadParam&> + int, BluetoothGattStatus, BluetoothGattReadParam, + int, BluetoothGattStatus, const BluetoothGattReadParam&> ReadCharacteristicNotification; typedef BluetoothNotificationHALRunnable3< GattClientNotificationHandlerWrapper, void, - int, int, BluetoothGattWriteParam, - int, int, const BluetoothGattWriteParam&> + int, BluetoothGattStatus, BluetoothGattWriteParam, + int, BluetoothGattStatus, const BluetoothGattWriteParam&> WriteCharacteristicNotification; typedef BluetoothNotificationHALRunnable3< GattClientNotificationHandlerWrapper, void, - int, int, BluetoothGattReadParam, - int, int, const BluetoothGattReadParam&> + int, BluetoothGattStatus, BluetoothGattReadParam, + int, BluetoothGattStatus, const BluetoothGattReadParam&> ReadDescriptorNotification; typedef BluetoothNotificationHALRunnable3< GattClientNotificationHandlerWrapper, void, - int, int, BluetoothGattWriteParam, - int, int, const BluetoothGattWriteParam&> + int, BluetoothGattStatus, BluetoothGattWriteParam, + int, BluetoothGattStatus, const BluetoothGattWriteParam&> WriteDescriptorNotification; typedef BluetoothNotificationHALRunnable2< GattClientNotificationHandlerWrapper, void, - int, int> + int, BluetoothGattStatus> ExecuteWriteNotification; typedef BluetoothNotificationHALRunnable4< GattClientNotificationHandlerWrapper, void, - int, nsString, int, int, - int, const nsAString&, int, int> + int, nsString, int, BluetoothGattStatus, + int, const nsAString&, int, BluetoothGattStatus> ReadRemoteRssiNotification; typedef BluetoothNotificationHALRunnable2< GattClientNotificationHandlerWrapper, void, - int, int> + BluetoothGattStatus, int> ListenNotification; // Bluedroid GATT client callbacks diff --git a/dom/bluetooth2/bluedroid/BluetoothGattManager.cpp b/dom/bluetooth2/bluedroid/BluetoothGattManager.cpp index f197ee0cc46..510e62a9989 100644 --- a/dom/bluetooth2/bluedroid/BluetoothGattManager.cpp +++ b/dom/bluetooth2/bluedroid/BluetoothGattManager.cpp @@ -488,7 +488,7 @@ BluetoothGattManager::Disconnect(const nsAString& aAppUuid, // Notification Handlers // void -BluetoothGattManager::RegisterClientNotification(int aStatus, +BluetoothGattManager::RegisterClientNotification(BluetoothGattStatus aStatus, int aClientIf, const BluetoothUuid& aAppUuid) { @@ -505,7 +505,7 @@ BluetoothGattManager::RegisterClientNotification(int aStatus, BluetoothService* bs = BluetoothService::Get(); NS_ENSURE_TRUE_VOID(bs); - if (aStatus) { // operation failed + if (aStatus != GATT_STATUS_SUCCESS) { BT_API2_LOGR( "RegisterClient failed, clientIf = %d, status = %d, appUuid = %s", aClientIf, aStatus, NS_ConvertUTF16toUTF8(uuid).get()); @@ -550,7 +550,7 @@ BluetoothGattManager::ScanResultNotification( void BluetoothGattManager::ConnectNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, int aClientIf, const nsAString& aDeviceAddr) { @@ -565,7 +565,7 @@ BluetoothGattManager::ConnectNotification(int aConnId, NS_ENSURE_TRUE_VOID(index != sClients->NoIndex); nsRefPtr client = sClients->ElementAt(index); - if (aStatus) { // operation failed + if (aStatus != GATT_STATUS_SUCCESS) { BT_API2_LOGR("Connect failed, clientIf = %d, connId = %d, status = %d", aClientIf, aConnId, aStatus); @@ -602,7 +602,7 @@ BluetoothGattManager::ConnectNotification(int aConnId, void BluetoothGattManager::DisconnectNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, int aClientIf, const nsAString& aDeviceAddr) { @@ -617,7 +617,7 @@ BluetoothGattManager::DisconnectNotification(int aConnId, NS_ENSURE_TRUE_VOID(index != sClients->NoIndex); nsRefPtr client = sClients->ElementAt(index); - if (aStatus) { // operation failed + if (aStatus != GATT_STATUS_SUCCESS) { // Notify BluetoothGatt that the client remains connected bs->DistributeSignal( NS_LITERAL_STRING(GATT_CONNECTION_STATE_CHANGED_ID), @@ -650,7 +650,8 @@ BluetoothGattManager::DisconnectNotification(int aConnId, } void -BluetoothGattManager::SearchCompleteNotification(int aConnId, int aStatus) +BluetoothGattManager::SearchCompleteNotification(int aConnId, + BluetoothGattStatus aStatus) { } void @@ -660,7 +661,7 @@ BluetoothGattManager::SearchResultNotification( void BluetoothGattManager::GetCharacteristicNotification( - int aConnId, int aStatus, + int aConnId, BluetoothGattStatus aStatus, const BluetoothGattServiceId& aServiceId, const BluetoothGattId& aCharId, int aCharProperty) @@ -668,7 +669,7 @@ BluetoothGattManager::GetCharacteristicNotification( void BluetoothGattManager::GetDescriptorNotification( - int aConnId, int aStatus, + int aConnId, BluetoothGattStatus aStatus, const BluetoothGattServiceId& aServiceId, const BluetoothGattId& aCharId, const BluetoothGattId& aDescriptorId) @@ -676,14 +677,14 @@ BluetoothGattManager::GetDescriptorNotification( void BluetoothGattManager::GetIncludedServiceNotification( - int aConnId, int aStatus, + int aConnId, BluetoothGattStatus aStatus, const BluetoothGattServiceId& aServiceId, const BluetoothGattServiceId& aIncludedServId) { } void BluetoothGattManager::RegisterNotificationNotification( - int aConnId, int aIsRegister, int aStatus, + int aConnId, int aIsRegister, BluetoothGattStatus aStatus, const BluetoothGattServiceId& aServiceId, const BluetoothGattId& aCharId) { } @@ -695,37 +696,42 @@ BluetoothGattManager::NotifyNotification( void BluetoothGattManager::ReadCharacteristicNotification( - int aConnId, int aStatus, const BluetoothGattReadParam& aReadParam) + int aConnId, BluetoothGattStatus aStatus, + const BluetoothGattReadParam& aReadParam) { } void BluetoothGattManager::WriteCharacteristicNotification( - int aConnId, int aStatus, const BluetoothGattWriteParam& aWriteParam) + int aConnId, BluetoothGattStatus aStatus, + const BluetoothGattWriteParam& aWriteParam) { } void BluetoothGattManager::ReadDescriptorNotification( - int aConnId, int aStatus, const BluetoothGattReadParam& aReadParam) + int aConnId, BluetoothGattStatus aStatus, + const BluetoothGattReadParam& aReadParam) { } void BluetoothGattManager::WriteDescriptorNotification( - int aConnId, int aStatus, const BluetoothGattWriteParam& aWriteParam) + int aConnId, BluetoothGattStatus aStatus, + const BluetoothGattWriteParam& aWriteParam) { } void -BluetoothGattManager::ExecuteWriteNotification(int aConnId, int aStatus) +BluetoothGattManager::ExecuteWriteNotification(int aConnId, + BluetoothGattStatus aStatus) { } void BluetoothGattManager::ReadRemoteRssiNotification(int aClientIf, const nsAString& aBdAddr, int aRssi, - int aStatus) + BluetoothGattStatus aStatus) { } void -BluetoothGattManager::ListenNotification(int aStatus, +BluetoothGattManager::ListenNotification(BluetoothGattStatus aStatus, int aServerIf) { } diff --git a/dom/bluetooth2/bluedroid/BluetoothGattManager.h b/dom/bluetooth2/bluedroid/BluetoothGattManager.h index 8af8b5f5d99..f5d7336c6cf 100644 --- a/dom/bluetooth2/bluedroid/BluetoothGattManager.h +++ b/dom/bluetooth2/bluedroid/BluetoothGattManager.h @@ -51,7 +51,7 @@ private: void HandleShutdown(); - void RegisterClientNotification(int aStatus, + void RegisterClientNotification(BluetoothGattStatus aStatus, int aClientIf, const BluetoothUuid& aAppUuid) MOZ_OVERRIDE; @@ -60,40 +60,41 @@ private: const BluetoothGattAdvData& aAdvData) MOZ_OVERRIDE; void ConnectNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, int aClientIf, const nsAString& aBdAddr) MOZ_OVERRIDE; void DisconnectNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, int aClientIf, const nsAString& aBdAddr) MOZ_OVERRIDE; - void SearchCompleteNotification(int aConnId, int aStatus) MOZ_OVERRIDE; + void SearchCompleteNotification(int aConnId, + BluetoothGattStatus aStatus) MOZ_OVERRIDE; void SearchResultNotification(int aConnId, const BluetoothGattServiceId& aServiceId) MOZ_OVERRIDE; void GetCharacteristicNotification( - int aConnId, int aStatus, + int aConnId, BluetoothGattStatus aStatus, const BluetoothGattServiceId& aServiceId, const BluetoothGattId& aCharId, int aCharProperty) MOZ_OVERRIDE; void GetDescriptorNotification( - int aConnId, int aStatus, + int aConnId, BluetoothGattStatus aStatus, const BluetoothGattServiceId& aServiceId, const BluetoothGattId& aCharId, const BluetoothGattId& aDescriptorId) MOZ_OVERRIDE; void GetIncludedServiceNotification( - int aConnId, int aStatus, + int aConnId, BluetoothGattStatus aStatus, const BluetoothGattServiceId& aServiceId, const BluetoothGattServiceId& aIncludedServId) MOZ_OVERRIDE; void RegisterNotificationNotification( - int aConnId, int aIsRegister, int aStatus, + int aConnId, int aIsRegister, BluetoothGattStatus aStatus, const BluetoothGattServiceId& aServiceId, const BluetoothGattId& aCharId) MOZ_OVERRIDE; @@ -102,32 +103,34 @@ private: MOZ_OVERRIDE; void ReadCharacteristicNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, const BluetoothGattReadParam& aReadParam) MOZ_OVERRIDE; void WriteCharacteristicNotification( - int aConnId, int aStatus, + int aConnId, BluetoothGattStatus aStatus, const BluetoothGattWriteParam& aWriteParam) MOZ_OVERRIDE; void ReadDescriptorNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, const BluetoothGattReadParam& aReadParam) MOZ_OVERRIDE; void WriteDescriptorNotification(int aConnId, - int aStatus, + BluetoothGattStatus aStatus, const BluetoothGattWriteParam& aWriteParam) MOZ_OVERRIDE; - void ExecuteWriteNotification(int aConnId, int aStatus) MOZ_OVERRIDE; + void ExecuteWriteNotification(int aConnId, + BluetoothGattStatus aStatus) MOZ_OVERRIDE; void ReadRemoteRssiNotification(int aClientIf, const nsAString& aBdAddr, int aRssi, - int aStatus) MOZ_OVERRIDE; + BluetoothGattStatus aStatus) MOZ_OVERRIDE; - void ListenNotification(int aStatus, int aServerIf) MOZ_OVERRIDE; + void ListenNotification(BluetoothGattStatus aStatus, + int aServerIf) MOZ_OVERRIDE; static bool mInShutdown; }; diff --git a/dom/bluetooth2/bluedroid/BluetoothHALHelpers.h b/dom/bluetooth2/bluedroid/BluetoothHALHelpers.h index 90aaf2bf8bc..2be8fba2077 100644 --- a/dom/bluetooth2/bluedroid/BluetoothHALHelpers.h +++ b/dom/bluetooth2/bluedroid/BluetoothHALHelpers.h @@ -766,6 +766,23 @@ Convert(btrc_remote_features_t aIn, unsigned long& aOut) } #endif // ANDROID_VERSION >= 19 +inline nsresult +Convert(int aIn, BluetoothGattStatus& aOut) +{ + /** + * Currently we only map bluedroid's GATT status into GATT_STATUS_SUCCESS and + * GATT_STATUS_ERROR. This function needs to be revised if we want to support + * specific error status. + */ + if (!aIn) { + aOut = GATT_STATUS_SUCCESS; + } else { + aOut = GATT_STATUS_ERROR; + } + + return NS_OK; +} + nsresult Convert(const uint8_t* aIn, BluetoothGattAdvData& aOut);