I don't know why this is happening.

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Wed Jan 21 09:32:48 2015 +0000
Revision:
259:a95264ad705c
Parent:
258:85de85adfac7
Child:
262:1749228403b7
Synchronized with git rev 580f31d8
Author: marcuschang
Added chained callbacks for onDataSent.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 258:85de85adfac7 1 /* mbed Microcontroller Library
rgrover1 258:85de85adfac7 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 258:85de85adfac7 3 *
rgrover1 258:85de85adfac7 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 258:85de85adfac7 5 * you may not use this file except in compliance with the License.
rgrover1 258:85de85adfac7 6 * You may obtain a copy of the License at
rgrover1 258:85de85adfac7 7 *
rgrover1 258:85de85adfac7 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 258:85de85adfac7 9 *
rgrover1 258:85de85adfac7 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 258:85de85adfac7 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 258:85de85adfac7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 258:85de85adfac7 13 * See the License for the specific language governing permissions and
rgrover1 258:85de85adfac7 14 * limitations under the License.
rgrover1 258:85de85adfac7 15 */
rgrover1 258:85de85adfac7 16
rgrover1 258:85de85adfac7 17 #ifndef __GATT_SERVER_H__
rgrover1 258:85de85adfac7 18 #define __GATT_SERVER_H__
rgrover1 258:85de85adfac7 19
rgrover1 258:85de85adfac7 20 #include "GattService.h"
rgrover1 258:85de85adfac7 21 #include "GattServerEvents.h"
rgrover1 258:85de85adfac7 22 #include "GattCharacteristicWriteCBParams.h"
rgrover1 258:85de85adfac7 23 #include "CallChainOfFunctionPointersWithContext.h"
rgrover1 258:85de85adfac7 24
rgrover1 258:85de85adfac7 25 class GattServer {
rgrover1 258:85de85adfac7 26 public:
rgrover1 258:85de85adfac7 27 /* Event callback handlers. */
rgrover1 258:85de85adfac7 28 typedef void (*EventCallback_t)(uint16_t attributeHandle);
rgrover1 258:85de85adfac7 29 typedef void (*ServerEventCallback_t)(void); /**< independent of any particular attribute */
rgrover1 258:85de85adfac7 30
rgrover1 258:85de85adfac7 31 protected:
rgrover1 259:a95264ad705c 32 GattServer() : serviceCount(0), characteristicCount(0), onDataSent(), onDataWritten(), onUpdatesEnabled(NULL), onUpdatesDisabled(NULL), onConfirmationReceived(NULL) {
rgrover1 258:85de85adfac7 33 /* empty */
rgrover1 258:85de85adfac7 34 }
rgrover1 258:85de85adfac7 35
rgrover1 258:85de85adfac7 36 friend class BLEDevice;
rgrover1 258:85de85adfac7 37 private:
rgrover1 258:85de85adfac7 38 /* These functions must be defined in the sub-class */
rgrover1 258:85de85adfac7 39 virtual ble_error_t addService(GattService &) = 0;
rgrover1 258:85de85adfac7 40 virtual ble_error_t readValue(uint16_t handle, uint8_t buffer[], uint16_t *const lengthP) = 0;
rgrover1 258:85de85adfac7 41 virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t, bool localOnly = false) = 0;
rgrover1 258:85de85adfac7 42 virtual ble_error_t initializeGATTDatabase(void) = 0;
rgrover1 258:85de85adfac7 43
rgrover1 258:85de85adfac7 44 // ToDo: For updateValue, check the CCCD to see if the value we are
rgrover1 258:85de85adfac7 45 // updating has the notify or indicate bits sent, and if BOTH are set
rgrover1 258:85de85adfac7 46 // be sure to call sd_ble_gatts_hvx() twice with notify then indicate!
rgrover1 258:85de85adfac7 47 // Strange use case, but valid and must be covered!
rgrover1 258:85de85adfac7 48
rgrover1 259:a95264ad705c 49 void setOnDataSent(void (*callback)(unsigned count)) {onDataSent.add(callback);}
rgrover1 259:a95264ad705c 50 template <typename T>
rgrover1 259:a95264ad705c 51 void setOnDataSent(T *objPtr, void (T::*memberPtr)(unsigned count)) {
rgrover1 259:a95264ad705c 52 onDataSent.add(objPtr, memberPtr);
rgrover1 259:a95264ad705c 53 }
rgrover1 258:85de85adfac7 54 void setOnDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP)) {onDataWritten.add(callback);}
rgrover1 258:85de85adfac7 55 template <typename T>
rgrover1 258:85de85adfac7 56 void setOnDataWritten(T *objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context)) {
rgrover1 258:85de85adfac7 57 onDataWritten.add(objPtr, memberPtr);
rgrover1 258:85de85adfac7 58 }
rgrover1 258:85de85adfac7 59 void setOnUpdatesEnabled(EventCallback_t callback) {onUpdatesEnabled = callback;}
rgrover1 258:85de85adfac7 60 void setOnUpdatesDisabled(EventCallback_t callback) {onUpdatesDisabled = callback;}
rgrover1 258:85de85adfac7 61 void setOnConfirmationReceived(EventCallback_t callback) {onConfirmationReceived = callback;}
rgrover1 258:85de85adfac7 62
rgrover1 258:85de85adfac7 63 protected:
rgrover1 258:85de85adfac7 64 void handleDataWrittenEvent(const GattCharacteristicWriteCBParams *params) {
rgrover1 258:85de85adfac7 65 if (onDataWritten.hasCallbacksAttached()) {
rgrover1 258:85de85adfac7 66 onDataWritten.call(params);
rgrover1 258:85de85adfac7 67 }
rgrover1 258:85de85adfac7 68 }
rgrover1 258:85de85adfac7 69
rgrover1 258:85de85adfac7 70 void handleEvent(GattServerEvents::gattEvent_e type, uint16_t charHandle) {
rgrover1 258:85de85adfac7 71 switch (type) {
rgrover1 258:85de85adfac7 72 case GattServerEvents::GATT_EVENT_UPDATES_ENABLED:
rgrover1 258:85de85adfac7 73 if (onUpdatesEnabled) {
rgrover1 258:85de85adfac7 74 onUpdatesEnabled(charHandle);
rgrover1 258:85de85adfac7 75 }
rgrover1 258:85de85adfac7 76 break;
rgrover1 258:85de85adfac7 77 case GattServerEvents::GATT_EVENT_UPDATES_DISABLED:
rgrover1 258:85de85adfac7 78 if (onUpdatesDisabled) {
rgrover1 258:85de85adfac7 79 onUpdatesDisabled(charHandle);
rgrover1 258:85de85adfac7 80 }
rgrover1 258:85de85adfac7 81 break;
rgrover1 258:85de85adfac7 82 case GattServerEvents::GATT_EVENT_CONFIRMATION_RECEIVED:
rgrover1 258:85de85adfac7 83 if (onConfirmationReceived) {
rgrover1 258:85de85adfac7 84 onConfirmationReceived(charHandle);
rgrover1 258:85de85adfac7 85 }
rgrover1 258:85de85adfac7 86 break;
rgrover1 258:85de85adfac7 87 }
rgrover1 258:85de85adfac7 88 }
rgrover1 258:85de85adfac7 89
rgrover1 258:85de85adfac7 90 void handleDataSentEvent(unsigned count) {
rgrover1 259:a95264ad705c 91 if (onDataSent.hasCallbacksAttached()) {
rgrover1 259:a95264ad705c 92 onDataSent.call(count);
rgrover1 258:85de85adfac7 93 }
rgrover1 258:85de85adfac7 94 }
rgrover1 258:85de85adfac7 95
rgrover1 258:85de85adfac7 96 protected:
rgrover1 258:85de85adfac7 97 uint8_t serviceCount;
rgrover1 258:85de85adfac7 98 uint8_t characteristicCount;
rgrover1 258:85de85adfac7 99
rgrover1 258:85de85adfac7 100 private:
rgrover1 259:a95264ad705c 101 CallChainOfFunctionPointersWithContext<unsigned> onDataSent;
rgrover1 258:85de85adfac7 102 CallChainOfFunctionPointersWithContext<const GattCharacteristicWriteCBParams *> onDataWritten;
rgrover1 258:85de85adfac7 103 EventCallback_t onUpdatesEnabled;
rgrover1 258:85de85adfac7 104 EventCallback_t onUpdatesDisabled;
rgrover1 258:85de85adfac7 105 EventCallback_t onConfirmationReceived;
rgrover1 258:85de85adfac7 106
rgrover1 258:85de85adfac7 107 private:
rgrover1 258:85de85adfac7 108 /* disallow copy and assignment */
rgrover1 258:85de85adfac7 109 GattServer(const GattServer &);
rgrover1 258:85de85adfac7 110 GattServer& operator=(const GattServer &);
rgrover1 258:85de85adfac7 111 };
rgrover1 258:85de85adfac7 112
rgrover1 258:85de85adfac7 113 #endif // ifndef __GATT_SERVER_H__