17 #ifndef SCIP2_RESPONSE_H 18 #define SCIP2_RESPONSE_H 20 #include <boost/asio.hpp> 39 responses_[response->getCommandCode()] = response;
54 const boost::posix_time::ptime &time_read,
55 const std::string &echo_back,
56 const std::string &status,
57 std::istream &stream)
const 59 const std::string command_code(echo_back.substr(0, 2));
60 const auto response = responses_.find(command_code);
61 if (response == responses_.end())
63 std::cerr <<
"Unknown response " << command_code << std::endl;
66 (*(response->second))(time_read, echo_back, status, stream);
68 template <
typename TResponse>
71 const auto response = responses_.find(TResponse().getCommandCode());
72 assert(
response != responses_.end());
73 auto response_downcast = std::dynamic_pointer_cast<TResponse>(
response->second);
74 assert(response_downcast);
76 response_downcast->registerCallback(cb);
82 #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
const std::string response