what to do on received messages is now handled via template policies

This commit is contained in:
Kjistóf 2016-12-03 16:26:13 +01:00
parent 5cfef17cc2
commit 88aff84db1

View File

@ -15,8 +15,24 @@ namespace chat
using boost::asio::ip::tcp; using boost::asio::ip::tcp;
struct receive_policy_stdout
{
static void message_do_what(chat_message msg)
{
std::cout << msg << '\n';
}
// TODO: handshake_policy
};
/* most ezt így üres template paraméterekkel kell példányosítani,
* pl.: client_network_manager<> cnm;
* meg lehet oldani úgy, hogy ne kelljen? usingot/typedefet nem enged saját magára */
template <class receive_policy = receive_policy_stdout>
class client_network_manager class client_network_manager
{ {
// TODO: add static assert to check receive_policy
/* members */ /* members */
private: private:
asio::io_service& _ios; asio::io_service& _ios;
@ -128,7 +144,8 @@ namespace chat
send(chat_message(message::PONG)); send(chat_message(message::PONG));
break; break;
case byte(message::MESSAGE): case byte(message::MESSAGE):
std::cout << data << '\n'; chat_message msg(message::MESSAGE, data);
receive_policy::message_do_what(msg);
break; break;
} }