Explorar o código

Refactor RPCServer and rename to ConsoleServer

Daniele Bartolini %!s(int64=12) %!d(string=hai) anos
pai
achega
923f41766d

+ 1 - 3
engine/Android.mk

@@ -82,9 +82,6 @@ LOCAL_SRC_FILES :=\
 	resource/ResourceLoader.cpp\
 	resource/ResourceManager.cpp\
 	resource/ResourceRegistry.cpp\
-\
-	rpc/RPCServer.cpp\
-	rpc/RPCHandler.cpp\
 \
 	lua/LuaStack.cpp\
 	lua/LuaEnvironment.cpp\
@@ -119,6 +116,7 @@ LOCAL_SRC_FILES :=\
 	Sprite.cpp\
 	Unit.cpp\
 	World.cpp\
+	ConsoleServer.cpp\
 \
 
 LOCAL_C_INCLUDES	:=\

+ 2 - 13
engine/CMakeLists.txt

@@ -101,6 +101,7 @@ set (SRC
 	RenderWorld.cpp
 	Mesh.cpp
 	Sprite.cpp
+	ConsoleServer.cpp
 )
 
 set (HEADERS
@@ -116,6 +117,7 @@ set (HEADERS
 	Mesh.h
 	Sprite.h
 	SpriteAnimator.h
+	ConsoleServer.h
 )
 
 set (CORE_SRC
@@ -311,7 +313,6 @@ endif (CROWN_DEBUG OR CROWN_DEVELOPMENT)
 
 set (RESOURCE_HEADERS
 	resource/Resource.h
-	resource/ResourceFormat.h
 	resource/ResourceLoader.h
 	resource/ResourceManager.h
 	resource/ResourceRegistry.h
@@ -328,16 +329,6 @@ set (RESOURCE_HEADERS
 	resource/SpriteResource.h
 )
 
-set (RPC_SRC
-	rpc/RPCHandler.cpp
-	rpc/RPCServer.cpp
-)
-
-set (RPC_HEADERS
-	rpc/RPCServer.h
-	rpc/RPCHandler.h
-)
-
 set (OS_SRC
 )
 
@@ -608,7 +599,6 @@ set (CROWN_SOURCES
 	${INPUT_SRC}
 	${RENDERERS_SRC}
 	${RESOURCE_SRC}
-	${RPC_SRC}
 	${OS_SRC}
 	${LUA_SRC}
 	${AUDIO_SRC}
@@ -630,7 +620,6 @@ set (CROWN_HEADERS
 	${INPUT_HEADERS}
 	${RENDERERS_HEADERS}
 	${RESOURCE_HEADERS}
-	${RPC_HEADERS}
 	${OS_HEADERS}
 	${LUA_HEADERS}
 	${AUDIO_HEADERS}

+ 120 - 107
engine/rpc/RPCServer.cpp → engine/ConsoleServer.cpp

@@ -24,62 +24,30 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "RPCServer.h"
-#include "Log.h"
+#include "ConsoleServer.h"
 #include "JSONParser.h"
-#include "RPCHandler.h"
 #include "TempAllocator.h"
 #include "StringStream.h"
+#include "Log.h"
+#include "Device.h"
+#include "ProxyAllocator.h"
+#include "LuaEnvironment.h"
 
 namespace crown
 {
 
 //-----------------------------------------------------------------------------
-RPCServer::RPCServer()
+ConsoleServer::ConsoleServer()
 	: m_num_clients(0)
 	, m_receive_buffer(default_allocator())
 	, m_send_buffer(default_allocator())
-	, m_handlers_head(NULL)
 	, m_receive_callbacks(default_allocator())
 	, m_send_callbacks(default_allocator())
 {
 }
 
 //-----------------------------------------------------------------------------
-void RPCServer::add_handler(RPCHandler* handler)
-{
-	CE_ASSERT_NOT_NULL(handler);
-
-	if (m_handlers_head != NULL)
-	{
-		handler->m_next = m_handlers_head;
-	}
-
-	m_handlers_head = handler;
-}
-
-//-----------------------------------------------------------------------------
-void RPCServer::remove_handler(RPCHandler* handler)
-{
-	CE_ASSERT_NOT_NULL(handler);
-
-	RPCHandler* cur = m_handlers_head;
-	RPCHandler* prev = NULL;
-
-	for (; cur != NULL && cur != handler; prev = cur, cur = cur->m_next) ;
-
-	if (cur == m_handlers_head)
-	{
-		m_handlers_head = cur->m_next;
-	}
-	else
-	{
-		prev->m_next = cur->m_next;
-	}
-}
-
-//-----------------------------------------------------------------------------
-void RPCServer::init(bool wait)
+void ConsoleServer::init(bool wait)
 {
 	m_listener.open(10001);
 
@@ -93,9 +61,9 @@ void RPCServer::init(bool wait)
 }
 
 //-----------------------------------------------------------------------------
-void RPCServer::shutdown()
+void ConsoleServer::shutdown()
 {
-	for (uint32_t i = 0; i < MAX_RPC_CLIENTS; i++)
+	for (uint32_t i = 0; i < MAX_CONSOLE_CLIENTS; i++)
 	{
 		m_clients[i].close();
 	}
@@ -104,28 +72,7 @@ void RPCServer::shutdown()
 }
 
 //-----------------------------------------------------------------------------
-void RPCServer::update()
-{
-	// Check for new clients
-	TCPSocket client;
-	if (m_listener.listen(client))
-	{
-		add_client(client);
-	}
-
-	// Update all clients
-	for (uint32_t i = 0; i < MAX_RPC_CLIENTS; i++)
-	{
-		ClientId id = *(m_clients_table.begin() + i);
-		if (id.id != INVALID_ID)
-		{
-			update_client(id);
-		}
-	}
-}
-
-//-----------------------------------------------------------------------------
-void RPCServer::log_to_all(const char* message, LogSeverity::Enum severity)
+void ConsoleServer::log_to_all(const char* message, LogSeverity::Enum severity)
 {
 	TempAllocator2048 alloc;
 	StringStream json(alloc);
@@ -149,10 +96,9 @@ void RPCServer::log_to_all(const char* message, LogSeverity::Enum severity)
 }
 
 //-----------------------------------------------------------------------------
-void RPCServer::send_message_to(ClientId client, const char* message)
+void ConsoleServer::send_message_to(ClientId client, const char* message)
 {
 	RPCCallback cb;
-	cb.handler = NULL;
 	cb.client = client;
 	cb.message_index = m_send_buffer.size();
 
@@ -163,10 +109,10 @@ void RPCServer::send_message_to(ClientId client, const char* message)
 }
 
 //-----------------------------------------------------------------------------
-void RPCServer::send_message_to_all(const char* message)
+void ConsoleServer::send_message_to_all(const char* message)
 {
 	// Update all clients
-	for (uint32_t i = 0; i < MAX_RPC_CLIENTS; i++)
+	for (uint32_t i = 0; i < MAX_CONSOLE_CLIENTS; i++)
 	{
 		ClientId id = *(m_clients_table.begin() + i);
 		if (id.id != INVALID_ID)
@@ -177,14 +123,45 @@ void RPCServer::send_message_to_all(const char* message)
 }
 
 //-----------------------------------------------------------------------------
-void RPCServer::execute_callbacks()
+void ConsoleServer::update()
+{
+	// Check for new clients
+	TCPSocket client;
+	if (m_listener.listen(client))
+	{
+		add_client(client);
+	}
+
+	// Update all clients
+	for (uint32_t i = 0; i < MAX_CONSOLE_CLIENTS; i++)
+	{
+		ClientId id = *(m_clients_table.begin() + i);
+		if (id.id != INVALID_ID)
+		{
+			update_client(id);
+		}
+	}
+}
+
+//-----------------------------------------------------------------------------
+void ConsoleServer::process_requests()
 {
 	for (uint32_t i = 0; i < m_receive_callbacks.size(); i++)
 	{
 		RPCCallback cb = m_receive_callbacks.front();
 		m_receive_callbacks.pop_front();
 
-		cb.handler->execute_command(this, cb.client, &m_receive_buffer[cb.message_index]);
+		const char* request = &m_receive_buffer[cb.message_index];
+		JSONParser parser(request);
+		JSONElement request_type = parser.root().key("type");
+		const char* type = request_type.string_value();
+
+		// Determine request type
+		if (string::strcmp("ping", type) == 0) process_ping(cb.client, request);
+		else if (string::strcmp("script", type) == 0) process_script(cb.client, request);
+		else if (string::strcmp("stats", type) == 0) process_stats(cb.client, request);
+		else if (string::strcmp("command", type) == 0) process_command(cb.client, request);
+		else continue;
 	}
 
 	m_receive_callbacks.clear();
@@ -193,9 +170,9 @@ void RPCServer::execute_callbacks()
 	for (uint32_t i = 0; i < m_send_callbacks.size(); i++)
 	{
 		RPCCallback cb = m_send_callbacks.front();
-		m_send_callbacks.pop_front();
+	 	m_send_callbacks.pop_front();
 
-		m_clients[cb.client.index].write(&m_send_buffer[cb.message_index], string::strlen(&m_send_buffer[cb.message_index]));
+	 	m_clients[cb.client.index].write(&m_send_buffer[cb.message_index], string::strlen(&m_send_buffer[cb.message_index]));
 	}
 
 	m_send_callbacks.clear();
@@ -203,7 +180,7 @@ void RPCServer::execute_callbacks()
 }
 
 //-----------------------------------------------------------------------------
-void RPCServer::update_client(ClientId id)
+void ConsoleServer::update_client(ClientId id)
 {
 	size_t total_read = 0;
 	uint32_t message_index = m_receive_buffer.size();
@@ -239,32 +216,16 @@ void RPCServer::update_client(ClientId id)
 	m_receive_buffer.push_back('\0');
 
 	// Process only if received something
-	// TODO: Bad JSON strings crash
 	if (total_read > 0)
 	{
-		JSONParser parser(&m_receive_buffer[message_index]);
-		JSONElement root = parser.root();
-		JSONElement type = root.key_or_nil("type");
-
-		if (!type.is_nil())
-		{
-			RPCHandler* handler = find_handler(type.string_value());
-			if (handler != NULL)
-			{
-				push_callback(handler, id, message_index);
-			}
-		}
-		else
-		{
-			Log::d("Wrong message, type is nil");
-		}
+		add_request(id, message_index);
 	}
 }
 
 //-----------------------------------------------------------------------------
-void RPCServer::add_client(TCPSocket& client)
+void ConsoleServer::add_client(TCPSocket& client)
 {
-	if (m_num_clients < MAX_RPC_CLIENTS)
+	if (m_num_clients < MAX_CONSOLE_CLIENTS)
 	{
 		ClientId id = m_clients_table.create();
 		m_clients[id.index] = client;
@@ -277,7 +238,7 @@ void RPCServer::add_client(TCPSocket& client)
 }
 
 //-----------------------------------------------------------------------------
-void RPCServer::remove_client(ClientId id)
+void ConsoleServer::remove_client(ClientId id)
 {
 	CE_ASSERT(m_num_clients > 0, "No client connected");
 
@@ -287,32 +248,84 @@ void RPCServer::remove_client(ClientId id)
 }
 
 //-----------------------------------------------------------------------------
-RPCHandler* RPCServer::find_handler(const char* type)
+void ConsoleServer::add_request(ClientId client, uint32_t message_index)
+{
+	RPCCallback cb;
+	cb.client = client;
+	cb.message_index = message_index;
+	m_receive_callbacks.push_back(cb);
+}
+
+//-----------------------------------------------------------------------------
+void ConsoleServer::process_ping(ClientId client, const char* /*msg*/)
 {
-	const RPCHandler* handler = m_handlers_head;
+	send_message_to(client, "{\"type\":\"pong\"}");
+}
+
+//-----------------------------------------------------------------------------
+void ConsoleServer::process_script(ClientId /*client*/, const char* msg)
+{
+	JSONParser parser(msg);
+	JSONElement root = parser.root();
 
-	while (handler != NULL)
+	const char* script = root.key("script").string_value();
+	device()->lua_environment()->execute_string(script);
+}
+
+//-----------------------------------------------------------------------------
+void ConsoleServer::process_stats(ClientId client, const char* /*msg*/)
+{
+	TempAllocator2048 alloc;
+	StringStream response(alloc);
+
+	response << "{\"type\":\"response\",";
+	response << "{\"allocators\":[";
+
+	// Walk all proxy allocators
+	ProxyAllocator* proxy = ProxyAllocator::begin();
+	while (proxy != NULL)
 	{
-		if (handler->type() == hash::murmur2_32(type, string::strlen(type), 0))
-		{
-			return (RPCHandler*)handler;
-		}
+		response << "{";
+		response << "\"name\":\"" << proxy->name() << "\",";
+		response << "\"allocated_size\":\"" << proxy->allocated_size() << "\"";
+		response << "},";
 
-		handler = handler->m_next;
+		proxy = ProxyAllocator::next(proxy);
 	}
 
-	return NULL;
+	response << "]" << "}";
+
+	send_message_to(client, response.c_str());
 }
 
 //-----------------------------------------------------------------------------
-void RPCServer::push_callback(RPCHandler* handler, ClientId client, uint32_t message_index)
+void ConsoleServer::process_command(ClientId /*client*/, const char* msg)
 {
-	RPCCallback cb;
-	cb.handler = handler;
-	cb.client = client;
-	cb.message_index = message_index;
+	JSONParser parser(msg);
+	JSONElement root = parser.root();
+	JSONElement command = root.key("command");
 
-	m_receive_callbacks.push_back(cb);
+	const char* cmd = command.string_value();
+
+	if (string::strcmp("reload", cmd) == 0)
+	{
+		JSONElement resource_type = root.key_or_nil("resource_type");
+		JSONElement resource_name = root.key_or_nil("resource_name");
+
+		char t[256];
+		char n[256];
+		string::strncpy(t, resource_type.string_value(), 256);
+		string::strncpy(n, resource_name.string_value(), 256);
+		device()->reload(t, n);
+	}
+	else if (string::strcmp("pause", cmd) == 0)
+	{
+		device()->pause();
+	}
+	else if (string::strcmp("unpause", cmd) == 0)
+	{
+		device()->unpause();
+	}
 }
 
 } // namespace crown

+ 25 - 25
engine/rpc/RPCServer.h → engine/ConsoleServer.h

@@ -35,61 +35,61 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-class RPCHandler;
 typedef Id ClientId;
-#define MAX_RPC_CLIENTS 16
+#define MAX_CONSOLE_CLIENTS 16
 
 struct RPCCallback
 {
-	RPCHandler* handler;
 	ClientId client;
 	uint32_t message_index;
 };
 
-class RPCServer
+class ConsoleServer
 {
 public:
 
-						RPCServer();
+								ConsoleServer();
 
-	void				add_handler(RPCHandler* handler);
-	void				remove_handler(RPCHandler* handler);
+	/// Initializes the system. If @a wait is true, this function
+	/// blocks until a client is connected.
+	void						init(bool wait);
+	void						shutdown();
 
-	void				init(bool wait);
-	void				shutdown();
+	void						log_to_all(const char* message, LogSeverity::Enum severity);
 
-	void				update();
+	void						send_message_to(ClientId client, const char* message);
+	void						send_message_to_all(const char* message);
 
-	void				log_to_all(const char* message, LogSeverity::Enum severity);
+	/// Collects requests from clients without processing them.
+	void						update();
 
-	void				send_message_to(ClientId client, const char* message);
-	void				send_message_to_all(const char* message);
-
-	void				execute_callbacks();
+	/// Processes all the requests collected by update() possibly accessing
+	/// global resources. It should be called only when "it is safe".
+	void						process_requests();
 
 private:
 
-	void				update_client(ClientId id);
-	void				add_client(TCPSocket& client);
-	void				remove_client(ClientId id);
+	void						update_client(ClientId id);
+	void						add_client(TCPSocket& client);
+	void						remove_client(ClientId id);
 
-	// Returns a handler for processing type messages or NULL.
-	RPCHandler*			find_handler(const char* type);
-	void				push_callback(RPCHandler* handler, ClientId client, uint32_t message_index);
+	void						add_request(ClientId client, uint32_t message_index);
+	void						process_ping(ClientId client, const char* msg);
+	void						process_script(ClientId client, const char* msg);
+	void						process_stats(ClientId client, const char* msg);
+	void						process_command(ClientId client, const char* msg);
 
 private:
 
 	TCPListener					m_listener;
 
 	uint8_t						m_num_clients;
-	IdTable<MAX_RPC_CLIENTS> 	m_clients_table;
-	TCPSocket					m_clients[MAX_RPC_CLIENTS];
+	IdTable<MAX_CONSOLE_CLIENTS>	m_clients_table;
+	TCPSocket					m_clients[MAX_CONSOLE_CLIENTS];
 
 	List<char>					m_receive_buffer;
 	List<char>					m_send_buffer;
 
-	RPCHandler*					m_handlers_head;
-
 	Queue<RPCCallback>			m_receive_callbacks;
 	Queue<RPCCallback>			m_send_callbacks;
 };

+ 1 - 0
engine/Crown.h

@@ -104,6 +104,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 // Engine
 #include "Camera.h"
 #include "Device.h"
+#include "ConsoleServer.h"
 
 // Engine/Input
 #include "Keyboard.h"

+ 10 - 14
engine/Device.cpp

@@ -51,7 +51,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Bundle.h"
 #include "TempAllocator.h"
 #include "ResourcePackage.h"
-#include "RPCServer.h"
+#include "ConsoleServer.h"
 #include "SoundRenderer.h"
 #include "World.h"
 #include "LuaStack.h"
@@ -93,7 +93,7 @@ Device::Device()
 	, m_sound_renderer(NULL)
 
 	, m_bundle_compiler(NULL)
-	, m_rpc(NULL)
+	, m_console(NULL)
 	, m_resource_manager(NULL)
 	, m_resource_bundle(NULL)
 
@@ -118,12 +118,8 @@ void Device::init()
 
 	// RPC only in debug or development builds
 	#if defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT)
-		m_rpc = CE_NEW(m_allocator, RPCServer);
-		m_rpc->add_handler(&m_command_handler);
-		m_rpc->add_handler(&m_script_handler);
-		m_rpc->add_handler(&m_stats_handler);
-		m_rpc->add_handler(&m_ping_handler);
-		m_rpc->init(false);
+		m_console = CE_NEW(m_allocator, ConsoleServer);
+		m_console->init(false);
 	#endif
 
 	// Default bundle filesystem
@@ -247,10 +243,10 @@ void Device::shutdown()
 	}
 
 	#if defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT)
-		m_rpc->execute_callbacks();
-		m_rpc->shutdown();
-		CE_DELETE(m_allocator, m_rpc);
-		m_rpc = NULL;
+		m_console->process_requests();
+		m_console->shutdown();
+		CE_DELETE(m_allocator, m_console);
+		m_console = NULL;
 	#endif
 
 	m_allocator.clear();
@@ -390,7 +386,7 @@ void Device::frame()
 	m_last_time = m_current_time;
 	m_time_since_start += m_last_delta_time;
 
-	m_rpc->update();
+	m_console->update();
 
 	if (!m_is_paused)
 	{
@@ -407,7 +403,7 @@ void Device::frame()
 		m_sound_renderer->frame();
 	}
 
-	m_rpc->execute_callbacks();
+	m_console->process_requests();
 
 	clear_lua_temporaries();
 

+ 3 - 9
engine/Device.h

@@ -31,7 +31,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "OS.h"
 #include "LinearAllocator.h"
 #include "Resource.h"
-#include "RPCHandler.h"
 #include "Physics.h"
 
 namespace crown
@@ -50,7 +49,7 @@ class LuaEnvironment;
 class SoundRenderer;
 class BundleCompiler;
 class ResourcePackage;
-class RPCServer;
+class ConsoleServer;
 class World;
 class Camera;
 
@@ -153,7 +152,7 @@ public:
 	Mouse*					mouse();
 	Touch*					touch();
 	Accelerometer*			accelerometer();
-	RPCServer*				rpc() { return m_rpc; }
+	ConsoleServer*			console() { return m_console; }
 	physx::PxPhysics*		physx() { return m_physx->m_physics; };
 
 protected:
@@ -198,15 +197,10 @@ protected:
 
 	// Private subsystems
 	BundleCompiler*			m_bundle_compiler;
-	RPCServer*				m_rpc;
+	ConsoleServer*			m_console;
 	ResourceManager*		m_resource_manager;
 	Bundle*					m_resource_bundle;
 
-	RPCCommandHandler		m_command_handler;
-	RPCScriptHandler		m_script_handler;
-	RPCStatsHandler			m_stats_handler;
-	RPCPingHandler			m_ping_handler;
-
 	Physics*				m_physx;
 
 	bool 					m_renderer_init_request;

+ 3 - 3
engine/core/Log.cpp

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Log.h"
 #include "Device.h"
-#include "RPCServer.h"
+#include "ConsoleServer.h"
 
 namespace crown
 {
@@ -61,9 +61,9 @@ void Log::log_message(LogSeverity::Enum severity, const char* message, ::va_list
 	os::printf(buf);
 	::fflush(stdout);
 
-	if (device()->rpc() != NULL && string::strlen(buf) > 0)
+	if (device()->console() != NULL && string::strlen(buf) > 0)
 	{
-		device()->rpc()->log_to_all(buf, severity);
+		device()->console()->log_to_all(buf, severity);
 	}
 }
 

+ 0 - 151
engine/rpc/RPCHandler.cpp

@@ -1,151 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include <stdio.h>
-#include "RPCHandler.h"
-#include "RPCServer.h"
-#include "ProxyAllocator.h"
-#include "StringUtils.h"
-#include "TempAllocator.h"
-#include "StringStream.h"
-#include "Device.h"
-#include "LuaEnvironment.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-RPCCommandHandler::RPCCommandHandler()
-	: RPCHandler("command")
-{
-}
-
-//-----------------------------------------------------------------------------
-void RPCCommandHandler::execute_command(RPCServer* server, ClientId client, const char* message)
-{
-	(void)server;
-	(void)client;
-
-	JSONParser parser(message);
-	JSONElement root = parser.root();
-	JSONElement command = root.key_or_nil("command");
-
-	if (!command.is_nil())
-	{
-		const char* cmd = command.string_value();
-
-		if (string::strcmp("reload", cmd) == 0)
-		{
-			JSONElement resource_type = root.key_or_nil("resource_type");
-			if (!resource_type.is_nil())
-			{
-				JSONElement resource_name = root.key_or_nil("resource_name");
-				if (!resource_name.is_nil())
-				{
-					char t[256];
-					char n[256];
-					string::strncpy(t, resource_type.string_value(), 256);
-					string::strncpy(n, resource_name.string_value(), 256);
-					device()->reload(t, n);
-				}
-			}
-		}
-		else if (string::strcmp("pause", cmd) == 0)
-		{
-			device()->pause();
-		}
-		else if (string::strcmp("unpause", cmd) == 0)
-		{
-			device()->unpause();
-		}
-	}
-}
-
-//-----------------------------------------------------------------------------
-RPCScriptHandler::RPCScriptHandler()
-	: RPCHandler("script")
-{
-}
-
-//-----------------------------------------------------------------------------
-void RPCScriptHandler::execute_command(RPCServer* server, ClientId client, const char* message)
-{
-	(void)server;
-	(void)client;
-
-	JSONParser parser(message);
-	JSONElement root = parser.root();
-
-	const char* script = root.key("script").string_value();
-	device()->lua_environment()->execute_string(script);
-}
-
-//-----------------------------------------------------------------------------
-RPCStatsHandler::RPCStatsHandler()
-	: RPCHandler("stats")
-{
-}
-
-//-----------------------------------------------------------------------------
-void RPCStatsHandler::execute_command(RPCServer* server, ClientId client, const char* message)
-{
-	(void)message;
-
-	TempAllocator2048 alloc;
-	StringStream response(alloc);
-
-	response << "{ \"type\" : \"response\", ";
-
-	ProxyAllocator* proxy = ProxyAllocator::begin();
-
-	while (proxy != NULL)
-	{
-		response << "\"allocator\" : \"" << proxy->name() << "\",";
-		response << "\"allocated_size\" : \"" << proxy->allocated_size() << "\"";
-
-		proxy = ProxyAllocator::next(proxy);
-	}
-
-	response << " }";
-
-	(void)message;
-	server->send_message_to(client, response.c_str());
-}
-
-//-----------------------------------------------------------------------------
-RPCPingHandler::RPCPingHandler()
-	: RPCHandler("ping")
-{
-}
-
-//-----------------------------------------------------------------------------
-void RPCPingHandler::execute_command(RPCServer* server, ClientId client, const char* message)
-{
-	(void)message;
-	server->send_message_to(client, "{\"type\":\"pong\"}");
-}
-
-} // namespace crown

+ 0 - 96
engine/rpc/RPCHandler.h

@@ -1,96 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Types.h"
-#include "Hash.h"
-#include "JSONParser.h"
-#include "StringUtils.h"
-
-namespace crown
-{
-
-typedef Id ClientId;
-class TCPClient;
-class RPCServer;
-
-class RPCHandler
-{
-public:
-
-						RPCHandler(const char* type);
-	uint32_t			type() const { return m_type; }
-	virtual void		execute_command(RPCServer* server, ClientId client, const char* message) = 0;
-
-private:
-
-	uint32_t			m_type;
-	RPCHandler*			m_next;
-
-private:
-
-	friend class		RPCServer;
-};
-
-//-----------------------------------------------------------------------------
-inline RPCHandler::RPCHandler(const char* type)
-	: m_type(hash::murmur2_32(type, string::strlen(type), 0)), m_next(NULL)
-{
-}
-
-class RPCCommandHandler : public RPCHandler
-{
-public:
-			RPCCommandHandler();
-	void	execute_command(RPCServer* server, ClientId client, const char* message);
-};
-
-class RPCScriptHandler : public RPCHandler
-{
-public:
-
-			RPCScriptHandler();
-	void	execute_command(RPCServer* server, ClientId client, const char* message);
-};
-
-class RPCStatsHandler : public RPCHandler
-{
-public:
-
-			RPCStatsHandler();
-	void	execute_command(RPCServer* server, ClientId client, const char* message);
-};
-
-class RPCPingHandler : public RPCHandler
-{
-public:
-
-			RPCPingHandler();
-	void	execute_command(RPCServer* server, ClientId client, const char* message);
-};
-
-} // namespace crown