diff --git a/frameworks/cj/access/include/bluetooth_access_ffi.h b/frameworks/cj/access/include/bluetooth_access_ffi.h index 3426ce34a0ea4fd714aa64250a7577fb688a5458..e77213f4e1a05959b91298c48f8acb67276b152d 100644 --- a/frameworks/cj/access/include/bluetooth_access_ffi.h +++ b/frameworks/cj/access/include/bluetooth_access_ffi.h @@ -16,10 +16,10 @@ #ifndef BLUETOOTH_ACCESS_FFI_H #define BLUETOOTH_ACCESS_FFI_H -#include "native/ffi_remote_data.h" - #include +#include "native/ffi_remote_data.h" + extern "C" { const int32_t REGISTER_STATE_CHANGE_TYPE = 0; diff --git a/frameworks/cj/access/include/bluetooth_access_impl.h b/frameworks/cj/access/include/bluetooth_access_impl.h index df8930e7285827f7114fd67e1df0e6fd831aaeca..f0e276c9e4627b71d18410732f9c6db0d3c18e00 100644 --- a/frameworks/cj/access/include/bluetooth_access_impl.h +++ b/frameworks/cj/access/include/bluetooth_access_impl.h @@ -15,11 +15,11 @@ #ifndef BLUETOOTH_ACCESS_IMPL_H #define BLUETOOTH_ACCESS_IMPL_H +#include + #include "bluetooth_host.h" #include "napi_bluetooth_utils.h" -#include - namespace OHOS { namespace CJSystemapi { namespace CJBluetoothAccess { @@ -39,29 +39,29 @@ public: }; class CjBluetoothAccessObserver : public BluetoothHostObserver { - public: +public: CjBluetoothAccessObserver(); ~CjBluetoothAccessObserver() override = default; void OnStateChanged(const int transport, const int status) override; - void OnDiscoveryStateChanged(int status) override{}; + void OnDiscoveryStateChanged(int status) override {}; void OnDiscoveryResult( - const BluetoothRemoteDevice &device, int rssi, const std::string deviceName, int deviceClass) override{}; - void OnPairRequested(const BluetoothRemoteDevice &device) override{}; - void OnPairConfirmed(const BluetoothRemoteDevice &device, int reqType, int number) override{}; - void OnScanModeChanged(int mode) override{}; - void OnDeviceNameChanged(const std::string &deviceName) override{}; - void OnDeviceAddrChanged(const std::string &address) override{}; + const BluetoothRemoteDevice& device, int rssi, const std::string deviceName, int deviceClass) override {}; + void OnPairRequested(const BluetoothRemoteDevice& device) override {}; + void OnPairConfirmed(const BluetoothRemoteDevice& device, int reqType, int number) override {}; + void OnScanModeChanged(int mode) override {}; + void OnDeviceNameChanged(const std::string& deviceName) override {}; + void OnDeviceAddrChanged(const std::string& address) override {}; void RegisterStateChangeFunc(std::function cjCallback); private: - bool DealStateChange(const int transport, const int status, BluetoothState &state); - void GetBrStateByStatus(const int status, BluetoothState &state, bool &isCallback); - void GetBleStateByStatus(const int status, BluetoothState &state); - std::function stateChangeFunc{nullptr}; + bool DealStateChange(const int transport, const int status, BluetoothState& state); + void GetBrStateByStatus(const int status, BluetoothState& state, bool& isCallback); + void GetBleStateByStatus(const int status, BluetoothState& state); + std::function stateChangeFunc { nullptr }; }; -} // namespace BluetoothAccess +} // namespace CJBluetoothAccess } // namespace CJSystemapi } // namespace OHOS diff --git a/frameworks/cj/access/src/bluetooth_access_callback.cpp b/frameworks/cj/access/src/bluetooth_access_callback.cpp index 96b24ea83f68db724fd78e1429278e3289b37aaf..13132f5eee9c2d96bb9d0277e3f41b47811094c5 100644 --- a/frameworks/cj/access/src/bluetooth_access_callback.cpp +++ b/frameworks/cj/access/src/bluetooth_access_callback.cpp @@ -16,9 +16,8 @@ #define LOG_TAG "bt_cj_access_callback" #endif -#include "bluetooth_access_impl.h" - #include "bluetooth_access_ffi.h" +#include "bluetooth_access_impl.h" #include "bluetooth_errorcode.h" #include "bluetooth_log.h" #include "cj_lambda.h" @@ -27,22 +26,20 @@ namespace OHOS { namespace CJSystemapi { namespace CJBluetoothAccess { using Bluetooth::BluetoothHost; -using Bluetooth::BT_ERR_INTERNAL_ERROR; using Bluetooth::BluetoothState; -using Bluetooth::BT_TRANSPORT_BREDR; +using Bluetooth::BT_ERR_INTERNAL_ERROR; using Bluetooth::BT_TRANSPORT_BLE; +using Bluetooth::BT_TRANSPORT_BREDR; using Bluetooth::BTStateID; -CjBluetoothAccessObserver::CjBluetoothAccessObserver() -{} +CjBluetoothAccessObserver::CjBluetoothAccessObserver() {} -std::shared_ptr g_bluetoothAccessObserver = - std::make_shared(); +std::shared_ptr g_bluetoothAccessObserver = std::make_shared(); bool g_flag = false; static void RegisterAccessObserverToHost() { - BluetoothHost *host = &BluetoothHost::GetDefaultHost(); + BluetoothHost* host = &BluetoothHost::GetDefaultHost(); host->RegisterObserver(g_bluetoothAccessObserver); } @@ -62,7 +59,7 @@ void CjBluetoothAccessObserver::OnStateChanged(const int transport, const int st stateChangeFunc(static_cast(state)); } -bool CjBluetoothAccessObserver::DealStateChange(const int transport, const int status, BluetoothState &state) +bool CjBluetoothAccessObserver::DealStateChange(const int transport, const int status, BluetoothState& state) { HILOGD("transport is %{public}d, status is %{public}d", transport, status); bool isCallback = true; @@ -74,7 +71,7 @@ bool CjBluetoothAccessObserver::DealStateChange(const int transport, const int s return isCallback; } -void CjBluetoothAccessObserver::GetBrStateByStatus(const int status, BluetoothState &state, bool &isCallback) +void CjBluetoothAccessObserver::GetBrStateByStatus(const int status, BluetoothState& state, bool& isCallback) { switch (status) { case BTStateID::STATE_TURNING_ON: @@ -98,7 +95,7 @@ void CjBluetoothAccessObserver::GetBrStateByStatus(const int status, BluetoothSt } } -void CjBluetoothAccessObserver::GetBleStateByStatus(const int status, BluetoothState &state) +void CjBluetoothAccessObserver::GetBleStateByStatus(const int status, BluetoothState& state) { switch (status) { case BTStateID::STATE_TURNING_ON: @@ -146,6 +143,6 @@ void AccessImpl::RegisterAccessObserver(int32_t callbackType, void (*callback)() return; } -} // namespace BluetoothAccess +} // namespace CJBluetoothAccess } // namespace CJSystemapi } // namespace OHOS \ No newline at end of file diff --git a/frameworks/cj/access/src/bluetooth_access_ffi.cpp b/frameworks/cj/access/src/bluetooth_access_ffi.cpp index a3b4cf263b3a189c85a9f4d573eefd11cbc7b341..2518608dbc44fd5e835ec578589c885bd3c15f3f 100644 --- a/frameworks/cj/access/src/bluetooth_access_ffi.cpp +++ b/frameworks/cj/access/src/bluetooth_access_ffi.cpp @@ -17,6 +17,7 @@ #endif #include "bluetooth_access_ffi.h" + #include "bluetooth_access_impl.h" #include "bluetooth_log.h" @@ -47,6 +48,6 @@ void FfiBluetoothAccOn(int32_t callbackType, void (*callback)(), int32_t* errCod return AccessImpl::RegisterAccessObserver(callbackType, callback, errCode); } } -} // namespace BluetoothAccess +} // namespace CJBluetoothAccess } // namespace CJSystemapi } // namespace OHOS \ No newline at end of file diff --git a/frameworks/cj/access/src/bluetooth_access_impl.cpp b/frameworks/cj/access/src/bluetooth_access_impl.cpp index 92cb2cb8427c62e7c22441ad3d9cf199b39038da..cf461fb5a11ec44c23ec0e0e200a44a8504b09fd 100644 --- a/frameworks/cj/access/src/bluetooth_access_impl.cpp +++ b/frameworks/cj/access/src/bluetooth_access_impl.cpp @@ -17,6 +17,7 @@ #endif #include "bluetooth_access_impl.h" + #include "bluetooth_errorcode.h" #include "bluetooth_log.h" @@ -24,19 +25,19 @@ namespace OHOS { namespace CJSystemapi { namespace CJBluetoothAccess { using Bluetooth::BluetoothHost; -using Bluetooth::BTStateID; using Bluetooth::BluetoothState; +using Bluetooth::BTStateID; void AccessImpl::EnableBluetooth(int32_t* errCode) { - BluetoothHost *host = &BluetoothHost::GetDefaultHost(); + BluetoothHost* host = &BluetoothHost::GetDefaultHost(); *errCode = host->EnableBle(); return; } void AccessImpl::DisableBluetooth(int32_t* errCode) { - BluetoothHost *host = &BluetoothHost::GetDefaultHost(); + BluetoothHost* host = &BluetoothHost::GetDefaultHost(); *errCode = host->DisableBt(); return; } diff --git a/frameworks/cj/ble/include/bluetooth_ble_clientDevice.h b/frameworks/cj/ble/include/bluetooth_ble_clientDevice.h index 42ea58dbbaca70e6b09012eb07578603e5dbd6d1..eb9e2ae19e792ff94ac63b444e6fa6628cf8875b 100644 --- a/frameworks/cj/ble/include/bluetooth_ble_clientDevice.h +++ b/frameworks/cj/ble/include/bluetooth_ble_clientDevice.h @@ -36,15 +36,15 @@ using Bluetooth::INVALID_MAC_ADDRESS; class FfiGattClientCallback : public GattClientCallback { public: void OnConnectionStateChanged(int connectionState, int ret) override; - void OnCharacteristicChanged(const GattCharacteristic &characteristic) override; - void OnCharacteristicReadResult(const GattCharacteristic &characteristic, int ret) override; - void OnCharacteristicWriteResult(const GattCharacteristic &characteristic, int ret) override; - void OnDescriptorReadResult(const GattDescriptor &descriptor, int ret) override; - void OnDescriptorWriteResult(const GattDescriptor &descriptor, int ret) override; + void OnCharacteristicChanged(const GattCharacteristic& characteristic) override; + void OnCharacteristicReadResult(const GattCharacteristic& characteristic, int ret) override; + void OnCharacteristicWriteResult(const GattCharacteristic& characteristic, int ret) override; + void OnDescriptorReadResult(const GattDescriptor& descriptor, int ret) override; + void OnDescriptorWriteResult(const GattDescriptor& descriptor, int ret) override; void OnMtuUpdate(int mtu, int ret) override; - void OnServicesDiscovered(int status) override{}; - void OnConnectionParameterChanged(int interval, int latency, int timeout, int status) override{}; - void OnSetNotifyCharacteristic(const GattCharacteristic &characteristic, int status) override{}; + void OnServicesDiscovered(int status) override {}; + void OnConnectionParameterChanged(int interval, int latency, int timeout, int status) override {}; + void OnSetNotifyCharacteristic(const GattCharacteristic& characteristic, int status) override; void OnReadRemoteRssiValueResult(int rssi, int status) override; void RegisterBLECharacteristicChangeFunc(std::function cjCallback); @@ -55,6 +55,8 @@ public: void RegisterReadDescriptorCallback(std::function cjCallback); void RegisterWriteCharacteristicCallback(std::function cjCallback); void RegisterWriteDescriptorCallback(std::function cjCallback); + void RegisterCharacteristicChangeNotificationCallback(std::function cjCallback); + void RegisterCharacteristicChangeIndicationCallback(std::function cjCallback); FfiGattClientCallback(); ~FfiGattClientCallback() override = default; @@ -63,16 +65,18 @@ private: friend class FfiClientDevice; std::string deviceAddr_ = INVALID_MAC_ADDRESS; - int remoteRssi{-1}; + int remoteRssi { -1 }; - std::function bleCharacteristicChangeFunc{nullptr}; - std::function bleConnectionStateChangeFunc{nullptr}; - std::function bleMtuChangeFunc{nullptr}; - std::function getRssiValueFunc{nullptr}; - std::function readCharacteristicFunc{nullptr}; - std::function readDescriptorFunc{nullptr}; - std::function writeCharacteristicFunc{nullptr}; - std::function writeDescriptorValueFunc{nullptr}; + std::function bleCharacteristicChangeFunc { nullptr }; + std::function bleConnectionStateChangeFunc { nullptr }; + std::function bleMtuChangeFunc { nullptr }; + std::function getRssiValueFunc { nullptr }; + std::function readCharacteristicFunc { nullptr }; + std::function readDescriptorFunc { nullptr }; + std::function writeCharacteristicFunc { nullptr }; + std::function writeDescriptorValueFunc { nullptr }; + std::function characteristicChangeNotificationFunc { nullptr }; + std::function characteristicChangeIndicationFunc { nullptr }; }; class FfiClientDevice : public OHOS::FFI::FFIData { @@ -89,16 +93,20 @@ public: int32_t Connect(); int32_t Disconnect(); int32_t Close(); - std::string GetDeviceName(int32_t *errCode); - int32_t GetServices(CArrGattService &service); - int32_t ReadCharacteristicValue(NativeBLECharacteristic &characteristic, void (*callback)()); - int32_t ReadDescriptorValue(NativeBLEDescriptor &inputDescriptor, void (*callback)()); + std::string GetDeviceName(int32_t* errCode); + int32_t GetServices(CArrGattService& service); + int32_t ReadCharacteristicValue(NativeBLECharacteristic& characteristic, void (*callback)()); + int32_t ReadDescriptorValue(NativeBLEDescriptor& inputDescriptor, void (*callback)()); int32_t WriteCharacteristicValue(NativeBLECharacteristic characteristic, int32_t writeType, void (*callback)()); int32_t WriteDescriptorValue(NativeBLEDescriptor inputDescriptor, void (*callback)()); int32_t GetRssiValue(void (*callback)()); int32_t SetBLEMtuSize(int32_t mut); int32_t SetCharacteristicChangeNotification(NativeBLECharacteristic characteristic, bool enable); int32_t SetCharacteristicChangeIndication(NativeBLECharacteristic characteristic, bool enable); + int32_t SetCharacteristicChangeNotificationCallback( + NativeBLECharacteristic characteristic, bool enable, void (*callback)()); + int32_t SetCharacteristicChangeIndicationCallback( + NativeBLECharacteristic characteristic, bool enable, void (*callback)()); int32_t RegisterBleGattClientDeviceObserver(int32_t callbackType, void (*callback)()); diff --git a/frameworks/cj/ble/include/bluetooth_ble_common.h b/frameworks/cj/ble/include/bluetooth_ble_common.h index 27f84be9a3d417caba28c14eb27daec83a5a6d47..7bb6f2757d3f0c4050b88eb6c1ca36ebac7ca209 100644 --- a/frameworks/cj/ble/include/bluetooth_ble_common.h +++ b/frameworks/cj/ble/include/bluetooth_ble_common.h @@ -34,19 +34,19 @@ enum ProfileConnectionState { STATE_DISCONNECTING = 3 // the current profile is being disconnected }; -char *MallocCString(const std::string &origin); -CArrString Convert2CArrString(std::vector &tids); +char* MallocCString(const std::string& origin); +CArrString Convert2CArrString(std::vector& tids); CArrUI8 Convert2CArrUI8(std::vector vec); std::string GetGattClientDeviceId(); CArrBLECharacteristic Convert2CArrBLECharacteristic(std::vector characteristics); CArrGattService Convert2CArrGattService(std::vector services); -CArrBLEDescriptor Convert2CArrBLEDescriptor(std::vector &descriptors); +CArrBLEDescriptor Convert2CArrBLEDescriptor(std::vector& descriptors); NativeGattProperties ConvertGattPropertiesToCJ(int properties); -NativeBLECharacteristic ConvertBLECharacteristicToCJ(GattCharacteristic &characteristic); +NativeBLECharacteristic ConvertBLECharacteristicToCJ(GattCharacteristic& characteristic); NativeGattService ConvertGattServiceToCJ(GattService service); -NativeBLEDescriptor ConvertBLEDescriptorToCJ(GattDescriptor &descriptor); -uint16_t ConvertGattPermissions(const NativeGattPermission &nativePermissions); -uint16_t ConvertGattProperties(const NativeGattProperties &nativeProperties); +NativeBLEDescriptor ConvertBLEDescriptorToCJ(GattDescriptor& descriptor); +uint16_t ConvertGattPermissions(const NativeGattPermission& nativePermissions); +uint16_t ConvertGattProperties(const NativeGattProperties& nativeProperties); int GetProfileConnectionState(int state); void FreeNativeBLECharacteristic(NativeBLECharacteristic characteristic); void FreeNativeBLEDescriptor(NativeBLEDescriptor descriptor); diff --git a/frameworks/cj/ble/include/bluetooth_ble_ffi.h b/frameworks/cj/ble/include/bluetooth_ble_ffi.h index 6f0d86143d748edde4b6b7742c1db2bfd5b6710b..5d34f94bbc898f88c0acccd11c572a1e3d36ea6c 100644 --- a/frameworks/cj/ble/include/bluetooth_ble_ffi.h +++ b/frameworks/cj/ble/include/bluetooth_ble_ffi.h @@ -16,19 +16,19 @@ #ifndef BLUETOOTH_BLE_FFI_H #define BLUETOOTH_BLE_FFI_H +#include + #include "cj_common_ffi.h" #include "native/ffi_remote_data.h" -#include - extern "C" { typedef struct { - char *deviceId; - char *name; - char *serviceUuid; - char *serviceUuidMask; - char *serviceSolicitationUuid; - char *serviceSolicitationUuidMask; + char* deviceId; + char* name; + char* serviceUuid; + char* serviceUuidMask; + char* serviceSolicitationUuid; + char* serviceSolicitationUuidMask; CArrUI8 serviceData; CArrUI8 serviceDataMask; uint16_t manufactureId; @@ -37,7 +37,7 @@ typedef struct { } NativeScanFilter; typedef struct { - NativeScanFilter *head; + NativeScanFilter* head; int64_t size; } CArrNativeScanFilter; @@ -60,17 +60,17 @@ typedef struct { } NativeManufactureData; typedef struct { - NativeManufactureData *head; + NativeManufactureData* head; int64_t size; } CArrNativeManufactureData; typedef struct { - char *serviceUuid; + char* serviceUuid; CArrUI8 serviceValue; } NativeServiceData; typedef struct { - NativeServiceData *head; + NativeServiceData* head; int64_t size; } CArrNativeServiceData; @@ -103,22 +103,22 @@ typedef struct { } CAdvertisingStateChangeInfo; typedef struct { - char *deviceId; + char* deviceId; int32_t rssi; CArrUI8 data; - char *deviceName; + char* deviceName; bool connectable; } NativeScanResult; typedef struct { - NativeScanResult *head; + NativeScanResult* head; int64_t size; } CArrScanResult; typedef struct { - char *serviceUuid; - char *characteristicUuid; - char *descriptorUuid; + char* serviceUuid; + char* characteristicUuid; + char* descriptorUuid; CArrUI8 descriptorValue; } NativeBLEDescriptor; @@ -128,7 +128,7 @@ typedef struct { } RetNativeBLEDescriptor; typedef struct { - NativeBLEDescriptor *head; + NativeBLEDescriptor* head; int64_t size; } CArrBLEDescriptor; @@ -141,8 +141,8 @@ typedef struct { } NativeGattProperties; typedef struct { - char *serviceUuid; - char *characteristicUuid; + char* serviceUuid; + char* characteristicUuid; CArrUI8 characteristicValue; CArrBLEDescriptor descriptors; NativeGattProperties properties; @@ -154,33 +154,33 @@ typedef struct { } RetNativeBLECharacteristic; typedef struct { - NativeBLECharacteristic *head; + NativeBLECharacteristic* head; int64_t size; } CArrBLECharacteristic; struct NativeGattService; struct CArrGattService { - NativeGattService *head; + NativeGattService* head; int64_t size; }; struct NativeGattService { - char *serviceUuid; + char* serviceUuid; bool isPrimary; CArrBLECharacteristic characteristics; CArrGattService includeServices; }; typedef struct { - char *serviceUuid; - char *characteristicUuid; + char* serviceUuid; + char* characteristicUuid; CArrUI8 characteristicValue; bool confirm; } NativeNotifyCharacteristic; typedef struct { - char *deviceId; + char* deviceId; int32_t transId; int32_t status; int32_t offset; @@ -189,47 +189,47 @@ typedef struct { } NativeServerResponse; typedef struct { - char *deviceId; + char* deviceId; int32_t transId; int32_t offset; - char *characteristicUuid; - char *serviceUuid; + char* characteristicUuid; + char* serviceUuid; } NativeCharacteristicReadRequest; typedef struct { - char *deviceId; + char* deviceId; int32_t transId; int32_t offset; bool isPrepared; bool needRsp; CArrUI8 value; - char *characteristicUuid; - char *serviceUuid; + char* characteristicUuid; + char* serviceUuid; } NativeCharacteristicWriteRequest; typedef struct { - char *deviceId; + char* deviceId; int32_t transId; int32_t offset; - char *descriptorUuid; - char *characteristicUuid; - char *serviceUuid; + char* descriptorUuid; + char* characteristicUuid; + char* serviceUuid; } NativeDescriptorReadRequest; typedef struct { - char *deviceId; + char* deviceId; int32_t transId; int32_t offset; bool isPrepared; bool needRsp; CArrUI8 value; - char *descriptorUuid; - char *characteristicUuid; - char *serviceUuid; + char* descriptorUuid; + char* characteristicUuid; + char* serviceUuid; } NativeDescriptorWriteRequest; typedef struct { - char *deviceId; + char* deviceId; int32_t state; } NativeBLEConnectionChangeState; @@ -254,52 +254,56 @@ struct NativeGattPermission { bool writeEncrypted = false; }; -FFI_EXPORT int64_t FfiBluetoothBleCreateGattServer(int32_t *errCode); -FFI_EXPORT int64_t FfiBluetoothBleCreateGattClientDevice(const char *deviceId, int32_t *errCode); -FFI_EXPORT CArrString FfiBluetoothBleGetConnectedBleDevices(int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleStartBleScan(CArrNativeScanFilter filters, NativeScanOptions *options, int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleStopBleScan(int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleStartAdvertising(NativeAdvertiseSetting setting, NativeAdvertiseData advData, - NativeAdvertiseData *advResponse, int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleStopAdvertising(int32_t *errCode); -FFI_EXPORT int32_t FfiBluetoothBleStartAdvertisingWithId(NativeAdvertisingParams advertisingParams, int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleEnableAdvertising(NativeAdvertisingEnableParams advertisingEnableParams, - int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleDisableAdvertising(NativeAdvertisingDisableParams advertisingDisableParams, - int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleStopAdvertisingWithId(uint32_t advertisingId, int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleOn(int32_t callbackType, void (*callback)(), int32_t *errCode); - -FFI_EXPORT void FfiBluetoothBleGattClientDeviceConnect(int64_t id, int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattClientDeviceDisconnect(int64_t id, int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattClientDeviceClose(int64_t id, int32_t *errCode); -FFI_EXPORT char *FfiBluetoothBleGattClientDeviceGetDeviceName(int64_t id, int32_t *errCode); -FFI_EXPORT CArrGattService FfiBluetoothBleGattClientDeviceGetServices(int64_t id, int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattClientDeviceReadCharacteristicValue(int64_t id, - NativeBLECharacteristic characteristic, void (*callback)(), int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattClientDeviceReadDescriptorValue(int64_t id, NativeBLEDescriptor descriptor, - void (*callback)(), int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattClientDeviceWriteCharacteristicValue(int64_t id, - NativeBLECharacteristic characteristic, int32_t writeType, void (*callback)(), int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattClientDeviceWriteDescriptorValue(int64_t id, NativeBLEDescriptor descriptor, - void (*callback)(), int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattClientDeviceGetRssiValue(int64_t id, void (*callback)(), int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattClientDeviceSetBLEMtuSize(int64_t id, int32_t mut, int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattClientDeviceSetCharacteristicChangeNotification(int64_t id, - NativeBLECharacteristic characteristic, bool enable, int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattClientDeviceSetCharacteristicChangeIndication(int64_t id, - NativeBLECharacteristic characteristic, bool enable, int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattClientDeviceOn(int64_t id, int32_t callbackType, void (*callback)(), - int32_t *errCode); - -FFI_EXPORT void FfiBluetoothBleGattServerAddService(int64_t id, NativeGattService service, int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattServerRemoveService(int64_t id, char *serviceUuid, int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattServerClose(int64_t id, int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattServerNotifyCharacteristicChanged(int64_t id, char *deviceId, - NativeNotifyCharacteristic characteristic, int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattServerSendResponse(int64_t id, NativeServerResponse serverResponse, - int32_t *errCode); -FFI_EXPORT void FfiBluetoothBleGattServerOn(int64_t id, int32_t callbackType, void (*callback)(), int32_t *errCode); +FFI_EXPORT int64_t FfiBluetoothBleCreateGattServer(int32_t* errCode); +FFI_EXPORT int64_t FfiBluetoothBleCreateGattClientDevice(const char* deviceId, int32_t* errCode); +FFI_EXPORT CArrString FfiBluetoothBleGetConnectedBleDevices(int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleStartBleScan(CArrNativeScanFilter filters, NativeScanOptions* options, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleStopBleScan(int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleStartAdvertising( + NativeAdvertiseSetting setting, NativeAdvertiseData advData, NativeAdvertiseData* advResponse, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleStopAdvertising(int32_t* errCode); +FFI_EXPORT int32_t FfiBluetoothBleStartAdvertisingWithId(NativeAdvertisingParams advertisingParams, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleEnableAdvertising( + NativeAdvertisingEnableParams advertisingEnableParams, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleDisableAdvertising( + NativeAdvertisingDisableParams advertisingDisableParams, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleStopAdvertisingWithId(uint32_t advertisingId, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleOn(int32_t callbackType, void (*callback)(), int32_t* errCode); + +FFI_EXPORT void FfiBluetoothBleGattClientDeviceConnect(int64_t id, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattClientDeviceDisconnect(int64_t id, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattClientDeviceClose(int64_t id, int32_t* errCode); +FFI_EXPORT char* FfiBluetoothBleGattClientDeviceGetDeviceName(int64_t id, int32_t* errCode); +FFI_EXPORT CArrGattService FfiBluetoothBleGattClientDeviceGetServices(int64_t id, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattClientDeviceReadCharacteristicValue( + int64_t id, NativeBLECharacteristic characteristic, void (*callback)(), int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattClientDeviceReadDescriptorValue( + int64_t id, NativeBLEDescriptor descriptor, void (*callback)(), int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattClientDeviceWriteCharacteristicValue( + int64_t id, NativeBLECharacteristic characteristic, int32_t writeType, void (*callback)(), int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattClientDeviceWriteDescriptorValue( + int64_t id, NativeBLEDescriptor descriptor, void (*callback)(), int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattClientDeviceGetRssiValue(int64_t id, void (*callback)(), int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattClientDeviceSetBLEMtuSize(int64_t id, int32_t mut, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattClientDeviceSetCharacteristicChangeNotification( + int64_t id, NativeBLECharacteristic characteristic, bool enable, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattClientDeviceSetCharacteristicChangeIndication( + int64_t id, NativeBLECharacteristic characteristic, bool enable, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattClientDeviceSetCharacteristicChangeNotificationV2( + int64_t id, NativeBLECharacteristic characteristic, bool enable, void (*callback)(), int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattClientDeviceSetCharacteristicChangeIndicationV2( + int64_t id, NativeBLECharacteristic characteristic, bool enable, void (*callback)(), int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattClientDeviceOn( + int64_t id, int32_t callbackType, void (*callback)(), int32_t* errCode); + +FFI_EXPORT void FfiBluetoothBleGattServerAddService(int64_t id, NativeGattService service, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattServerRemoveService(int64_t id, char* serviceUuid, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattServerClose(int64_t id, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattServerNotifyCharacteristicChanged( + int64_t id, char* deviceId, NativeNotifyCharacteristic characteristic, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattServerSendResponse( + int64_t id, NativeServerResponse serverResponse, int32_t* errCode); +FFI_EXPORT void FfiBluetoothBleGattServerOn(int64_t id, int32_t callbackType, void (*callback)(), int32_t* errCode); } #endif // BLUETOOTH_BLE_FFI_H \ No newline at end of file diff --git a/frameworks/cj/ble/include/bluetooth_ble_gattServer.h b/frameworks/cj/ble/include/bluetooth_ble_gattServer.h index 46efbfdf2e987112c85485b34082b1720875cd26..312a9ad40d65cd62e729ba57cca24c6a8eca899c 100644 --- a/frameworks/cj/ble/include/bluetooth_ble_gattServer.h +++ b/frameworks/cj/ble/include/bluetooth_ble_gattServer.h @@ -33,20 +33,20 @@ using Bluetooth::GattService; class FfiGattServerCallback : public GattServerCallback { public: - void OnConnectionStateUpdate(const BluetoothRemoteDevice &device, int state) override; - void OnServiceAdded(GattService service, int ret) override{}; - void OnCharacteristicReadRequest(const BluetoothRemoteDevice &device, GattCharacteristic &characteristic, - int requestId) override; - void OnCharacteristicWriteRequest(const BluetoothRemoteDevice &device, GattCharacteristic &characteristic, - int requestId) override; - void OnDescriptorReadRequest(const BluetoothRemoteDevice &device, GattDescriptor &descriptor, - int requestId) override; - void OnDescriptorWriteRequest(const BluetoothRemoteDevice &device, GattDescriptor &descriptor, - int requestId) override; - void OnMtuUpdate(const BluetoothRemoteDevice &device, int mtu) override; - void OnNotificationCharacteristicChanged(const BluetoothRemoteDevice &device, int result) override{}; - void OnConnectionParameterChanged(const BluetoothRemoteDevice &device, int interval, int latency, int timeout, - int status) override{}; + void OnConnectionStateUpdate(const BluetoothRemoteDevice& device, int state) override; + void OnServiceAdded(GattService service, int ret) override {}; + void OnCharacteristicReadRequest( + const BluetoothRemoteDevice& device, GattCharacteristic& characteristic, int requestId) override; + void OnCharacteristicWriteRequest( + const BluetoothRemoteDevice& device, GattCharacteristic& characteristic, int requestId) override; + void OnDescriptorReadRequest( + const BluetoothRemoteDevice& device, GattDescriptor& descriptor, int requestId) override; + void OnDescriptorWriteRequest( + const BluetoothRemoteDevice& device, GattDescriptor& descriptor, int requestId) override; + void OnMtuUpdate(const BluetoothRemoteDevice& device, int mtu) override; + void OnNotificationCharacteristicChanged(const BluetoothRemoteDevice& device, int result) override {}; + void OnConnectionParameterChanged( + const BluetoothRemoteDevice& device, int interval, int latency, int timeout, int status) override {}; void RegisterCharacteristicReadFunc(std::function cjCallback); void RegisterCharacteristicWriteFunc(std::function cjCallback); @@ -59,12 +59,12 @@ public: ~FfiGattServerCallback() override = default; private: - std::function characteristicReadFunc{nullptr}; - std::function characteristicWriteFunc{nullptr}; - std::function descriptorReadFunc{nullptr}; - std::function descriptorWriteFunc{nullptr}; - std::function connectionStateChangeFunc{nullptr}; - std::function bleMtuChangeFunc{nullptr}; + std::function characteristicReadFunc { nullptr }; + std::function characteristicWriteFunc { nullptr }; + std::function descriptorReadFunc { nullptr }; + std::function descriptorWriteFunc { nullptr }; + std::function connectionStateChangeFunc { nullptr }; + std::function bleMtuChangeFunc { nullptr }; }; class FfiGattServer : public OHOS::FFI::FFIData { @@ -83,7 +83,7 @@ public: int32_t SendResponse(NativeServerResponse serverResponse); int32_t RegisterBleGattServerObserver(int32_t callbackType, void (*callback)()); - std::shared_ptr &GetServer() + std::shared_ptr& GetServer() { return server_; } diff --git a/frameworks/cj/ble/include/bluetooth_ble_impl.h b/frameworks/cj/ble/include/bluetooth_ble_impl.h index 613196c056916c20d6e3dbf1793f778020821490..7e0df990f7ee1a7c1fe283fa5385735d3105b755 100644 --- a/frameworks/cj/ble/include/bluetooth_ble_impl.h +++ b/frameworks/cj/ble/include/bluetooth_ble_impl.h @@ -15,6 +15,8 @@ #ifndef BLUETOOTH_BLE_IMPL_H #define BLUETOOTH_BLE_IMPL_H +#include + #include "bluetooth_ble_advertiser.h" #include "bluetooth_ble_central_manager.h" #include "bluetooth_ble_clientDevice.h" @@ -23,8 +25,6 @@ #include "bluetooth_host.h" #include "napi_bluetooth_utils.h" -#include - namespace OHOS { namespace CJSystemapi { namespace CJBluetoothBle { @@ -42,18 +42,18 @@ public: FfiBluetoothBleCentralManagerCallback(); ~FfiBluetoothBleCentralManagerCallback() override = default; - static FfiBluetoothBleCentralManagerCallback &GetInstance(void); + static FfiBluetoothBleCentralManagerCallback& GetInstance(void); - void OnScanCallback(const BleScanResult &result) override; - void OnFoundOrLostCallback(const BleScanResult &result, uint8_t callbackType) override{}; - void OnBleBatchScanResultsEvent(const std::vector &results) override{}; - void OnStartOrStopScanEvent(int resultCode, bool isStartScan) override{}; - void OnNotifyMsgReportFromLpDevice(const UUID &uuid, int msgType, const std::vector &value) override{}; + void OnScanCallback(const BleScanResult& result) override; + void OnFoundOrLostCallback(const BleScanResult& result, uint8_t callbackType) override {}; + void OnBleBatchScanResultsEvent(const std::vector& results) override {}; + void OnStartOrStopScanEvent(int resultCode, bool isStartScan) override {}; + void OnNotifyMsgReportFromLpDevice(const UUID& uuid, int msgType, const std::vector& value) override {}; void RegisterBLEDeviceFindFunc(std::function cjCallback); private: - std::function bleDeviceFindFunc{nullptr}; + std::function bleDeviceFindFunc { nullptr }; }; class FfiBluetoothBleAdvertiseCallback : public BleAdvertiseCallback { @@ -67,7 +67,7 @@ public: void OnEnableResultEvent(int result, int advHandle) override; void OnDisableResultEvent(int result, int advHandle) override; void OnStopResultEvent(int result, int advHandle) override; - void OnSetAdvDataEvent(int result) override{}; + void OnSetAdvDataEvent(int result) override {}; void OnGetAdvHandleEvent(int result, int advHandle) override; void OnChangeAdvResultEvent(int result, int advHandle) override; @@ -75,8 +75,8 @@ public: int32_t GetAdvHandleEvent(); private: - int32_t handleEvent{-1}; - std::function advertisingStateChangeFunc{nullptr}; + int32_t handleEvent { -1 }; + std::function advertisingStateChangeFunc { nullptr }; }; class BleImpl { @@ -84,15 +84,15 @@ public: BleImpl() = default; ~BleImpl() = default; - static int32_t CreateGattServer(FfiGattServer *&ffiGattServer); - static int32_t CreateGattClientDevice(std::string deviceId, FfiClientDevice *&ffiClientDevice); - static int32_t GetConnectedBleDevices(CArrString &res); - static int32_t StartBleScan(CArrNativeScanFilter filters, NativeScanOptions *options); + static int32_t CreateGattServer(FfiGattServer*& ffiGattServer); + static int32_t CreateGattClientDevice(std::string deviceId, FfiClientDevice*& ffiClientDevice); + static int32_t GetConnectedBleDevices(CArrString& res); + static int32_t StartBleScan(CArrNativeScanFilter filters, NativeScanOptions* options); static int32_t StopBleScan(); - static int32_t StartAdvertising(NativeAdvertiseSetting setting, NativeAdvertiseData advData, - NativeAdvertiseData *advResponse); + static int32_t StartAdvertising( + NativeAdvertiseSetting setting, NativeAdvertiseData advData, NativeAdvertiseData* advResponse); static int32_t StopAdvertising(); - static int32_t StartAdvertising(NativeAdvertisingParams advertisingParams, int32_t &id); + static int32_t StartAdvertising(NativeAdvertisingParams advertisingParams, int32_t& id); static int32_t EnableAdvertising(NativeAdvertisingEnableParams advertisingEnableParams); static int32_t DisableAdvertising(NativeAdvertisingDisableParams advertisingDisableParams); static int32_t StopAdvertising(uint32_t advertisingId); diff --git a/frameworks/cj/ble/src/bluetooth_ble_clientDevice.cpp b/frameworks/cj/ble/src/bluetooth_ble_clientDevice.cpp index 51c28417407f19bf97d34f63205831e95be516de..6852708ae6a14db08be187231985dd60f36511e8 100644 --- a/frameworks/cj/ble/src/bluetooth_ble_clientDevice.cpp +++ b/frameworks/cj/ble/src/bluetooth_ble_clientDevice.cpp @@ -55,7 +55,7 @@ int32_t FfiClientDevice::Close() return client_->Close(); } -std::string FfiClientDevice::GetDeviceName(int32_t *errCode) +std::string FfiClientDevice::GetDeviceName(int32_t* errCode) { std::string deviceName = ""; std::string deviceAddr = GetGattClientDeviceId(); @@ -65,7 +65,7 @@ std::string FfiClientDevice::GetDeviceName(int32_t *errCode) return deviceName; } -int32_t FfiClientDevice::GetServices(CArrGattService &service) +int32_t FfiClientDevice::GetServices(CArrGattService& service) { if (client_ == nullptr) { return BT_ERR_INTERNAL_ERROR; @@ -79,10 +79,10 @@ int32_t FfiClientDevice::GetServices(CArrGattService &service) return ret; } -static GattCharacteristic *GetCharacteristic(const std::shared_ptr &client, const UUID &serviceUuid, - const UUID &characterUuid) +static GattCharacteristic* GetCharacteristic( + const std::shared_ptr& client, const UUID& serviceUuid, const UUID& characterUuid) { - GattCharacteristic *character = nullptr; + GattCharacteristic* character = nullptr; if (client) { auto service = client->GetService(serviceUuid); if (service.has_value()) { @@ -92,21 +92,21 @@ static GattCharacteristic *GetCharacteristic(const std::shared_ptr & return character; } -static GattCharacteristic *GetGattcCharacteristic(const std::shared_ptr &client, - NativeBLECharacteristic &nativeCharacteristic) +static GattCharacteristic* GetGattcCharacteristic( + const std::shared_ptr& client, NativeBLECharacteristic& nativeCharacteristic) { - GattCharacteristic *character = GetCharacteristic(client, UUID::FromString(nativeCharacteristic.serviceUuid), - UUID::FromString(nativeCharacteristic.characteristicUuid)); + GattCharacteristic* character = GetCharacteristic(client, UUID::FromString(nativeCharacteristic.serviceUuid), + UUID::FromString(nativeCharacteristic.characteristicUuid)); if (character) { - character->SetValue(nativeCharacteristic.characteristicValue.head, - nativeCharacteristic.characteristicValue.size); + character->SetValue( + nativeCharacteristic.characteristicValue.head, nativeCharacteristic.characteristicValue.size); } return character; } -int32_t FfiClientDevice::ReadCharacteristicValue(NativeBLECharacteristic &characteristic, void (*callback)()) +int32_t FfiClientDevice::ReadCharacteristicValue(NativeBLECharacteristic& characteristic, void (*callback)()) { - GattCharacteristic *character = GetGattcCharacteristic(client_, characteristic); + GattCharacteristic* character = GetGattcCharacteristic(client_, characteristic); if (character == nullptr) { HILOGE("character is nullptr"); @@ -124,13 +124,13 @@ int32_t FfiClientDevice::ReadCharacteristicValue(NativeBLECharacteristic &charac return BT_NO_ERROR; } -static GattDescriptor *GetGattcDescriptor(const std::shared_ptr &client, - const NativeBLEDescriptor &nativeDescriptor) +static GattDescriptor* GetGattcDescriptor( + const std::shared_ptr& client, const NativeBLEDescriptor& nativeDescriptor) { - GattDescriptor *descriptor = nullptr; + GattDescriptor* descriptor = nullptr; if (client) { - auto *character = GetCharacteristic(client, UUID::FromString(nativeDescriptor.serviceUuid), - UUID::FromString(nativeDescriptor.characteristicUuid)); + auto* character = GetCharacteristic(client, UUID::FromString(nativeDescriptor.serviceUuid), + UUID::FromString(nativeDescriptor.characteristicUuid)); if (character == nullptr) { HILOGE("character is nullptr"); return nullptr; @@ -143,9 +143,9 @@ static GattDescriptor *GetGattcDescriptor(const std::shared_ptr &cli return descriptor; } -int32_t FfiClientDevice::ReadDescriptorValue(NativeBLEDescriptor &inputDescriptor, void (*callback)()) +int32_t FfiClientDevice::ReadDescriptorValue(NativeBLEDescriptor& inputDescriptor, void (*callback)()) { - GattDescriptor *descriptor = GetGattcDescriptor(client_, inputDescriptor); + GattDescriptor* descriptor = GetGattcDescriptor(client_, inputDescriptor); if (descriptor == nullptr) { HILOGE("descriptor is nullptr"); @@ -163,11 +163,11 @@ int32_t FfiClientDevice::ReadDescriptorValue(NativeBLEDescriptor &inputDescripto return BT_NO_ERROR; } -int32_t FfiClientDevice::WriteCharacteristicValue(NativeBLECharacteristic characteristic, int32_t writeType, - void (*callback)()) +int32_t FfiClientDevice::WriteCharacteristicValue( + NativeBLECharacteristic characteristic, int32_t writeType, void (*callback)()) { - GattCharacteristic *character = GetGattcCharacteristic(client_, characteristic); - std::vector value{}; + GattCharacteristic* character = GetGattcCharacteristic(client_, characteristic); + std::vector value {}; if (character == nullptr) { HILOGE("character is nullptr"); @@ -189,7 +189,7 @@ int32_t FfiClientDevice::WriteCharacteristicValue(NativeBLECharacteristic charac int32_t FfiClientDevice::WriteDescriptorValue(NativeBLEDescriptor inputDescriptor, void (*callback)()) { - GattDescriptor *descriptor = GetGattcDescriptor(client_, inputDescriptor); + GattDescriptor* descriptor = GetGattcDescriptor(client_, inputDescriptor); if (descriptor == nullptr) { HILOGE("descriptor is nullptr"); @@ -229,7 +229,7 @@ int32_t FfiClientDevice::SetBLEMtuSize(int32_t mut) int32_t FfiClientDevice::SetCharacteristicChangeNotification(NativeBLECharacteristic characteristic, bool enable) { - GattCharacteristic *character = GetGattcCharacteristic(client_, characteristic); + GattCharacteristic* character = GetGattcCharacteristic(client_, characteristic); if (character == nullptr) { HILOGE("character is nullptr"); return BT_ERR_INTERNAL_ERROR; @@ -243,7 +243,7 @@ int32_t FfiClientDevice::SetCharacteristicChangeNotification(NativeBLECharacteri int32_t FfiClientDevice::SetCharacteristicChangeIndication(NativeBLECharacteristic characteristic, bool enable) { - GattCharacteristic *character = GetGattcCharacteristic(client_, characteristic); + GattCharacteristic* character = GetGattcCharacteristic(client_, characteristic); if (character == nullptr) { HILOGE("character is nullptr"); return BT_ERR_INTERNAL_ERROR; @@ -255,6 +255,46 @@ int32_t FfiClientDevice::SetCharacteristicChangeIndication(NativeBLECharacterist return ret; } +int32_t FfiClientDevice::SetCharacteristicChangeNotificationCallback( + NativeBLECharacteristic characteristic, bool enable, void (*callback)()) +{ + GattCharacteristic* character = GetGattcCharacteristic(client_, characteristic); + if (character == nullptr) { + HILOGE("character is nullptr"); + return BT_ERR_INTERNAL_ERROR; + } + int ret = BT_ERR_INTERNAL_ERROR; + if (client_) { + ret = client_->SetNotifyCharacteristic(*character, enable); + } + if (ret != BT_NO_ERROR) { + return ret; + } + auto characteristicChangeIndicationFunc = CJLambda::Create(reinterpret_cast(callback)); + callback_->RegisterCharacteristicChangeIndicationCallback(characteristicChangeIndicationFunc); + return BT_NO_ERROR; +} + +int32_t FfiClientDevice::SetCharacteristicChangeIndicationCallback( + NativeBLECharacteristic characteristic, bool enable, void (*callback)()) +{ + GattCharacteristic* character = GetGattcCharacteristic(client_, characteristic); + if (character == nullptr) { + HILOGE("character is nullptr"); + return BT_ERR_INTERNAL_ERROR; + } + int ret = BT_ERR_INTERNAL_ERROR; + if (client_) { + ret = client_->SetIndicateCharacteristic(*character, enable); + } + if (ret != BT_NO_ERROR) { + return ret; + } + auto characteristicChangeNotificationFunc = CJLambda::Create(reinterpret_cast(callback)); + callback_->RegisterCharacteristicChangeNotificationCallback(characteristicChangeNotificationFunc); + return BT_NO_ERROR; +} + int32_t FfiClientDevice::RegisterBleGattClientDeviceObserver(int32_t callbackType, void (*callback)()) { if (callbackType == BLE_CHARACTERISTIC_CHANGE) { diff --git a/frameworks/cj/ble/src/bluetooth_ble_common.cpp b/frameworks/cj/ble/src/bluetooth_ble_common.cpp index 267f3914c0b579134eef83a4b0fbd5be2d5156ec..7f7b759b01feeb203f311d5f26456f1be391f980 100644 --- a/frameworks/cj/ble/src/bluetooth_ble_common.cpp +++ b/frameworks/cj/ble/src/bluetooth_ble_common.cpp @@ -15,12 +15,12 @@ #include "bluetooth_ble_common.h" -#include "bluetooth_ble_ffi.h" -#include "bluetooth_log.h" - #include #include +#include "bluetooth_ble_ffi.h" +#include "bluetooth_log.h" + namespace OHOS { namespace CJSystemapi { namespace CJBluetoothBle { @@ -35,31 +35,31 @@ namespace { std::string g_deviceAddr; } // namespace -char *MallocCString(const std::string &origin) +char* MallocCString(const std::string& origin) { if (origin.empty()) { return nullptr; } auto length = origin.length() + 1; - char *res = static_cast(malloc(sizeof(char) * length)); + char* res = static_cast(malloc(sizeof(char) * length)); if (res == nullptr) { return nullptr; } return std::char_traits::copy(res, origin.c_str(), length); } -CArrString Convert2CArrString(std::vector &tids) +CArrString Convert2CArrString(std::vector& tids) { - CArrString res{}; + CArrString res {}; if (tids.empty()) { return res; } size_t size = tids.size(); - if (size == 0 || size > std::numeric_limits::max() / sizeof(char *)) { + if (size == 0 || size > std::numeric_limits::max() / sizeof(char*)) { return res; } - res.head = static_cast(malloc(sizeof(char *) * size)); + res.head = static_cast(malloc(sizeof(char*) * size)); if (res.head == nullptr) { return res; } @@ -75,7 +75,7 @@ CArrString Convert2CArrString(std::vector &tids) CArrUI8 Convert2CArrUI8(std::vector vec) { - CArrUI8 res{}; + CArrUI8 res {}; if (vec.empty()) { return res; } @@ -83,7 +83,7 @@ CArrUI8 Convert2CArrUI8(std::vector vec) if (size == 0 || size > std::numeric_limits::max() / sizeof(uint8_t)) { return res; } - res.head = static_cast(malloc(sizeof(uint8_t) * vec.size())); + res.head = static_cast(malloc(sizeof(uint8_t) * vec.size())); if (res.head == nullptr) { return res; } @@ -95,9 +95,9 @@ CArrUI8 Convert2CArrUI8(std::vector vec) return res; } -NativeBLEDescriptor ConvertBLEDescriptorToCJ(GattDescriptor &descriptor) +NativeBLEDescriptor ConvertBLEDescriptorToCJ(GattDescriptor& descriptor) { - NativeBLEDescriptor outDescriptor{}; + NativeBLEDescriptor outDescriptor {}; outDescriptor.descriptorUuid = MallocCString(descriptor.GetUuid().ToString()); if (descriptor.GetCharacteristic() != nullptr) { outDescriptor.characteristicUuid = MallocCString(descriptor.GetCharacteristic()->GetUuid().ToString()); @@ -108,15 +108,15 @@ NativeBLEDescriptor ConvertBLEDescriptorToCJ(GattDescriptor &descriptor) } size_t valueSize; - uint8_t *valueData = descriptor.GetValue(&valueSize).get(); + uint8_t* valueData = descriptor.GetValue(&valueSize).get(); vector vec(valueData, valueData + valueSize); outDescriptor.descriptorValue = Convert2CArrUI8(vec); return outDescriptor; } -CArrBLEDescriptor Convert2CArrBLEDescriptor(vector &descriptors) +CArrBLEDescriptor Convert2CArrBLEDescriptor(vector& descriptors) { - CArrBLEDescriptor res{}; + CArrBLEDescriptor res {}; if (descriptors.empty()) { return res; } @@ -124,7 +124,7 @@ CArrBLEDescriptor Convert2CArrBLEDescriptor(vector &descriptors) if (size == 0 || size > (std::numeric_limits::max() / sizeof(NativeBLEDescriptor))) { return res; } - res.head = static_cast(malloc(sizeof(NativeBLEDescriptor) * size)); + res.head = static_cast(malloc(sizeof(NativeBLEDescriptor) * size)); if (res.head == nullptr) { return res; } @@ -147,7 +147,7 @@ bool HasProperty(int properties, int propertyMask) NativeGattProperties ConvertGattPropertiesToCJ(int properties) { - NativeGattProperties outProperties{}; + NativeGattProperties outProperties {}; outProperties.write = HasProperty(properties, GattCharacteristic::WRITE); outProperties.writeNoResponse = HasProperty(properties, GattCharacteristic::WRITE_WITHOUT_RESPONSE); outProperties.read = HasProperty(properties, GattCharacteristic::READ); @@ -156,16 +156,16 @@ NativeGattProperties ConvertGattPropertiesToCJ(int properties) return outProperties; } -NativeBLECharacteristic ConvertBLECharacteristicToCJ(GattCharacteristic &characteristic) +NativeBLECharacteristic ConvertBLECharacteristicToCJ(GattCharacteristic& characteristic) { - NativeBLECharacteristic outCharacteristic{}; + NativeBLECharacteristic outCharacteristic {}; outCharacteristic.characteristicUuid = MallocCString(characteristic.GetUuid().ToString()); if (characteristic.GetService() != nullptr) { outCharacteristic.serviceUuid = MallocCString(characteristic.GetService()->GetUuid().ToString()); } size_t valueSize = 0; - uint8_t *valueData = characteristic.GetValue(&valueSize).get(); + uint8_t* valueData = characteristic.GetValue(&valueSize).get(); vector vec(valueData, valueData + valueSize); outCharacteristic.characteristicValue = Convert2CArrUI8(vec); @@ -178,7 +178,7 @@ NativeBLECharacteristic ConvertBLECharacteristicToCJ(GattCharacteristic &charact CArrBLECharacteristic Convert2CArrBLECharacteristic(std::vector characteristics) { - CArrBLECharacteristic res{}; + CArrBLECharacteristic res {}; if (characteristics.empty()) { return res; } @@ -186,7 +186,7 @@ CArrBLECharacteristic Convert2CArrBLECharacteristic(std::vector std::numeric_limits::max() / sizeof(NativeBLECharacteristic)) { return res; } - res.head = static_cast(malloc(sizeof(NativeBLECharacteristic) * size)); + res.head = static_cast(malloc(sizeof(NativeBLECharacteristic) * size)); if (res.head == nullptr) { return res; } @@ -200,13 +200,13 @@ CArrBLECharacteristic Convert2CArrBLECharacteristic(std::vector services; vector> srvs = service.GetIncludedServices(); - for (auto &srv : srvs) { + for (auto& srv : srvs) { services.push_back(srv.get()); } outService.includeServices = Convert2CArrGattService(services); @@ -215,7 +215,7 @@ NativeGattService ConvertGattServiceToCJ(GattService service) CArrGattService Convert2CArrGattService(std::vector services) { - CArrGattService res{}; + CArrGattService res {}; if (services.empty()) { return res; } @@ -223,7 +223,7 @@ CArrGattService Convert2CArrGattService(std::vector services) if (size == 0 || size > std::numeric_limits::max() / sizeof(NativeGattService)) { return res; } - res.head = static_cast(malloc(sizeof(NativeGattService) * services.size())); + res.head = static_cast(malloc(sizeof(NativeGattService) * services.size())); if (res.head == nullptr) { return res; } @@ -240,7 +240,7 @@ std::string GetGattClientDeviceId() return g_deviceAddr; } -uint16_t ConvertGattPermissions(const NativeGattPermission &nativePermissions) +uint16_t ConvertGattPermissions(const NativeGattPermission& nativePermissions) { uint16_t permissions = 0; if (nativePermissions.readable) { @@ -258,7 +258,7 @@ uint16_t ConvertGattPermissions(const NativeGattPermission &nativePermissions) return permissions; } -uint16_t ConvertGattProperties(const NativeGattProperties &nativeProperties) +uint16_t ConvertGattProperties(const NativeGattProperties& nativeProperties) { uint16_t properties = 0; if (nativeProperties.read) { diff --git a/frameworks/cj/ble/src/bluetooth_ble_ffi.cpp b/frameworks/cj/ble/src/bluetooth_ble_ffi.cpp index edb055d355903a9f11559e6c4b831500f690af2c..84bcdae9a637333902b33273c6d09907a7493e9b 100644 --- a/frameworks/cj/ble/src/bluetooth_ble_ffi.cpp +++ b/frameworks/cj/ble/src/bluetooth_ble_ffi.cpp @@ -29,9 +29,9 @@ using Bluetooth::BT_ERR_INTERNAL_ERROR; using Bluetooth::BT_NO_ERROR; extern "C" { -int64_t FfiBluetoothBleCreateGattServer(int32_t *errCode) +int64_t FfiBluetoothBleCreateGattServer(int32_t* errCode) { - FfiGattServer *nativeGattServer = nullptr; + FfiGattServer* nativeGattServer = nullptr; *errCode = BleImpl::CreateGattServer(nativeGattServer); if (*errCode != BT_NO_ERROR) { return -1; @@ -39,9 +39,9 @@ int64_t FfiBluetoothBleCreateGattServer(int32_t *errCode) return nativeGattServer->GetID(); } -int64_t FfiBluetoothBleCreateGattClientDevice(const char *deviceId, int32_t *errCode) +int64_t FfiBluetoothBleCreateGattClientDevice(const char* deviceId, int32_t* errCode) { - FfiClientDevice *nativeGattClientDevice = nullptr; + FfiClientDevice* nativeGattClientDevice = nullptr; *errCode = BleImpl::CreateGattClientDevice(deviceId, nativeGattClientDevice); if (*errCode != BT_NO_ERROR) { return -1; @@ -49,70 +49,70 @@ int64_t FfiBluetoothBleCreateGattClientDevice(const char *deviceId, int32_t *err return nativeGattClientDevice->GetID(); } -CArrString FfiBluetoothBleGetConnectedBleDevices(int32_t *errCode) +CArrString FfiBluetoothBleGetConnectedBleDevices(int32_t* errCode) { - CArrString res{}; + CArrString res {}; *errCode = BleImpl::GetConnectedBleDevices(res); return res; } -void FfiBluetoothBleStartBleScan(CArrNativeScanFilter filters, NativeScanOptions *options, int32_t *errCode) +void FfiBluetoothBleStartBleScan(CArrNativeScanFilter filters, NativeScanOptions* options, int32_t* errCode) { *errCode = BleImpl::StartBleScan(filters, options); return; } -void FfiBluetoothBleStopBleScan(int32_t *errCode) +void FfiBluetoothBleStopBleScan(int32_t* errCode) { *errCode = BleImpl::StopBleScan(); return; } -void FfiBluetoothBleStartAdvertising(NativeAdvertiseSetting setting, NativeAdvertiseData advData, - NativeAdvertiseData *advResponse, int32_t *errCode) +void FfiBluetoothBleStartAdvertising( + NativeAdvertiseSetting setting, NativeAdvertiseData advData, NativeAdvertiseData* advResponse, int32_t* errCode) { *errCode = BleImpl::StartAdvertising(setting, advData, advResponse); return; } -void FfiBluetoothBleStopAdvertising(int32_t *errCode) +void FfiBluetoothBleStopAdvertising(int32_t* errCode) { *errCode = BleImpl::StopAdvertising(); return; } -int32_t FfiBluetoothBleStartAdvertisingWithId(NativeAdvertisingParams advertisingParams, int32_t *errCode) +int32_t FfiBluetoothBleStartAdvertisingWithId(NativeAdvertisingParams advertisingParams, int32_t* errCode) { int32_t id = -1; *errCode = BleImpl::StartAdvertising(advertisingParams, id); return id; } -void FfiBluetoothBleEnableAdvertising(NativeAdvertisingEnableParams advertisingEnableParams, int32_t *errCode) +void FfiBluetoothBleEnableAdvertising(NativeAdvertisingEnableParams advertisingEnableParams, int32_t* errCode) { *errCode = BleImpl::EnableAdvertising(advertisingEnableParams); return; } -void FfiBluetoothBleDisableAdvertising(NativeAdvertisingDisableParams advertisingDisableParams, int32_t *errCode) +void FfiBluetoothBleDisableAdvertising(NativeAdvertisingDisableParams advertisingDisableParams, int32_t* errCode) { *errCode = BleImpl::DisableAdvertising(advertisingDisableParams); return; } -void FfiBluetoothBleStopAdvertisingWithId(uint32_t advertisingId, int32_t *errCode) +void FfiBluetoothBleStopAdvertisingWithId(uint32_t advertisingId, int32_t* errCode) { *errCode = BleImpl::StopAdvertising(advertisingId); return; } -void FfiBluetoothBleOn(int32_t callbackType, void (*callback)(), int32_t *errCode) +void FfiBluetoothBleOn(int32_t callbackType, void (*callback)(), int32_t* errCode) { *errCode = BleImpl::RegisterBleObserver(callbackType, callback); return; } -void FfiBluetoothBleGattClientDeviceConnect(int64_t id, int32_t *errCode) +void FfiBluetoothBleGattClientDeviceConnect(int64_t id, int32_t* errCode) { auto clientDevice = FFIData::GetData(id); if (clientDevice == nullptr) { @@ -123,7 +123,7 @@ void FfiBluetoothBleGattClientDeviceConnect(int64_t id, int32_t *errCode) return; } -void FfiBluetoothBleGattClientDeviceDisconnect(int64_t id, int32_t *errCode) +void FfiBluetoothBleGattClientDeviceDisconnect(int64_t id, int32_t* errCode) { auto clientDevice = FFIData::GetData(id); if (clientDevice == nullptr) { @@ -134,7 +134,7 @@ void FfiBluetoothBleGattClientDeviceDisconnect(int64_t id, int32_t *errCode) return; } -void FfiBluetoothBleGattClientDeviceClose(int64_t id, int32_t *errCode) +void FfiBluetoothBleGattClientDeviceClose(int64_t id, int32_t* errCode) { auto clientDevice = FFIData::GetData(id); if (clientDevice == nullptr) { @@ -145,7 +145,7 @@ void FfiBluetoothBleGattClientDeviceClose(int64_t id, int32_t *errCode) return; } -char *FfiBluetoothBleGattClientDeviceGetDeviceName(int64_t id, int32_t *errCode) +char* FfiBluetoothBleGattClientDeviceGetDeviceName(int64_t id, int32_t* errCode) { auto clientDevice = FFIData::GetData(id); if (clientDevice == nullptr) { @@ -156,9 +156,9 @@ char *FfiBluetoothBleGattClientDeviceGetDeviceName(int64_t id, int32_t *errCode) return MallocCString(name); } -CArrGattService FfiBluetoothBleGattClientDeviceGetServices(int64_t id, int32_t *errCode) +CArrGattService FfiBluetoothBleGattClientDeviceGetServices(int64_t id, int32_t* errCode) { - CArrGattService service{}; + CArrGattService service {}; auto clientDevice = FFIData::GetData(id); if (clientDevice == nullptr) { *errCode = BT_ERR_INTERNAL_ERROR; @@ -168,8 +168,8 @@ CArrGattService FfiBluetoothBleGattClientDeviceGetServices(int64_t id, int32_t * return service; } -void FfiBluetoothBleGattClientDeviceReadCharacteristicValue(int64_t id, NativeBLECharacteristic characteristic, - void (*callback)(), int32_t *errCode) +void FfiBluetoothBleGattClientDeviceReadCharacteristicValue( + int64_t id, NativeBLECharacteristic characteristic, void (*callback)(), int32_t* errCode) { auto clientDevice = FFIData::GetData(id); if (clientDevice == nullptr) { @@ -180,8 +180,8 @@ void FfiBluetoothBleGattClientDeviceReadCharacteristicValue(int64_t id, NativeBL return; } -void FfiBluetoothBleGattClientDeviceReadDescriptorValue(int64_t id, NativeBLEDescriptor descriptor, void (*callback)(), - int32_t *errCode) +void FfiBluetoothBleGattClientDeviceReadDescriptorValue( + int64_t id, NativeBLEDescriptor descriptor, void (*callback)(), int32_t* errCode) { auto clientDevice = FFIData::GetData(id); if (clientDevice == nullptr) { @@ -192,8 +192,8 @@ void FfiBluetoothBleGattClientDeviceReadDescriptorValue(int64_t id, NativeBLEDes return; } -void FfiBluetoothBleGattClientDeviceWriteCharacteristicValue(int64_t id, NativeBLECharacteristic characteristic, - int32_t writeType, void (*callback)(), int32_t *errCode) +void FfiBluetoothBleGattClientDeviceWriteCharacteristicValue( + int64_t id, NativeBLECharacteristic characteristic, int32_t writeType, void (*callback)(), int32_t* errCode) { auto clientDevice = FFIData::GetData(id); if (clientDevice == nullptr) { @@ -204,8 +204,8 @@ void FfiBluetoothBleGattClientDeviceWriteCharacteristicValue(int64_t id, NativeB return; } -void FfiBluetoothBleGattClientDeviceWriteDescriptorValue(int64_t id, NativeBLEDescriptor descriptor, void (*callback)(), - int32_t *errCode) +void FfiBluetoothBleGattClientDeviceWriteDescriptorValue( + int64_t id, NativeBLEDescriptor descriptor, void (*callback)(), int32_t* errCode) { auto clientDevice = FFIData::GetData(id); if (clientDevice == nullptr) { @@ -216,7 +216,7 @@ void FfiBluetoothBleGattClientDeviceWriteDescriptorValue(int64_t id, NativeBLEDe return; } -void FfiBluetoothBleGattClientDeviceGetRssiValue(int64_t id, void (*callback)(), int32_t *errCode) +void FfiBluetoothBleGattClientDeviceGetRssiValue(int64_t id, void (*callback)(), int32_t* errCode) { auto clientDevice = FFIData::GetData(id); if (clientDevice == nullptr) { @@ -227,7 +227,7 @@ void FfiBluetoothBleGattClientDeviceGetRssiValue(int64_t id, void (*callback)(), return; } -void FfiBluetoothBleGattClientDeviceSetBLEMtuSize(int64_t id, int32_t mut, int32_t *errCode) +void FfiBluetoothBleGattClientDeviceSetBLEMtuSize(int64_t id, int32_t mut, int32_t* errCode) { auto clientDevice = FFIData::GetData(id); if (clientDevice == nullptr) { @@ -238,9 +238,8 @@ void FfiBluetoothBleGattClientDeviceSetBLEMtuSize(int64_t id, int32_t mut, int32 return; } -void FfiBluetoothBleGattClientDeviceSetCharacteristicChangeNotification(int64_t id, - NativeBLECharacteristic characteristic, - bool enable, int32_t *errCode) +void FfiBluetoothBleGattClientDeviceSetCharacteristicChangeNotification( + int64_t id, NativeBLECharacteristic characteristic, bool enable, int32_t* errCode) { auto clientDevice = FFIData::GetData(id); if (clientDevice == nullptr) { @@ -251,9 +250,8 @@ void FfiBluetoothBleGattClientDeviceSetCharacteristicChangeNotification(int64_t return; } -void FfiBluetoothBleGattClientDeviceSetCharacteristicChangeIndication(int64_t id, - NativeBLECharacteristic characteristic, - bool enable, int32_t *errCode) +void FfiBluetoothBleGattClientDeviceSetCharacteristicChangeIndication( + int64_t id, NativeBLECharacteristic characteristic, bool enable, int32_t* errCode) { auto clientDevice = FFIData::GetData(id); if (clientDevice == nullptr) { @@ -264,7 +262,31 @@ void FfiBluetoothBleGattClientDeviceSetCharacteristicChangeIndication(int64_t id return; } -void FfiBluetoothBleGattClientDeviceOn(int64_t id, int32_t callbackType, void (*callback)(), int32_t *errCode) +void FfiBluetoothBleGattClientDeviceSetCharacteristicChangeNotificationV2( + int64_t id, NativeBLECharacteristic characteristic, bool enable, void (*callback)(), int32_t* errCode) +{ + auto clientDevice = FFIData::GetData(id); + if (clientDevice == nullptr) { + *errCode = BT_ERR_INTERNAL_ERROR; + return; + } + *errCode = clientDevice->SetCharacteristicChangeNotificationCallback(characteristic, enable, callback); + return; +} + +void FfiBluetoothBleGattClientDeviceSetCharacteristicChangeIndicationV2( + int64_t id, NativeBLECharacteristic characteristic, bool enable, void (*callback)(), int32_t* errCode) +{ + auto clientDevice = FFIData::GetData(id); + if (clientDevice == nullptr) { + *errCode = BT_ERR_INTERNAL_ERROR; + return; + } + *errCode = clientDevice->SetCharacteristicChangeIndicationCallback(characteristic, enable, callback); + return; +} + +void FfiBluetoothBleGattClientDeviceOn(int64_t id, int32_t callbackType, void (*callback)(), int32_t* errCode) { auto clientDevice = FFIData::GetData(id); if (clientDevice == nullptr) { @@ -275,7 +297,7 @@ void FfiBluetoothBleGattClientDeviceOn(int64_t id, int32_t callbackType, void (* return; } -void FfiBluetoothBleGattServerAddService(int64_t id, NativeGattService service, int32_t *errCode) +void FfiBluetoothBleGattServerAddService(int64_t id, NativeGattService service, int32_t* errCode) { auto gattServer = FFIData::GetData(id); if (gattServer == nullptr) { @@ -286,7 +308,7 @@ void FfiBluetoothBleGattServerAddService(int64_t id, NativeGattService service, return; } -void FfiBluetoothBleGattServerRemoveService(int64_t id, char *serviceUuid, int32_t *errCode) +void FfiBluetoothBleGattServerRemoveService(int64_t id, char* serviceUuid, int32_t* errCode) { auto gattServer = FFIData::GetData(id); if (gattServer == nullptr) { @@ -297,7 +319,7 @@ void FfiBluetoothBleGattServerRemoveService(int64_t id, char *serviceUuid, int32 return; } -void FfiBluetoothBleGattServerClose(int64_t id, int32_t *errCode) +void FfiBluetoothBleGattServerClose(int64_t id, int32_t* errCode) { auto gattServer = FFIData::GetData(id); if (gattServer == nullptr) { @@ -308,8 +330,8 @@ void FfiBluetoothBleGattServerClose(int64_t id, int32_t *errCode) return; } -void FfiBluetoothBleGattServerNotifyCharacteristicChanged(int64_t id, char *deviceId, - NativeNotifyCharacteristic characteristic, int32_t *errCode) +void FfiBluetoothBleGattServerNotifyCharacteristicChanged( + int64_t id, char* deviceId, NativeNotifyCharacteristic characteristic, int32_t* errCode) { auto gattServer = FFIData::GetData(id); if (gattServer == nullptr) { @@ -320,7 +342,7 @@ void FfiBluetoothBleGattServerNotifyCharacteristicChanged(int64_t id, char *devi return; } -void FfiBluetoothBleGattServerSendResponse(int64_t id, NativeServerResponse serverResponse, int32_t *errCode) +void FfiBluetoothBleGattServerSendResponse(int64_t id, NativeServerResponse serverResponse, int32_t* errCode) { auto gattServer = FFIData::GetData(id); if (gattServer == nullptr) { @@ -331,7 +353,7 @@ void FfiBluetoothBleGattServerSendResponse(int64_t id, NativeServerResponse serv return; } -void FfiBluetoothBleGattServerOn(int64_t id, int32_t callbackType, void (*callback)(), int32_t *errCode) +void FfiBluetoothBleGattServerOn(int64_t id, int32_t callbackType, void (*callback)(), int32_t* errCode) { auto gattServer = FFIData::GetData(id); if (gattServer == nullptr) { diff --git a/frameworks/cj/ble/src/bluetooth_ble_ffiAdvertiseCallback.cpp b/frameworks/cj/ble/src/bluetooth_ble_ffiAdvertiseCallback.cpp index e35aa6af0b99af5f1e68cbaf62983a955fa2666f..fad21973a503be9d49ce05a6fcdd6958a51e6c3e 100644 --- a/frameworks/cj/ble/src/bluetooth_ble_ffiAdvertiseCallback.cpp +++ b/frameworks/cj/ble/src/bluetooth_ble_ffiAdvertiseCallback.cpp @@ -20,9 +20,7 @@ namespace CJSystemapi { namespace CJBluetoothBle { using Bluetooth::AdvertisingState; -FfiBluetoothBleAdvertiseCallback::FfiBluetoothBleAdvertiseCallback() -{ -} +FfiBluetoothBleAdvertiseCallback::FfiBluetoothBleAdvertiseCallback() {} std::shared_ptr FfiBluetoothBleAdvertiseCallback::GetInstance(void) { @@ -39,7 +37,7 @@ void FfiBluetoothBleAdvertiseCallback::RegisterAdvertisingStateChangeFunc( void FfiBluetoothBleAdvertiseCallback::OnStartResultEvent(int result, int advHandle) { - CAdvertisingStateChangeInfo info{0}; + CAdvertisingStateChangeInfo info { 0 }; info.advertisingId = advHandle; info.state = static_cast(AdvertisingState::STARTED); if (advertisingStateChangeFunc != nullptr) { @@ -50,7 +48,7 @@ void FfiBluetoothBleAdvertiseCallback::OnStartResultEvent(int result, int advHan void FfiBluetoothBleAdvertiseCallback::OnEnableResultEvent(int result, int advHandle) { - CAdvertisingStateChangeInfo info{0}; + CAdvertisingStateChangeInfo info { 0 }; info.advertisingId = advHandle; info.state = static_cast(AdvertisingState::ENABLED); if (advertisingStateChangeFunc != nullptr) { @@ -61,7 +59,7 @@ void FfiBluetoothBleAdvertiseCallback::OnEnableResultEvent(int result, int advHa void FfiBluetoothBleAdvertiseCallback::OnDisableResultEvent(int result, int advHandle) { - CAdvertisingStateChangeInfo info{0}; + CAdvertisingStateChangeInfo info { 0 }; info.advertisingId = advHandle; info.state = static_cast(AdvertisingState::DISABLED); if (advertisingStateChangeFunc != nullptr) { @@ -72,7 +70,7 @@ void FfiBluetoothBleAdvertiseCallback::OnDisableResultEvent(int result, int advH void FfiBluetoothBleAdvertiseCallback::OnStopResultEvent(int result, int advHandle) { - CAdvertisingStateChangeInfo info{0}; + CAdvertisingStateChangeInfo info { 0 }; info.advertisingId = advHandle; info.state = static_cast(AdvertisingState::STOPPED); if (advertisingStateChangeFunc != nullptr) { @@ -87,8 +85,7 @@ void FfiBluetoothBleAdvertiseCallback::OnGetAdvHandleEvent(int result, int advHa return; } -void FfiBluetoothBleAdvertiseCallback::OnChangeAdvResultEvent(int result, int advHandle) -{} +void FfiBluetoothBleAdvertiseCallback::OnChangeAdvResultEvent(int result, int advHandle) {} int32_t FfiBluetoothBleAdvertiseCallback::GetAdvHandleEvent() { diff --git a/frameworks/cj/ble/src/bluetooth_ble_ffiCentralManagerCallback.cpp b/frameworks/cj/ble/src/bluetooth_ble_ffiCentralManagerCallback.cpp index 193cc2abb9ac5d652c5adb6ce603c9a2bba23987..9a0bf76ce39c93c4a5ff56c57b9d687bc553feae 100644 --- a/frameworks/cj/ble/src/bluetooth_ble_ffiCentralManagerCallback.cpp +++ b/frameworks/cj/ble/src/bluetooth_ble_ffiCentralManagerCallback.cpp @@ -20,11 +20,9 @@ namespace OHOS { namespace CJSystemapi { namespace CJBluetoothBle { -FfiBluetoothBleCentralManagerCallback::FfiBluetoothBleCentralManagerCallback() -{ -} +FfiBluetoothBleCentralManagerCallback::FfiBluetoothBleCentralManagerCallback() {} -FfiBluetoothBleCentralManagerCallback &FfiBluetoothBleCentralManagerCallback::GetInstance(void) +FfiBluetoothBleCentralManagerCallback& FfiBluetoothBleCentralManagerCallback::GetInstance(void) { static FfiBluetoothBleCentralManagerCallback instance; return instance; @@ -35,20 +33,20 @@ void FfiBluetoothBleCentralManagerCallback::RegisterBLEDeviceFindFunc(std::funct bleDeviceFindFunc = cjCallback; } -void FfiBluetoothBleCentralManagerCallback::OnScanCallback(const BleScanResult &result) +void FfiBluetoothBleCentralManagerCallback::OnScanCallback(const BleScanResult& result) { if (bleDeviceFindFunc == nullptr) { return; } - CArrScanResult outResults{}; + CArrScanResult outResults {}; outResults.size = 1; - NativeScanResult *resultValue = static_cast(malloc(sizeof(NativeScanResult) * outResults.size)); + NativeScanResult* resultValue = static_cast(malloc(sizeof(NativeScanResult) * outResults.size)); if (resultValue == nullptr) { return; } for (int i = 0; i < outResults.size; i++) { BleScanResult bleScanResult = result; - NativeScanResult nativeResult{}; + NativeScanResult nativeResult {}; nativeResult.deviceId = MallocCString(bleScanResult.GetPeripheralDevice().GetDeviceAddr()); nativeResult.rssi = bleScanResult.GetRssi(); nativeResult.data = Convert2CArrUI8(bleScanResult.GetPayload()); diff --git a/frameworks/cj/ble/src/bluetooth_ble_ffiGattClientCallback.cpp b/frameworks/cj/ble/src/bluetooth_ble_ffiGattClientCallback.cpp index db400fa01a3c49b5dac2b458e6ef1d7ed272a68f..153f77d7078c5baa4fac7d2a16338584e4e92d15 100644 --- a/frameworks/cj/ble/src/bluetooth_ble_ffiGattClientCallback.cpp +++ b/frameworks/cj/ble/src/bluetooth_ble_ffiGattClientCallback.cpp @@ -14,7 +14,6 @@ */ #include "bluetooth_ble_clientDevice.h" - #include "bluetooth_ble_common.h" #include "bluetooth_log.h" @@ -22,34 +21,32 @@ namespace OHOS { namespace CJSystemapi { namespace CJBluetoothBle { -FfiGattClientCallback::FfiGattClientCallback() -{ -} +FfiGattClientCallback::FfiGattClientCallback() {} void FfiGattClientCallback::OnReadRemoteRssiValueResult(int rssi, int status) { if (getRssiValueFunc != nullptr) { - RetDataI32 res{}; + RetDataI32 res {}; res.code = status; res.data = rssi; getRssiValueFunc(res); } } -void FfiGattClientCallback::OnCharacteristicChanged(const GattCharacteristic &characteristic) +void FfiGattClientCallback::OnCharacteristicChanged(const GattCharacteristic& characteristic) { - NativeBLECharacteristic outCharacteristic{}; + NativeBLECharacteristic outCharacteristic {}; - GattCharacteristic character_ = const_cast(characteristic); + GattCharacteristic character_ = const_cast(characteristic); outCharacteristic.characteristicUuid = MallocCString(character_.GetUuid().ToString().c_str()); if (character_.GetService() != nullptr) { outCharacteristic.serviceUuid = MallocCString(character_.GetService()->GetUuid().ToString().c_str()); } size_t valueSize = 0; - uint8_t *valueData = character_.GetValue(&valueSize).get(); + uint8_t* valueData = character_.GetValue(&valueSize).get(); - CArrUI8 arr{}; + CArrUI8 arr {}; arr.head = valueData; arr.size = static_cast(valueSize); outCharacteristic.characteristicValue = arr; @@ -63,11 +60,11 @@ void FfiGattClientCallback::OnCharacteristicChanged(const GattCharacteristic &ch FreeNativeBLECharacteristic(outCharacteristic); } -void FfiGattClientCallback::OnCharacteristicReadResult(const GattCharacteristic &characteristic, int ret) +void FfiGattClientCallback::OnCharacteristicReadResult(const GattCharacteristic& characteristic, int ret) { HILOGI("UUID: %{public}s, ret: %{public}d", characteristic.GetUuid().ToString().c_str(), ret); - RetNativeBLECharacteristic res{}; - res.data = ConvertBLECharacteristicToCJ(const_cast(characteristic)); + RetNativeBLECharacteristic res {}; + res.data = ConvertBLECharacteristicToCJ(const_cast(characteristic)); res.code = ret; if (readCharacteristicFunc != nullptr) { readCharacteristicFunc(res); @@ -75,7 +72,7 @@ void FfiGattClientCallback::OnCharacteristicReadResult(const GattCharacteristic FreeNativeBLECharacteristic(res.data); } -void FfiGattClientCallback::OnCharacteristicWriteResult(const GattCharacteristic &characteristic, int ret) +void FfiGattClientCallback::OnCharacteristicWriteResult(const GattCharacteristic& characteristic, int ret) { HILOGI("UUID: %{public}s, ret: %{public}d", characteristic.GetUuid().ToString().c_str(), ret); if (writeCharacteristicFunc != nullptr) { @@ -83,11 +80,11 @@ void FfiGattClientCallback::OnCharacteristicWriteResult(const GattCharacteristic } } -void FfiGattClientCallback::OnDescriptorReadResult(const GattDescriptor &descriptor, int ret) +void FfiGattClientCallback::OnDescriptorReadResult(const GattDescriptor& descriptor, int ret) { HILOGI("UUID: %{public}s, ret: %{public}d", descriptor.GetUuid().ToString().c_str(), ret); - RetNativeBLEDescriptor res{}; - res.data = ConvertBLEDescriptorToCJ(const_cast(descriptor)); + RetNativeBLEDescriptor res {}; + res.data = ConvertBLEDescriptorToCJ(const_cast(descriptor)); res.code = ret; if (readDescriptorFunc != nullptr) { readDescriptorFunc(res); @@ -95,7 +92,7 @@ void FfiGattClientCallback::OnDescriptorReadResult(const GattDescriptor &descrip FreeNativeBLEDescriptor(res.data); } -void FfiGattClientCallback::OnDescriptorWriteResult(const GattDescriptor &descriptor, int ret) +void FfiGattClientCallback::OnDescriptorWriteResult(const GattDescriptor& descriptor, int ret) { HILOGI("UUID: %{public}s, ret: %{public}d", descriptor.GetUuid().ToString().c_str(), ret); if (writeDescriptorValueFunc != nullptr) { @@ -107,7 +104,7 @@ void FfiGattClientCallback::OnConnectionStateChanged(int connectionState, int re { int connectState_ = connectionState; - NativeBLEConnectionChangeState outState{}; + NativeBLEConnectionChangeState outState {}; outState.deviceId = MallocCString(deviceAddr_.c_str()); outState.state = GetProfileConnectionState(connectState_); @@ -125,6 +122,16 @@ void FfiGattClientCallback::OnMtuUpdate(int mtu, int ret) bleMtuChangeFunc(mtu); } } +void FfiGattClientCallback::OnSetNotifyCharacteristic(const GattCharacteristic& characteristic, int status) +{ + HILOGI("UUID: %{public}s, ret: %{public}d", characteristic.GetUuid().ToString().c_str(), status); + if (characteristicChangeNotificationFunc != nullptr) { + characteristicChangeNotificationFunc(status); + } + if (characteristicChangeIndicationFunc != nullptr) { + characteristicChangeIndicationFunc(status); + } +} void FfiGattClientCallback::RegisterBLECharacteristicChangeFunc(std::function cjCallback) { @@ -167,6 +174,16 @@ void FfiGattClientCallback::RegisterWriteDescriptorCallback(std::function cjCallback) +{ + characteristicChangeNotificationFunc = cjCallback; +} + +void FfiGattClientCallback::RegisterCharacteristicChangeIndicationCallback(std::function cjCallback) +{ + characteristicChangeIndicationFunc = cjCallback; +} + } // namespace CJBluetoothBle } // namespace CJSystemapi } // namespace OHOS \ No newline at end of file diff --git a/frameworks/cj/ble/src/bluetooth_ble_ffiGattServerCallback.cpp b/frameworks/cj/ble/src/bluetooth_ble_ffiGattServerCallback.cpp index 177ff2c300fdc3ae7604cd65107e6b447eaf3d72..62036ab1b4202a85a65b95329cdb3b06bdaaf5af 100644 --- a/frameworks/cj/ble/src/bluetooth_ble_ffiGattServerCallback.cpp +++ b/frameworks/cj/ble/src/bluetooth_ble_ffiGattServerCallback.cpp @@ -13,9 +13,8 @@ * limitations under the License. */ -#include "bluetooth_ble_gattServer.h" - #include "bluetooth_ble_common.h" +#include "bluetooth_ble_gattServer.h" #include "bluetooth_gatt_characteristic.h" #include "bluetooth_gatt_descriptor.h" #include "bluetooth_log.h" @@ -27,17 +26,15 @@ using Bluetooth::BTConnectState; using Bluetooth::GattCharacteristic; using Bluetooth::GattDescriptor; -FfiGattServerCallback::FfiGattServerCallback() -{ -} +FfiGattServerCallback::FfiGattServerCallback() {} -void FfiGattServerCallback::OnCharacteristicReadRequest(const BluetoothRemoteDevice &device, - GattCharacteristic &characteristic, int requestId) +void FfiGattServerCallback::OnCharacteristicReadRequest( + const BluetoothRemoteDevice& device, GattCharacteristic& characteristic, int requestId) { int transId_ = requestId; std::string deviceAddr_ = device.GetDeviceAddr(); - NativeCharacteristicReadRequest request{}; + NativeCharacteristicReadRequest request {}; request.deviceId = MallocCString(deviceAddr_.c_str()); request.transId = transId_; request.offset = 0; @@ -57,13 +54,13 @@ void FfiGattServerCallback::OnCharacteristicReadRequest(const BluetoothRemoteDev request.serviceUuid = nullptr; } -void FfiGattServerCallback::OnCharacteristicWriteRequest(const BluetoothRemoteDevice &device, - GattCharacteristic &characteristic, int requestId) +void FfiGattServerCallback::OnCharacteristicWriteRequest( + const BluetoothRemoteDevice& device, GattCharacteristic& characteristic, int requestId) { int transId_ = requestId; std::string deviceAddr_ = device.GetDeviceAddr(); - NativeCharacteristicWriteRequest request{}; + NativeCharacteristicWriteRequest request {}; request.deviceId = MallocCString(deviceAddr_.c_str()); request.transId = transId_; request.offset = 0; @@ -71,9 +68,9 @@ void FfiGattServerCallback::OnCharacteristicWriteRequest(const BluetoothRemoteDe request.needRsp = characteristic.GetWriteType() == GattCharacteristic::WriteType::DEFAULT; size_t valueSize; - uint8_t *valueData = characteristic.GetValue(&valueSize).get(); + uint8_t* valueData = characteristic.GetValue(&valueSize).get(); - CArrUI8 arr{}; + CArrUI8 arr {}; arr.head = valueData; arr.size = static_cast(valueSize); request.value = arr; @@ -93,13 +90,13 @@ void FfiGattServerCallback::OnCharacteristicWriteRequest(const BluetoothRemoteDe request.serviceUuid = nullptr; } -void FfiGattServerCallback::OnDescriptorReadRequest(const BluetoothRemoteDevice &device, GattDescriptor &descriptor, - int requestId) +void FfiGattServerCallback::OnDescriptorReadRequest( + const BluetoothRemoteDevice& device, GattDescriptor& descriptor, int requestId) { int transId_ = requestId; std::string deviceAddr_ = device.GetDeviceAddr(); - NativeDescriptorReadRequest request{}; + NativeDescriptorReadRequest request {}; request.deviceId = MallocCString(deviceAddr_.c_str()); request.transId = transId_; @@ -124,13 +121,13 @@ void FfiGattServerCallback::OnDescriptorReadRequest(const BluetoothRemoteDevice request.serviceUuid = nullptr; } -void FfiGattServerCallback::OnDescriptorWriteRequest(const BluetoothRemoteDevice &device, GattDescriptor &descriptor, - int requestId) +void FfiGattServerCallback::OnDescriptorWriteRequest( + const BluetoothRemoteDevice& device, GattDescriptor& descriptor, int requestId) { int transId_ = requestId; std::string deviceAddr_ = device.GetDeviceAddr(); - NativeDescriptorWriteRequest request{}; + NativeDescriptorWriteRequest request {}; request.deviceId = MallocCString(deviceAddr_.c_str()); request.transId = transId_; @@ -139,9 +136,9 @@ void FfiGattServerCallback::OnDescriptorWriteRequest(const BluetoothRemoteDevice request.needRsp = true; size_t valueSize; - uint8_t *valueData = descriptor.GetValue(&valueSize).get(); + uint8_t* valueData = descriptor.GetValue(&valueSize).get(); - CArrUI8 arr{}; + CArrUI8 arr {}; arr.head = valueData; arr.size = static_cast(valueSize); request.value = arr; @@ -168,7 +165,7 @@ void FfiGattServerCallback::OnDescriptorWriteRequest(const BluetoothRemoteDevice request.serviceUuid = nullptr; } -void FfiGattServerCallback::OnConnectionStateUpdate(const BluetoothRemoteDevice &device, int state) +void FfiGattServerCallback::OnConnectionStateUpdate(const BluetoothRemoteDevice& device, int state) { std::lock_guard lock(FfiGattServer::deviceListMutex_); if (state == static_cast(BTConnectState::CONNECTED)) { @@ -198,7 +195,7 @@ void FfiGattServerCallback::OnConnectionStateUpdate(const BluetoothRemoteDevice std::string deviceAddr_ = device.GetDeviceAddr(); int connectState_ = GetProfileConnectionState(state); - NativeBLEConnectionChangeState changeState{}; + NativeBLEConnectionChangeState changeState {}; changeState.deviceId = MallocCString(deviceAddr_.c_str()); changeState.state = connectState_; @@ -210,7 +207,7 @@ void FfiGattServerCallback::OnConnectionStateUpdate(const BluetoothRemoteDevice changeState.deviceId = nullptr; } -void FfiGattServerCallback::OnMtuUpdate(const BluetoothRemoteDevice &device, int mtu) +void FfiGattServerCallback::OnMtuUpdate(const BluetoothRemoteDevice& device, int mtu) { if (bleMtuChangeFunc != nullptr) { bleMtuChangeFunc(mtu); diff --git a/frameworks/cj/ble/src/bluetooth_ble_gattServer.cpp b/frameworks/cj/ble/src/bluetooth_ble_gattServer.cpp index 159b65523fdeb69f707f104f6c0355991e539db9..e89f366907a14b37757acc8089ff50b6928677ba 100644 --- a/frameworks/cj/ble/src/bluetooth_ble_gattServer.cpp +++ b/frameworks/cj/ble/src/bluetooth_ble_gattServer.cpp @@ -31,7 +31,7 @@ using Bluetooth::BTTransport; using Bluetooth::GattServiceType; using Bluetooth::UUID; -static int CheckGattsAddService(NativeGattService service, std::unique_ptr &outService) +static int CheckGattsAddService(NativeGattService service, std::unique_ptr& outService) { GattServiceType type = service.isPrimary ? GattServiceType::PRIMARY : GattServiceType::SECONDARY; outService = std::make_unique(UUID::FromString(service.serviceUuid), type); @@ -46,8 +46,8 @@ static int CheckGattsAddService(NativeGattService service, std::unique_ptr gattService{nullptr}; + std::unique_ptr gattService { nullptr }; auto status = CheckGattsAddService(service, gattService); if (status != BT_NO_ERROR) { return status; @@ -108,8 +108,8 @@ int32_t FfiGattServer::Close() return server_->Close(); } -static GattCharacteristic *GetGattCharacteristic(const std::shared_ptr &server, const UUID &serviceUuid, - const UUID &characterUuid) +static GattCharacteristic* GetGattCharacteristic( + const std::shared_ptr& server, const UUID& serviceUuid, const UUID& characterUuid) { auto service = server->GetService(serviceUuid, true); if (!service.has_value()) { @@ -119,7 +119,7 @@ static GattCharacteristic *GetGattCharacteristic(const std::shared_ptrSendResponse(remoteDevice, serverResponse.transId, serverResponse.status, serverResponse.offset, - serverResponse.value.head, static_cast(serverResponse.value.size)); + serverResponse.value.head, static_cast(serverResponse.value.size)); ; } diff --git a/frameworks/cj/ble/src/bluetooth_ble_impl.cpp b/frameworks/cj/ble/src/bluetooth_ble_impl.cpp index 164468c11e213c9a1313ba74571a36e9d0d4cd96..2539b3e44e4842e37c696038358835ea26ad4acd 100644 --- a/frameworks/cj/ble/src/bluetooth_ble_impl.cpp +++ b/frameworks/cj/ble/src/bluetooth_ble_impl.cpp @@ -52,14 +52,14 @@ std::shared_ptr BleAdvertiserGetInstance(void) return instance; } -BleCentralManager *BleCentralManagerGetInstance(void) +BleCentralManager* BleCentralManagerGetInstance(void) { static BleCentralManager instance(FfiBluetoothBleCentralManagerCallback::GetInstance()); return &instance; } } // namespace -int32_t BleImpl::CreateGattServer(FfiGattServer *&ffiGattServer) +int32_t BleImpl::CreateGattServer(FfiGattServer*& ffiGattServer) { ffiGattServer = FFIData::Create(); if (ffiGattServer == nullptr) { @@ -68,7 +68,7 @@ int32_t BleImpl::CreateGattServer(FfiGattServer *&ffiGattServer) return BT_NO_ERROR; } -int32_t BleImpl::CreateGattClientDevice(std::string deviceId, FfiClientDevice *&ffiClientDevice) +int32_t BleImpl::CreateGattClientDevice(std::string deviceId, FfiClientDevice*& ffiClientDevice) { if (!IsValidAddress(deviceId)) { HILOGE("Invalid deviceId: %{public}s", deviceId.c_str()); @@ -78,7 +78,7 @@ int32_t BleImpl::CreateGattClientDevice(std::string deviceId, FfiClientDevice *& return BT_NO_ERROR; } -int32_t BleImpl::GetConnectedBleDevices(CArrString &res) +int32_t BleImpl::GetConnectedBleDevices(CArrString& res) { std::lock_guard lock(FfiGattServer::deviceListMutex_); std::vector devicesList = FfiGattServer::deviceList_; @@ -86,8 +86,8 @@ int32_t BleImpl::GetConnectedBleDevices(CArrString &res) return BT_NO_ERROR; } -static void ParseScanFilterDeviceIdParameters(int32_t &status, NativeScanFilter &scanFilter, - BleScanFilter &bleScanFilter) +static void ParseScanFilterDeviceIdParameters( + int32_t& status, NativeScanFilter& scanFilter, BleScanFilter& bleScanFilter) { if (scanFilter.deviceId != nullptr) { std::string deviceId = std::string(scanFilter.deviceId); @@ -99,8 +99,8 @@ static void ParseScanFilterDeviceIdParameters(int32_t &status, NativeScanFilter } } -static void ParseScanFilterLocalNameParameters(int32_t &status, NativeScanFilter &scanFilter, - BleScanFilter &bleScanFilter) +static void ParseScanFilterLocalNameParameters( + int32_t& status, NativeScanFilter& scanFilter, BleScanFilter& bleScanFilter) { if (scanFilter.name != nullptr) { std::string name = std::string(scanFilter.name); @@ -112,7 +112,7 @@ static void ParseScanFilterLocalNameParameters(int32_t &status, NativeScanFilter } } -static int32_t ParseUuidParams(char *name, UUID &outUuid) +static int32_t ParseUuidParams(char* name, UUID& outUuid) { std::string uuid = std::string(name); if (!IsValidUuid(uuid)) { @@ -123,11 +123,11 @@ static int32_t ParseUuidParams(char *name, UUID &outUuid) return BT_NO_ERROR; } -static void ParseScanFilterServiceUuidParameters(int32_t &status, NativeScanFilter &scanFilter, - BleScanFilter &bleScanFilter) +static void ParseScanFilterServiceUuidParameters( + int32_t& status, NativeScanFilter& scanFilter, BleScanFilter& bleScanFilter) { if (scanFilter.serviceUuid != nullptr) { - UUID uuid{}; + UUID uuid {}; status = ParseUuidParams(scanFilter.serviceUuid, uuid); if (status != BT_NO_ERROR) { return; @@ -136,7 +136,7 @@ static void ParseScanFilterServiceUuidParameters(int32_t &status, NativeScanFilt } if (scanFilter.serviceUuidMask != nullptr) { - UUID uuidMask{}; + UUID uuidMask {}; status = ParseUuidParams(scanFilter.serviceUuidMask, uuidMask); if (status != BT_NO_ERROR) { return; @@ -145,11 +145,11 @@ static void ParseScanFilterServiceUuidParameters(int32_t &status, NativeScanFilt } } -static void ParseScanFilterSolicitationUuidParameters(int32_t &status, NativeScanFilter &scanFilter, - BleScanFilter &bleScanFilter) +static void ParseScanFilterSolicitationUuidParameters( + int32_t& status, NativeScanFilter& scanFilter, BleScanFilter& bleScanFilter) { if (scanFilter.serviceSolicitationUuid != nullptr) { - UUID uuid{}; + UUID uuid {}; status = ParseUuidParams(scanFilter.serviceSolicitationUuid, uuid); if (status != BT_NO_ERROR) { return; @@ -158,7 +158,7 @@ static void ParseScanFilterSolicitationUuidParameters(int32_t &status, NativeSca } if (scanFilter.serviceSolicitationUuidMask != nullptr) { - UUID uuidMask{}; + UUID uuidMask {}; status = ParseUuidParams(scanFilter.serviceSolicitationUuidMask, uuidMask); if (status != BT_NO_ERROR) { return; @@ -167,29 +167,29 @@ static void ParseScanFilterSolicitationUuidParameters(int32_t &status, NativeSca } } -static void ParseScanFilterServiceDataParameters(int32_t &status, NativeScanFilter &scanFilter, - BleScanFilter &bleScanFilter) +static void ParseScanFilterServiceDataParameters( + int32_t& status, NativeScanFilter& scanFilter, BleScanFilter& bleScanFilter) { - std::vector data{}; + std::vector data {}; if (scanFilter.serviceData.head != nullptr) { bleScanFilter.SetServiceData(std::move(data)); } - std::vector dataMask{}; + std::vector dataMask {}; if (scanFilter.serviceDataMask.head != nullptr) { bleScanFilter.SetServiceDataMask(std::move(dataMask)); } } -static void ParseScanFilterManufactureDataParameters(int32_t &status, NativeScanFilter &scanFilter, - BleScanFilter &bleScanFilter) +static void ParseScanFilterManufactureDataParameters( + int32_t& status, NativeScanFilter& scanFilter, BleScanFilter& bleScanFilter) { if (scanFilter.manufactureId != 0) { bleScanFilter.SetManufacturerId(scanFilter.manufactureId); HILOGI("Scan filter manufacturerId is %{public}#x", scanFilter.manufactureId); } - std::vector data{}; + std::vector data {}; if (scanFilter.manufactureData.head != nullptr) { for (int64_t i = 0; i < scanFilter.manufactureData.size; i++) { data.push_back(scanFilter.manufactureData.head[i]); @@ -197,7 +197,7 @@ static void ParseScanFilterManufactureDataParameters(int32_t &status, NativeScan bleScanFilter.SetManufactureData(std::move(data)); } - std::vector dataMask{}; + std::vector dataMask {}; if (scanFilter.manufactureDataMask.head != nullptr) { for (int64_t i = 0; i < scanFilter.manufactureDataMask.size; i++) { dataMask.push_back(scanFilter.manufactureDataMask.head[i]); @@ -206,7 +206,7 @@ static void ParseScanFilterManufactureDataParameters(int32_t &status, NativeScan } } -static void ParseScanFilter(int32_t &status, NativeScanFilter &scanFilter, BleScanFilter &bleScanFilter) +static void ParseScanFilter(int32_t& status, NativeScanFilter& scanFilter, BleScanFilter& bleScanFilter) { ParseScanFilterDeviceIdParameters(status, scanFilter, bleScanFilter); ParseScanFilterLocalNameParameters(status, scanFilter, bleScanFilter); @@ -216,8 +216,8 @@ static void ParseScanFilter(int32_t &status, NativeScanFilter &scanFilter, BleSc ParseScanFilterManufactureDataParameters(status, scanFilter, bleScanFilter); } -static int32_t CheckBleScanParams(CArrNativeScanFilter filters, NativeScanOptions *scanOptions, - std::vector &outScanfilters, BleScanSettings &outSettinngs) +static int32_t CheckBleScanParams(CArrNativeScanFilter filters, NativeScanOptions* scanOptions, + std::vector& outScanfilters, BleScanSettings& outSettinngs) { std::vector scanfilters; uint32_t length = static_cast(filters.size); @@ -241,7 +241,7 @@ static int32_t CheckBleScanParams(CArrNativeScanFilter filters, NativeScanOption return BT_NO_ERROR; } -int32_t BleImpl::StartBleScan(CArrNativeScanFilter filters, NativeScanOptions *options) +int32_t BleImpl::StartBleScan(CArrNativeScanFilter filters, NativeScanOptions* options) { std::vector scanfilters; BleScanSettings settings; @@ -263,8 +263,8 @@ int32_t BleImpl::StopBleScan() return BleCentralManagerGetInstance()->StopScan(); } -static void ParseAdvertisingSettingsParameters(int32_t *errCode, NativeAdvertiseSetting &setting, - BleAdvertiserSettings &outSettings) +static void ParseAdvertisingSettingsParameters( + int32_t* errCode, NativeAdvertiseSetting& setting, BleAdvertiserSettings& outSettings) { uint32_t interval = setting.interval; const uint32_t minInterval = 32; @@ -295,10 +295,10 @@ static void ParseAdvertisingSettingsParameters(int32_t *errCode, NativeAdvertise return; } -static void ParseServiceUuidParameters(int32_t *errCode, NativeAdvertiseData advData, BleAdvertiserData &outData) +static void ParseServiceUuidParameters(int32_t* errCode, NativeAdvertiseData advData, BleAdvertiserData& outData) { for (int64_t i = 0; i < advData.serviceUuids.size; ++i) { - UUID uuid{}; + UUID uuid {}; *errCode = ParseUuidParams(advData.serviceUuids.head[i], uuid); if (*errCode != BT_NO_ERROR) { return; @@ -309,30 +309,30 @@ static void ParseServiceUuidParameters(int32_t *errCode, NativeAdvertiseData adv return; } -static void ParseManufactureDataParameters(int32_t *errCode, NativeAdvertiseData advData, BleAdvertiserData &outData) +static void ParseManufactureDataParameters(int32_t* errCode, NativeAdvertiseData advData, BleAdvertiserData& outData) { CArrNativeManufactureData parameter = advData.manufactureData; for (int64_t i = 0; i < parameter.size; ++i) { NativeManufactureData manufactureData = parameter.head[i]; CArrUI8 manufactureValue = manufactureData.manufactureValue; - std::string value(reinterpret_cast(manufactureValue.head), manufactureValue.size); + std::string value(reinterpret_cast(manufactureValue.head), manufactureValue.size); outData.AddManufacturerData(manufactureData.manufactureId, value); } return; } -static void ParseServiceDataParameters(int32_t *errCode, NativeAdvertiseData advData, BleAdvertiserData &outData) +static void ParseServiceDataParameters(int32_t* errCode, NativeAdvertiseData advData, BleAdvertiserData& outData) { CArrNativeServiceData data = advData.serviceData; for (int64_t i = 0; i < data.size; ++i) { NativeServiceData serviceData = data.head[i]; - std::string value(reinterpret_cast(serviceData.serviceValue.head), serviceData.serviceValue.size); + std::string value(reinterpret_cast(serviceData.serviceValue.head), serviceData.serviceValue.size); outData.AddServiceData(ParcelUuid::FromString(std::string(serviceData.serviceUuid)), value); } return; } -static void ParseAdvertisDataParameters(int32_t *errCode, NativeAdvertiseData advData, BleAdvertiserData &outData) +static void ParseAdvertisDataParameters(int32_t* errCode, NativeAdvertiseData advData, BleAdvertiserData& outData) { ParseServiceUuidParameters(errCode, advData, outData); ParseManufactureDataParameters(errCode, advData, outData); @@ -343,8 +343,8 @@ static void ParseAdvertisDataParameters(int32_t *errCode, NativeAdvertiseData ad return; } -int32_t BleImpl::StartAdvertising(NativeAdvertiseSetting setting, NativeAdvertiseData advData, - NativeAdvertiseData *advResponse) +int32_t BleImpl::StartAdvertising( + NativeAdvertiseSetting setting, NativeAdvertiseData advData, NativeAdvertiseData* advResponse) { std::shared_ptr bleAdvertiser = BleAdvertiserGetInstance(); BleAdvertiserSettings nativeSettings; @@ -361,8 +361,8 @@ int32_t BleImpl::StartAdvertising(NativeAdvertiseSetting setting, NativeAdvertis if (errCode != BT_NO_ERROR) { return errCode; } - return bleAdvertiser->StartAdvertising(nativeSettings, nativeAdvData, nativeRspData, 0, - FfiBluetoothBleAdvertiseCallback::GetInstance()); + return bleAdvertiser->StartAdvertising( + nativeSettings, nativeAdvData, nativeRspData, 0, FfiBluetoothBleAdvertiseCallback::GetInstance()); } int32_t BleImpl::StopAdvertising() @@ -385,7 +385,7 @@ static bool IsValidAdvertiserDuration(uint32_t duration) return true; } -int32_t BleImpl::StartAdvertising(NativeAdvertisingParams advertisingParams, int32_t &id) +int32_t BleImpl::StartAdvertising(NativeAdvertisingParams advertisingParams, int32_t& id) { std::shared_ptr bleAdvertiser = BleAdvertiserGetInstance(); BleAdvertiserSettings nativeSettings; @@ -402,8 +402,8 @@ int32_t BleImpl::StartAdvertising(NativeAdvertisingParams advertisingParams, int return BT_ERR_INVALID_PARAM; } HILOGI("duration: %{public}u", duration); - errCode = bleAdvertiser->StartAdvertising(nativeSettings, nativeAdvData, nativeRspData, duration, - FfiBluetoothBleAdvertiseCallback::GetInstance()); + errCode = bleAdvertiser->StartAdvertising( + nativeSettings, nativeAdvData, nativeRspData, duration, FfiBluetoothBleAdvertiseCallback::GetInstance()); if (errCode != BT_NO_ERROR) { return errCode; }