mikymod 12 лет назад
Родитель
Сommit
6004952bbf
3 измененных файлов с 81 добавлено и 0 удалено
  1. 3 0
      src/CMakeLists.txt
  2. 48 0
      src/ConsoleServer.cpp
  3. 30 0
      src/ConsoleServer.h

+ 3 - 0
src/CMakeLists.txt

@@ -35,6 +35,7 @@ set (SRC
 
 	Game.cpp
 	JSONParser.cpp
+	ConsoleServer.cpp
 
 	FPSSystem.cpp
 )
@@ -60,6 +61,8 @@ set (HEADERS
 
 	Game.h
 	JSONParser.h
+	ConsoleServer.h
+
 	FPSSystem.h
 )
 

+ 48 - 0
src/ConsoleServer.cpp

@@ -0,0 +1,48 @@
+#include "ConsoleServer.h"
+#include "Log.h"
+#include "StringUtils.h"
+#include "Device.h"
+
+namespace crown
+{
+
+//-----------------------------------------------------------------------------
+ConsoleServer::ConsoleServer()
+{
+}
+
+//-----------------------------------------------------------------------------
+void ConsoleServer::start(uint32_t port)
+{
+	m_socket.open(port);
+}
+
+//-----------------------------------------------------------------------------
+void ConsoleServer::stop()
+{
+	m_socket.close();
+}
+
+//-----------------------------------------------------------------------------
+void ConsoleServer::receive_command()
+{
+	// legge socket
+	int32_t bytes_read = m_socket.receive((void*)data, 1024);
+	if (bytes_read > 0)
+	{
+		parse_command();
+	}
+}
+
+//-----------------------------------------------------------------------------
+void ConsoleServer::parse_command()
+{
+	char* command = (char*)data;
+
+	if (string::strcmp(command, "device stop") == 0)
+	{
+		device()->stop();
+	}
+}
+
+}

+ 30 - 0
src/ConsoleServer.h

@@ -0,0 +1,30 @@
+#include "Types.h"
+#include "TCPSocket.h"
+#include "Thread.h"
+#include "Mutex.h"
+#include "Cond.h"
+
+namespace crown
+{
+
+class ConsoleServer
+{
+public:
+
+					ConsoleServer();
+
+	void			start(uint32_t port);
+	void			stop();
+	void			receive_command();
+
+
+private:
+
+	void 			parse_command();
+
+	os::TCPSocket	m_socket;
+
+	uint8_t			data[1024];
+};
+
+} // namespace crown