diff --git a/interfaces/innerkits/native_cpp/c_adapter/ohos_bt_gatt.cpp b/interfaces/innerkits/native_cpp/c_adapter/ohos_bt_gatt.cpp index 1f9fee925f02705f440a59055a0e6ac09d44cb26..0788e7372804089bdf154f74698d283095ab9cea 100644 --- a/interfaces/innerkits/native_cpp/c_adapter/ohos_bt_gatt.cpp +++ b/interfaces/innerkits/native_cpp/c_adapter/ohos_bt_gatt.cpp @@ -106,28 +106,54 @@ public: class BleAdvCallback : public BleAdvertiseCallback { public: - BleAdvCallback(BleAdvertiser *handle) { + BleAdvCallback(BleAdvertiser *handle, int advId) { advHandle = handle; - } - - ~BleAdvCallback() { - delete advHandle; + isStarted = false; + advId_ = advId; } void OnStartResultEvent(int result) { + if (result != 0) { + HILOGE("result : %{public}d", result); + return; + } + if (isStarted) { + HILOGI("adv stoped."); + isStarted = false; + if (g_AppCallback != NULL && g_AppCallback->advDisableCb != NULL) { + HILOGI("adv stoped advId_: %{public}d.", advId_); + g_AppCallback->advDisableCb(advId_, 0); + } + g_BleAdvCallbacks[advId_] = NULL; + HILOGI("g_BleAdvCallbacks[%{public}d] = %{public}p.", advId_, g_BleAdvCallbacks[advId_]); + delete this; + } else { + HILOGI("adv started."); + isStarted = true; + if (g_AppCallback != NULL && g_AppCallback->advEnableCb != NULL) { + g_AppCallback->advEnableCb(advId_, 0); + } + + } } BleAdvertiser *GetAdvHandle() { return advHandle; } protected: + ~BleAdvCallback() { + delete advHandle; + } + BleAdvertiserData *advData; BleAdvertiserData *advResponseData; BleAdvertiserSettings *advSetting; private: BleAdvertiser *advHandle; + bool isStarted; + int advId_; }; /** @@ -216,9 +242,6 @@ int BleStopAdv(int advId) { if (advId >= 0 && advId < MAX_BLE_ADV_NUM) { g_BleAdvCallbacks[advId]->GetAdvHandle()->StopAdvertising(*g_BleAdvCallbacks[advId]); - g_BleAdvCallbacks[advId]->GetAdvHandle()->Close(*g_BleAdvCallbacks[advId]); - delete g_BleAdvCallbacks[advId]; - g_BleAdvCallbacks[advId] = NULL; } return OHOS_BT_STATUS_SUCCESS; } @@ -375,9 +398,10 @@ int BleStartAdvEx(int *advId, const StartAdvRawData rawData, BleAdvParams advPar int i = 0; for (i = 0; i < MAX_BLE_ADV_NUM; i++) { if (g_BleAdvCallbacks[i] == NULL) { - g_BleAdvCallbacks[i] = new BleAdvCallback(new BleAdvertiser()); + g_BleAdvCallbacks[i] = new BleAdvCallback(new BleAdvertiser(), i); break; } + HILOGI("g_BleAdvCallbacks[%{public}d] = %{public}p.", i, g_BleAdvCallbacks[i]); } if (i == MAX_BLE_ADV_NUM) { diff --git a/interfaces/innerkits/native_cpp/framework/include/bluetooth_observer_map.h b/interfaces/innerkits/native_cpp/framework/include/bluetooth_observer_map.h index b1c58065a5c3425bb0c5ed14dbcacbe90cac2590..22abc005a00c043e8920348fc88fb3e934282f2b 100644 --- a/interfaces/innerkits/native_cpp/framework/include/bluetooth_observer_map.h +++ b/interfaces/innerkits/native_cpp/framework/include/bluetooth_observer_map.h @@ -33,6 +33,7 @@ public: void ForEach(const std::function &observer, int handle); uint8_t GetAdvertiserHandle(T *observer); + T *PopAdvertiserObserver(uint8_t advHandle); T *GetAdvertiserObserver(uint8_t advHandle); bool IsExistAdvertiserCallback(T *observer, int &handle); @@ -102,6 +103,7 @@ void BluetoothObserverMap::ForEach(const std::function &o template uint8_t BluetoothObserverMap::GetAdvertiserHandle(T *observer) { + std::lock_guard lock(lock_); uint8_t advHandle = bluetooth::BLE_INVALID_ADVERTISING_HANDLE; if (observer == nullptr) { return advHandle; @@ -118,9 +120,26 @@ uint8_t BluetoothObserverMap::GetAdvertiserHandle(T *observer) return advHandle; } +template +T *BluetoothObserverMap::PopAdvertiserObserver(uint8_t advHandle) +{ + std::lock_guard lock(lock_); + T *t = nullptr; + auto it = observers_.begin(); + for (; it != observers_.end(); it++) { + if (it->first == advHandle) { + t = it->second; + observers_.erase(it++); + break; + } + } + return t; +} + template T *BluetoothObserverMap::GetAdvertiserObserver(uint8_t advHandle) { + std::lock_guard lock(lock_); auto it = observers_.begin(); for (; it != observers_.end(); it++) { if (it->first == advHandle) { diff --git a/interfaces/innerkits/native_cpp/framework/src/bluetooth_ble_advertiser.cpp b/interfaces/innerkits/native_cpp/framework/src/bluetooth_ble_advertiser.cpp index 0b0edc2ed70d81add3182e9ef065cf67f7e8a289..41415831c5f169f96d6ca67f5766c3d09ce66cdf 100644 --- a/interfaces/innerkits/native_cpp/framework/src/bluetooth_ble_advertiser.cpp +++ b/interfaces/innerkits/native_cpp/framework/src/bluetooth_ble_advertiser.cpp @@ -40,18 +40,16 @@ struct BleAdvertiser::impl { void OnStartResultEvent(int32_t result, int32_t advHandle, int32_t opcode) override { HILOGD("BleAdvertiser::impl::BluetoothBleAdvertiserCallbackImp::OnStartResultEvent"); - bleAdvertiser_.callbacks_.ForEach( - [result, advHandle](int32_t handle, BleAdvertiseCallback *observer) { - if (advHandle == handle) { - observer->OnStartResultEvent(result); - } - }, - advHandle); - if ((opcode == BLE_ADV_STOP_COMPLETE_OP_CODE && result == 0) || opcode == BLE_ADV_START_FAILED_OP_CODE) { - BleAdvertiseCallback *observer = bleAdvertiser_.callbacks_.GetAdvertiserObserver(advHandle); - if (observer != nullptr) { - bleAdvertiser_.callbacks_.Deregister(observer); - } + BleAdvertiseCallback *observer = nullptr; + if ((opcode == bluetooth::BLE_ADV_STOP_COMPLETE_OP_CODE && result == 0) || + (opcode == bluetooth::BLE_ADV_START_FAILED_OP_CODE)) { + observer = bleAdvertiser_.callbacks_.PopAdvertiserObserver(advHandle); + } else { + observer = bleAdvertiser_.callbacks_.GetAdvertiserObserver(advHandle); + } + + if (observer != nullptr) { + observer->OnStartResultEvent(result); } } @@ -76,6 +74,7 @@ struct BleAdvertiser::impl { BleAdvertiser::impl::impl() { + HILOGE("BleAdvertiser::impl::impl()"); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!samgr) { HILOGE("BleAdvertiser::impl::impl() error: no samgr"); @@ -217,7 +216,7 @@ void BleAdvertiser::StartAdvertising(const BleAdvertiserSettings &settings, cons void BleAdvertiser::StopAdvertising(BleAdvertiseCallback &callback) { - HILOGD("BleAdvertiser::StartAdvertising"); + HILOGD("BleAdvertiser::StopAdvertising"); if (pimpl->proxy_ != nullptr) { uint8_t advHandle = pimpl->callbacks_.GetAdvertiserHandle(&callback); if (advHandle == BLE_INVALID_ADVERTISING_HANDLE) { @@ -230,9 +229,17 @@ void BleAdvertiser::StopAdvertising(BleAdvertiseCallback &callback) void BleAdvertiser::Close(BleAdvertiseCallback &callback) { + HILOGD("BleAdvertiser::Close"); if (pimpl->proxy_ != nullptr) { uint8_t advHandle = pimpl->callbacks_.GetAdvertiserHandle(&callback); - pimpl->proxy_->Close(advHandle); + if (advHandle != BLE_INVALID_ADVERTISING_HANDLE) { + pimpl->proxy_->Close(advHandle); + } + + BleAdvertiseCallback *observer = pimpl->callbacks_.GetAdvertiserObserver(advHandle); + if (observer != nullptr) { + pimpl->callbacks_.Deregister(observer); + } } } diff --git a/interfaces/innerkits/native_cpp/framework/src/bluetooth_gatt_client.cpp b/interfaces/innerkits/native_cpp/framework/src/bluetooth_gatt_client.cpp index 2e15db29569837b221f489ef28a46e83fb3caf0b..53b51f7dc1526a6ce1bb85bbae1858963122f3f0 100644 --- a/interfaces/innerkits/native_cpp/framework/src/bluetooth_gatt_client.cpp +++ b/interfaces/innerkits/native_cpp/framework/src/bluetooth_gatt_client.cpp @@ -649,7 +649,7 @@ int GattClient::WriteCharacteristic(GattCharacteristic &characteristic) } result = pimpl->proxy_->SignedWriteCharacteristic(pimpl->applicationId_, &character); } else { - withoutRespond = (characteristic.GetWriteType() == (int)GattCharacteristic::WriteType::DEFAULT ? false : true); + withoutRespond = ((characteristic.GetWriteType() == (int)GattCharacteristic::WriteType::DEFAULT) ? false : true); if (!pimpl->proxy_) { HILOGI("GattClient::WriteCharacteristic() proxy_ is null when used!"); return GattStatus::GATT_FAILURE; diff --git a/interfaces/innerkits/native_cpp/framework/src/bluetooth_gatt_descriptor.cpp b/interfaces/innerkits/native_cpp/framework/src/bluetooth_gatt_descriptor.cpp index 18f25640d2263f04939978f3485fc961e1cbca37..3512c180aab98541346ea9017ecff67d43253934 100644 --- a/interfaces/innerkits/native_cpp/framework/src/bluetooth_gatt_descriptor.cpp +++ b/interfaces/innerkits/native_cpp/framework/src/bluetooth_gatt_descriptor.cpp @@ -32,7 +32,7 @@ GattDescriptor::GattDescriptor(const GattDescriptor &src) length_(src.length_), uuid_(src.uuid_) { - if (0 != length_ && nullptr != src.value_) { + if (length_ != 0 && src.value_ != nullptr) { value_ = std::make_unique(length_); memcpy(value_.get(), src.value_.get(), length_); } else { @@ -50,7 +50,7 @@ GattDescriptor &GattDescriptor::operator=(const GattDescriptor &src) characteristic_ = src.characteristic_; length_ = src.length_; - if (0 != length_ && nullptr != src.value_) { + if (length_ != 0 && src.value_ != nullptr) { value_ = std::make_unique(length_); memcpy(value_.get(), src.value_.get(), length_); } else { @@ -84,7 +84,7 @@ const std::unique_ptr &GattDescriptor::GetValue(size_t *size) const void GattDescriptor::SetValue(const uint8_t *values, const size_t length) { - if (0 == length || nullptr == values) { + if (length == 0 || values == nullptr) { return; } value_ = std::make_unique(length); diff --git a/interfaces/innerkits/native_cpp/framework/src/bluetooth_gatt_server.cpp b/interfaces/innerkits/native_cpp/framework/src/bluetooth_gatt_server.cpp index 0682133ee3ff661011c174708828528cee2f7c6a..b2443eb3bb9725f30faa1f57c047c3f4241b8ca0 100644 --- a/interfaces/innerkits/native_cpp/framework/src/bluetooth_gatt_server.cpp +++ b/interfaces/innerkits/native_cpp/framework/src/bluetooth_gatt_server.cpp @@ -29,6 +29,7 @@ namespace OHOS { namespace Bluetooth { +#define EIGHT_BITS 8 std::string GattServerServiceName = "bluetooth-gatt-server-server"; constexpr uint8_t REQUEST_TYPE_CHARACTERISTICS_READ = 0x00; @@ -132,7 +133,7 @@ public: } server_.pimpl->callback_.OnCharacteristicReadRequest( BluetoothRemoteDevice(device.addr_.GetAddress(), - (device.transport_ == GATT_TRANSPORT_TYPE_LE ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR)), + (device.transport_ == GATT_TRANSPORT_TYPE_LE) ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR), gattcharacter.value().get(), server_.pimpl->BuildRequestId(REQUEST_TYPE_CHARACTERISTICS_READ, device.transport_)); return; @@ -160,7 +161,7 @@ public: server_.pimpl->callback_.OnCharacteristicWriteRequest( BluetoothRemoteDevice(device.addr_.GetAddress(), - (device.transport_ == GATT_TRANSPORT_TYPE_LE ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR)), + (device.transport_ == GATT_TRANSPORT_TYPE_LE) ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR), gattcharacter.value().get(), server_.pimpl->BuildRequestId(REQUEST_TYPE_CHARACTERISTICS_WRITE, device.transport_)); return; @@ -183,7 +184,7 @@ public: } server_.pimpl->callback_.OnDescriptorReadRequest( BluetoothRemoteDevice(device.addr_.GetAddress(), - (device.transport_ == GATT_TRANSPORT_TYPE_LE ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR)), + (device.transport_ == GATT_TRANSPORT_TYPE_LE) ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR), gattdesc.value().get(), server_.pimpl->BuildRequestId(REQUEST_TYPE_DESCRIPTOR_READ, device.transport_)); return; @@ -208,7 +209,7 @@ public: } server_.pimpl->callback_.OnDescriptorWriteRequest( BluetoothRemoteDevice(device.addr_.GetAddress(), - (device.transport_ == GATT_TRANSPORT_TYPE_LE ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR)), + (device.transport_ == GATT_TRANSPORT_TYPE_LE) ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR), gattdesc.value().get(), server_.pimpl->BuildRequestId(REQUEST_TYPE_DESCRIPTOR_WRITE, device.transport_)); return; @@ -223,7 +224,7 @@ public: { server_.pimpl->callback_.OnNotificationCharacteristicChanged( BluetoothRemoteDevice(device.addr_.GetAddress(), - (device.transport_ == GATT_TRANSPORT_TYPE_LE ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR)), + (device.transport_ == GATT_TRANSPORT_TYPE_LE) ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR), result); return; } @@ -245,7 +246,7 @@ public: server_.pimpl->callback_.OnConnectionStateUpdate( BluetoothRemoteDevice(device.addr_.GetAddress(), - (device.transport_ == GATT_TRANSPORT_TYPE_LE ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR)), + (device.transport_ == GATT_TRANSPORT_TYPE_LE) ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR), state); return; @@ -255,7 +256,7 @@ public: { server_.pimpl->callback_.OnMtuUpdate( BluetoothRemoteDevice(device.addr_.GetAddress(), - (device.transport_ == GATT_TRANSPORT_TYPE_LE ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR)), + (device.transport_ == GATT_TRANSPORT_TYPE_LE) ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR), mtu); return; } @@ -281,7 +282,7 @@ public: { server_.pimpl->callback_.OnConnectionParameterChanged( BluetoothRemoteDevice(device.addr_.GetAddress(), - (device.transport_ == GATT_TRANSPORT_TYPE_LE ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR)), + (device.transport_ == GATT_TRANSPORT_TYPE_LE) ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR), interval, latency, timeout, @@ -415,7 +416,7 @@ bluetooth::GattDevice *GattServer::impl::FindConnectedDevice(const BluetoothRemo for (auto &gattDevice : devices_) { if (device.GetDeviceAddr().compare(gattDevice.addr_.GetAddress()) == 0 && (device.GetTransportType() == - (gattDevice.transport_ == GATT_TRANSPORT_TYPE_LE ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR))) { + (gattDevice.transport_ == GATT_TRANSPORT_TYPE_LE) ? BT_TRANSPORT_BLE : BT_TRANSPORT_BREDR)) { return &gattDevice; } } @@ -439,7 +440,7 @@ int GattServer::impl::BuildRequestId(uint8_t type, uint8_t transport) { int requestId = 0; - requestId = type << 8; + requestId = type << EIGHT_BITS; requestId |= transport; return requestId; @@ -658,7 +659,7 @@ int GattServer::SendResponse( } int result = GattStatus::INVALID_PARAMETER; - uint8_t requestType = requestId >> 8; + uint8_t requestType = requestId >> EIGHT_BITS; uint8_t transport = requestId & 0xFF; if (transport != GATT_TRANSPORT_TYPE_CLASSIC && transport != GATT_TRANSPORT_TYPE_LE) { return result; diff --git a/interfaces/innerkits/native_cpp/framework/test/unittest/ble/ble_test.cpp b/interfaces/innerkits/native_cpp/framework/test/unittest/ble/ble_test.cpp index 0cf2dd5854ebefc3d7287fcccd172e536c49010c..168d17fb714753cb177b7ff165f06c7ee176e72c 100644 --- a/interfaces/innerkits/native_cpp/framework/test/unittest/ble/ble_test.cpp +++ b/interfaces/innerkits/native_cpp/framework/test/unittest/ble/ble_test.cpp @@ -21,12 +21,11 @@ namespace OHOS { namespace Bluetooth { - BleTest *BleTest::bleInstance_ = nullptr; - namespace { - const static int defaultInt = 150; +const static int INTERVAL = 350; +const static int MAX_ADV_LENGTH = 1650; Bluetooth::UUID g_uuid = Bluetooth::UUID::FromString("00000000-0000-1000-8000-00805F9B34FB"); Bluetooth::UUID g_serviceDataUuid = Bluetooth::UUID::FromString("00000000-0000-1000-8000-00805F9B34FA"); std::string g_serviceData = "123"; @@ -37,14 +36,13 @@ std::mutex g_mx; std::condition_variable g_cv; bool g_ready = false; int g_wait_time = 3; - } // namespace void BleTest::InitAdvertiseSettings() { BleTest::bleInstance_->bleAdvertiserSettings_.SetConnectable(true); BleTest::bleInstance_->bleAdvertiserSettings_.SetLegacyMode(true); - BleTest::bleInstance_->bleAdvertiserSettings_.SetInterval(350); + BleTest::bleInstance_->bleAdvertiserSettings_.SetInterval(INTERVAL); BleTest::bleInstance_->bleAdvertiserSettings_.SetTxPower(BLE_ADV_TX_POWER_LEVEL::BLE_ADV_TX_POWER_MEDIUM); BleTest::bleInstance_->bleAdvertiserSettings_.SetPrimaryPhy(PHY_TYPE::PHY_LE_ALL_SUPPORTED); BleTest::bleInstance_->bleAdvertiserSettings_.SetSecondaryPhy(PHY_TYPE::PHY_LE_2M); @@ -202,7 +200,7 @@ HWTEST_F(BleTest, BLE_ModuleTest_StartAdvertising_00100, TestSize.Level1) bleAdvertise.StartAdvertising( BleTest::bleInstance_->bleAdvertiserSettings_, advData1, scanData1, bleAdvertiseCallbackTest_); bleAdvertise.StopAdvertising(bleAdvertiseCallbackTest_); - EXPECT_EQ(1650, host_->GetBleMaxAdvertisingDataLength()); + EXPECT_EQ(MAX_ADV_LENGTH, host_->GetBleMaxAdvertisingDataLength()); bleAdvertise.Close(bleAdvertiseCallbackTest_); EXPECT_TRUE(DisableBle()); @@ -215,7 +213,7 @@ HWTEST_F(BleTest, BLE_ModuleTest_StartAdvertising_00200, TestSize.Level1) BleTest::bleInstance_->InitAdvertiseSettings(); EXPECT_TRUE(BleTest::bleInstance_->bleAdvertiserSettings_.IsConnectable()); EXPECT_TRUE(BleTest::bleInstance_->bleAdvertiserSettings_.IsLegacyMode()); - EXPECT_EQ((uint16_t)350, BleTest::bleInstance_->bleAdvertiserSettings_.GetInterval()); + EXPECT_EQ((uint16_t)INTERVAL, BleTest::bleInstance_->bleAdvertiserSettings_.GetInterval()); EXPECT_EQ( BLE_ADV_TX_POWER_LEVEL::BLE_ADV_TX_POWER_MEDIUM, BleTest::bleInstance_->bleAdvertiserSettings_.GetTxPower()); EXPECT_EQ(PHY_TYPE::PHY_LE_ALL_SUPPORTED, BleTest::bleInstance_->bleAdvertiserSettings_.GetPrimaryPhy()); @@ -259,6 +257,5 @@ HWTEST_F(BleTest, BLE_ModuleTest_StartCentralManager_00200, TestSize.Level1) EXPECT_EQ(PHY_TYPE::PHY_LE_ALL_SUPPORTED, BleTest::bleInstance_->bleScanSettings_.GetPhy()); GTEST_LOG_(INFO) << "BLE_ModuleTest_StartCentralManager_00200 end"; } - } // namespace Bluetooth } // namespace OHOS diff --git a/interfaces/innerkits/native_cpp/framework/test/unittest/ble/ble_test.h b/interfaces/innerkits/native_cpp/framework/test/unittest/ble/ble_test.h index d0d8006c308e024e1dd01493c6878a9da7b7ab14..39ee70d7cdd648116101dc3ac9f4098f416bbc6d 100644 --- a/interfaces/innerkits/native_cpp/framework/test/unittest/ble/ble_test.h +++ b/interfaces/innerkits/native_cpp/framework/test/unittest/ble/ble_test.h @@ -20,7 +20,6 @@ namespace OHOS { namespace Bluetooth { - using namespace testing::ext; class BleAdvertiseCallbackTest : public Bluetooth::BleAdvertiseCallback { @@ -98,6 +97,5 @@ public: private: bool isHaveUuid = false; }; - } // namespace Bluetooth } // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_client_test.cpp b/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_client_test.cpp index a119e40a6ead255009ca4e42b8ec792561c60b6a..071043d821b4412ff9fdfd932577d8e2d751af72 100644 --- a/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_client_test.cpp +++ b/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_client_test.cpp @@ -28,7 +28,6 @@ using namespace bluetooth; namespace OHOS { namespace Bluetooth { - class GattClientCallbackTest : public GattClientCallback { public: GattClientCallbackTest() @@ -307,6 +306,5 @@ HWTEST_F(GattClientTest, GattClient_ModuleTest_RequestConnectionPriority, TestSi EXPECT_EQ(result, (int)bluetooth::GattStatus::GATT_SUCCESS); GTEST_LOG_(INFO) << "GattClient_ModuleTest_RequestConnectionPriority end"; } - } // namespace Bluetooth } // namespace OHOS diff --git a/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_descriptor_test.cpp b/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_descriptor_test.cpp index cf7467e80501b83010826b1af3a27c3ddda9a628..356df2f38bb338e471c04713d634d7c10e8bec59 100644 --- a/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_descriptor_test.cpp +++ b/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_descriptor_test.cpp @@ -21,7 +21,6 @@ using namespace testing::ext; namespace OHOS { namespace Bluetooth { - class GattDescriptorTest : public testing::Test { public: GattDescriptorTest() @@ -143,6 +142,5 @@ HWTEST_F(GattDescriptorTest, GattDescriptor_ModuleTest_SetValue, TestSize.Level1 GTEST_LOG_(INFO) << "GattDescriptor::GattDescriptor ends"; GTEST_LOG_(INFO) << "GattDescriptor::SetValue ends"; } - } // namespace Bluetooth } // namespace OHOS diff --git a/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_manager_test.cpp b/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_manager_test.cpp index 53807d384141e152209145dc68e16c04a9be633a..73f7f50f277d349fa1f440278b85e8e2edcbbab7 100644 --- a/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_manager_test.cpp +++ b/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_manager_test.cpp @@ -23,18 +23,10 @@ using namespace testing; using namespace testing::ext; -using namespace bluetooth; +// using namespace bluetooth; namespace OHOS { namespace Bluetooth { - -// URI: scheme://authority/path1/path2/path3?id = 1&name = mingming&old#fragment -/* - * @tc.number: Xxx_Unittest_AttachId_GetId_0100 - * @tc.name: AttachId/GetId - * @tc.desc: Test if attachd and getid return values are correct. - */ - class GattClientCallbackTest : public GattClientCallback { public: GattClientCallbackTest() @@ -136,7 +128,6 @@ HWTEST_F(GattManagerTest, GattManager_ModuleTest_GetDevicesByStates, TestSize.Le HWTEST_F(GattManagerTest, GattManager_ModuleTest_GetConnectedDevices, TestSize.Level1) { - GTEST_LOG_(INFO) << "GattManager::GattManager ends"; BluetoothRemoteDevice device; GattClient client(device); diff --git a/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_server_test.cpp b/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_server_test.cpp index a23cf6e1333a910a0ade00753b2e172f9c2ccb96..51adc713dd7582c783cf122b58e73fdaf1394090 100644 --- a/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_server_test.cpp +++ b/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_server_test.cpp @@ -22,7 +22,6 @@ using namespace testing::ext; namespace OHOS { namespace Bluetooth { -using namespace bluetooth; class BluetoothGattServerCallbackCommon : public GattServerCallback { public: BluetoothGattServerCallbackCommon() = default; @@ -81,12 +80,11 @@ void GattServerTest::SetUp() void GattServerTest::TearDown() {} -// URI: scheme://authority/path1/path2/path3?id = 1&name = mingming&old#fragment - -// * @tc.number: Xxx_Unittest_AttachId_GetId_0100 -// * @tc.name: AttachId/GetId -// * @tc.desc: Test if attachd and getid return values are correct. - +/* + * @tc.number: GattServer001 + * @tc.name: AddService + * @tc.desc: Check the addservice interface. +*/ HWTEST_F(GattServerTest, GattServer_ModuleTest_AddService, TestSize.Level1) { GTEST_LOG_(INFO) << "GattServer_ModuleTest_AddService start"; @@ -96,114 +94,149 @@ HWTEST_F(GattServerTest, GattServer_ModuleTest_AddService, TestSize.Level1) GattService serviceOne(uuidSerPer, GattServiceType::PRIMARY); int ret = server.AddService(serviceOne); - EXPECT_EQ(ret, bluetooth::GattStatus::GATT_SUCCESS); + EXPECT_EQ(ret, 0); GTEST_LOG_(INFO) << "GattServer_ModuleTest_AddService end"; } -// HWTEST_F(GattServerTest, GattServer_ModuleTest_CancelConnection, TestSize.Level1) -// { - -// GTEST_LOG_(INFO) << "GattServer_ModuleTest_CancelConnection start"; -// GattServer server(callback_); - -// BluetoothRemoteDevice deviceBle_; - -// server.CancelConnection(deviceBle_); -// GTEST_LOG_(INFO) << "GattServer_ModuleTest_CancelConnection end"; -// } - -// HWTEST_F(GattServerTest, GattServer_ModuleTest_RemoveService, TestSize.Level1) -// { -// GTEST_LOG_(INFO) << "GattServer_ModuleTest_RemoveService start"; -// GattServer server(callback_); - -// std::list &list = server.GetServices(); -// int ret = server.RemoveGattService(list.back()); -// EXPECT_EQ(ret, bluetooth::GattStatus::GATT_SUCCESS); -// GTEST_LOG_(INFO) << "GattServer_ModuleTest_RemoveService end"; -// } - -// HWTEST_F(GattServerTest, GattServer_ModuleTest_ClearServices, TestSize.Level1) -// { - -// GTEST_LOG_(INFO) << "GattServer_ModuleTest_ClearServices start"; -// GattServer server(callback_); - -// std::list& list = server.GetServices(); -// GTEST_LOG_(INFO) << (int)list.size(); -// server.ClearServices(); -// list = server.GetServices(); -// EXPECT_EQ((int)list.size(), 0); -// GTEST_LOG_(INFO) << "GattServer_ModuleTest_ClearServices end"; -// } - -// HWTEST_F(GattServerTest, GattServer_ModuleTest_Notify, TestSize.Level1) -// { -// GTEST_LOG_(INFO) << "GattServer_ModuleTest_Notify start"; -// GattServer server(callback_); - -// BluetoothRemoteDevice deviceBle_; -// UUID uuidSerPer; -// uuidSerPer = UUID::FromString("00001810-0000-1000-8000-00805F9B34FB"); -// GattCharacteristic* aa = new GattCharacteristic(uuidSerPer,1,1); -// int res = server.NotifyCharacteristicChanged(deviceBle_, *aa, false); -// EXPECT_EQ(res, (int)bluetooth::GattStatus::GATT_SUCCESS); - -// GTEST_LOG_(INFO) << "GattServer_ModuleTest_Notify end"; -// } - -// HWTEST_F(GattServerTest, GattServer_ModuleTest_SendResponse, TestSize.Level1) -// { -// GTEST_LOG_(INFO) << "GattServer_ModuleTest_SendResponse start"; -// GattServer server(callback_); - -// BluetoothRemoteDevice deviceBle_; -// string valueChrTwo = "2"; -// int ret = server.SendResponse(deviceBle_, -// 0, -// (int)GattStatus::GATT_SUCCESS, -// 1, -// (uint8_t *)valueChrTwo.c_str(), -// valueChrTwo.size()); -// EXPECT_EQ(ret, bluetooth::GattStatus::GATT_SUCCESS); -// GTEST_LOG_(INFO) << "GattServer_ModuleTest_SendResponse end"; - -// } - -// HWTEST_F(GattServerTest, GattServer_ModuleTest_GetServices, TestSize.Level1) -// { -// GTEST_LOG_(INFO) << "GattServer_ModuleTest_GetServices start"; -// GattServer server(callback_); - -// UUID uuidSerPer; -// uuidSerPer = UUID::FromString("00001810-0000-1000-8000-00805F9B34FB"); - -// GattService serviceOne(uuidSerPer, GattServiceType::PRIMARY); -// int ret = server.AddService(serviceOne); - -// EXPECT_EQ(ret, bluetooth::GattStatus::GATT_SUCCESS); -// std::list list = server.GetServices(); -// EXPECT_EQ((int)list.size(), 1); - -// GTEST_LOG_(INFO) << "GattServer_ModuleTest_GetServices end"; -// } - -// HWTEST_F(GattServerTest, GattServer_ModuleTest_GetService, TestSize.Level1) -// { -// GTEST_LOG_(INFO) << "GattServer_ModuleTest_GetService start"; -// GattServer server(callback_); - -// UUID uuidSerPer; -// uuidSerPer = UUID::FromString("00001810-0000-1000-8000-00805F9B34FB"); - -// GattService serviceOne(uuidSerPer, GattServiceType::PRIMARY); -// int ret = server.AddService(serviceOne); - -// EXPECT_EQ(ret, bluetooth::GattStatus::GATT_SUCCESS); - -// std::optional listSecondary = server.GetService(uuidSerPer, false); -// EXPECT_FALSE(listSecondary->IsPrimary()); -// GTEST_LOG_(INFO) << "GattServer_ModuleTest_GetService end"; -// } +/* + * @tc.number: GattServer002 + * @tc.name: CancelConnection + * @tc.desc: Check the CancelConnection interface. +*/ +HWTEST_F(GattServerTest, GattServer_ModuleTest_CancelConnection, TestSize.Level1) +{ + + GTEST_LOG_(INFO) << "GattServer_ModuleTest_CancelConnection start"; + GattServer server(callback_); + + BluetoothRemoteDevice deviceBle_; + + server.CancelConnection(deviceBle_); + GTEST_LOG_(INFO) << "GattServer_ModuleTest_CancelConnection end"; +} + +/* + * @tc.number: GattServer003 + * @tc.name: RemoveService + * @tc.desc: Check the RemoveService interface. +*/ +HWTEST_F(GattServerTest, GattServer_ModuleTest_RemoveService, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GattServer_ModuleTest_RemoveService start"; + GattServer server(callback_); + + std::list &list = server.GetServices(); + int ret = server.RemoveGattService(list.back()); + EXPECT_EQ(ret, 0); + GTEST_LOG_(INFO) << "GattServer_ModuleTest_RemoveService end"; +} + +/* + * @tc.number: GattServer005 + * @tc.name: ClearServices + * @tc.desc: Check the ClearServices interface. +*/ +HWTEST_F(GattServerTest, GattServer_ModuleTest_ClearServices, TestSize.Level1) +{ + + GTEST_LOG_(INFO) << "GattServer_ModuleTest_ClearServices start"; + GattServer server(callback_); + + std::list& list = server.GetServices(); + GTEST_LOG_(INFO) << (int)list.size(); + server.ClearServices(); + list = server.GetServices(); + EXPECT_EQ((int)list.size(), 0); + GTEST_LOG_(INFO) << "GattServer_ModuleTest_ClearServices end"; +} + +/* + * @tc.number: GattServer006 + * @tc.name: NotifyCharacteristicChanged + * @tc.desc: Check the NotifyCharacteristicChanged interface. +*/ +HWTEST_F(GattServerTest, GattServer_ModuleTest_NotifyCharacteristicChanged, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GattServer_ModuleTest_Notify start"; + GattServer server(callback_); + + BluetoothRemoteDevice deviceBle_; + UUID uuidSerPer; + uuidSerPer = UUID::FromString("00001810-0000-1000-8000-00805F9B34FB"); + GattCharacteristic* aa = new GattCharacteristic(uuidSerPer,1,1); + int res = server.NotifyCharacteristicChanged(deviceBle_, *aa, false); + EXPECT_EQ(res, 0); + + GTEST_LOG_(INFO) << "GattServer_ModuleTest_Notify end"; +} + +/* + * @tc.number: GattServer007 + * @tc.name: SendResponse + * @tc.desc: Check the SendResponse interface. +*/ +HWTEST_F(GattServerTest, GattServer_ModuleTest_SendResponse, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GattServer_ModuleTest_SendResponse start"; + GattServer server(callback_); + + BluetoothRemoteDevice deviceBle_; + string valueChrTwo = "2"; + int ret = server.SendResponse(deviceBle_, + 0, + (int)GattStatus::GATT_SUCCESS, + 1, + (uint8_t *)valueChrTwo.c_str(), + valueChrTwo.size()); + EXPECT_EQ(ret, 0); + GTEST_LOG_(INFO) << "GattServer_ModuleTest_SendResponse end"; +} + +/* + * @tc.number: GattServer008 + * @tc.name: GetServices + * @tc.desc: Check the GetServices interface. +*/ +HWTEST_F(GattServerTest, GattServer_ModuleTest_GetServices, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GattServer_ModuleTest_GetServices start"; + GattServer server(callback_); + + UUID uuidSerPer; + uuidSerPer = UUID::FromString("00001810-0000-1000-8000-00805F9B34FB"); + + GattService serviceOne(uuidSerPer, GattServiceType::PRIMARY); + int ret = server.AddService(serviceOne); + + EXPECT_EQ(ret, 0); + std::list list = server.GetServices(); + EXPECT_EQ((int)list.size(), 1); + + GTEST_LOG_(INFO) << "GattServer_ModuleTest_GetServices end"; +} + +/* + * @tc.number: GattServer009 + * @tc.name: GetService + * @tc.desc: Check the GetService interface. +*/ + +HWTEST_F(GattServerTest, GattServer_ModuleTest_GetService, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GattServer_ModuleTest_GetService start"; + GattServer server(callback_); + + UUID uuidSerPer; + uuidSerPer = UUID::FromString("00001810-0000-1000-8000-00805F9B34FB"); + + GattService serviceOne(uuidSerPer, GattServiceType::PRIMARY); + int ret = server.AddService(serviceOne); + + EXPECT_EQ(ret, 0); + + std::optional listSecondary = server.GetService(uuidSerPer, false); + EXPECT_FALSE(listSecondary->IsPrimary()); + GTEST_LOG_(INFO) << "GattServer_ModuleTest_GetService end"; +} } // namespace Bluetooth } // namespace OHOS diff --git a/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_service_test.cpp b/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_service_test.cpp index f3a9d53721a8e64918cfc7dc1274de571f2cee6d..8c1301cab4045a542ebc24e2d72037bae7f3dff0 100644 --- a/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_service_test.cpp +++ b/interfaces/innerkits/native_cpp/framework/test/unittest/gatt/gatt_service_test.cpp @@ -22,7 +22,6 @@ using namespace testing::ext; namespace OHOS { namespace Bluetooth { - class GattServiceTest : public testing::Test { public: GattServiceTest() @@ -206,6 +205,5 @@ HWTEST_F(GattServiceTest, GattService_ModuleTest_GetCharacteristics, TestSize.Le GTEST_LOG_(INFO) << "GattService::GattService ends"; GTEST_LOG_(INFO) << "GattService::GetCharacteristics ends"; } - } // namespace Bluetooth } // namespace OHOS diff --git a/interfaces/innerkits/native_cpp/include/bluetooth_gatt_descriptor.h b/interfaces/innerkits/native_cpp/include/bluetooth_gatt_descriptor.h index a7243a8ef4f416b93da38a8d4ca46e02097b85d5..c4fa28f287248a5a73d32ff989e62e6bdc02a7cf 100644 --- a/interfaces/innerkits/native_cpp/include/bluetooth_gatt_descriptor.h +++ b/interfaces/innerkits/native_cpp/include/bluetooth_gatt_descriptor.h @@ -143,8 +143,6 @@ public: */ void SetValue(const uint8_t *values, const size_t length); - - private: /** * @brief The handle of descriptor. @@ -194,9 +192,6 @@ private: */ UUID uuid_; friend class GattCharacteristic; - - - }; } // namespace Bluetooth } // namespace OHOS diff --git a/interfaces/innerkits/native_cpp/include/bluetooth_gatt_manager.h b/interfaces/innerkits/native_cpp/include/bluetooth_gatt_manager.h index 17e2bf5e520350ff070115dbd215e05c33e9c4a0..df53a0ad9618494ce57560d620ca2c1b16558ccd 100644 --- a/interfaces/innerkits/native_cpp/include/bluetooth_gatt_manager.h +++ b/interfaces/innerkits/native_cpp/include/bluetooth_gatt_manager.h @@ -85,7 +85,6 @@ public: */ ~GattManager(); - private: BLUETOOTH_DECLARE_IMPL(); }; diff --git a/interfaces/innerkits/native_cpp/include/bluetooth_gatt_service.h b/interfaces/innerkits/native_cpp/include/bluetooth_gatt_service.h index 90b8fbb77fbfdfbb0c04ba08611aabea71b467ae..c0a2a1cc73cb6b8147c9de1d8079645d499714ca 100644 --- a/interfaces/innerkits/native_cpp/include/bluetooth_gatt_service.h +++ b/interfaces/innerkits/native_cpp/include/bluetooth_gatt_service.h @@ -40,7 +40,6 @@ namespace OHOS { namespace Bluetooth { - /** A GATT-based Service type. * Define GATT-based Service types. */ diff --git a/ohos.build b/ohos.build index 65e731de83b05b25c3404a59a30c746f2c3abb6d..b1a698545ca03996a688ed40a8b0c7039fc10333 100644 --- a/ohos.build +++ b/ohos.build @@ -35,6 +35,10 @@ } ], "test_list": [ + "//foundation/communication/bluetooth/interfaces/innerkits/native_cpp/framework/test/unittest/gatt:unittest", + "//foundation/communication/bluetooth/interfaces/innerkits/native_cpp/framework/test/unittest/spp:unittest", + "//foundation/communication/bluetooth/interfaces/innerkits/native_cpp/framework/test/unittest/host:unittest", + "//foundation/communication/bluetooth/interfaces/innerkits/native_cpp/framework/test/unittest:unittest" ] } } diff --git a/services/bluetooth_standard/common/ble_aidl_data.h b/services/bluetooth_standard/common/ble_parcel_data.h similarity index 99% rename from services/bluetooth_standard/common/ble_aidl_data.h rename to services/bluetooth_standard/common/ble_parcel_data.h index d0f92745373ba6599fb2c65bf87ae870f1f964e5..5d3085f7a9ec1f682cfb8a18f0f03de7f50e9571 100644 --- a/services/bluetooth_standard/common/ble_aidl_data.h +++ b/services/bluetooth_standard/common/ble_parcel_data.h @@ -31,8 +31,8 @@ * @since 6 */ -#ifndef BLE_AIDL_DATA_H -#define BLE_AIDL_DATA_H +#ifndef BLE_PARCEL_DATA_H +#define BLE_PARCEL_DATA_H #include #include @@ -645,4 +645,4 @@ public: }; } // namespace bluetooth -#endif /// BLE_AIDL_DATA_H +#endif /// BLE_PARCEL_DATA_H diff --git a/services/bluetooth_standard/common/ble_service_data.cpp b/services/bluetooth_standard/common/ble_service_data.cpp index a9aac5e93cb8f3e11ab472874ce8ad6fde266deb..63cc13e92c932ec281b24f5a245bb6b9be80d934 100644 --- a/services/bluetooth_standard/common/ble_service_data.cpp +++ b/services/bluetooth_standard/common/ble_service_data.cpp @@ -267,7 +267,7 @@ void BleAdvertiserDataImpl::AddServiceData(const Uuid &uuid, const std::string & cdata[1] = BLE_AD_TYPE_SERVICE_DATA; /// 0x16 uint16_t uuid16 = uuid.ConvertTo16Bits(); AddData(std::string(cdata, BLE_ADV_DATA_FIELD_TYPE_AND_LEN) + - std::string((char *)&uuid16, BLE_UUID_LEN_16) + data); + std::string(reinterpret_cast(&uuid16), BLE_UUID_LEN_16) + data); break; } @@ -277,7 +277,7 @@ void BleAdvertiserDataImpl::AddServiceData(const Uuid &uuid, const std::string & cdata[1] = BLE_AD_TYPE_32SERVICE_DATA; /// 0x20 uint32_t uuid32 = uuid.ConvertTo32Bits(); AddData(std::string(cdata, BLE_ADV_DATA_FIELD_TYPE_AND_LEN) + - std::string((char *)&uuid32, BLE_UUID_LEN_32) + data); + std::string(reinterpret_cast(&uuid32), BLE_UUID_LEN_32) + data); break; } @@ -288,7 +288,7 @@ void BleAdvertiserDataImpl::AddServiceData(const Uuid &uuid, const std::string & uint8_t uuidData[BLE_UUID_LEN_128]; uuid.ConvertToBytesLE(uuidData); AddData(std::string(cdata, BLE_ADV_DATA_FIELD_TYPE_AND_LEN) + - std::string((char *)uuidData, BLE_UUID_LEN_128) + data); + std::string(reinterpret_cast(uuidData), BLE_UUID_LEN_128) + data); break; } @@ -335,7 +335,7 @@ void BleAdvertiserDataImpl::SetAppearance(uint16_t appearance) cdata[0] = BLE_ADV_DATA_BYTE_FIELD_LEN; cdata[1] = BLE_AD_TYPE_APPEARANCE; /// 0x19 AddData(std::string(cdata, BLE_ADV_DATA_FIELD_TYPE_AND_LEN) + - std::string((char *)&appearance, BLE_ADV_DATA_FIELD_TYPE_AND_LEN)); + std::string(reinterpret_cast(&appearance), BLE_ADV_DATA_FIELD_TYPE_AND_LEN)); } /** @@ -353,8 +353,8 @@ void BleAdvertiserDataImpl::SetCompleteServices(const Uuid &uuid) cdata[0] = BLE_UUID_LEN_16 + 1; cdata[1] = BLE_AD_TYPE_16SRV_CMPL; /// 0x03 uint16_t uuid16 = uuid.ConvertTo16Bits(); - AddData( - std::string(cdata, BLE_ADV_DATA_FIELD_TYPE_AND_LEN) + std::string((char *)&uuid16, BLE_UUID_LEN_16)); + AddData(std::string(cdata, BLE_ADV_DATA_FIELD_TYPE_AND_LEN) + + std::string(reinterpret_cast(&uuid16), BLE_UUID_LEN_16)); break; } @@ -363,8 +363,8 @@ void BleAdvertiserDataImpl::SetCompleteServices(const Uuid &uuid) cdata[0] = BLE_UUID_LEN_32 + 1; cdata[1] = BLE_AD_TYPE_32SRV_CMPL; /// 0x05 uint32_t uuid32 = uuid.ConvertTo32Bits(); - AddData( - std::string(cdata, BLE_ADV_DATA_FIELD_TYPE_AND_LEN) + std::string((char *)&uuid32, BLE_UUID_LEN_32)); + AddData(std::string(cdata, BLE_ADV_DATA_FIELD_TYPE_AND_LEN) + + std::string(reinterpret_cast(&uuid32), BLE_UUID_LEN_32)); break; } @@ -374,8 +374,8 @@ void BleAdvertiserDataImpl::SetCompleteServices(const Uuid &uuid) cdata[1] = BLE_AD_TYPE_128SRV_CMPL; /// 0x07 uint8_t uuidData[BLE_UUID_LEN_128]; uuid.ConvertToBytesLE(uuidData); - AddData( - std::string(cdata, BLE_ADV_DATA_FIELD_TYPE_AND_LEN) + std::string((char *)uuidData, BLE_UUID_LEN_128)); + AddData(std::string(cdata, BLE_ADV_DATA_FIELD_TYPE_AND_LEN) + + std::string(reinterpret_cast(uuidData), BLE_UUID_LEN_128)); break; } @@ -872,7 +872,7 @@ void BlePeripheralDevice::SetServiceUUID32Bits(BlePeripheralDeviceParseAdvData & void BlePeripheralDevice::SetServiceUUID128Bits(const BlePeripheralDeviceParseAdvData &parseAdvData) { for (size_t var = 0; var < parseAdvData.length / BLE_UUID_LEN_128; ++var) { - std::array data; + std::array data = {}; for (int i = 0; i < BLE_UUID_LEN_128; i++) { data[i] = *(parseAdvData.payload + var * BLE_UUID_LEN_128 + i); } @@ -1185,7 +1185,7 @@ void BlePeripheralDevice::SetManufacturerData(std::string manufacturerData) void BlePeripheralDevice::SetServiceDataUUID(Uuid uuid, std::string data) { isServiceData_ = true; - std::vector::iterator iter = std::find(serviceDataUUIDs_.begin(), serviceDataUUIDs_.end(), uuid); + auto iter = std::find(serviceDataUUIDs_.begin(), serviceDataUUIDs_.end(), uuid); if (iter == serviceDataUUIDs_.end()) { serviceDataUUIDs_.push_back(uuid); serviceData_.push_back(data); @@ -1201,7 +1201,7 @@ void BlePeripheralDevice::SetServiceDataUUID(Uuid uuid, std::string data) void BlePeripheralDevice::SetServiceUUID(Uuid serviceUUID) { isServiceUUID_ = true; - std::vector::iterator iter = std::find(serviceUUIDs_.begin(), serviceUUIDs_.end(), serviceUUID); + auto iter = std::find(serviceUUIDs_.begin(), serviceUUIDs_.end(), serviceUUID); if (iter == serviceUUIDs_.end()) { serviceUUIDs_.push_back(serviceUUID); } diff --git a/services/bluetooth_standard/ipc/parcel/bluetooth_ble_advertiser_data.h b/services/bluetooth_standard/ipc/parcel/bluetooth_ble_advertiser_data.h index 8942e4c49f224626b21eeb59917ee07cac5dbc63..34f3e30085b9b7c8eba32da81e2bf34ec219f662 100644 --- a/services/bluetooth_standard/ipc/parcel/bluetooth_ble_advertiser_data.h +++ b/services/bluetooth_standard/ipc/parcel/bluetooth_ble_advertiser_data.h @@ -15,7 +15,7 @@ #ifndef BLUETOOTH_PARCEL_BLE_ADVERTISER_DATA_H #define BLUETOOTH_PARCEL_BLE_ADVERTISER_DATA_H -#include "ble_aidl_data.h" +#include "ble_parcel_data.h" #include "parcel.h" namespace OHOS { diff --git a/services/bluetooth_standard/ipc/parcel/bluetooth_ble_advertiser_settings.h b/services/bluetooth_standard/ipc/parcel/bluetooth_ble_advertiser_settings.h index aeda58f192ba23bb7bcd9c54be10ddb01a13db95..6b33a8e284b55383bf7cd54885107621810bb5b1 100644 --- a/services/bluetooth_standard/ipc/parcel/bluetooth_ble_advertiser_settings.h +++ b/services/bluetooth_standard/ipc/parcel/bluetooth_ble_advertiser_settings.h @@ -16,7 +16,7 @@ #ifndef BLUETOOTH_PARCEL_BLE_ADVERTISER_SETTINGS_H #define BLUETOOTH_PARCEL_BLE_ADVERTISER_SETTINGS_H -#include "ble_aidl_data.h" +#include "ble_parcel_data.h" #include "parcel.h" namespace OHOS { diff --git a/services/bluetooth_standard/ipc/parcel/bluetooth_ble_scan_result.h b/services/bluetooth_standard/ipc/parcel/bluetooth_ble_scan_result.h index f0bb0b381c94eab4924ab590f1456cd50f692fd2..a5ebaa2e51505a4b442238182bae0088b8769d75 100644 --- a/services/bluetooth_standard/ipc/parcel/bluetooth_ble_scan_result.h +++ b/services/bluetooth_standard/ipc/parcel/bluetooth_ble_scan_result.h @@ -16,7 +16,7 @@ #ifndef BLUETOOTH_PARCEL_BLE_SCAN_RESULT_H #define BLUETOOTH_PARCEL_BLE_SCAN_RESULT_H -#include "ble_aidl_data.h" +#include "ble_parcel_data.h" #include "parcel.h" namespace OHOS { diff --git a/services/bluetooth_standard/ipc/parcel/bluetooth_ble_scan_settings.h b/services/bluetooth_standard/ipc/parcel/bluetooth_ble_scan_settings.h index 6a00f8a8b506e686022df77d8b6b06089ebe4c3a..15e9f79e3d78e4867d184af43d5de85468dc629c 100644 --- a/services/bluetooth_standard/ipc/parcel/bluetooth_ble_scan_settings.h +++ b/services/bluetooth_standard/ipc/parcel/bluetooth_ble_scan_settings.h @@ -16,7 +16,7 @@ #ifndef BLUETOOTH_PARCEL_BLE_SCAN_SETTINGS_H #define BLUETOOTH_PARCEL_BLE_SCAN_SETTINGS_H -#include "ble_aidl_data.h" +#include "ble_parcel_data.h" #include "parcel.h" namespace OHOS { diff --git a/services/bluetooth_standard/ipc/parcel/bluetooth_bt_uuid.cpp b/services/bluetooth_standard/ipc/parcel/bluetooth_bt_uuid.cpp index 73a7ff9800ee889cb7dc81aeeab00bd49d353cb8..9cc4fc1b71245d7dade12fc85e90726cfc3108aa 100644 --- a/services/bluetooth_standard/ipc/parcel/bluetooth_bt_uuid.cpp +++ b/services/bluetooth_standard/ipc/parcel/bluetooth_bt_uuid.cpp @@ -18,17 +18,18 @@ namespace OHOS { namespace Bluetooth { +#define EIGHT 8 bool BluetoothUuid::Marshalling(Parcel &parcel) const { uint64_t most_sig_bits = - ((((uint64_t)uuid_[0]) << 56) | (((uint64_t)uuid_[1]) << 48) | (((uint64_t)uuid_[2]) << 40) | - (((uint64_t)uuid_[3]) << 32) | (((uint64_t)uuid_[4]) << 24) | (((uint64_t)uuid_[5]) << 16) | - (((uint64_t)uuid_[6]) << 8) | uuid_[7]); + ((((uint64_t)uuid_[0]) << EIGHT*7) | (((uint64_t)uuid_[1]) << EIGHT*6) | (((uint64_t)uuid_[2]) << EIGHT*5) | + (((uint64_t)uuid_[3]) << EIGHT*4) | (((uint64_t)uuid_[4]) << EIGHT*3) | (((uint64_t)uuid_[5]) << EIGHT*2) | + (((uint64_t)uuid_[6]) << EIGHT) | uuid_[7]); uint64_t least_sig_bits = - ((((uint64_t)uuid_[8]) << 56) | (((uint64_t)uuid_[9]) << 48) | (((uint64_t)uuid_[10]) << 40) | - (((uint64_t)uuid_[11]) << 32) | (((uint64_t)uuid_[12]) << 24) | (((uint64_t)uuid_[13]) << 16) | - (((uint64_t)uuid_[14]) << 8) | uuid_[15]); + ((((uint64_t)uuid_[8]) << EIGHT*7) | (((uint64_t)uuid_[9]) << EIGHT*6) | (((uint64_t)uuid_[10]) << EIGHT*5) | + (((uint64_t)uuid_[11]) << EIGHT*4) | (((uint64_t)uuid_[12]) << EIGHT*3) | (((uint64_t)uuid_[13]) << EIGHT*2) | + (((uint64_t)uuid_[14]) << EIGHT) | uuid_[15]); bool ret = parcel.WriteUint64(most_sig_bits); if (!ret) { diff --git a/services/bluetooth_standard/server/include/bluetooth_ble_central_manager_server.h b/services/bluetooth_standard/server/include/bluetooth_ble_central_manager_server.h index bd24d0490c870b64bff8c257a40c1ca3e24dd38a..d1c8b5e839b94eb745f8bb9d3c631ee8711df0e5 100644 --- a/services/bluetooth_standard/server/include/bluetooth_ble_central_manager_server.h +++ b/services/bluetooth_standard/server/include/bluetooth_ble_central_manager_server.h @@ -30,7 +30,8 @@ public: ~BluetoothBleCentralManagerServer() override; virtual void RegisterBleCentralManagerCallback(const sptr &callback) override; - virtual void DeregisterBleCentralManagerCallback(const sptr &callback) override; + virtual void DeregisterBleCentralManagerCallback( + const sptr &callback) override; virtual void StartScan() override; virtual void StartScan(const BluetoothBleScanSettings &settings) override; virtual void StopScan() override; diff --git a/services/bluetooth_standard/server/src/bluetooth_gatt_server_server.cpp b/services/bluetooth_standard/server/src/bluetooth_gatt_server_server.cpp index 86ea6d478efbeb7de2709cc170dee5e8d1fef41d..13a1a2a33859366f7970b6e8a0c23f3be5b91a54 100644 --- a/services/bluetooth_standard/server/src/bluetooth_gatt_server_server.cpp +++ b/services/bluetooth_standard/server/src/bluetooth_gatt_server_server.cpp @@ -296,7 +296,6 @@ int BluetoothGattServerServer::RespondDescriptorWrite( int BluetoothGattServerServer::RegisterApplication(const sptr &callback) { - std::lock_guard lck(pimpl->registerMutex_); pimpl->serverService_ = pimpl->GetServicePtr(); if (!pimpl->serverService_) { @@ -311,7 +310,6 @@ int BluetoothGattServerServer::RegisterApplication(const sptr lck(pimpl->registerMutex_); if (!pimpl->serverService_) { return bluetooth::GattStatus::REQUEST_NOT_SUPPORT; diff --git a/services/bluetooth_standard/service/src/ble/ble_advertiser_impl.cpp b/services/bluetooth_standard/service/src/ble/ble_advertiser_impl.cpp index b0009361986d12a3476c8d1fd24a92589721719f..3007b90288058860304d950c96852620d026d7d7 100644 --- a/services/bluetooth_standard/service/src/ble/ble_advertiser_impl.cpp +++ b/services/bluetooth_standard/service/src/ble/ble_advertiser_impl.cpp @@ -20,7 +20,6 @@ #include "ble_adapter.h" #include "ble_defs.h" #include "ble_feature.h" -#include "ble_feature.h" #include "ble_properties.h" #include "ble_utils.h" #include "securec.h" @@ -487,13 +486,6 @@ void BleAdvertiserImpl::Close(uint8_t advHandle) const } StopAdvertising(advHandle); - int ret = DeregisterCallbackToGap(); - if (ret != BT_NO_ERROR) { - iter->second.advStatus_ = ADVERTISE_FAILED_INTERNAL_ERROR; - LOG_DEBUG("[BleAdvertiserImpl] %{public}s:Deregister Callback to gap failed!.", __func__); - callback_->OnStartResultEvent(ret, advHandle); - return; - } iter->second.advStatus_ = ADVERTISE_NOT_STARTED; } @@ -1777,7 +1769,8 @@ void BleAdvertiserImpl::HandleGapExAdvEvent(const BLE_GAP_CB_EVENT &event, int s LOG_ERROR("[BleAdvertiserImpl] %{public}s:clrear event! %{public}d.", __func__, event); break; case BLE_GAP_EX_ADV_SCAN_REQUEST_RECEIVED_EVT: - LOG_ERROR("[BleAdvertiserImpl] %{public}s:scan request! %{public}d status %{public}d.", __func__, event, status); + LOG_ERROR( + "[BleAdvertiserImpl] %{public}s:scan request! %{public}d status %{public}d.", __func__, event, status); break; case BLE_GAP_EX_ADC_TERMINATED_ADV_SET_EVT: GapExAdvTerminatedAdvSetEvt(status, handle); @@ -1876,8 +1869,9 @@ void BleAdvertiserImpl::GenResPriAddrResultTask(uint8_t result, BtAddr btAddr) c void BleAdvertiserImpl::GenResPriAddrResult(uint8_t result, const uint8_t addr[BT_ADDRESS_SIZE], void *context) { - LOG_DEBUG( - "[BleAdvertiserImpl] %{public}s:ResPriAddr = %{public}s", __func__, RawAddress::ConvertToString(addr).GetAddress().c_str()); + LOG_DEBUG("[BleAdvertiserImpl] %{public}s:ResPriAddr = %{public}s", + __func__, + RawAddress::ConvertToString(addr).GetAddress().c_str()); auto *bleAdvertiser = static_cast(context);