#ifndef _THREAD_H_
#define _THREAD_H_
//
//   File : thread.h
//   Creation date : Tue Sep 20 09 2000 18:28:44 by Szymon Stefanek
//
//   This file is part of the KVirc irc client distribution
//   Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
//
//   This program is FREE software. You can redistribute it and/or
//   modify it under the terms of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your opinion) 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 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 "kvi_settings.h"
#include "kvi_thread.h"
#include "kvi_sockettype.h"

#include "kvi_pointerlist.h"

#include <qobject.h>

#ifdef COMPILE_SSL_SUPPORT
	#include "kvi_ssl.h"
#endif

// KviThreadDataEvent<int>
#define KVI_DCC_THREAD_EVENT_ERROR (KVI_THREAD_USER_EVENT_BASE + 1)
// KviThreadDataEvent<KviStr>
#define KVI_DCC_THREAD_EVENT_DATA (KVI_THREAD_USER_EVENT_BASE + 2)
// KviThreadEvent
#define KVI_DCC_THREAD_EVENT_SUCCESS (KVI_THREAD_USER_EVENT_BASE + 3)
// KviThreadDataEvent<KviStr>
#define KVI_DCC_THREAD_EVENT_MESSAGE (KVI_THREAD_USER_EVENT_BASE + 4)
// KviThreadDataEvent<int>
#define KVI_DCC_THREAD_EVENT_ACTION (KVI_THREAD_USER_EVENT_BASE + 5)

typedef struct _KviDccThreadIncomingData
{
	int    iLen;
	char * buffer;
} KviDccThreadIncomingData;

class KviDccThread : public KviSensitiveThread
{
public:
	KviDccThread(QObject * par,kvi_socket_t fd);
	~KviDccThread();
protected:
	KviMutex              * m_pMutex;     // OWNED! PROTECTS m_pOutBuffers
	kvi_socket_t            m_fd;
	QObject               * m_pParent;    // READ ONLY!
#ifdef COMPILE_SSL_SUPPORT
	KviSSL                * m_pSSL;
#endif
protected:
	bool handleInvalidSocketRead(int readLen);
public:
	QObject * parent(){ return m_pParent; };
	void postErrorEvent(int err);
	// Warning!..newer call __tr() here!...use __tr_no_lookup()
	void postMessageEvent(const char * message);
#ifdef COMPILE_SSL_SUPPORT
	void raiseSSLError();
	void setSSL(KviSSL * s);
#endif
};

#endif //_THREAD_H_
