summaryrefslogtreecommitdiffhomepage
path: root/whiteboard.h
blob: e39b94e9d7a5cc2170d26d3c8a126e146aba9328 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#pragma once

#include <filesystem>
#include <memory>
#include <mutex>
#include <string>

#include <boost/asio/ip/tcp.hpp>

#include "config.h"
#include "connectionregistry.h"
#include "storage.h"

class Whiteboard
{
public:
 Whiteboard();
 int run(int argc, char* argv[]);

private:
 std::unique_ptr<Config> m_config;
 std::unique_ptr<Storage> m_storage;
 std::mutex m_storage_mutex;
 std::mutex m_websocket_mutex;

 ConnectionRegistry m_registry;
 
 using connection = std::shared_ptr<boost::beast::websocket::stream<boost::asio::ip::tcp::socket>>;
 std::string handle_request(connection& c, const std::string& request);
 void notify_other_connections(connection& c, const std::string& id); // notify all other id-related connections about changes
 void do_session(boost::asio::ip::tcp::socket socket);
 void storage_cleanup();
};