pairpal
Loading...
Searching...
No Matches
server.hpp
1#ifndef SERVER_HPP
2#define SERVER_HPP
3
4#include <atomic>
5#include <chat.hpp>
6#include <pair.hpp>
7#include <storage.hpp>
8#include <thread>
9#include <zmq.hpp>
10
15class Server {
16 public:
21 explicit Server(std::string listenAddr);
22
26 virtual ~Server();
27
32 auto start() -> bool;
33
38 auto stop() -> bool;
39
44 [[nodiscard]] auto getListenAddr() const -> std::string;
45
46 private:
47 std::string listenAddr_;
48 zmq::context_t context_;
49 zmq::socket_t socket_;
50 std::atomic_bool
51 running_;
52 std::thread serverThread_;
53
54 Chat chat_;
55 Pair pair_;
56 Storage storage_;
57
61 void run_();
62
68 [[nodiscard]] auto handleRequest_(const zmq::message_t& request)
69 -> zmq::message_t;
70
77 virtual auto addUser_(const std::string& username,
78 const std::string& password) -> bool;
79
85 virtual auto removeUser_(const std::string& username) -> bool;
86
92 [[nodiscard]] virtual auto isExistUser_(const std::string& username) -> bool;
93
98 [[nodiscard]] virtual auto listAllUsers() -> std::vector<std::string>;
99
106 virtual auto authenticateUser_(const std::string& username,
107 const std::string& password) -> bool;
108
115 virtual auto addUserTag_(const std::string& username, const std::string& tag)
116 -> bool;
117
124 virtual auto removeUserTag_(const std::string& username,
125 const std::string& tag) -> bool;
126
132 [[nodiscard]] virtual auto getUserTags_(const std::string& username)
133 -> std::vector<std::string>;
134
142 virtual auto sendMessage_(const std::string& from, const std::string& to,
143 const std::string& message) -> bool;
144
150 [[nodiscard]] virtual auto getSentMessages_(const std::string& username)
151 -> std::vector<std::string>;
152
158 [[nodiscard]] virtual auto getReceivedMessages_(const std::string& username)
159 -> std::vector<std::string>;
160
166 [[nodiscard]] virtual auto getPair_(const std::string& username)
167 -> std::vector<std::string>;
168};
169
170#endif // SERVER_HPP
A class to handle Chat_test functionalities including sending and retrieving messages.
Definition chat.hpp:18
A class to manage user pairs and their similarities.
Definition pair.hpp:12
Represents a server that can be started, stopped, and restarted.
Definition server.hpp:15
Server(std::string listenAddr)
Constructs a Server object.
virtual ~Server()
Destroys the Server object.
auto stop() -> bool
Stops the server.
auto getListenAddr() const -> std::string
Gets the address the server is listening on.
auto start() -> bool
Starts the server on the specified port.
A class to manage user data.
Definition storage.hpp:14