/***************************************************************************
*   Copyright (C) 2006 by Ian Reinhart Geiser   *
*   geiseri@sourcextreme.com   *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU Library General Public License as       *
*   published by the Free Software Foundation; either version 2 of the    *
*   License, or (at your option) any later version.                       *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU Library General Public     *
*   License along with this program; if not, write to the                 *
*   Free Software Foundation, Inc.,                                       *
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/
#include "serverinstance.h"
#include "server.h"
#include "localnode.h"

#include <QEvent>
#include <QCoreApplication>

namespace KRPC
{
	ServerInstance *ServerInstance::sInstance = 0;
}

KRPC::ServerInstance::ServerInstance( QObject *parent )
: QThread( parent ), m_server(0)
{
	QCoreApplication::instance()->installEventFilter(this);
	QHostAddress address("10.0.5.9");
	uint port = 8080;
	m_serverNode = new LocalNode(address, port);
}

KRPC::ServerInstance::~ServerInstance()
{
}

void KRPC::ServerInstance::run( )
{
	Server listener;
	m_server = &listener;
	listener.start( m_serverNode->address(), m_serverNode->port() );
	exec();
	listener.stop();

	m_server = 0;
}

KRPC::ServerInstance *KRPC::ServerInstance::instance( )
{
	if( sInstance == 0)
		sInstance = new ServerInstance();
	return sInstance;
}

bool KRPC::ServerInstance::eventFilter( QObject * target, QEvent * event )
{
	return false;
}



KRPC::NodeInterface* KRPC::ServerInstance::serverNode() const
{
	return m_serverNode;
}

