SVCS - English Documentation
Loading...
Searching...
No Matches
Server.hxx
Go to the documentation of this file.
1
17#pragma once
18
22#include "RemoteProtocol.hxx"
23
24#include <boost/asio.hpp>
25#include <memory>
26#include <string>
27#include <thread>
28#include <vector>
29#include <atomic>
30#include <unordered_set>
31#include <mutex>
32
50namespace svcs::server {
51
52using namespace svcs::core;
53using namespace svcs::services;
54
55using boost::asio::ip::tcp;
56
72class Server {
73public:
89 Server(boost::asio::io_context& io_context,
90 unsigned short port,
91 std::shared_ptr<RepositoryManager> repo_manager,
92 std::shared_ptr<ISubject> event_bus);
93
101 ~Server();
102
112 bool start();
113
123 void stop();
124
134 bool isRunning() const;
135
145 unsigned short getPort() const;
146
156 size_t getActiveConnections() const;
157
158private:
166 void startAccept();
167
179 void handleAccept(std::shared_ptr<tcp::socket> socket, const boost::system::error_code& error);
180
190 void spawnClientHandler(std::shared_ptr<tcp::socket> socket);
191
201 void handleClient(std::shared_ptr<tcp::socket> socket);
202
214 std::string determineServiceType(std::shared_ptr<tcp::socket> socket);
215
225
229 bool executeProtocol(std::shared_ptr<tcp::socket> socket, const std::string& service_type);
230
240 void removeClientConnection(std::shared_ptr<tcp::socket> socket);
241
251 void notifyServerEvent(const std::string& message) const;
252
262 void notifyClientConnection(const std::string& message) const;
263
273 void notifyServerError(const std::string& message) const;
274
275private:
283 boost::asio::io_context& io_context_;
284
292 tcp::acceptor acceptor_;
293
301 std::shared_ptr<RepositoryManager> repository_manager_;
302
310 std::shared_ptr<ISubject> event_bus_;
311
319 std::atomic<bool> is_running_;
320
328 std::unordered_set<std::shared_ptr<tcp::socket>> active_connections_;
329
337 mutable std::mutex connections_mutex_;
338};
339
340}
Defines the event structure used for the Observer pattern notifications.
Defines the interface for the Subject (Publisher) component of the Observer pattern.
Declaration of the RemoteProtocol class for handling remote communication protocol.
Declaration of the RepositoryManager class, managing all repository-level file operations.
~Server()
Destructor - stops the server and cleans up resources.
Definition Server.cxx:37
void stop()
Stops the server gracefully.
Definition Server.cxx:66
bool isRunning() const
Checks if the server is currently running.
Definition Server.cxx:99
bool start()
Starts the server and begins accepting connections.
Definition Server.cxx:43
size_t getActiveConnections() const
Gets the number of currently active client connections.
Definition Server.cxx:114
Server(boost::asio::io_context &io_context, unsigned short port, std::shared_ptr< RepositoryManager > repo_manager, std::shared_ptr< ISubject > event_bus)
Constructs a Server with specified dependencies.
Definition Server.cxx:24
unsigned short getPort() const
Gets the port number the server is listening on.
Definition Server.cxx:104
Core VCS data structures and object model.
Server-side components and administration commands.
Service layer components and infrastructure services.