From 7c7d514000f054a920f7f1fc4512cde8475c1565 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 25 May 2016 14:48:11 -0500 Subject: [PATCH 1/2] Added callback null check for each template class per @c1728p9 #131 --- hal/api/Callback.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/hal/api/Callback.h b/hal/api/Callback.h index d7b4d12ec8..b90baf91af 100644 --- a/hal/api/Callback.h +++ b/hal/api/Callback.h @@ -106,6 +106,9 @@ public: /** Call the attached function */ R call(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func, a0, a1, a2, a3, a4); } @@ -244,6 +247,9 @@ public: /** Call the attached function */ R call(A0 a0, A1 a1, A2 a2, A3 a3) { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func, a0, a1, a2, a3); } @@ -382,6 +388,9 @@ public: /** Call the attached function */ R call(A0 a0, A1 a1, A2 a2) { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func, a0, a1, a2); } @@ -520,6 +529,9 @@ public: /** Call the attached function */ R call(A0 a0, A1 a1) { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func, a0, a1); } @@ -658,6 +670,9 @@ public: /** Call the attached function */ R call(A0 a0) { + if (!_thunk) { + return (R)0; + } return _thunk(_obj, &_func, a0); } @@ -796,7 +811,7 @@ public: /** Call the attached function */ R call() { - if (NULL == _thunk) { + if (!_thunk) { return (R)0; } return _thunk(_obj, &_func); From 753720af56ea624d0033e820f5a4d466110c586b Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 25 May 2016 14:48:25 -0500 Subject: [PATCH 2/2] Fixed ambigous function declarations in serial class Caused by default argument and overly generalized templated types. SerialBase::attach(T *obj, M method, IrqType type=RxIrq) -> SerialBase::attach(T *obj, void (T::*method)(), IrqType type=RxIrq) SerialBase::attach(T *obj, void (*method)(T*), IrqType type=RxIrq) --- hal/api/CAN.h | 16 ++++++++++++++-- hal/api/SerialBase.h | 15 +++++++++++++-- .../ATParser/BufferedSerial/BufferedSerial.h | 14 ++++++++++++-- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/hal/api/CAN.h b/hal/api/CAN.h index 65221ccdec..241cd4c822 100644 --- a/hal/api/CAN.h +++ b/hal/api/CAN.h @@ -218,8 +218,20 @@ public: * @param method pointer to the member function to be called * @param event Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, TxIrq for transmitted or aborted, EwIrq for error warning, DoIrq for data overrun, WuIrq for wake-up, EpIrq for error passive, AlIrq for arbitration lost, BeIrq for bus error) */ - template - void attach(T* obj, void (T::*method)(void), IrqType type=RxIrq) { + template + void attach(T* obj, void (T::*method)(), IrqType type=RxIrq) { + attach(Callback(obj, method), type); + } + + /** Attach a member function to call whenever a CAN frame received interrupt + * is generated. + * + * @param obj pointer to the object to call the member function on + * @param method pointer to the member function to be called + * @param event Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, TxIrq for transmitted or aborted, EwIrq for error warning, DoIrq for data overrun, WuIrq for wake-up, EpIrq for error passive, AlIrq for arbitration lost, BeIrq for bus error) + */ + template + void attach(T* obj, void (*method)(T*), IrqType type=RxIrq) { attach(Callback(obj, method), type); } diff --git a/hal/api/SerialBase.h b/hal/api/SerialBase.h index e9387f48ac..ed2e744790 100644 --- a/hal/api/SerialBase.h +++ b/hal/api/SerialBase.h @@ -100,8 +100,19 @@ public: * @param method pointer to the member function to be called * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) */ - template - void attach(T *obj, M method, IrqType type=RxIrq) { + template + void attach(T *obj, void (T::*method)(), IrqType type=RxIrq) { + attach(Callback(obj, method), type); + } + + /** Attach a member function to call whenever a serial interrupt is generated + * + * @param obj pointer to the object to call the member function on + * @param method pointer to the member function to be called + * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) + */ + template + void attach(T *obj, void (*method)(T*), IrqType type=RxIrq) { attach(Callback(obj, method), type); } diff --git a/net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedSerial.h b/net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedSerial.h index 5c58928e72..07bcb9b245 100644 --- a/net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedSerial.h +++ b/net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedSerial.h @@ -149,8 +149,18 @@ public: * @param method pointer to the member function to call * @param type Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty) */ - template - void attach(T *obj, M method, IrqType type=RxIrq) { + template + void attach(T *obj, void (T::*method)(), IrqType type=RxIrq) { + attach(Callback(obj, method), type); + } + + /** Attach a member function to call whenever a serial interrupt is generated + * @param obj pointer to the object to call the member function on + * @param method pointer to the member function to call + * @param type Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty) + */ + template + void attach(T *obj, void (*method)(T*), IrqType type=RxIrq) { attach(Callback(obj, method), type); } };