A simple chat server.
More...
#include <SimpleChatServer.h>
A simple chat server.
Definition at line 84 of file SimpleChatServer.h.
◆ ClientMap
◆ UserSet
◆ SimpleChatServer() [1/2]
SimpleChatServer::SimpleChatServer |
( |
Wt::WServer & |
server | ) |
|
◆ SimpleChatServer() [2/2]
◆ changeName()
Changes the name.
Definition at line 111 of file SimpleChatServer.C.
116 std::unique_lock<std::recursive_mutex> lock(
mutex_);
118 UserSet::iterator i =
users_.find(user);
121 if (
users_.count(newUser) == 0) {
Encapsulate a chat event.
void postChatEvent(const ChatEvent &event)
std::recursive_mutex mutex_
◆ connect()
Connects to the chat server.
The passed callback method is posted to when a new chat event is received.
Returns whether the client has been connected (or false if the client was already connected).
Definition at line 59 of file SimpleChatServer.C.
62 std::unique_lock<std::recursive_mutex> lock(
mutex_);
65 ClientInfo clientInfo;
68 clientInfo.eventCallback = handleEvent;
std::string sessionId() const
static WApplication * instance()
◆ disconnect()
bool SimpleChatServer::disconnect |
( |
Client * |
client | ) |
|
Disconnect from the chat server.
Returns whether the client has been disconnected (or false if the client was not connected).
Definition at line 77 of file SimpleChatServer.C.
79 std::unique_lock<std::recursive_mutex> lock(
mutex_);
◆ login()
bool SimpleChatServer::login |
( |
const Wt::WString & |
user | ) |
|
Try to login with given user name.
Returns false if the login was not successful.
Definition at line 84 of file SimpleChatServer.C.
86 std::unique_lock<std::recursive_mutex> lock(
mutex_);
◆ logout()
void SimpleChatServer::logout |
( |
const Wt::WString & |
user | ) |
|
Logout from the server.
Definition at line 98 of file SimpleChatServer.C.
100 std::unique_lock<std::recursive_mutex> lock(
mutex_);
102 UserSet::iterator i =
users_.find(user);
◆ operator=()
◆ postChatEvent()
void SimpleChatServer::postChatEvent |
( |
const ChatEvent & |
event | ) |
|
|
private |
Definition at line 152 of file SimpleChatServer.C.
154 std::unique_lock<std::recursive_mutex> lock(
mutex_);
170 if (app && app->
sessionId() == i->second.sessionId)
171 i->second.eventCallback(event);
174 std::bind(i->second.eventCallback, event));
WT_API void post(const std::string &sessionId, const std::function< void()> &function, const std::function< void()> &fallBackFunction=std::function< void()>())
◆ sendMessage()
◆ suggestGuest()
Get a suggestion for a guest user name.
Definition at line 134 of file SimpleChatServer.C.
136 std::unique_lock<std::recursive_mutex> lock(
mutex_);
138 for (
int i = 1;; ++i) {
139 std::string s =
"guest " + std::to_string(i);
◆ users()
Get the users currently logged in.
Definition at line 178 of file SimpleChatServer.C.
180 std::unique_lock<std::recursive_mutex> lock(
mutex_);
std::set< Wt::WString > UserSet
Typedef for a collection of user names.
◆ clients_
◆ mutex_
std::recursive_mutex SimpleChatServer::mutex_ |
|
private |
◆ server_
◆ users_
The documentation for this class was generated from the following files: