Added common type for callback parameter

This commit is contained in:
2020-10-09 15:53:39 +02:00
parent 6bed667169
commit 183d14c18a
2 changed files with 9 additions and 7 deletions

View File

@ -61,7 +61,7 @@ private:
AsyncHTTPRequest::AsyncHTTPRequest(): _readyState(ReadyState::Idle), _HTTPcode(0), _chunked(false), _debug(DEBUG_IOTA_HTTP_SET)
, _timeout(DEFAULT_RX_TIMEOUT), _lastActivity(0), _requestStartTime(0), _requestEndTime(0), _URL(nullptr)
, _connectedHost(nullptr), _connectedPort(-1), _client(nullptr), _contentLength(0), _contentRead(0)
, _readyStateChangeCB(nullptr), _readyStateChangeCBarg(nullptr), _onDataCB(nullptr), _onDataCBarg(nullptr)
, _readyStateChangeCB(nullptr), _readyStateChangeCBarg{}, _onDataCB(nullptr), _onDataCBarg(nullptr)
, _request(nullptr), _response(nullptr), _chunks(nullptr), _headers(nullptr)
{
#ifdef ESP32
@ -161,14 +161,14 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
return _connect();
}
//**************************************************************************************************************
void AsyncHTTPRequest::onReadyStateChange(readyStateChangeCB cb, void* arg)
void AsyncHTTPRequest::onReadyStateChange(readyStateChangeCB cb, callback_arg_t arg)
{
_readyStateChangeCB = cb;
_readyStateChangeCBarg = arg;
}
//**************************************************************************************************************
void AsyncHTTPRequest::onReadyStateChangeArg(void* arg)
void AsyncHTTPRequest::onReadyStateChangeArg(callback_arg_t arg)
{
_readyStateChangeCBarg = arg;
}

View File

@ -91,6 +91,8 @@ enum class ReadyState
class AsyncHTTPRequest
{
using callback_arg_t = void*;
struct header
{
header* next;
@ -135,7 +137,7 @@ class AsyncHTTPRequest
}
};
using readyStateChangeCB = std::function<void(void*, AsyncHTTPRequest*, ReadyState readyState)>;
using readyStateChangeCB = std::function<void(callback_arg_t, AsyncHTTPRequest*, ReadyState readyState)>;
using onDataCB = std::function<void(void*, AsyncHTTPRequest*, size_t available)>;
public:
@ -149,8 +151,8 @@ class AsyncHTTPRequest
bool debug() const; // is debug on or off?
bool open(const char* method, const char* URL); // Initiate a request
void onReadyStateChange(readyStateChangeCB, void* arg = 0); // Optional event handler for ready state change
void onReadyStateChangeArg(void* arg = 0); // set event handlers arg
void onReadyStateChange(readyStateChangeCB, callback_arg_t arg = 0); // Optional event handler for ready state change
void onReadyStateChangeArg(callback_arg_t arg = 0); // set event handlers arg
// or you can simply poll readyState()
void setTimeout(int seconds); // overide default timeout (seconds)
@ -217,7 +219,7 @@ class AsyncHTTPRequest
size_t _contentLength; // content-length header value or sum of chunk headers
size_t _contentRead; // number of bytes retrieved by user since last open()
readyStateChangeCB _readyStateChangeCB; // optional callback for readyState change
void* _readyStateChangeCBarg; // associated user argument
callback_arg_t _readyStateChangeCBarg; // associated user argument
onDataCB _onDataCB; // optional callback when data received
void* _onDataCBarg; // associated user argument