aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/server/session_manager.cpp
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2019-11-30 01:38:08 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2019-12-01 05:23:11 +0300
commit90bd600c5025ede4db99122f13dfb07b27de46ae (patch)
tree0b581b43e5fcb54114c6c373352ed6ab5fcd61dc /server/session_manager.cpp
downloadmath-server-90bd600c5025ede4db99122f13dfb07b27de46ae.tar.gz
math-server-90bd600c5025ede4db99122f13dfb07b27de46ae.zip
initial commit
Diffstat (limited to 'server/session_manager.cpp')
-rw-r--r--server/session_manager.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/server/session_manager.cpp b/server/session_manager.cpp
new file mode 100644
index 0000000..a42fca4
--- /dev/null
+++ b/server/session_manager.cpp
@@ -0,0 +1,37 @@
+#include "log.hpp"
+#include "session.hpp"
+#include "session_manager.hpp"
+
+#include <memory>
+#include <mutex>
+
+namespace math::server {
+
+SessionPtr SessionManager::make_session(boost::asio::io_context& io_context) {
+ return std::make_shared<Session>(*this, io_context);
+}
+
+void SessionManager::start(const SessionPtr& session) {
+ std::lock_guard<std::mutex> lck{m_mtx};
+ m_sessions.emplace(session);
+ session->start();
+}
+
+void SessionManager::stop(const SessionPtr& session) {
+ std::lock_guard<std::mutex> lck{m_mtx};
+ const auto removed = m_sessions.erase(session) > 0;
+ if (removed) {
+ session->stop();
+ }
+}
+
+void SessionManager::stop_all() {
+ std::lock_guard<std::mutex> lck{m_mtx};
+ log::log("Closing the remaining %1% session(s)...", m_sessions.size());
+ for (const auto& session : m_sessions) {
+ session->stop();
+ }
+ m_sessions.clear();
+}
+
+}