receive_policy must provide an invalid_msg_do_what method

This commit is contained in:
Kjistóf 2016-12-05 12:57:57 +01:00
parent e1f42bf31d
commit 3faabb1e4e
3 changed files with 14 additions and 2 deletions

View File

@ -171,6 +171,8 @@ namespace chat
receive_policy::logout_do_what
(chat_message(message::LOGOUT, content));
break;
default:
receive_policy::invalid_msg_do_what(msg);
}
for (auto& fun : _subscriptions) // notify subscribers

View File

@ -10,7 +10,8 @@
* - static void handshake_do_what(chat_message)
* - static void serverdirection_do_what(chat_message)
* - static void login_do_what(chat_message)
* - static void logout_do_what(chat_message) */
* - static void logout_do_what(chat_message)
* - static void invalid_msg_do_what(chat_message) */
template <class PolicyCandidate, typename = void>
struct is_valid_receive_policy : std::false_type {};
@ -48,6 +49,12 @@ struct is_valid_receive_policy<
::logout_do_what(std::declval<chat::chat_message>())),
void
>::value
&&
std::is_same<
decltype(PolicyCandidate
::invalid_msg_do_what(std::declval<chat::chat_message>())),
void
>::value
>::type>
: std::true_type {};

View File

@ -1,5 +1,6 @@
#include <iostream>
#include <thread>
#include <stdexcept>
#include "chat_networking.hpp"
@ -20,6 +21,9 @@ struct receive_policy_stdout
static void logout_do_what(const chat::chat_message& msg)
{ std::cout << msg.get_content() << " kilépett.\n"; }
static void invalid_msg_do_what(const chat::chat_message& msg)
{ throw std::runtime_error("Invalid message received!"); }
};
struct send_policy_stdout
@ -45,7 +49,6 @@ int main()
chat::client_network_manager<receive_policy_stdout, send_policy_stdout> cnm(ios, epit, "BATMAN");
std::thread t([&ios]{ ios.run(); });
std::string input;
while (true)
{