receive_policy must provide an invalid_msg_do_what method
This commit is contained in:
parent
e1f42bf31d
commit
3faabb1e4e
@ -171,6 +171,8 @@ namespace chat
|
|||||||
receive_policy::logout_do_what
|
receive_policy::logout_do_what
|
||||||
(chat_message(message::LOGOUT, content));
|
(chat_message(message::LOGOUT, content));
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
receive_policy::invalid_msg_do_what(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& fun : _subscriptions) // notify subscribers
|
for (auto& fun : _subscriptions) // notify subscribers
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
* - static void handshake_do_what(chat_message)
|
* - static void handshake_do_what(chat_message)
|
||||||
* - static void serverdirection_do_what(chat_message)
|
* - static void serverdirection_do_what(chat_message)
|
||||||
* - static void login_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>
|
template <class PolicyCandidate, typename = void>
|
||||||
struct is_valid_receive_policy : std::false_type {};
|
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>())),
|
::logout_do_what(std::declval<chat::chat_message>())),
|
||||||
void
|
void
|
||||||
>::value
|
>::value
|
||||||
|
&&
|
||||||
|
std::is_same<
|
||||||
|
decltype(PolicyCandidate
|
||||||
|
::invalid_msg_do_what(std::declval<chat::chat_message>())),
|
||||||
|
void
|
||||||
|
>::value
|
||||||
>::type>
|
>::type>
|
||||||
: std::true_type {};
|
: std::true_type {};
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <stdexcept>
|
||||||
#include "chat_networking.hpp"
|
#include "chat_networking.hpp"
|
||||||
|
|
||||||
|
|
||||||
@ -20,6 +21,9 @@ struct receive_policy_stdout
|
|||||||
|
|
||||||
static void logout_do_what(const chat::chat_message& msg)
|
static void logout_do_what(const chat::chat_message& msg)
|
||||||
{ std::cout << msg.get_content() << " kilépett.\n"; }
|
{ 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
|
struct send_policy_stdout
|
||||||
@ -45,7 +49,6 @@ int main()
|
|||||||
chat::client_network_manager<receive_policy_stdout, send_policy_stdout> cnm(ios, epit, "BATMAN");
|
chat::client_network_manager<receive_policy_stdout, send_policy_stdout> cnm(ios, epit, "BATMAN");
|
||||||
std::thread t([&ios]{ ios.run(); });
|
std::thread t([&ios]{ ios.run(); });
|
||||||
|
|
||||||
|
|
||||||
std::string input;
|
std::string input;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user