/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


#ifndef	__SCRIPT_NETWORK_DEBUGGER__
#define	__SCRIPT_NETWORK_DEBUGGER__


		#include "async/async_call_queue.h"
		#include "script/script_vm_debug_profile_base.h"


namespace GS {
	namespace Script {
		class NetworkDebuggerThread;

/*!
	@short	Networked debugger VM event handler.
	This event handler spawns and communicates with a network controller thread.
	@author Emmanuel Julien (ejulien@owloh.com)
*/
class	NetworkDebugger : public IDebuggerProfiler
{
		NetworkDebuggerThread *thread;

		bool		start_signal;

public:

		ASync::CallQueue async;

		String		GetPeerAddress();

		bool		IsConnected() const;
		void		Stop();

		void		BroadcastNetworkCommand(const String &);
		bool		GetStartSignal() const { return start_signal; }

		// Network debugger interface.
virtual	void		OnNetworkReady(const String &, int) {}
virtual	void		OnControllerConnected() {}
virtual	void		OnControllerDisconnected() {}
virtual	void		OnControllerPacketReceived(const Array <char> &);

		// Debugger interface implementation.
		void		OnSuspendExecution(const char *source, int line);
		bool		OnUpdateSuspendedExecution();

		// VM interface implementation.
		void		OnFatalError(const char *reason);
		void		OnCompilerError(const char *error, const char *source, int line);
		void		OnRuntimeException(const char *error);

		NetworkDebugger(IVM *vm, IDebugger *dbg, const char *address, int port);
		~NetworkDebugger();
};

	} // Script
} // GS


#endif	// __SCRIPT_NETWORK_DEBUGGER__



