From 202d7d1de3ec2805d21e91cf233d1ede3555f9ab Mon Sep 17 00:00:00 2001 From: Anonymous Date: Thu, 16 Jan 2014 00:05:25 -0700 Subject: [PATCH] Added sharedRemoteDebugServer library --- engine/shared/library/CMakeLists.txt | 1 + .../sharedRemoteDebugServer/CMakeLists.txt | 11 ++ .../FirstSharedRemoteDebugServer.h | 1 + .../SharedRemoteDebugServer.h | 1 + .../SharedRemoteDebugServerConnection.h | 1 + .../src/CMakeLists.txt | 26 +++++ .../shared/FirstSharedRemoteDebugServer.cpp | 8 ++ .../src/shared/FirstSharedRemoteDebugServer.h | 18 ++++ .../src/shared/SharedRemoteDebugServer.cpp | 101 ++++++++++++++++++ .../src/shared/SharedRemoteDebugServer.h | 40 +++++++ .../SharedRemoteDebugServerConnection.cpp | 65 +++++++++++ .../SharedRemoteDebugServerConnection.h | 38 +++++++ 12 files changed, 311 insertions(+) create mode 100644 engine/shared/library/sharedRemoteDebugServer/CMakeLists.txt create mode 100644 engine/shared/library/sharedRemoteDebugServer/include/public/sharedRemoteDebugServer/FirstSharedRemoteDebugServer.h create mode 100644 engine/shared/library/sharedRemoteDebugServer/include/public/sharedRemoteDebugServer/SharedRemoteDebugServer.h create mode 100644 engine/shared/library/sharedRemoteDebugServer/include/public/sharedRemoteDebugServer/SharedRemoteDebugServerConnection.h create mode 100644 engine/shared/library/sharedRemoteDebugServer/src/CMakeLists.txt create mode 100644 engine/shared/library/sharedRemoteDebugServer/src/shared/FirstSharedRemoteDebugServer.cpp create mode 100644 engine/shared/library/sharedRemoteDebugServer/src/shared/FirstSharedRemoteDebugServer.h create mode 100644 engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServer.cpp create mode 100644 engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServer.h create mode 100644 engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServerConnection.cpp create mode 100644 engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServerConnection.h diff --git a/engine/shared/library/CMakeLists.txt b/engine/shared/library/CMakeLists.txt index 94a5d742..c5eb64aa 100644 --- a/engine/shared/library/CMakeLists.txt +++ b/engine/shared/library/CMakeLists.txt @@ -21,6 +21,7 @@ add_subdirectory(sharedObject) add_subdirectory(sharedPathfinding) add_subdirectory(sharedRandom) add_subdirectory(sharedRegex) +add_subdirectory(sharedRemoteDebugServer) add_subdirectory(sharedSkillSystem) add_subdirectory(sharedSynchronization) add_subdirectory(sharedTerrain) diff --git a/engine/shared/library/sharedRemoteDebugServer/CMakeLists.txt b/engine/shared/library/sharedRemoteDebugServer/CMakeLists.txt new file mode 100644 index 00000000..ea315e32 --- /dev/null +++ b/engine/shared/library/sharedRemoteDebugServer/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 2.8) + +project(sharedRemoteDebugServer) + +if(WIN32) + add_definitions(/D_CRT_SECURE_NO_WARNINGS) +endif() + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/public) + +add_subdirectory(src) diff --git a/engine/shared/library/sharedRemoteDebugServer/include/public/sharedRemoteDebugServer/FirstSharedRemoteDebugServer.h b/engine/shared/library/sharedRemoteDebugServer/include/public/sharedRemoteDebugServer/FirstSharedRemoteDebugServer.h new file mode 100644 index 00000000..84cc14c2 --- /dev/null +++ b/engine/shared/library/sharedRemoteDebugServer/include/public/sharedRemoteDebugServer/FirstSharedRemoteDebugServer.h @@ -0,0 +1 @@ +#include "../../src/shared/FirstSharedRemoteDebugServer.h" diff --git a/engine/shared/library/sharedRemoteDebugServer/include/public/sharedRemoteDebugServer/SharedRemoteDebugServer.h b/engine/shared/library/sharedRemoteDebugServer/include/public/sharedRemoteDebugServer/SharedRemoteDebugServer.h new file mode 100644 index 00000000..78c00241 --- /dev/null +++ b/engine/shared/library/sharedRemoteDebugServer/include/public/sharedRemoteDebugServer/SharedRemoteDebugServer.h @@ -0,0 +1 @@ +#include "../../src/shared/SharedRemoteDebugServer.h" diff --git a/engine/shared/library/sharedRemoteDebugServer/include/public/sharedRemoteDebugServer/SharedRemoteDebugServerConnection.h b/engine/shared/library/sharedRemoteDebugServer/include/public/sharedRemoteDebugServer/SharedRemoteDebugServerConnection.h new file mode 100644 index 00000000..9edc414b --- /dev/null +++ b/engine/shared/library/sharedRemoteDebugServer/include/public/sharedRemoteDebugServer/SharedRemoteDebugServerConnection.h @@ -0,0 +1 @@ +#include "../../src/shared/SharedRemoteDebugServerConnection.h" diff --git a/engine/shared/library/sharedRemoteDebugServer/src/CMakeLists.txt b/engine/shared/library/sharedRemoteDebugServer/src/CMakeLists.txt new file mode 100644 index 00000000..fc03f40a --- /dev/null +++ b/engine/shared/library/sharedRemoteDebugServer/src/CMakeLists.txt @@ -0,0 +1,26 @@ + +set(SHARED_SOURCES + shared/FirstSharedRemoteDebugServer.cpp + shared/FirstSharedRemoteDebugServer.h + shared/SharedRemoteDebugServerConnection.cpp + shared/SharedRemoteDebugServerConnection.h + shared/SharedRemoteDebugServer.cpp + shared/SharedRemoteDebugServer.h +) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/shared + ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDebug/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFile/include/public + ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundation/include/public + ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public + ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMemoryManager/include/public + ${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedNetwork/include/public + #${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedUtility/include/public + ${SWG_EXTERNALS_SOURCE_DIR}/ours/library/archive/include + #${SWG_EXTERNALS_SOURCE_DIR}/ours/library/unicode/include +) + +add_library(sharedRemoteDebugServer STATIC + ${SHARED_SOURCES} +) diff --git a/engine/shared/library/sharedRemoteDebugServer/src/shared/FirstSharedRemoteDebugServer.cpp b/engine/shared/library/sharedRemoteDebugServer/src/shared/FirstSharedRemoteDebugServer.cpp new file mode 100644 index 00000000..bc497d85 --- /dev/null +++ b/engine/shared/library/sharedRemoteDebugServer/src/shared/FirstSharedRemoteDebugServer.cpp @@ -0,0 +1,8 @@ +// ====================================================================== +// +// FirstSharedRemoteDebugServer.cpp +// Copyright 2002 Sony Online Entertainment +// +// ====================================================================== + +#include "sharedRemoteDebugServer/FirstSharedRemoteDebugServer.h" diff --git a/engine/shared/library/sharedRemoteDebugServer/src/shared/FirstSharedRemoteDebugServer.h b/engine/shared/library/sharedRemoteDebugServer/src/shared/FirstSharedRemoteDebugServer.h new file mode 100644 index 00000000..e5f1804b --- /dev/null +++ b/engine/shared/library/sharedRemoteDebugServer/src/shared/FirstSharedRemoteDebugServer.h @@ -0,0 +1,18 @@ +// ====================================================================== +// +// FirstSharedRemoteDebugServer.h +// Copyright 2002 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_FirstSharedRemoteDebugServer_H +#define INCLUDED_FirstSharedRemoteDebugServer_H + +// ====================================================================== + +#include "sharedFoundation/FirstSharedFoundation.h" + +// ====================================================================== + +#endif + diff --git a/engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServer.cpp b/engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServer.cpp new file mode 100644 index 00000000..0e305c96 --- /dev/null +++ b/engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServer.cpp @@ -0,0 +1,101 @@ +// ====================================================================== +// +// SharedRemoteDebugServer.cpp +// Copyright 2002 Sony Online Entertainment +// +// ====================================================================== + +#include "sharedRemoteDebugServer/FirstSharedRemoteDebugServer.h" +#include "Archive/ByteStream.h" +#include "sharedRemoteDebugServer/SharedRemoteDebugServer.h" +#include "sharedRemoteDebugServer/SharedRemoteDebugServerConnection.h" +#include "sharedFoundation/ConfigSharedFoundation.h" +#include "sharedNetwork/Service.h" +#include "sharedNetwork/Connection.h" +#include "sharedNetwork/NetworkSetupData.h" +#include "sharedDebug/RemoteDebug_inner.h" + +//------------------------------------------------------------------- + +//static definitions +Service * SharedRemoteDebugServer::ms_serviceHandle; +SharedRemoteDebugServerConnection * SharedRemoteDebugServer::ms_connection; +bool SharedRemoteDebugServer::ms_installed; +unsigned int SharedRemoteDebugServer::ms_remoteDebugToolChannelID; + +//------------------------------------------------------------------- + +void SharedRemoteDebugServer::install() +{ + ms_serviceHandle = NULL; + ms_connection = NULL; + + if (!ConfigSharedFoundation::getUseRemoteDebug()) + return; + + DEBUG_FATAL(ms_installed, ("sharedRemoteDebugServer already installed")); + + NetworkSetupData setup; + setup.port = static_cast(ConfigSharedFoundation::getDefaultRemoteDebugPort()); + setup.maxConnections = 5; + ms_serviceHandle = new Service(ConnectionAllocator(), setup); + + //even though this is the game client, this is a remoteDebug *server*, since it sends data to a Qt app for viewing + RemoteDebugServer::install(NULL, open, close, send, NULL); + + //this value needs to be true before the call to RemoteDebugServer::open + ms_installed = true; + + //try to connect to a localhost instance of the remotedebug app + RemoteDebugServer::open("127.0.0.1", 4444); +} + +//------------------------------------------------------------------- + +void SharedRemoteDebugServer::remove(void) +{ + if(!ms_installed) + return; + + close(); + + NOT_NULL(ms_serviceHandle); + delete ms_serviceHandle; + delete ms_connection; + + RemoteDebugServer::remove(); + ms_installed = false; +} + +//------------------------------------------------------------------- + +void SharedRemoteDebugServer::open(const char *server, uint16 port) +{ + DEBUG_FATAL(!ms_installed, ("sharedRemoteDebugServer not installed")); + + //attempt to auto-connect to a localhost client app (if it's auto-listening) + + ms_connection = new SharedRemoteDebugServerConnection(server, port); +} + +//------------------------------------------------------------------- + +void SharedRemoteDebugServer::close(void) +{ + DEBUG_FATAL(!ms_installed, ("sharedRemoteDebugServer not installed")); + delete ms_connection; + ms_connection = NULL; +} + +//------------------------------------------------------------------- + +void SharedRemoteDebugServer::send(void *buffer, uint32 bufferLen) +{ + DEBUG_FATAL(!ms_installed, ("sharedRemoteDebugServer not installed")); + + NOT_NULL(ms_connection); + ms_connection->send(Archive::ByteStream(reinterpret_cast(buffer), bufferLen), false); + //always send on VNL channel 0, send the buffer, it's length, and unreliable +} + +//------------------------------------------------------------------- diff --git a/engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServer.h b/engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServer.h new file mode 100644 index 00000000..79a09c6c --- /dev/null +++ b/engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServer.h @@ -0,0 +1,40 @@ +// ====================================================================== +// +// SharedRemoteDebugServer.h +// copyright 2001 Sony Online Entertainment +// +// ====================================================================== + +#ifndef INCLUDED_SharedRemoteDebugServer_H +#define INCLUDED_SharedRemoteDebugServer_H + +class SharedRemoteDebugServerConnectionHandler; +class SharedRemoteDebugServerConnection; +class Service; + +class SharedRemoteDebugServer +{ +friend class SharedRemoteDebugServerConnectionHandler; + +public: + static void install(); + static void remove(void); + +private: + ///The client-specific Service used to transmit data + ///true if system has been installed, false otherwise + static bool ms_installed; + + static unsigned int ms_remoteDebugToolChannelID; + + static Service * ms_serviceHandle; + static SharedRemoteDebugServerConnection * ms_connection; + + static void open(const char *server, uint16 port); + static void close(void); + static void send(void *buffer, uint32 bufferLen); + static void receive(void *buffer, uint32 bufferLen); +}; + +#endif // INCLUDED_SharedRemoteDebugServer_H + diff --git a/engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServerConnection.cpp b/engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServerConnection.cpp new file mode 100644 index 00000000..ef51481a --- /dev/null +++ b/engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServerConnection.cpp @@ -0,0 +1,65 @@ +// ====================================================================== +// +// SharedRemoteDebugServerConnection.cpp +// Copyright 2002 Sony Online Entertainment +// +// ====================================================================== + +#include "sharedRemoteDebugServer/FirstSharedRemoteDebugServer.h" +#include "Archive/ByteStream.h" +#include "sharedRemoteDebugServer/SharedRemoteDebugServer.h" +#include "sharedRemoteDebugServer/SharedRemoteDebugServerConnection.h" +#include "sharedDebug/RemoteDebug_inner.h" +#include "sharedNetwork/NetworkSetupData.h" + +//----------------------------------------------------------------------- + +SharedRemoteDebugServerConnection::SharedRemoteDebugServerConnection(const std::string & a, const unsigned short p) : +Connection(a, p, NetworkSetupData()), +m_remotedebugCommandChannel (NULL) +{ +} + +//----------------------------------------------------------------------- + +SharedRemoteDebugServerConnection::SharedRemoteDebugServerConnection(UdpConnectionMT * u, TcpClient * t) : +Connection(u, t), +m_remotedebugCommandChannel (NULL) +{ +} + +//----------------------------------------------------------------------- + +SharedRemoteDebugServerConnection::~SharedRemoteDebugServerConnection() +{ +} + +//----------------------------------------------------------------------- + +void SharedRemoteDebugServerConnection::onConnectionClosed() +{ + RemoteDebugServer::close(); +} + +//----------------------------------------------------------------------- + +void SharedRemoteDebugServerConnection::onConnectionOpened() +{ + RemoteDebugServer::isReady(); +} + +//----------------------------------------------------------------------- + +void SharedRemoteDebugServerConnection::onConnectionOverflowing(const unsigned int bytesPending) +{ + UNREF(bytesPending); +} + +//----------------------------------------------------------------------- + +void SharedRemoteDebugServerConnection::onReceive(const Archive::ByteStream & message) +{ + RemoteDebugServer::receive(message.getBuffer(), message.getSize()); +} + +//----------------------------------------------------------------------- diff --git a/engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServerConnection.h b/engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServerConnection.h new file mode 100644 index 00000000..b8cfdff5 --- /dev/null +++ b/engine/shared/library/sharedRemoteDebugServer/src/shared/SharedRemoteDebugServerConnection.h @@ -0,0 +1,38 @@ +// ====================================================================== +// +// SharedRemoteDebugServerConnection.h +// copyright 2001, Sony Online Entertainment +// +// ====================================================================== + +#ifndef _SharedRemoteDebugServerConnection_H +#define _SharedRemoteDebugServerConnection_H + +//----------------------------------------------------------------------- + +#include "sharedNetwork/Connection.h" + +class SharedRemoteDebugServerCommandChannel; + +//----------------------------------------------------------------------- + +class SharedRemoteDebugServerConnection : public Connection +{ +public: + SharedRemoteDebugServerConnection(const std::string & remoteAddress, const unsigned short remotePort); + SharedRemoteDebugServerConnection(UdpConnectionMT *, TcpClient *); + virtual ~SharedRemoteDebugServerConnection(); + void onConnectionClosed (); + void onConnectionOpened (); + void onConnectionOverflowing (const unsigned int bytesPending); + void onReceive (const Archive::ByteStream & message); + +private: + SharedRemoteDebugServerConnection(const SharedRemoteDebugServerConnection &); + SharedRemoteDebugServerConnection & operator = (const SharedRemoteDebugServerConnection &); + SharedRemoteDebugServerCommandChannel *m_remotedebugCommandChannel; +}; + +//----------------------------------------------------------------------- + +#endif // _SharedRemoteDebugServerConnection_H