/***************************************************************************
*   Copyright (C) 2006 by Ian Reinhart Geiser   *
*   geiseri@kde.org   *
*                                                                         *
*   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 "commandthread.h"
#include "command.h"

#include <QTcpSocket>
#include <QTimer>
#include  <QUuid>

namespace KRPC
{
}

KRPC::CommandThread::CommandThread(int descriptor, QObject *parent )
: QThread( parent ), m_descriptor(descriptor)
{
	setObjectName( QUuid::createUuid () );
}


KRPC::CommandThread::~CommandThread()
{

}


void KRPC::CommandThread::run( )
{
	qDebug("thread start %s", qPrintable(QThread::currentThread()->objectName()) );
	QTcpSocket socket;
	if( socket.setSocketDescriptor( m_descriptor ) )
	{
		Command cmd(&socket);
		connect( &socket, SIGNAL(disconnected()), this, SLOT(quit()));
		connect( &cmd, SIGNAL(finished()), this, SLOT(quit()));
		exec();
	}
	else
		qDebug("Error setting socket descriptor.");
	socket.close();
	qDebug("thread end %s", qPrintable(QThread::currentThread()->objectName()) );

}


