abc

Fork of BLE_API by Bluetooth Low Energy

Revision:
406:cec6778acc66
Parent:
405:8fc6e6855806
Child:
407:ca6b956b33d1
--- a/public/Gap.h	Mon May 18 09:54:27 2015 +0100
+++ b/public/Gap.h	Mon May 18 09:54:27 2015 +0100
@@ -21,6 +21,7 @@
 #include "GapAdvertisingParams.h"
 #include "GapEvents.h"
 #include "CallChain.h"
+#include "FunctionPointerWithContext.h"
 
 using namespace mbed;
 
@@ -152,12 +153,15 @@
     typedef void (*LinkSecuredCallback_t)(Handle_t handle, SecurityMode_t securityMode);
     typedef void (*PasskeyDisplayCallback_t)(Handle_t handle, const Passkey_t passkey);
 
-    typedef void (*AdvertisementReportCallback_t)(const address_t      peerAddr,
-                                                  int8_t               rssi,
-                                                  bool                 isScanResponse,
-                                                  AdvertisementType_t  type,
-                                                  uint8_t              advertisingDataLen,
-                                                  const uint8_t       *advertisingData);
+    struct AdvertisementCallbackParams_t {
+        Address_t            peerAddr;
+        int8_t               rssi;
+        bool                 isScanResponse;
+        AdvertisementType_t  type;
+        uint8_t              advertisingDataLen;
+        const uint8_t       *advertisingData;
+    };
+    typedef FunctionPointerWithContext<const AdvertisementCallbackParams_t *> AdvertisementReportCallback_t;
 
     friend class BLEDevice;
 
@@ -168,7 +172,7 @@
     virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &) = 0;
     virtual ble_error_t startAdvertising(const GapAdvertisingParams &)                             = 0;
     virtual ble_error_t stopAdvertising(void)                                                      = 0;
-    virtual ble_error_t startScan(const GapScanningParams &scanningParams, AdvertisementReportCallback_t callback) = 0;
+    virtual ble_error_t startScan(const GapScanningParams &scanningParams, void (*callback)(const AdvertisementCallbackParams_t *params)) = 0;
     virtual ble_error_t stopScan()                                                                 = 0;
     virtual uint16_t    getMinAdvertisingInterval(void) const                                      = 0;
     virtual uint16_t    getMinNonConnectableAdvertisingInterval(void) const                        = 0;
@@ -322,9 +326,14 @@
                                     AdvertisementType_t  type,
                                     uint8_t              advertisingDataLen,
                                     const uint8_t       *advertisingData) {
-        if (onAdvertisementReport) {
-            onAdvertisementReport(peerAddr, rssi, isScanResponse, type, advertisingDataLen, advertisingData);
-        }
+        AdvertisementCallbackParams_t params;
+        memcpy(params.peerAddr, peerAddr, ADDR_LEN);
+        params.rssi               = rssi;
+        params.isScanResponse     = isScanResponse;
+        params.type               = type;
+        params.advertisingDataLen = advertisingDataLen;
+        params.advertisingData    = advertisingData;
+        onAdvertisementReport.call(&params);
     }
 
     void processEvent(GapEvents::gapEvent_e type) {