[Kde-java] QtJava rewritten as a SMOKE adaptor?

Richard Dale Richard_Dale at tipitina.demon.co.uk
Thu Aug 14 15:45:25 CEST 2003


On Tuesday 12 August 2003 11:20, Gert-Jan van der Heiden wrote:
> On Tuesday 12 August 2003 12:05, Richard Dale wrote:
> > An intValue() call is needed in QApplication.exec() because the return
> > value from proxy will be an 'Integer':
> >
> > public int exec() {
> >         return proxy.exec().intValue();
> > }
>
> Ah, I see, the last tree code lines made me understand (inspite of your
> first mail...). Looks good!
Actually, I'm wrong - the Proxy instance converts from an Integer to an int 
automatically and the intValue() call isn't needed.

I'm making some progress with generating the java code for the new proxy style 
calls. Please find 'kalyptusCxxToJava.pm' attached - it replaces the version 
that generated jni calls. Build kalyptus with that, and then run the Qt 
headers through it to see what the api will look like.

$ kalyptus -fjava *.h

I've found two proxies are needed for each class, one to handle static method 
calls, and another proxy for instance methods. Here is an example from 
QFont.java, where the proxy for static calls is created:

 	private static QFontInterface staticQFont = null;
	static {
		staticQFont = (QFontInterface) 
Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(),
			new Class[] { QFontInterface.class },
			new SmokeInvocation() );
	}

Another Proxy instance created in the QFont() constructor, and initialized 
with the the owner of the proxy ('this' in the code below), and a long which 
is the address of the Qt C++ instance returned by the newQFont() call:

	private Object _proxy = null;

 	private QFontInterface proxyQFont() {
 		return (QFontInterface) _proxy;
	}
...
	private long newQFont() {
		return staticQFont.newQFont();
	}
	public QFont() {
		_proxy = Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(),
			new Class[] { QFontInterface.class },
			new SmokeInvocation(this, newQFont()) );
	}


There is a small test of the principle in Doit.java, from qtjava_0.1.tar.gz 
attached:

class Doit {
	static void main(String[] args) {
		QFont myFont = new QFont();
		myFont.setPointSize(18);
		QFont.substitute("Times Roman");
	}
}

It produces the following output:

baldhead duke 2269% java Doit
SmokeInvocation()
SmokeInvocation.invoke: public abstract long qt.QFontInterface.newQFont()
SmokeInvocation(obj, qt)
SmokeInvocation.invoke: public abstract void 
qt.QFontInterface.setPointSize(int)
SmokeInvocation.invoke: public abstract java.lang.String 
qt.QFontInterface.substitute(java.lang.String)

Showing that a constructor, an instance method and a static method have all 
called via the SmokeInvocation.invoke() method.

-- Richard


-------------- next part --------------
A non-text attachment was scrubbed...
Name: qtjava-0.1.tar.gz
Type: application/x-tgz
Size: 23586 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kde-java/attachments/20030814/ceca2479/qtjava-0.1.tar-0001.bin


More information about the Kde-java mailing list