Skip to content
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

implementing AWOT in a class #146

Open
Bart-van-Ingen opened this issue Apr 12, 2023 · 5 comments
Open

implementing AWOT in a class #146

Bart-van-Ingen opened this issue Apr 12, 2023 · 5 comments

Comments

@Bart-van-Ingen
Copy link

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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

@raffaeler
Copy link

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

@lasselukkari
Copy link
Owner

lasselukkari commented Nov 6, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants