Sfoglia il codice sorgente

Put init code into console_server_globals

Daniele Bartolini 11 anni fa
parent
commit
9f71ee795b
2 ha cambiato i file con 39 aggiunte e 5 eliminazioni
  1. 26 4
      engine/console_server.cpp
  2. 13 1
      engine/console_server.h

+ 26 - 4
engine/console_server.cpp

@@ -36,6 +36,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "filesystem.h"
 #include "math_utils.h"
 #include "memory.h"
+#include "main.h"
 
 namespace crown
 {
@@ -305,6 +306,7 @@ void ConsoleServer::process_command(TCPSocket /*client*/, const char* msg)
 //-----------------------------------------------------------------------------
 void ConsoleServer::processs_filesystem(TCPSocket client, const char* msg)
 {
+/*
 	using namespace string_stream;
 
 	JSONParser parser(msg);
@@ -319,9 +321,9 @@ void ConsoleServer::processs_filesystem(TCPSocket client, const char* msg)
 		DynamicString file_name;
 		root.key("file").to_string(file_name);
 
-		File* file = device()->filesystem()->open(file_name.c_str(), FOM_READ);
+		File* file = crown::filesystem()->open(file_name.c_str(), FOM_READ);
 		size_t file_size = file->size();
-		device()->filesystem()->close(file);
+		crown::filesystem()->close(file);
 
 		TempAllocator64 alloc;
 		StringStream response(alloc);
@@ -338,11 +340,11 @@ void ConsoleServer::processs_filesystem(TCPSocket client, const char* msg)
 		root.key("file").to_string(file_name);
 
 		// Read the file data
-		File* file = device()->filesystem()->open(file_name.c_str(), FOM_READ);
+		File* file = crown::filesystem()->open(file_name.c_str(), FOM_READ);
 		char* bytes = (char*) default_allocator().allocate((size_t) file_size.to_int());
 		file->seek((size_t) file_position.to_int());
 		file->read(bytes, (size_t) file_size.to_int());
-		device()->filesystem()->close(file);
+		crown::filesystem()->close(file);
 
 		// Encode data to base64
 		size_t dummy;
@@ -361,6 +363,26 @@ void ConsoleServer::processs_filesystem(TCPSocket client, const char* msg)
 		default_allocator().deallocate(bytes_encoded);
 		default_allocator().deallocate(bytes);
 	}
+*/
 }
 
+namespace console_server_globals
+{
+	ConsoleServer* _console = NULL;
+
+	void init()
+	{
+		_console = CE_NEW(default_allocator(), ConsoleServer);
+	}
+
+	void shutdown()
+	{
+		CE_DELETE(default_allocator(), _console);
+	}
+
+	ConsoleServer& console()
+	{
+		return *_console;
+	}
+} // namespace console_server
 } // namespace crown

+ 13 - 1
engine/console_server.h

@@ -30,7 +30,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "container_types.h"
 #include "queue.h"
 #include "id_array.h"
-#include "config.h"
+#include <cstdarg>
 
 namespace crown
 {
@@ -96,4 +96,16 @@ private:
 	ClientArray m_clients;
 };
 
+/// Functions for accessing global console.
+namespace console_server_globals
+{
+	// Creates the global console server.
+	void init();
+
+	/// Destroys the global console server.
+	void shutdown();
+
+	/// Returns the global console server object.
+	ConsoleServer& console();
+} // namespace console_server_globals
 } // namespace crown