High level Bluetooth Low Energy API and radio abstraction layer

Dependencies:   nRF51822

Dependents:   LinkNode_LIS3DH

Fork of BLE_API by Bluetooth Low Energy

Revision:
31:2c94f0501807
Parent:
30:9614522cf932
Child:
34:da2ea8cd6216
--- a/hw/GattServer.h	Fri Jan 17 14:25:29 2014 +0000
+++ b/hw/GattServer.h	Tue Apr 01 11:04:56 2014 +0100
@@ -17,10 +17,10 @@
 #ifndef __GATT_SERVER_H__
 #define __GATT_SERVER_H__
 
+#include "mbed.h"
 #include "blecommon.h"
-#include "UUID.h"
 #include "GattService.h"
-#include "mbed.h"
+#include "GattServerEvents.h"
 
 /**************************************************************************/
 /*!
@@ -31,48 +31,46 @@
 /**************************************************************************/
 class GattServer
 {
-    protected:
-        FunctionPointer m_callback_event;
+    private:
+        GattServerEvents *m_pEventHandler;
 
     public:
-        /******************************************************************/
-        /*!
-            \brief
-            Identifies GATT events generated by the radio HW when an event
-            callback occurs
-        */
-        /******************************************************************/
-        typedef enum gatt_event_e
-        {
-          GATT_EVENT_DATA_SENT              = 1,    /* Fired when a msg was successfully sent out */
-          GATT_EVENT_DATA_WRITTEN           = 2,    /* Client wrote data to Server (separate into char and descriptor writes?) */     
-          GATT_EVENT_UPDATES_ENABLED        = 3,    /* Notify/Indicate Enabled in CCCD */
-          GATT_EVENT_UPDATES_DISABLED       = 4,    /* Notify/Indicate Disnabled in CCCD */
-          GATT_EVENT_CONFIRMATION_RECEIVED  = 5     /* Response received from Indicate message */
-        } gattEvent_t;
-
         /* These functions must be defined in the sub-class */
         virtual ble_error_t addService(GattService &) = 0;
-        virtual ble_error_t readValue(uint8_t, uint8_t[], uint16_t) = 0;
-        virtual ble_error_t updateValue(uint8_t, uint8_t[], uint16_t) = 0;
-        
+        virtual ble_error_t readValue(uint16_t, uint8_t[], uint16_t) = 0;
+        virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t, bool localOnly = false) = 0;
+
         // ToDo: For updateValue, check the CCCD to see if the value we are
         // updating has the notify or indicate bits sent, and if BOTH are set
         // be sure to call sd_ble_gatts_hvx() twice with notify then indicate!
         // Strange use case, but valid and must be covered!
 
+        /* Event callback handlers */
+        void setEventHandler(GattServerEvents *pEventHandler) {m_pEventHandler = pEventHandler;}
+        void handleEvent(GattServerEvents::gattEvent_e type, uint16_t charHandle) {
+            if (NULL == m_pEventHandler)
+                  return;
+            switch(type) {
+                  case GattServerEvents::GATT_EVENT_DATA_SENT:
+                        m_pEventHandler->onDataSent(charHandle);
+                        break;
+                  case GattServerEvents::GATT_EVENT_DATA_WRITTEN:
+                        m_pEventHandler->onDataWritten(charHandle);
+                        break;
+                  case GattServerEvents::GATT_EVENT_UPDATES_ENABLED:
+                        m_pEventHandler->onUpdatesEnabled(charHandle);
+                        break;
+                  case GattServerEvents::GATT_EVENT_UPDATES_DISABLED:
+                        m_pEventHandler->onUpdatesDisabled(charHandle);
+                        break;
+                  case GattServerEvents::GATT_EVENT_CONFIRMATION_RECEIVED:
+                        m_pEventHandler->onConfirmationReceived(charHandle);
+                        break;
+            }
+        }
+
         uint8_t serviceCount;
         uint8_t characteristicCount;
-
-        /* Event callback */
-        void attach(void (*function)(void)) { 
-            m_callback_event.attach( function );
-        }
- 
-        template<typename T>
-        void attach(T *object, void (T::*member)(void)) {
-            m_callback_event.attach( object, member );
-        }
 };
 
 #endif