lasselukkari / aWOT

Arduino web server library.
MIT License
283 stars 41 forks source link

implementing AWOT in a class #146

Open Bart-van-Ingen opened 1 year ago

Bart-van-Ingen commented 1 year ago

I am getting the following error when trying to implement AWOT in a class

src/WebServerAccessPoint.cpp: In member function 'void WebServerAccessPoint::start_server()':
src/WebServerAccessPoint.cpp:42:36: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function.  Say '&WebServerAccessPoint::serve_html_file' [-fpermissive]
     web_server_app.get("/", &this->serve_html_file);
                                    ^~~~~~~~~~~~~~~
src/WebServerAccessPoint.cpp:42:51: error: no matching function for call to 'awot::Application::get(const char [2], void (WebServerAccessPoint::*)(awot::Request&, awot::Response&))'
     web_server_app.get("/", &this->serve_html_file);
                                                   ^
In file included from include/WebServerAccessPoint.h:8,
                 from src/WebServerAccessPoint.cpp:2:
.pio/libdeps/esp32dev/aWOT/src/aWOT.h:300:8: note: candidate: 'void awot::Application::get(const char*, void (*)(awot::Request&, awot::Response&))'
   void get(const char* path, Router::Middleware* middleware);
        ^~~

the function has return type void, why shouldnt this work ?

Bart-van-Ingen commented 1 year ago

I have tried the example found here : https://github.com/lasselukkari/aWOT/blob/master/examples/MemberFunction/MemberFunction.ino

but this example on compilation creates the following error

src/main.cpp: In function 'void setup()':
src/main.cpp:50:106: error: no matching function for call to 'awot::Application::get(const char [2], std::_Bind_helper<false, void (Counter::*)(awot::Request&, awot::Response&), Counter*, const std::_Placeholder<1>&, const std::_Placeholder<2>&>::type)'
   app.get("/", std::bind(&Counter::handleRequest, &counter, std::placeholders::_1, std::placeholders::_2));
                                                                                                          ^
In file included from src/main.cpp:8:
.pio/libdeps/esp32dev/aWOT/src/aWOT.h:300:8: note: candidate: 'void awot::Application::get(const char*, void (*)(awot::Request&, awot::Response&))'
   void get(const char* path, Router::Middleware* middleware);
        ^~~
.pio/libdeps/esp32dev/aWOT/src/aWOT.h:300:8: note:   no known conversion for argument 2 from 'std::_Bind_helper<false, void (Counter::*)(awot::Request&, awot::Response&), Counter*, const std::_Placeholder<1>&, const std::_Placeholder<2>&>::type' {aka 'std::_Bind<void (Counter::*(Counter*, std::_Placeholder<1>, std::_Placeholder<2>))(awot::Request&, awot::Response&)>'} to 'void (*)(awot::Request&, awot::Response&)'
.pio/libdeps/esp32dev/aWOT/src/aWOT.h:301:8: note: candidate: 'void awot::Application::get(void (*)(awot::Request&, awot::Response&))'
   void get(Router::Middleware* middleware);
        ^~~
.pio/libdeps/esp32dev/aWOT/src/aWOT.h:301:8: note:   candidate expects 1 argument, 2 provided
*** [.pio/build/esp32dev/src/main.cpp.o] Error 1
lasselukkari commented 1 year ago

It seems that I have forgotten to release the latest version that enables the support for std:function callbacks. I'll try to make the release in the following days.

In the meantime you can manually copy the latest version here from github and see if that solves the problem.

The support for the std:function callbacks is at the moment a bit suboptimal. The overloaded functions in Application and Router classes cause some extra hassle in some cases when defining the callback types. This is something that will be addressed in the upcoming v4.

Bart-van-Ingen commented 1 year ago

that is good news! any indication on when you expect the v4 to be done ?

raffaeler commented 8 months ago

Hi I still see this in v3.5. Am I missing something?

lasselukkari commented 7 months ago

Hi I still see this in v3.5. Am I missing something?

Sorry I have been busy with real life. You are missing the v4 that is still just sitting on my computer. The problem is I have not had the time to update the docs and the other tooling to reflect the changes. The api has changed a lot for some of the functions. I will try to push the branch soon so you can try it out.