Replies: 2 comments 1 reply
-
|
This might be a side effect when we introduced the URIMatcher… I need to have a look deeper. @willmmiles fyi |
Beta Was this translation helpful? Give feedback.
-
|
@petricf : ok so you have this issue in 3.9.0 because we added an overload for all the flavors: now available: I suppose you have ArduinoJson in your compile path. So the compiler is not able to make the difference between the last 2 functions. One approach is to cast: server.on("/json1", HTTP_GET, static_cast<ArRequestHandlerFunction>(std::bind(&MyClass::handlePage, this, std::placeholders::_1)));
server.on("/json2", HTTP_GET, static_cast<ArRequestHandlerFunction>(std::bind(&MyClass::handleOtherPage, this, std::placeholders::_1)));another approach is to just use normal anonymous functions. Handlers should anyway only be setup once and only once. class MyClass {
void bindCallbacks() {
server.on("/json1", HTTP_GET, [this](AsyncWebServerRequest *request) {
...
});
server.on("/json2", HTTP_GET, [this](AsyncWebServerRequest *request) {
...
});
}
};Or have anonymous functions call the other ones and force inline ? class MyClass {
__attribute__((always_inline)) inline void handlePage(AsyncWebServerRequest *request) {}
__attribute__((always_inline)) inline void handleOtherPage(AsyncWebServerRequest *request) {}
void bindCallbacks() {
server.on("/json1", HTTP_GET, [this](AsyncWebServerRequest *request) {
handlePage(request);
});
server.on("/json2", HTTP_GET, [this](AsyncWebServerRequest *request) {
handleOtherPage(request);
});
}
}; |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I bind a member function of my class to AsyncWebServer::on (). Sample code:
class MyClass{...void handlePage (AsyncWebServerRequest * request);void handleOtherPage (AsyncWebServerRequest * request);...void bindCallbacks ();};`MyClass instance;` `AsyncWebServer webServer (80);`void MyClass::bindCallbacks (){webServer.on ("/page", HTTP_GET, std::bind (&MyClass::handlePage, this, std::placeholders::_1));webServer.on ("/page2", HTTP_GET, std::bind (&MyClass::handleOtherPage, this, std::placeholders::_1));}This worked well until version 3.8.1.
With the change from 3.8.1 to 3.9.0 i get following compilation error:
/home/petric/Arduino/Waveshare-ESP32C6/MyClass.cpp:51:16: error: call of overloaded 'on(char [8], WebRequestMethod, std::_Bind_helper<false, void (MyClass::*)(AsyncWebServerRequest*), MyClass*, const std::_Placeholder<1>&>::type)' is ambiguous51 | webServer.on ("/page", HTTP_GET, std::bind (&ActivityHandler::handleManagePage, this, std::placeholders::_1));| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/home/petric/Arduino/libraries/ESP_Async_WebServer/src/ESPAsyncWebServer.h:1526:28: note: candidate: 'AsyncCallbackWebHandler& AsyncWebServer::on(AsyncURIMatcher, WebRequestMethodComposite, ArRequestHandlerFunction, ArUploadHandlerFunction, ArBodyHandlerFunction)'1526 | AsyncCallbackWebHandler &on(| ^~/home/petric/Arduino/libraries/ESP_Async_WebServer/src/ESPAsyncWebServer.h:1532:32: note: candidate: 'AsyncCallbackJsonWebHandler& AsyncWebServer::on(AsyncURIMatcher, WebRequestMethodComposite, ArJsonRequestHandlerFunction)'1532 | AsyncCallbackJsonWebHandler &on(AsyncURIMatcher uri, WebRequestMethodComposite method, ArJsonRequestHandlerFunction onBody);| ^~Same error on binding handlerOtherPage.
I am not sure whether this is a bug or a coding error on my side.
Any ideas ?
Beta Was this translation helpful? Give feedback.
All reactions