/***************************************************************************
                            QSocket.cpp -  description
                             -------------------
    begin                : Wed Nov 21 17:05:56 2001
    copyright            : (C) 2000-2001 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Wed Nov 21 17:05:56 2001, using kalyptus 0.9.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 option) any later version.                                   *
 *                                                                         *
***************************************************************************/

#define _BOOL_H_
#include <qsocket.h>
#include <qstring.h>
#include <qcstring.h>

#include <qtjava/QtSupport.h>
#include <qtjava/QSocket.h>

class QSocketJBridge : public QSocket
{
public:
	QSocketJBridge(QObject* parent, const char* name) : QSocket(parent, name) {}
	~QSocketJBridge() {QtSupport::qtKeyDeleted(this);}
	void protected_sn_read(bool force) {
		QSocket::sn_read(force);
		return;
	}
	void protected_sn_write() {
		QSocket::sn_write();
		return;
	}
	void childEvent(QChildEvent* arg1) {
		if (! QtSupport::eventDelegate(this, "childEvent", arg1, "org.kde.qt.QChildEvent")) {
			QObject::childEvent(arg1);
		}
		return;
	}
	void customEvent(QCustomEvent* arg1) {
		if (! QtSupport::eventDelegate(this, "customEvent", arg1, "org.kde.qt.QCustomEvent")) {
			QObject::customEvent(arg1);
		}
		return;
	}
	void timerEvent(QTimerEvent* arg1) {
		if (! QtSupport::eventDelegate(this, "timerEvent", arg1, "org.kde.qt.QTimerEvent")) {
			QObject::timerEvent(arg1);
		}
		return;
	}
};


JNIEXPORT void JNICALL
Java_org_kde_qt_QSocket_newQSocket__Lorg_kde_qt_QObject_2Ljava_lang_String_2(JNIEnv *env, jobject obj, jobject parent, jstring name)
{
static QCString * _qstring_name = 0;
	if (QtSupport::getQt(env, obj) == 0) {
		QtSupport::setQt(env, obj, new QSocketJBridge((QObject*) QtSupport::getQt(env, parent), (char*) QtSupport::toCharString(env, name, &_qstring_name)));
		QtSupport::setObjectForQtKey(env, obj, QtSupport::getQt(env, obj));
	}
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSocket_newQSocket__(JNIEnv *env, jobject obj)
{
	if (QtSupport::getQt(env, obj) == 0) {
		QtSupport::setQt(env, obj, new QSocketJBridge(0, 0));
		QtSupport::setObjectForQtKey(env, obj, QtSupport::getQt(env, obj));
	}
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSocket_finalize(JNIEnv *env, jobject obj)
{
	if (QtSupport::allocatedInJavaWorld(env, obj) && ((QSocket*)QtSupport::getQt(env, obj))->parent() == (QObject *) 0) {
		delete (QSocket*)QtSupport::getQt(env, obj);
		QtSupport::setQt(env, obj, 0);
	}
	return;
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QSocket_state(JNIEnv *env, jobject obj)
{
	return (jint) ((QSocketJBridge*) QtSupport::getQt(env, obj))->state();
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QSocket_socket(JNIEnv *env, jobject obj)
{
	return (jint) ((QSocketJBridge*) QtSupport::getQt(env, obj))->socket();
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSocket_setSocket(JNIEnv *env, jobject obj, jint arg1)
{
	((QSocketJBridge*) QtSupport::getQt(env, obj))->setSocket((int) arg1);
	return;
}

JNIEXPORT jobject JNICALL
Java_org_kde_qt_QSocket_socketDevice(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)((QSocketJBridge*) QtSupport::getQt(env, obj))->socketDevice(), "org.kde.qt.QSocketDevice");
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSocket_setSocketDevice(JNIEnv *env, jobject obj, jobject arg1)
{
	((QSocketJBridge*) QtSupport::getQt(env, obj))->setSocketDevice((QSocketDevice*) QtSupport::getQt(env, arg1));
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSocket_connectToHost(JNIEnv *env, jobject obj, jstring host, jshort port)
{
static QString * _qstring_host = 0;
	((QSocketJBridge*) QtSupport::getQt(env, obj))->connectToHost((QString&) * (QString *) QtSupport::toQString(env, host, &_qstring_host), (Q_UINT16) port);
	return;
}

JNIEXPORT jstring JNICALL
Java_org_kde_qt_QSocket_peerName(JNIEnv *env, jobject obj)
{
	QString  _qstring;
	_qstring = ((QSocketJBridge*) QtSupport::getQt(env, obj))->peerName();
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_open(JNIEnv *env, jobject obj, jint mode)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->open((int) mode);
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSocket_close(JNIEnv *env, jobject obj)
{
	((QSocketJBridge*) QtSupport::getQt(env, obj))->close();
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSocket_flush(JNIEnv *env, jobject obj)
{
	((QSocketJBridge*) QtSupport::getQt(env, obj))->flush();
	return;
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QSocket_size(JNIEnv *env, jobject obj)
{
	return (jint) ((QSocketJBridge*) QtSupport::getQt(env, obj))->size();
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QSocket_at__(JNIEnv *env, jobject obj)
{
	return (jint) ((QSocketJBridge*) QtSupport::getQt(env, obj))->at();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_at__I(JNIEnv *env, jobject obj, jint arg1)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->at((QIODevice::Offset) arg1);
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_atEnd(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->atEnd();
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_QSocket_bytesAvailable(JNIEnv *env, jobject obj)
{
	return (jlong) ((QSocketJBridge*) QtSupport::getQt(env, obj))->bytesAvailable();
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_QSocket_waitForMore(JNIEnv *env, jobject obj, jint msecs)
{
	return (jlong) ((QSocketJBridge*) QtSupport::getQt(env, obj))->waitForMore((int) msecs);
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_QSocket_bytesToWrite(JNIEnv *env, jobject obj)
{
	return (jlong) ((QSocketJBridge*) QtSupport::getQt(env, obj))->bytesToWrite();
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_QSocket_readBlock(JNIEnv *env, jobject obj, jobject data, jlong maxlen)
{
static QCString * _qstring_data = 0;
	if (_qstring_data == 0) {
		_qstring_data = new QCString();
	}
	_qstring_data->resize((uint) maxlen);
	jlong result = (jlong) ((QSocketJBridge*) QtSupport::getQt(env, obj))->readBlock((char*)_qstring_data->data(), (Q_ULONG) maxlen);
	QtSupport::fromQCStringToStringBuffer(env, _qstring_data, data);
	return result;
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_QSocket_writeBlock___3B(JNIEnv *env, jobject obj, jstring data, jlong len)
{
static QCString * _qstring_data = 0;
	return (jlong) ((QSocketJBridge*) QtSupport::getQt(env, obj))->writeBlock((char*) QtSupport::toCharString(env, data, &_qstring_data), (Q_ULONG) len);
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_QSocket_readLine__Ljava_lang_StringBuffer_2J(JNIEnv *env, jobject obj, jobject data, jlong maxlen)
{
	QCString _qstring_data((uint) maxlen);
	jlong result = (jlong) ((QSocketJBridge*) QtSupport::getQt(env, obj))->readLine((char*) _qstring_data.data(), (Q_ULONG) maxlen);
	_qstring_data.truncate((uint) result);
	QtSupport::fromQCStringToStringBuffer(env, &_qstring_data, data);
	return result;
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QSocket_getch(JNIEnv *env, jobject obj)
{
	return (jint) ((QSocketJBridge*) QtSupport::getQt(env, obj))->getch();
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QSocket_putch(JNIEnv *env, jobject obj, jint arg1)
{
	return (jint) ((QSocketJBridge*) QtSupport::getQt(env, obj))->putch((int) arg1);
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QSocket_ungetch(JNIEnv *env, jobject obj, jint arg1)
{
	return (jint) ((QSocketJBridge*) QtSupport::getQt(env, obj))->ungetch((int) arg1);
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_canReadLine(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->canReadLine();
}

JNIEXPORT jstring JNICALL
Java_org_kde_qt_QSocket_readLine__(JNIEnv *env, jobject obj)
{
	QString  _qstring;
	_qstring = ((QSocketJBridge*) QtSupport::getQt(env, obj))->readLine();
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT jshort JNICALL
Java_org_kde_qt_QSocket_port(JNIEnv *env, jobject obj)
{
	return (jshort) ((QSocketJBridge*) QtSupport::getQt(env, obj))->port();
}

JNIEXPORT jshort JNICALL
Java_org_kde_qt_QSocket_peerPort(JNIEnv *env, jobject obj)
{
	return (jshort) ((QSocketJBridge*) QtSupport::getQt(env, obj))->peerPort();
}

JNIEXPORT jobject JNICALL
Java_org_kde_qt_QSocket_address(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)new QHostAddress (((QSocketJBridge*) QtSupport::getQt(env, obj))->address()), "org.kde.qt.QHostAddress", TRUE);
}

JNIEXPORT jobject JNICALL
Java_org_kde_qt_QSocket_peerAddress(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)new QHostAddress (((QSocketJBridge*) QtSupport::getQt(env, obj))->peerAddress()), "org.kde.qt.QHostAddress", TRUE);
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSocket_sn_1read__Z(JNIEnv *env, jobject obj, jboolean force)
{
	((QSocketJBridge*) QtSupport::getQt(env, obj))->protected_sn_read((bool) force);
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSocket_sn_1read__(JNIEnv *env, jobject obj)
{
	((QSocketJBridge*) QtSupport::getQt(env, obj))->protected_sn_read(FALSE);
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSocket_sn_1write(JNIEnv *env, jobject obj)
{
	((QSocketJBridge*) QtSupport::getQt(env, obj))->protected_sn_write();
	return;
}

	// From QIODevice
	
JNIEXPORT jint JNICALL
Java_org_kde_qt_QSocket_flags(JNIEnv *env, jobject obj)
{
	return (jint) ((QSocketJBridge*) QtSupport::getQt(env, obj))->flags();
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QSocket_mode(JNIEnv *env, jobject obj)
{
	return (jint) ((QSocketJBridge*) QtSupport::getQt(env, obj))->mode();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_isDirectAccess(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->isDirectAccess();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_isSequentialAccess(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->isSequentialAccess();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_isCombinedAccess(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->isCombinedAccess();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_isBuffered(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->isBuffered();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_isRaw(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->isRaw();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_isSynchronous(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->isSynchronous();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_isAsynchronous(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->isAsynchronous();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_isTranslated(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->isTranslated();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_isReadable(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->isReadable();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_isWritable(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->isWritable();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_isReadWrite(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->isReadWrite();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_isInactive(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->isInactive();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_isOpen(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->isOpen();
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QSocket_status(JNIEnv *env, jobject obj)
{
	return (jint) ((QSocketJBridge*) QtSupport::getQt(env, obj))->status();
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSocket_resetStatus(JNIEnv *env, jobject obj)
{
	((QSocketJBridge*) QtSupport::getQt(env, obj))->resetStatus();
	return;
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSocket_reset(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSocketJBridge*) QtSupport::getQt(env, obj))->reset();
}

JNIEXPORT jlong JNICALL
Java_org_kde_qt_QSocket_writeBlock__Ljava_lang_String_2J(JNIEnv *env, jobject obj, jstring data, jlong len)
{
static QCString * _qstring_data = 0;
	return (jlong) ((QSocketJBridge*) QtSupport::getQt(env, obj))->writeBlock((char*) QtSupport::toCharString(env, data, &_qstring_data), (Q_ULONG) len);
}

JNIEXPORT jbyteArray JNICALL
Java_org_kde_qt_QSocket_readAll(JNIEnv *env, jobject obj)
{
	QByteArray  _qbyteArray;
	_qbyteArray = ((QSocketJBridge*) QtSupport::getQt(env, obj))->readAll();
	return QtSupport::fromQByteArray(env, &_qbyteArray);
}



