Daniele Bartolini 10 years ago
parent
commit
a09a0aab79
2 changed files with 27 additions and 21 deletions
  1. 8 3
      src/console_server.cpp
  2. 19 18
      src/console_server.h

+ 8 - 3
src/console_server.cpp

@@ -17,8 +17,12 @@
 namespace crown
 {
 
-ConsoleServer::ConsoleServer(uint16_t port, bool wait)
-	: _clients(default_allocator())
+ConsoleServer::ConsoleServer(Allocator& a)
+	: _clients(a)
+{
+}
+
+void ConsoleServer::init(uint16_t port, bool wait)
 {
 	_server.bind(port);
 	_server.listen(5);
@@ -194,7 +198,8 @@ namespace console_server_globals
 
 	void init(uint16_t port, bool wait)
 	{
-		_console = new (_buffer) ConsoleServer(port, wait);
+		_console = new (_buffer) ConsoleServer(default_allocator());
+		_console->init(port, wait);
 	}
 
 	void shutdown()

+ 19 - 18
src/console_server.h

@@ -11,13 +11,31 @@
 namespace crown
 {
 
+/// Provides service to communicate with engine via TCP/IP.
+///
+/// @ingroup Device
 class ConsoleServer
 {
+	TCPSocket _server;
+	Vector<TCPSocket> _clients;
+
+	void send(TCPSocket client, const char* json);
+	void add_client(TCPSocket socket);
+	ReadResult update_client(TCPSocket client);
+	void process(TCPSocket client, const char* json);
+	void process_ping(TCPSocket client, const char* json);
+	void process_script(TCPSocket client, const char* json);
+	void process_command(TCPSocket client, const char* json);
+
 public:
 
+	ConsoleServer(Allocator& a);
+
 	/// Listens on the given @a port. If @a wait is true, this function
 	/// blocks until a client is connected.
-	ConsoleServer(uint16_t port, bool wait);
+	void init(uint16_t port, bool wait);
+
+	/// Shutdowns the server.
 	void shutdown();
 
 	/// Collects requests from clients and processes them all.
@@ -25,23 +43,6 @@ public:
 
 	/// Sends the given JSON-encoded string to all clients.
 	void send(const char* json);
-
-private:
-
-	void send(TCPSocket client, const char* json);
-
-	void add_client(TCPSocket socket);
-	ReadResult update_client(TCPSocket client);
-	void process(TCPSocket client, const char* json);
-
-	void process_ping(TCPSocket client, const char* json);
-	void process_script(TCPSocket client, const char* json);
-	void process_command(TCPSocket client, const char* json);
-
-private:
-
-	TCPSocket _server;
-	Vector<TCPSocket> _clients;
 };
 
 /// Functions for accessing global console.