cleanup around GattCallbackParamTypes

This commit is contained in:
Rohit Grover 2015-06-05 11:13:31 +01:00
parent 49c495d36f
commit c01f76cfbe
10 changed files with 80 additions and 78 deletions

View File

@ -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 <typename T> void onDataWritten(T * objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context));
void onDataWritten(void (*callback)(const GattWriteCallbackParams *eventDataP));
template <typename T> 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 <typename T> ble_error_t onDataRead(T * objPtr, void (T::*memberPtr)(const GattCharacteristicReadCBParams *context));
ble_error_t onDataRead(void (*callback)(const GattReadCallbackParams *eventDataP));
template <typename T> 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 <typename T> 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 <typename T> 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);
}

View File

@ -355,21 +355,21 @@ public:
/**
* Authorization.
*/
void setWriteAuthorizationCallback(void (*callback)(GattCharacteristicWriteAuthCBParams *)) {
void setWriteAuthorizationCallback(void (*callback)(GattWriteAuthCallbackParams *)) {
writeAuthorizationCallback.attach(callback);
enabledWriteAuthorization = true;
}
template <typename T>
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 <typename T>
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<GattCharacteristicReadAuthCBParams *> readAuthorizationCallback;
FunctionPointerWithContext<GattCharacteristicWriteAuthCBParams *> writeAuthorizationCallback;
FunctionPointerWithContext<GattReadAuthCallbackParams *> readAuthorizationCallback;
FunctionPointerWithContext<GattWriteAuthCallbackParams *> writeAuthorizationCallback;
private:
/* disallow copy and assignment */

View File

@ -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__*/

View File

@ -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 <typename T>
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 <typename T>
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<unsigned> onDataSent;
CallChainOfFunctionPointersWithContext<const GattCharacteristicWriteCBParams *> onDataWritten;
CallChainOfFunctionPointersWithContext<const GattCharacteristicReadCBParams *> onDataRead;
CallChainOfFunctionPointersWithContext<const GattWriteCallbackParams *> onDataWritten;
CallChainOfFunctionPointersWithContext<const GattReadCallbackParams *> onDataRead;
EventCallback_t onUpdatesEnabled;
EventCallback_t onUpdatesDisabled;
EventCallback_t onConfirmationReceived;

View File

@ -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 <typename T>
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 <typename T>
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<unsigned> onDataSent;
CallChainOfFunctionPointersWithContext<const GattCharacteristicWriteCBParams *> onDataWritten;
CallChainOfFunctionPointersWithContext<const GattCharacteristicReadCBParams *> onDataRead;
CallChainOfFunctionPointersWithContext<const GattWriteCallbackParams *> onDataWritten;
CallChainOfFunctionPointersWithContext<const GattReadCallbackParams *> onDataRead;
EventCallback_t onUpdatesEnabled;
EventCallback_t onUpdatesDisabled;
EventCallback_t onConfirmationReceived;

View File

@ -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();

View File

@ -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.

View File

@ -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<const AlertLevel_t *>(params->data);
}

View File

@ -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;

View File

@ -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 <typename T>
void basicAuthorizationCallback(GattCharacteristicWriteAuthCBParams *authParams) {
void basicAuthorizationCallback(GattWriteAuthCallbackParams *authParams) {
if (lockedState) {
authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INSUF_AUTHORIZATION;
} else if (authParams->len != sizeof(T)) {