I want to bind a callback, which will be called by a thread outside the Wt event loop. So obviously I want to use Wt::WServer::post, but I don't get how WApplication::bind should be used, since it's a nonstatic function. First attempt was this:
auto loaded_callback = [](const decltype(Wt::WApplication::sessionId) &session){
Wt::WServer::post(session,
Wt::WApplication::bind(&table_model::member_func),)
};
Which of course didn't work because bind
is nonstatic. However my next attempt
auto object_protect_bind =
Wt::WApplication::instance()->bind(&order_aggregate_table_model::load_future_in_map);
failed with a shitload of compiler errors
Error 153 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int \boost\function\function_template.hpp 922 1 MDDB_Web Error 156 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int \boost\function\function_template.hpp 926 1 MDDB_Web Error 160 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int \boost\function\function_template.hpp 927 1 MDDB_Web Error 150 error C2903: 'apply' : symbol is neither a class template nor a function template \boost\function\function_template.hpp 922 1 MDDB_Web Error 162 error C2825: 'manager_type': must be a class or namespace when followed by '::' \boost\function\function_template.hpp 934 1 MDDB_Web Error 154 error C2653: 'handler_type' : is not a class or namespace name \boost\function\function_template.hpp 926 1 MDDB_Web Error 158 error C2653: 'handler_type' : is not a class or namespace name \boost\function\function_template.hpp 927 1 MDDB_Web Error 164 error C2275: 'manager_type' : illegal use of this type as an expression \boost\function\function_template.hpp 934 1 MDDB_Web Error 165 error C2146: syntax error : missing '}' before identifier 'manage' \boost\function\function_template.hpp 934 1 MDDB_Web Error 159 error C2146: syntax error : missing ';' before identifier 'manager_type' \boost\function\function_template.hpp 927 1 MDDB_Web Error 155 error C2146: syntax error : missing ';' before identifier 'invoker_type' \boost\function\function_template.hpp 926 1 MDDB_Web Error 152 error C2143: syntax error : missing ';' before '<' \boost\function\function_template.hpp 922 1 MDDB_Web Error 163 error C2039: 'manage' : is not a member of '`global namespace'' \boost\function\function_template.hpp 934 1 MDDB_Web Error 151 error C2039: 'apply' : is not a member of 'boost::detail::function::get_invoker0' \boost\function\function_template.hpp 922 1 MDDB_Web Error 166 error C1903: unable to recover from previous error(s); stopping compilation \boost\function\function_template.hpp 934 1 MDDB_Web
while the overall solution I had in mind was:
auto sessionId = Wt::WApplication::instance()->sessionId();
auto server_ptr = Wt::WServer::instance();
auto object_protect_bind = Wt::WApplication::instance()->bind(&order_aggregate_table_model::load_future_in_map);
auto inner_bind = std::bind(object_protect_bind, this);
auto loaded_callback = []
(Wt::WServer* server,
const std::string &session,
boost::function<void()> widget_bind)
-> void {
server->post(session, widget_bind, boost::function<void()>());
};
this->data_future =
std::async(std::launch::async,
table_model::load_quiet_a_bunch_of_data,
query, database, std::bind(loaded_callback, server_ptr, sessionId, inner_bind));
Wt::WTimer::singleShot(20 * 1000, this, &table_model::load_future_in_map);
Any suggestions?