Skip to content

The use of bind in Ticker.h is prone to type inference failure #6129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions libraries/ESP8266mDNS/src/LEAmDNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ bool MDNSResponder::begin(const char* p_pcHostname) {
m_GotIPHandler = WiFi.onStationModeGotIP([this](const WiFiEventStationModeGotIP& pEvent) {
(void) pEvent;
// Ensure that _restart() runs in USER context
schedule_function(std::bind(&MDNSResponder::_restart, this));
schedule_function([this]() { MDNSResponder::_restart(); });
});

m_DisconnectedHandler = WiFi.onStationModeDisconnected([this](const WiFiEventStationModeDisconnected& pEvent) {
(void) pEvent;
// Ensure that _restart() runs in USER context
schedule_function(std::bind(&MDNSResponder::_restart, this));
});
schedule_function([this]() { MDNSResponder::_restart(); });
});

bResult = _restart();
}
Expand Down Expand Up @@ -137,10 +137,10 @@ bool MDNSResponder::begin(const char* p_pcHostname,
*/
bool MDNSResponder::close(void) {

m_GotIPHandler.reset(); // reset WiFi event callbacks.
m_DisconnectedHandler.reset();
m_GotIPHandler.reset(); // reset WiFi event callbacks.
m_DisconnectedHandler.reset();

_announce(false, true);
_announce(false, true);
_resetProbeStatus(false); // Stop probing

_releaseServiceQueries();
Expand All @@ -159,7 +159,7 @@ bool MDNSResponder::close(void) {
*/

bool MDNSResponder::end(void) {
return close();
return close();
}

/*
Expand Down Expand Up @@ -832,11 +832,11 @@ uint32_t MDNSResponder::answerCount(const MDNSResponder::hMDNSServiceQuery p_hSe

std::vector<MDNSResponder::MDNSServiceInfo> MDNSResponder::answerInfo (const MDNSResponder::hMDNSServiceQuery p_hServiceQuery) {
std::vector<MDNSResponder::MDNSServiceInfo> tempVector;
for (uint32_t i=0;i<answerCount(p_hServiceQuery);i++)
for (uint32_t i=0;i<answerCount(p_hServiceQuery);i++)
{
tempVector.emplace_back(*this,p_hServiceQuery,i);
tempVector.emplace_back(*this,p_hServiceQuery,i);
}
return tempVector;
return tempVector;
}

/*
Expand Down Expand Up @@ -1053,14 +1053,14 @@ const char* MDNSResponder::answerTxts(const MDNSResponder::hMDNSServiceQuery p_h
*/
bool MDNSResponder::setHostProbeResultCallback(MDNSResponder::MDNSHostProbeFn p_fnCallback) {

m_HostProbeInformation.m_fnHostProbeResultCallback = p_fnCallback;
m_HostProbeInformation.m_fnHostProbeResultCallback = p_fnCallback;

return true;
}

bool MDNSResponder::setHostProbeResultCallback(MDNSHostProbeFn1 pfn) {
using namespace std::placeholders;
return setHostProbeResultCallback(std::bind(pfn, std::ref(*this), _1, _2));
using namespace std::placeholders;
return setHostProbeResultCallback([resp=std::ref(*this), pfn](const char* p_pcDomainName, bool p_bProbeResult) { pfn(resp, p_pcDomainName, p_bProbeResult); });
}

/*
Expand Down Expand Up @@ -1088,8 +1088,10 @@ bool MDNSResponder::setServiceProbeResultCallback(const MDNSResponder::hMDNSServ

bool MDNSResponder::setServiceProbeResultCallback(const MDNSResponder::hMDNSService p_hService,
MDNSResponder::MDNSServiceProbeFn1 p_fnCallback) {
using namespace std::placeholders;
return setServiceProbeResultCallback(p_hService, std::bind(p_fnCallback, std::ref(*this), _1, _2, _3));
using namespace std::placeholders;
return setServiceProbeResultCallback(p_hService, [resp=std::ref(*this), p_fnCallback](const char* p_pcServiceName, const hMDNSService p_hMDNSService, bool p_bProbeResult) {
p_fnCallback(resp, p_pcServiceName, p_hMDNSService, p_bProbeResult);
});
}


Expand Down
8 changes: 4 additions & 4 deletions libraries/Ticker/Ticker.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Ticker

void attach_scheduled(float seconds, callback_function_t callback)
{
attach(seconds,std::bind(schedule_function, callback));
attach(seconds, [callback]() { schedule_function(callback); });
}

void attach(float seconds, callback_function_t callback)
Expand All @@ -54,7 +54,7 @@ class Ticker

void attach_ms_scheduled(uint32_t milliseconds, callback_function_t callback)
{
attach_ms(milliseconds, std::bind(schedule_function, callback));
attach_ms(milliseconds, [callback]() { schedule_function(callback); });
}

void attach_ms(uint32_t milliseconds, callback_function_t callback)
Expand Down Expand Up @@ -84,7 +84,7 @@ class Ticker

void once_scheduled(float seconds, callback_function_t callback)
{
once(seconds, std::bind(schedule_function, callback));
once(seconds, [callback]() { schedule_function(callback); });
}

void once(float seconds, callback_function_t callback)
Expand All @@ -95,7 +95,7 @@ class Ticker

void once_ms_scheduled(uint32_t milliseconds, callback_function_t callback)
{
once_ms(milliseconds, std::bind(schedule_function, callback));
once_ms(milliseconds, [callback]() { schedule_function(callback); });
}

void once_ms(uint32_t milliseconds, callback_function_t callback)
Expand Down