High level Bluetooth Low Energy API and radio abstraction layer
Fork of BLE_API by
Diff: hw/GattServer.h
- Revision:
- 34:da2ea8cd6216
- Parent:
- 31:2c94f0501807
- Child:
- 64:95529f47b782
--- a/hw/GattServer.h Thu Apr 03 01:45:33 2014 +0100 +++ b/hw/GattServer.h Wed May 21 15:01:14 2014 +0100 @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + */ #ifndef __GATT_SERVER_H__ #define __GATT_SERVER_H__ @@ -31,46 +31,54 @@ /**************************************************************************/ class GattServer { - private: - GattServerEvents *m_pEventHandler; +private: + GattServerEvents *m_pEventHandler; - public: - /* These functions must be defined in the sub-class */ - virtual ble_error_t addService(GattService &) = 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; +public: + /* These functions must be defined in the sub-class */ + virtual ble_error_t addService(GattService &) = 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! + // 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; + } - /* 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; - } + 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; + uint8_t serviceCount; + uint8_t characteristicCount; }; -#endif +#endif // ifndef __GATT_SERVER_H__