From c01f76cfbe503743be872582cf90b480d3fc8294 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Fri, 5 Jun 2015 11:13:31 +0100 Subject: [PATCH] cleanup around GattCallbackParamTypes --- public/BLEDevice.h | 16 +++--- public/GattCharacteristic.h | 16 +++--- public/GattCharacteristicCallbackParams.h | 64 ++++++++++++----------- public/GattClient.h | 20 +++---- public/GattServer.h | 16 +++--- services/DFUService.h | 4 +- services/HeartRateService.h | 2 +- services/LinkLossService.h | 2 +- services/UARTService.h | 4 +- services/URIBeaconConfigService.h | 14 ++--- 10 files changed, 80 insertions(+), 78 deletions(-) diff --git a/public/BLEDevice.h b/public/BLEDevice.h index 8c2643d..771381f 100644 --- a/public/BLEDevice.h +++ b/public/BLEDevice.h @@ -392,8 +392,8 @@ public: * @Note: it is also possible to setup a callback into a member function of * some object. */ - void onDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP)); - template void onDataWritten(T * objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context)); + void onDataWritten(void (*callback)(const GattWriteCallbackParams *eventDataP)); + template void onDataWritten(T * objPtr, void (T::*memberPtr)(const GattWriteCallbackParams *context)); /** * Setup a callback for when a characteristic is being read by a client. @@ -413,8 +413,8 @@ public: * @return BLE_ERROR_NOT_IMPLEMENTED if this functionality isn't available; * else BLE_ERROR_NONE. */ - ble_error_t onDataRead(void (*callback)(const GattCharacteristicReadCBParams *eventDataP)); - template ble_error_t onDataRead(T * objPtr, void (T::*memberPtr)(const GattCharacteristicReadCBParams *context)); + ble_error_t onDataRead(void (*callback)(const GattReadCallbackParams *eventDataP)); + template ble_error_t onDataRead(T * objPtr, void (T::*memberPtr)(const GattReadCallbackParams *context)); void onUpdatesEnabled(GattServer::EventCallback_t callback); void onUpdatesDisabled(GattServer::EventCallback_t callback); @@ -1001,22 +1001,22 @@ BLEDevice::onDataSent(T *objPtr, void (T::*memberPtr)(unsigned count)) { } inline void -BLEDevice::onDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP)) { +BLEDevice::onDataWritten(void (*callback)(const GattWriteCallbackParams *eventDataP)) { transport->getGattServer().setOnDataWritten(callback); } template inline void -BLEDevice::onDataWritten(T *objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context)) { +BLEDevice::onDataWritten(T *objPtr, void (T::*memberPtr)(const GattWriteCallbackParams *context)) { transport->getGattServer().setOnDataWritten(objPtr, memberPtr); } inline ble_error_t -BLEDevice::onDataRead(void (*callback)(const GattCharacteristicReadCBParams *eventDataP)) { +BLEDevice::onDataRead(void (*callback)(const GattReadCallbackParams *eventDataP)) { return transport->getGattServer().setOnDataRead(callback); } template inline ble_error_t -BLEDevice::onDataRead(T *objPtr, void (T::*memberPtr)(const GattCharacteristicReadCBParams *context)) { +BLEDevice::onDataRead(T *objPtr, void (T::*memberPtr)(const GattReadCallbackParams *context)) { return transport->getGattServer().setOnDataRead(objPtr, memberPtr); } diff --git a/public/GattCharacteristic.h b/public/GattCharacteristic.h index b2c86ad..07a3f71 100644 --- a/public/GattCharacteristic.h +++ b/public/GattCharacteristic.h @@ -355,21 +355,21 @@ public: /** * Authorization. */ - void setWriteAuthorizationCallback(void (*callback)(GattCharacteristicWriteAuthCBParams *)) { + void setWriteAuthorizationCallback(void (*callback)(GattWriteAuthCallbackParams *)) { writeAuthorizationCallback.attach(callback); enabledWriteAuthorization = true; } template - void setWriteAuthorizationCallback(T *object, void (T::*member)(GattCharacteristicWriteAuthCBParams *)) { + void setWriteAuthorizationCallback(T *object, void (T::*member)(GattWriteAuthCallbackParams *)) { writeAuthorizationCallback.attach(object, member); enabledWriteAuthorization = true; } - void setReadAuthorizationCallback(void (*callback)(GattCharacteristicReadAuthCBParams *)) { + void setReadAuthorizationCallback(void (*callback)(GattReadAuthCallbackParams *)) { readAuthorizationCallback.attach(callback); enabledReadAuthorization = true; } template - void setReadAuthorizationCallback(T *object, void (T::*member)(GattCharacteristicReadAuthCBParams *)) { + void setReadAuthorizationCallback(T *object, void (T::*member)(GattReadAuthCallbackParams *)) { readAuthorizationCallback.attach(object, member); enabledReadAuthorization = true; } @@ -380,7 +380,7 @@ public: * @param params to capture the context of the write-auth request; and also contains an out-parameter for reply. * @return true if the write is authorized to proceed. */ - GattCharacteristicAuthCBReply_t authorizeWrite(GattCharacteristicWriteAuthCBParams *params) { + GattAuthCallbackReply_t authorizeWrite(GattWriteAuthCallbackParams *params) { if (!isWriteAuthorizationEnabled()) { return AUTH_CALLBACK_REPLY_SUCCESS; } @@ -406,7 +406,7 @@ public: * * @return true if the read is authorized to proceed. */ - GattCharacteristicAuthCBReply_t authorizeRead(GattCharacteristicReadAuthCBParams *params) { + GattAuthCallbackReply_t authorizeRead(GattReadAuthCallbackParams *params) { if (!isReadAuthorizationEnabled()) { return AUTH_CALLBACK_REPLY_SUCCESS; } @@ -444,8 +444,8 @@ private: bool enabledReadAuthorization; bool enabledWriteAuthorization; - FunctionPointerWithContext readAuthorizationCallback; - FunctionPointerWithContext writeAuthorizationCallback; + FunctionPointerWithContext readAuthorizationCallback; + FunctionPointerWithContext writeAuthorizationCallback; private: /* disallow copy and assignment */ diff --git a/public/GattCharacteristicCallbackParams.h b/public/GattCharacteristicCallbackParams.h index 235a3f3..fd6d40e 100644 --- a/public/GattCharacteristicCallbackParams.h +++ b/public/GattCharacteristicCallbackParams.h @@ -14,33 +14,35 @@ * limitations under the License. */ -#ifndef __GATT_CHARACTERISTIC_CALLBACK_PARAMS_H__ -#define __GATT_CHARACTERISTIC_CALLBACK_PARAMS_H__ +#ifndef __GATT_CALLBACK_PARAM_TYPES_H__ +#define __GATT_CALLBACK_PARAM_TYPES_H__ -struct GattCharacteristicWriteCBParams { - GattAttribute::Handle_t charHandle; - enum Type { - GATTS_CHAR_OP_INVALID = 0x00, /**< Invalid Operation. */ - GATTS_CHAR_OP_WRITE_REQ = 0x01, /**< Write Request. */ - GATTS_CHAR_OP_WRITE_CMD = 0x02, /**< Write Command. */ - GATTS_CHAR_OP_SIGN_WRITE_CMD = 0x03, /**< Signed Write Command. */ - GATTS_CHAR_OP_PREP_WRITE_REQ = 0x04, /**< Prepare Write Request. */ - GATTS_CHAR_OP_EXEC_WRITE_REQ_CANCEL = 0x05, /**< Execute Write Request: Cancel all prepared writes. */ - GATTS_CHAR_OP_EXEC_WRITE_REQ_NOW = 0x06, /**< Execute Write Request: Immediately execute all prepared writes. */ - } op; /**< Type of write operation, */ - uint16_t offset; /**< Offset for the write operation. */ - uint16_t len; - const uint8_t *data; /* @note: data might not persist beyond the callback; make a local copy if needed. */ -}; +struct GattWriteCallbackParams { + enum WriteOp_t { + OP_INVALID = 0x00, /**< Invalid Operation. */ + OP_WRITE_REQ = 0x01, /**< Write Request. */ + OP_WRITE_CMD = 0x02, /**< Write Command. */ + OP_SIGN_WRITE_CMD = 0x03, /**< Signed Write Command. */ + OP_PREP_WRITE_REQ = 0x04, /**< Prepare Write Request. */ + OP_EXEC_WRITE_REQ_CANCEL = 0x05, /**< Execute Write Request: Cancel all prepared writes. */ + OP_EXEC_WRITE_REQ_NOW = 0x06, /**< Execute Write Request: Immediately execute all prepared writes. */ + }; -struct GattCharacteristicReadCBParams { - GattAttribute::Handle_t charHandle; - uint16_t offset; /**< Offset for the read operation. */ + GattAttribute::Handle_t handle; + WriteOp_t writeOp; /**< Type of write operation, */ + uint16_t offset; /**< Offset for the write operation. */ uint16_t len; - const uint8_t *data; /* @note: data might not persist beyond the callback; make a local copy if needed. */ + const uint8_t *data; /* @note: data might not persist beyond the callback; make a local copy if needed. */ }; -enum GattCharacteristicAuthCBReply_t { +struct GattReadCallbackParams { + GattAttribute::Handle_t handle; + uint16_t offset; /**< Offset for the read operation. */ + uint16_t len; + const uint8_t *data; /* @note: data might not persist beyond the callback; make a local copy if needed. */ +}; + +enum GattAuthCallbackReply_t { AUTH_CALLBACK_REPLY_SUCCESS = 0x00, /**< Success. */ AUTH_CALLBACK_REPLY_ATTERR_INVALID_HANDLE = 0x0101, /**< ATT Error: Invalid Attribute Handle. */ AUTH_CALLBACK_REPLY_ATTERR_READ_NOT_PERMITTED = 0x0102, /**< ATT Error: Read not permitted. */ @@ -55,22 +57,22 @@ enum GattCharacteristicAuthCBReply_t { AUTH_CALLBACK_REPLY_ATTERR_INSUF_RESOURCES = 0x0111, /**< ATT Error: Encrypted link required. */ }; -struct GattCharacteristicWriteAuthCBParams { - GattAttribute::Handle_t charHandle; +struct GattWriteAuthCallbackParams { + GattAttribute::Handle_t handle; uint16_t offset; /**< Offset for the write operation. */ uint16_t len; /**< Length of the incoming data. */ const uint8_t *data; /**< Incoming data, variable length. */ - GattCharacteristicAuthCBReply_t authorizationReply; /* This is the out parameter which needs to be set to true by the callback if the - * request is to proceed; false otherwise. */ + GattAuthCallbackReply_t authorizationReply; /* This is the out parameter which needs to be set to true by the callback if the + * request is to proceed; false otherwise. */ }; -struct GattCharacteristicReadAuthCBParams { - GattAttribute::Handle_t charHandle; +struct GattReadAuthCallbackParams { + GattAttribute::Handle_t handle; uint16_t offset; /**< Offset for the read operation. */ uint16_t len; /**< Optional: new length of the outgoing data. */ uint8_t *data; /**< Optional: new outgoing data. Leave at NULL if data is unchanged. */ - GattCharacteristicAuthCBReply_t authorizationReply; /* This is the out parameter which needs to be set to true by the callback if the - * request is to proceed; false otherwise. */ + GattAuthCallbackReply_t authorizationReply; /* This is the out parameter which needs to be set to true by the callback if the + * request is to proceed; false otherwise. */ }; -#endif /*__GATT_CHARACTERISTIC_CALLBACK_PARAMS_H__*/ +#endif /*__GATT_CALLBACK_PARAM_TYPES_H__*/ diff --git a/public/GattClient.h b/public/GattClient.h index b63d7da..0792f18 100644 --- a/public/GattClient.h +++ b/public/GattClient.h @@ -25,7 +25,7 @@ class GattClient { public: - typedef void (*ReadCallback_t)(const GattCharacteristicReadCBParams *params); + typedef void (*ReadCallback_t)(const GattReadCallbackParams *params); enum WriteOp_t { GATT_OP_INVALID = 0x00, /**< Invalid Operation. */ @@ -36,7 +36,7 @@ public: GATT_OP_EXEC_WRITE_REQ = 0x05, /**< Execute Write Request. */ }; - typedef void (*WriteCallback_t)(const GattCharacteristicWriteCBParams *params); + typedef void (*WriteCallback_t)(const GattWriteCallbackParams *params); public: /** @@ -116,9 +116,9 @@ private: void setOnDataSent(T *objPtr, void (T::*memberPtr)(unsigned count)) { onDataSent.add(objPtr, memberPtr); } - void setOnDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP)) {onDataWritten.add(callback);} + void setOnDataWritten(void (*callback)(const GattWriteCallbackParams *eventDataP)) {onDataWritten.add(callback);} template - void setOnDataWritten(T *objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context)) { + void setOnDataWritten(T *objPtr, void (T::*memberPtr)(const GattWriteCallbackParams *context)) { onDataWritten.add(objPtr, memberPtr); } @@ -129,7 +129,7 @@ private: virtual bool isOnDataReadAvailable() const { return false; } - ble_error_t setOnDataRead(void (*callback)(const GattCharacteristicReadCBParams *eventDataP)) { + ble_error_t setOnDataRead(void (*callback)(const GattReadCallbackParams *eventDataP)) { if (!isOnDataReadAvailable()) { return BLE_ERROR_NOT_IMPLEMENTED; } @@ -138,7 +138,7 @@ private: return BLE_ERROR_NONE; } template - ble_error_t setOnDataRead(T *objPtr, void (T::*memberPtr)(const GattCharacteristicReadCBParams *context)) { + ble_error_t setOnDataRead(T *objPtr, void (T::*memberPtr)(const GattReadCallbackParams *context)) { if (!isOnDataReadAvailable()) { return BLE_ERROR_NOT_IMPLEMENTED; } @@ -151,13 +151,13 @@ private: void setOnConfirmationReceived(EventCallback_t callback) {onConfirmationReceived = callback;} protected: - void handleDataWrittenEvent(const GattCharacteristicWriteCBParams *params) { + void handleDataWrittenEvent(const GattWriteCallbackParams *params) { if (onDataWritten.hasCallbacksAttached()) { onDataWritten.call(params); } } - void handleDataReadEvent(const GattCharacteristicReadCBParams *params) { + void handleDataReadEvent(const GattReadCallbackParams *params) { if (onDataRead.hasCallbacksAttached()) { onDataRead.call(params); } @@ -197,8 +197,8 @@ protected: private: CallChainOfFunctionPointersWithContext onDataSent; - CallChainOfFunctionPointersWithContext onDataWritten; - CallChainOfFunctionPointersWithContext onDataRead; + CallChainOfFunctionPointersWithContext onDataWritten; + CallChainOfFunctionPointersWithContext onDataRead; EventCallback_t onUpdatesEnabled; EventCallback_t onUpdatesDisabled; EventCallback_t onConfirmationReceived; diff --git a/public/GattServer.h b/public/GattServer.h index fd39235..129edda 100644 --- a/public/GattServer.h +++ b/public/GattServer.h @@ -63,9 +63,9 @@ private: void setOnDataSent(T *objPtr, void (T::*memberPtr)(unsigned count)) { onDataSent.add(objPtr, memberPtr); } - void setOnDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP)) {onDataWritten.add(callback);} + void setOnDataWritten(void (*callback)(const GattWriteCallbackParams *eventDataP)) {onDataWritten.add(callback);} template - void setOnDataWritten(T *objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context)) { + void setOnDataWritten(T *objPtr, void (T::*memberPtr)(const GattWriteCallbackParams *context)) { onDataWritten.add(objPtr, memberPtr); } @@ -76,7 +76,7 @@ private: virtual bool isOnDataReadAvailable() const { return false; } - ble_error_t setOnDataRead(void (*callback)(const GattCharacteristicReadCBParams *eventDataP)) { + ble_error_t setOnDataRead(void (*callback)(const GattReadCallbackParams *eventDataP)) { if (!isOnDataReadAvailable()) { return BLE_ERROR_NOT_IMPLEMENTED; } @@ -85,7 +85,7 @@ private: return BLE_ERROR_NONE; } template - ble_error_t setOnDataRead(T *objPtr, void (T::*memberPtr)(const GattCharacteristicReadCBParams *context)) { + ble_error_t setOnDataRead(T *objPtr, void (T::*memberPtr)(const GattReadCallbackParams *context)) { if (!isOnDataReadAvailable()) { return BLE_ERROR_NOT_IMPLEMENTED; } @@ -98,13 +98,13 @@ private: void setOnConfirmationReceived(EventCallback_t callback) {onConfirmationReceived = callback;} protected: - void handleDataWrittenEvent(const GattCharacteristicWriteCBParams *params) { + void handleDataWrittenEvent(const GattWriteCallbackParams *params) { if (onDataWritten.hasCallbacksAttached()) { onDataWritten.call(params); } } - void handleDataReadEvent(const GattCharacteristicReadCBParams *params) { + void handleDataReadEvent(const GattReadCallbackParams *params) { if (onDataRead.hasCallbacksAttached()) { onDataRead.call(params); } @@ -144,8 +144,8 @@ protected: private: CallChainOfFunctionPointersWithContext onDataSent; - CallChainOfFunctionPointersWithContext onDataWritten; - CallChainOfFunctionPointersWithContext onDataRead; + CallChainOfFunctionPointersWithContext onDataWritten; + CallChainOfFunctionPointersWithContext onDataRead; EventCallback_t onUpdatesEnabled; EventCallback_t onUpdatesDisabled; EventCallback_t onConfirmationReceived; diff --git a/services/DFUService.h b/services/DFUService.h index e99da11..c94b662 100644 --- a/services/DFUService.h +++ b/services/DFUService.h @@ -94,8 +94,8 @@ public: * @param[in] params * Information about the characterisitc being updated. */ - virtual void onDataWritten(const GattCharacteristicWriteCBParams *params) { - if (params->charHandle == controlPoint.getValueHandle()) { + virtual void onDataWritten(const GattWriteCallbackParams *params) { + if (params->handle == controlPoint.getValueHandle()) { /* At present, writing anything will do the trick--this needs to be improved. */ if (handoverCallback) { handoverCallback(); diff --git a/services/HeartRateService.h b/services/HeartRateService.h index 8da7747..a1d4122 100644 --- a/services/HeartRateService.h +++ b/services/HeartRateService.h @@ -114,7 +114,7 @@ public: * @param[in] params * Information about the characterisitc being updated. */ - virtual void onDataWritten(const GattCharacteristicWriteCBParams *params) { + virtual void onDataWritten(const GattWriteCallbackParams *params) { if (params->charHandle == controlPoint.getValueAttribute().getHandle()) { /* Do something here if the new value is 1; else you can override this method by * extending this class. diff --git a/services/LinkLossService.h b/services/LinkLossService.h index 6604b24..10f3e33 100644 --- a/services/LinkLossService.h +++ b/services/LinkLossService.h @@ -80,7 +80,7 @@ private: * @param[in] params * Information about the characterisitc being updated. */ - virtual void onDataWritten(const GattCharacteristicWriteCBParams *params) { + virtual void onDataWritten(const GattWriteCallbackParams *params) { if (params->charHandle == alertLevelChar.getValueHandle()) { alertLevel = *reinterpret_cast(params->data); } diff --git a/services/UARTService.h b/services/UARTService.h index fab5578..dc28461 100644 --- a/services/UARTService.h +++ b/services/UARTService.h @@ -167,8 +167,8 @@ private: * function from the global onDataWritten() callback handler; or if that's * not used, this method can be used as a callback directly. */ - void onDataWritten(const GattCharacteristicWriteCBParams *params) { - if (params->charHandle == getTXCharacteristicHandle()) { + void onDataWritten(const GattWriteCallbackParams *params) { + if (params->handle == getTXCharacteristicHandle()) { uint16_t bytesRead = params->len; if (bytesRead <= BLE_UART_SERVICE_MAX_DATA_LEN) { numBytesReceived = bytesRead; diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index 432f440..30e5ac4 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -232,8 +232,8 @@ class URIBeaconConfigService { * characteristics of this service. Attempts to do so are also applied to * the internal state of this service object. */ - void onDataWrittenCallback(const GattCharacteristicWriteCBParams *writeParams) { - uint16_t handle = writeParams->charHandle; + void onDataWrittenCallback(const GattWriteCallbackParams *writeParams) { + uint16_t handle = writeParams->handle; if (handle == lockChar.getValueHandle()) { // Validated earlier @@ -306,7 +306,7 @@ class URIBeaconConfigService { } private: - void lockAuthorizationCallback(GattCharacteristicWriteAuthCBParams *authParams) { + void lockAuthorizationCallback(GattWriteAuthCallbackParams *authParams) { if (lockedState) { authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INSUF_AUTHORIZATION; } else if (authParams->len != sizeof(Lock_t)) { @@ -319,7 +319,7 @@ class URIBeaconConfigService { } - void unlockAuthorizationCallback(GattCharacteristicWriteAuthCBParams *authParams) { + void unlockAuthorizationCallback(GattWriteAuthCallbackParams *authParams) { if (!lockedState) { authParams->authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS; } else if (authParams->len != sizeof(Lock_t)) { @@ -333,7 +333,7 @@ class URIBeaconConfigService { } } - void uriDataWriteAuthorizationCallback(GattCharacteristicWriteAuthCBParams *authParams) { + void uriDataWriteAuthorizationCallback(GattWriteAuthCallbackParams *authParams) { if (lockedState) { authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INSUF_AUTHORIZATION; } else if (authParams->offset != 0) { @@ -343,7 +343,7 @@ class URIBeaconConfigService { } } - void powerModeAuthorizationCallback(GattCharacteristicWriteAuthCBParams *authParams) { + void powerModeAuthorizationCallback(GattWriteAuthCallbackParams *authParams) { if (lockedState) { authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INSUF_AUTHORIZATION; } else if (authParams->len != sizeof(uint8_t)) { @@ -358,7 +358,7 @@ class URIBeaconConfigService { } template - void basicAuthorizationCallback(GattCharacteristicWriteAuthCBParams *authParams) { + void basicAuthorizationCallback(GattWriteAuthCallbackParams *authParams) { if (lockedState) { authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INSUF_AUTHORIZATION; } else if (authParams->len != sizeof(T)) {