17 #ifndef SCIP2_RESPONSE_H 18 #define SCIP2_RESPONSE_H 20 #include <boost/asio.hpp> 42 responses_[response->getCommandCode()] = response;
60 const boost::posix_time::ptime& time_read,
61 const std::string& echo_back,
62 const std::string& status,
63 std::istream& stream)
const 65 const std::string command_code(echo_back.substr(0, 2));
66 const auto response = responses_.find(command_code);
67 if (response == responses_.end())
69 logger::debug() <<
"Unknown response " << command_code << std::endl;
72 (*(response->second))(time_read, echo_back, status, stream);
74 template <
typename TResponse>
77 const auto response = responses_.find(TResponse().getCommandCode());
78 assert(response != responses_.end());
79 auto response_downcast = std::dynamic_pointer_cast<TResponse>(response->second);
80 assert(response_downcast);
82 response_downcast->registerCallback(cb);
88 #endif // SCIP2_RESPONSE_H
void registerResponse(Response::Ptr response)
std::shared_ptr< Response > Ptr
void registerCallback(typename TResponse::Callback cb)
std::map< std::string, Response::Ptr > responses_
void operator()(const boost::posix_time::ptime &time_read, const std::string &echo_back, const std::string &status, std::istream &stream) const