summaryrefslogtreecommitdiffstats
path: root/dcopjava
diff options
context:
space:
mode:
Diffstat (limited to 'dcopjava')
-rw-r--r--dcopjava/Makefile.am1
-rw-r--r--dcopjava/binding/Makefile.am16
-rw-r--r--dcopjava/binding/client.cpp211
-rw-r--r--dcopjava/binding/org/Makefile.am1
-rw-r--r--dcopjava/binding/org/kde/DCOP/Client.java63
-rw-r--r--dcopjava/binding/org/kde/DCOP/DCOPRef.java30
-rw-r--r--dcopjava/binding/org/kde/DCOP/Makefile.am9
-rw-r--r--dcopjava/binding/org/kde/DCOP/Response.java9
-rw-r--r--dcopjava/binding/org/kde/DCOP/Stub.java193
-rw-r--r--dcopjava/binding/org/kde/Makefile.am1
-rw-r--r--dcopjava/configure.in.in2
-rw-r--r--dcopjava/dcopidl2java/Makefile.am11
-rw-r--r--dcopjava/dcopidl2java/main.cpp110
-rw-r--r--dcopjava/dcopidl2java/main.h35
-rw-r--r--dcopjava/dcopidl2java/skel.cpp322
-rw-r--r--dcopjava/dcopidl2java/stubimpl.cpp312
-rw-r--r--dcopjava/tests/Makefile.am17
-rw-r--r--dcopjava/tests/main.cpp17
-rw-r--r--dcopjava/tests/test.h46
-rw-r--r--dcopjava/tests/test.java78
-rw-r--r--dcopjava/tests/test_impl.cpp108
-rw-r--r--dcopjava/tests/test_impl.h38
22 files changed, 1630 insertions, 0 deletions
diff --git a/dcopjava/Makefile.am b/dcopjava/Makefile.am
new file mode 100644
index 00000000..6a062a76
--- /dev/null
+++ b/dcopjava/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = binding dcopidl2java tests
diff --git a/dcopjava/binding/Makefile.am b/dcopjava/binding/Makefile.am
new file mode 100644
index 00000000..922e59ff
--- /dev/null
+++ b/dcopjava/binding/Makefile.am
@@ -0,0 +1,16 @@
+lib_LTLIBRARIES = libjavadcop.la
+
+libjavadcop_la_SOURCES = client.cpp
+libjavadcop_la_LDFLAGS = $(KDE_LDFLAGS) $(KDE_PLUGIN)
+libjavadcop_la_LIBADD = $(LIB_KDECORE)
+
+INCLUDES = $(jni_includes) $(all_includes)
+
+client.cpp: org_kde_DCOP_Client.h
+
+org_kde_DCOP_Client.h: org/kde/DCOP/Client.class
+ CLASSPATH=$(srcdir) $(JAVAH) -jni org.kde.DCOP.Client
+
+SUBDIRS = org
+
+CLEANFILES = org_kde_DCOP_Client.h
diff --git a/dcopjava/binding/client.cpp b/dcopjava/binding/client.cpp
new file mode 100644
index 00000000..5bdb9469
--- /dev/null
+++ b/dcopjava/binding/client.cpp
@@ -0,0 +1,211 @@
+#include <stdio.h>
+#include <jni.h>
+#define TRUE true // prevent qglobal from redefining it
+#define FALSE false
+#include <dcopclient.h>
+#include <kdebug.h>
+
+
+#include "org_kde_DCOP_Client.h"
+
+
+class client
+{
+public:
+
+ static DCOPClient *instance();
+
+private:
+
+ static DCOPClient *_client;
+
+};
+
+
+DCOPClient *client::_client = 0;
+
+
+DCOPClient *client::instance()
+{
+ if (!_client)
+ _client = new DCOPClient;
+
+ return _client;
+}
+
+
+JNIEXPORT jboolean JNICALL Java_org_kde_DCOP_Client_attach(JNIEnv *, jobject)
+{
+ kdDebug() << "javadcop::attach() called" << endl;
+
+ return client::instance()->attach();
+}
+
+
+JNIEXPORT jstring JNICALL Java_org_kde_DCOP_Client_registerAs(JNIEnv *env, jobject, jstring appName)
+{
+ QString name(env->GetStringUTFChars(appName, 0));
+
+ kdDebug() << "javadcop::registerAs(\"" << name << "\") called" << endl;
+
+ QString rname = client::instance()->registerAs(name.local8Bit(), false);
+
+ return env->NewStringUTF(rname.local8Bit().data());
+}
+
+
+JNIEXPORT jboolean JNICALL Java_org_kde_DCOP_Client_isAttached(JNIEnv *, jobject)
+{
+ kdDebug() << "javadcop::isAttached() called" << endl;
+
+ return client::instance()->isAttached();
+}
+
+
+JNIEXPORT jboolean JNICALL Java_org_kde_DCOP_Client_detach(JNIEnv *, jobject)
+{
+ kdDebug() << "javadcop::detach() called" << endl;
+
+ return client::instance()->detach();
+}
+
+
+JNIEXPORT jboolean JNICALL Java_org_kde_DCOP_Client_send__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2(JNIEnv *env, jobject, jstring remApp, jstring remObj, jstring remFun, jstring data)
+{
+ QString _remApp(env->GetStringUTFChars(remApp, 0));
+ QString _remObj(env->GetStringUTFChars(remObj, 0));
+ QString _remFun(env->GetStringUTFChars(remFun, 0));
+ QString _data(env->GetStringUTFChars(data, 0));
+
+ kdDebug() << "javadcop::send(" << _remApp << "," << _remObj << "," << _remFun << "," << _data << "," <<") called" << endl;
+
+ return client::instance()->send(_remApp.local8Bit(), _remObj.local8Bit(), _remFun.local8Bit(), _data.local8Bit());
+}
+
+
+QByteArray byteArray(JNIEnv *env, jbyteArray a)
+{
+ jsize len = env->GetArrayLength(a);
+ QByteArray _data(len);
+ jboolean isCopy;
+ _data.duplicate((const char *)env->GetByteArrayElements(a, &isCopy), len);
+
+ return _data;
+}
+
+
+JNIEXPORT jboolean JNICALL Java_org_kde_DCOP_Client_send__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2_3B(JNIEnv *env, jobject, jstring remApp, jstring remObj, jstring remFun, jbyteArray data)
+{
+ QString _remApp(env->GetStringUTFChars(remApp, 0));
+ QString _remObj(env->GetStringUTFChars(remObj, 0));
+ QString _remFun(env->GetStringUTFChars(remFun, 0));
+ QByteArray _data = byteArray(env, data);
+
+ kdDebug() << "javadcop::send(" << _remApp << "," << _remObj << "," << _remFun << ", data[" << _data.size() << "], " <<") called" << endl;
+ for (uint i=0; i<_data.size(); ++i)
+ kdDebug() << " data[" << i << "] = " << _data[i] << endl;
+
+ return client::instance()->send(_remApp.local8Bit(), _remObj.local8Bit(), _remFun.local8Bit(), _data);
+}
+
+
+JNIEXPORT jboolean JNICALL Java_org_kde_DCOP_Client_isRegistered(JNIEnv *, jobject)
+{
+ kdDebug() << "javadcop::isRegistered() called" << endl;
+
+ return client::instance()->isRegistered();
+}
+
+
+JNIEXPORT jstring JNICALL Java_org_kde_DCOP_Client_appId(JNIEnv *env, jobject)
+{
+ kdDebug() << "javadcop::appId called" << endl;
+
+ return env->NewStringUTF(client::instance()->appId().data());
+}
+
+
+JNIEXPORT void JNICALL Java_org_kde_DCOP_Client_suspend(JNIEnv *, jobject)
+{
+ kdDebug() << "javadcop::suspend() called" << endl;
+
+ client::instance()->suspend();
+}
+
+
+JNIEXPORT void JNICALL Java_org_kde_DCOP_Client_resume(JNIEnv *, jobject)
+{
+ kdDebug() << "javadcop::resume() called" << endl;
+
+ client::instance()->resume();
+}
+
+
+JNIEXPORT jobject JNICALL Java_org_kde_DCOP_Client_call(JNIEnv *env, jobject, jstring remApp, jstring remObj, jstring remFun, jbyteArray data, jboolean eventLoop)
+{
+ QString _remApp(env->GetStringUTFChars(remApp, 0));
+ QString _remObj(env->GetStringUTFChars(remObj, 0));
+ QString _remFun(env->GetStringUTFChars(remFun, 0));
+ QByteArray _data = byteArray(env, data);
+
+ kdDebug() << "javadcop::call(" << _remApp << "," << _remObj << "," << _remFun << ", data[" << _data.size() << "], " << eventLoop <<") called" << endl;
+ for (uint i=0; i<_data.size(); ++i)
+ kdDebug() << " data[" << i << "] = " << _data[i] << endl;
+
+ QCString _retType;
+ QByteArray _retData;
+ bool retval = client::instance()->call(_remApp.local8Bit(), _remObj.local8Bit(), _remFun.local8Bit(), _data, _retType, _retData, eventLoop);
+
+ kdDebug() << "Return type " << _retType << endl;
+
+ for (uint i=0; i<_retData.size(); ++i)
+ kdDebug() << " retData[" << i << "] = " << _retData[i] << endl;
+
+ // create a response object
+ jclass jcls;
+ jmethodID jmid;
+ jobject response;
+ jfieldID jfid;
+
+ jcls = env->FindClass("Lorg/kde/DCOP/Response;");
+ if (!jcls)
+ return NULL;
+
+ jmid = env->GetMethodID(jcls, "<init>", "()V");
+ if (!jmid)
+ return NULL;
+
+ response = env->NewObject(jcls, jmid);
+ if (!response)
+ return NULL;
+
+ jfid = env->GetFieldID(jcls, "returnType", "Ljava/lang/String;");
+ if (!jfid)
+ return NULL;
+ env->SetObjectField(response, jfid, env->NewStringUTF(_retType.data()));
+
+ jfid = env->GetFieldID(jcls, "returnValue", "Z");
+ if (!jfid)
+ return NULL;
+ env->SetBooleanField(response, jfid, retval);
+
+ jfid = env->GetFieldID(jcls, "returnData", "[B");
+ if (!jfid)
+ return NULL;
+ jbyteArray ba = env->NewByteArray(_retData.size());
+ env->SetByteArrayRegion(ba, 0, _retData.size(), (jbyte*) _retData.data());
+ env->SetObjectField(response, jfid, ba);
+
+ // return the response object
+ kdDebug() << "response object created" << endl;
+ return response;
+}
+
+JNIEXPORT jboolean JNICALL Java_org_kde_DCOP_Client_isApplicationRegistered(JNIEnv *env, jobject, jstring remApp)
+{
+ const QCString _remApp(env->GetStringUTFChars(remApp, 0));
+
+ kdDebug() << "javadcop::isApplicationRegistered() called" << endl;
+
+ return client::instance()->isApplicationRegistered(_remApp);
+}
diff --git a/dcopjava/binding/org/Makefile.am b/dcopjava/binding/org/Makefile.am
new file mode 100644
index 00000000..800b92ea
--- /dev/null
+++ b/dcopjava/binding/org/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = kde
diff --git a/dcopjava/binding/org/kde/DCOP/Client.java b/dcopjava/binding/org/kde/DCOP/Client.java
new file mode 100644
index 00000000..55ba943e
--- /dev/null
+++ b/dcopjava/binding/org/kde/DCOP/Client.java
@@ -0,0 +1,63 @@
+package org.kde.DCOP;
+
+
+public class Client
+{
+ // attach to DCOP server as 'anonymous'
+ public native boolean attach();
+
+ // attach to DCOP server using appName as key
+ public native String registerAs(String appName);
+
+ // report if we are registered at the server
+ public native boolean isRegistered();
+
+ // return the registered application id
+ public native String appId();
+
+ // suspend DCOP processing
+ public native void suspend();
+
+ // resume DCOP processing
+ public native void resume();
+
+ // detach from the DCOP server
+ public native boolean detach();
+
+ // report if we are attached to DCOP server
+ public native boolean isAttached();
+
+ // send a command to the server
+ public native boolean send(String remApp, String remObj, String remFun, byte[] data);
+
+ // send a command string to the server
+ public native boolean send(String remApp, String remObj, String remFun, String data);
+
+ // call a function and get the result
+ public native Response call(String remApp, String remObj, String remFun, byte[] data, boolean eventLoop);
+
+ // Checks whether remApp is registered with the DCOP server.
+ public native boolean isApplicationRegistered ( String remApp);
+
+ public static void main(String[] args)
+ {
+ Client client = new Client();
+
+ System.out.println("Registering as: " + client.registerAs("Java-App"));
+ if (client.isAttached())
+ System.out.println("Attached!");
+
+ client.send("kdesktop", "KDesktopIface", "selectAll()", "");
+
+ java.io.ByteArrayOutputStream bs = new java.io.ByteArrayOutputStream();
+ Response res = client.call("kdesktop", "KDesktopIface", "selectedURLs()", bs.toByteArray(), false);
+ System.out.println("Result type: " + res.returnType);
+ }
+
+ static
+ {
+ System.loadLibrary("javadcop");
+ }
+
+}
+
diff --git a/dcopjava/binding/org/kde/DCOP/DCOPRef.java b/dcopjava/binding/org/kde/DCOP/DCOPRef.java
new file mode 100644
index 00000000..29d37efd
--- /dev/null
+++ b/dcopjava/binding/org/kde/DCOP/DCOPRef.java
@@ -0,0 +1,30 @@
+package org.kde.DCOP;
+
+
+public class DCOPRef
+{
+ private String _app, _obj, _type;
+
+ public DCOPRef(String app, String obj, String type)
+ {
+ _app = app;
+ _obj = obj;
+ _type = type;
+ }
+
+ public String app()
+ {
+ return _app;
+ }
+
+ public String object()
+ {
+ return _obj;
+ }
+
+ public String type()
+ {
+ return _type;
+ }
+
+}
diff --git a/dcopjava/binding/org/kde/DCOP/Makefile.am b/dcopjava/binding/org/kde/DCOP/Makefile.am
new file mode 100644
index 00000000..30dcb410
--- /dev/null
+++ b/dcopjava/binding/org/kde/DCOP/Makefile.am
@@ -0,0 +1,9 @@
+class_DATA = DCOPRef.class Response.class Client.class Stub.class Response.class
+classdir = $(kde_libraries)/java/org/kde/DCOP
+
+SUFFIXES = .java .class
+
+.java.class:
+ CLASSPATH=$(top_srcdir)/dcopjava/binding $(JAVAC) -d ../../../ -cp ../../../ $(top_srcdir)/dcopjava/binding/org/kde/DCOP/$*.java
+
+CLEANFILES = $(class_DATA)
diff --git a/dcopjava/binding/org/kde/DCOP/Response.java b/dcopjava/binding/org/kde/DCOP/Response.java
new file mode 100644
index 00000000..5df99427
--- /dev/null
+++ b/dcopjava/binding/org/kde/DCOP/Response.java
@@ -0,0 +1,9 @@
+package org.kde.DCOP;
+
+
+public class Response
+{
+ public boolean returnValue;
+ public String returnType;
+ public byte[] returnData;
+}
diff --git a/dcopjava/binding/org/kde/DCOP/Stub.java b/dcopjava/binding/org/kde/DCOP/Stub.java
new file mode 100644
index 00000000..e9267fa5
--- /dev/null
+++ b/dcopjava/binding/org/kde/DCOP/Stub.java
@@ -0,0 +1,193 @@
+package org.kde.DCOP;
+
+
+import java.io.*;
+
+
+public class Stub
+{
+ private String _app, _obj;
+ private int _status;
+ private Client _client;
+
+ public Stub(String app, String obj)
+ {
+ _app = app;
+ _obj = obj;
+ _status = 0;
+
+ // TODO: The client should be shared between stubs.
+ _client = new Client();
+ _client.attach();
+ }
+
+ public String app()
+ {
+ return _app;
+ }
+
+ public String obj()
+ {
+ return _obj;
+ }
+
+
+ public Client client()
+ {
+ return _client;
+ }
+
+
+ public final static int CallFailed = 0;
+ public final static int CallSucceeded = 1;
+
+ public int status()
+ {
+ return _status;
+ }
+
+ public void setStatus(int status)
+ {
+ _status = status;
+ }
+
+ public boolean ok()
+ {
+ return _status == CallSucceeded;
+ }
+
+ public void callFailed()
+ {
+ _status = CallFailed;
+ }
+
+
+ // accessor methods for the datatypes used ---------------------------
+
+ protected boolean read_bool(DataInputStream is) throws IOException
+ {
+ return is.readBoolean();
+ }
+
+ protected void write_bool(DataOutputStream os, boolean val) throws IOException
+ {
+ os.writeBoolean(val);
+ }
+
+ protected short read_short_int(DataInputStream is) throws IOException
+ {
+ return is.readShort();
+ }
+
+ protected void write_short_int(DataOutputStream os, short val) throws IOException
+ {
+ os.writeShort(val);
+ }
+
+ protected int read_int(DataInputStream is) throws IOException
+ {
+ return is.readInt();
+ }
+
+ protected void write_int(DataOutputStream os, int val) throws IOException
+ {
+ os.writeInt(val);
+ }
+
+ protected int read_long_int(DataInputStream is) throws IOException
+ {
+ return is.readInt();
+ }
+
+ protected void write_long_int(DataOutputStream os, int val) throws IOException
+ {
+ os.writeInt(val);
+ }
+
+ protected float read_float(DataInputStream is) throws IOException
+ {
+ return is.readFloat();
+ }
+
+ protected void write_float(DataOutputStream os, float val) throws IOException
+ {
+ os.writeFloat(val);
+ }
+
+ protected double read_double(DataInputStream is) throws IOException
+ {
+ return is.readDouble();
+ }
+
+ protected void write_double(DataOutputStream os, double val) throws IOException
+ {
+ os.writeDouble(val);
+ }
+
+ protected String read_QString(DataInputStream is) throws IOException
+ {
+ int len = is.readInt();
+ if (len == 0xffffffff)
+ return new String();
+ else
+ {
+ StringBuffer b = new StringBuffer();
+ for (int i=0; i<len/2; ++i)
+ b.append(is.readChar());
+ return b.toString();
+ }
+ }
+
+ protected void write_QString(DataOutputStream os, String val) throws IOException
+ {
+ os.writeInt(val.length()*2);
+ for (int i=0; i<val.length(); ++i)
+ os.writeChar(val.charAt(i));
+ }
+
+ protected String read_QCString(DataInputStream is) throws IOException
+ {
+ int len = is.readInt();
+ StringBuffer b = new StringBuffer();
+ for (int i=0; i<len; ++i)
+ b.append((char)is.readByte());
+ return b.toString();
+ }
+
+ protected void write_QCString(DataOutputStream os, String val) throws IOException
+ {
+ os.writeInt(val.length()+1);
+ for (int i=0; i<val.length(); ++i)
+ os.writeByte(val.charAt(i));
+ os.writeByte(0);
+ }
+
+ protected String[] read_QStringList(DataInputStream is) throws IOException
+ {
+ int n = is.readInt();
+ String[] result = new String[n];
+ for (int i=0; i<n; ++i)
+ result[i] = read_QString(is);
+ return result;
+ }
+
+ protected void write_QStringList(DataOutputStream os, String[] val) throws IOException
+ {
+ os.writeInt(val.length);
+ for (int i=0; i<val.length; ++i)
+ write_QCString(os, val[i]);
+ }
+
+ protected void write_DCOPRef(DataOutputStream os, DCOPRef ref) throws IOException
+ {
+ write_QCString(os, ref.app());
+ write_QCString(os, ref.object());
+ write_QCString(os, ref.type());
+ }
+
+ protected DCOPRef read_DCOPRef(DataInputStream is) throws IOException
+ {
+ return new DCOPRef(read_QCString(is), read_QCString(is), read_QCString(is));
+ }
+
+}
diff --git a/dcopjava/binding/org/kde/Makefile.am b/dcopjava/binding/org/kde/Makefile.am
new file mode 100644
index 00000000..4e9d266d
--- /dev/null
+++ b/dcopjava/binding/org/kde/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = DCOP
diff --git a/dcopjava/configure.in.in b/dcopjava/configure.in.in
new file mode 100644
index 00000000..8356d761
--- /dev/null
+++ b/dcopjava/configure.in.in
@@ -0,0 +1,2 @@
+KDE_CHECK_JAVA([dcopjava])
+
diff --git a/dcopjava/dcopidl2java/Makefile.am b/dcopjava/dcopidl2java/Makefile.am
new file mode 100644
index 00000000..9dbe0a1c
--- /dev/null
+++ b/dcopjava/dcopidl2java/Makefile.am
@@ -0,0 +1,11 @@
+
+INCLUDES = $(all_includes)
+
+bin_PROGRAMS = dcopidl2java
+
+dcopidl2java_SOURCES = main.cpp skel.cpp stubimpl.cpp
+noinst_HEADERS = main.h
+
+dcopidl2java_LDADD = $(LIB_QT)
+dcopidl2java_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+
diff --git a/dcopjava/dcopidl2java/main.cpp b/dcopjava/dcopidl2java/main.cpp
new file mode 100644
index 00000000..1df03b98
--- /dev/null
+++ b/dcopjava/dcopidl2java/main.cpp
@@ -0,0 +1,110 @@
+/*****************************************************************
+Copyright (c) 1999 Torben Weis <weis@kde.org>
+Copyright (c) 2000 Matthias Ettrich <ettrich@kde.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+******************************************************************/
+#include <qdom.h>
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qstring.h>
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "main.h"
+
+
+
+void usage()
+{
+ fprintf( stderr, "Usage: dcopidl2java [ --no-skel | --no-stub | --package java-package ] file\n" );
+}
+
+int main( int argc, char** argv )
+{
+
+ if ( *qVersion() == '1' ) {
+ fprintf( stderr, "dcopidl2cpp appears to be linked to Qt 1 instead of Qt 2 ! Aborting.\n" );
+ exit(1);
+ }
+ int argpos = 1;
+ bool generate_skel = TRUE;
+ bool generate_stub = TRUE;
+ QString package;
+
+ while (argc > 2) {
+
+ if ( strcmp( argv[argpos], "--no-skel" ) == 0 )
+ {
+ generate_skel = FALSE;
+ for (int i = argpos; i < argc - 1; i++) argv[i] = argv[i+1];
+ argc--;
+ }
+ else if ( strcmp( argv[argpos], "--no-stub" ) == 0 )
+ {
+ generate_stub = FALSE;
+ for (int i = argpos; i < argc - 1; i++) argv[i] = argv[i+1];
+ argc--;
+ }
+ else if ( strcmp( argv[argpos], "--package" ) == 0 )
+ {
+ if (argpos + 1 < argc)
+ package = QString(argv[argpos+1]);
+
+ for (int i = argpos; i < argc - 2; i++) argv[i] = argv[i+2];
+ argc -= 2;
+ } else {
+ usage();
+ exit(1);
+
+ }
+ }
+
+ QFile in( argv[argpos] );
+ if ( !in.open( IO_ReadOnly ) )
+ qFatal("Could not read %s", argv[argpos] );
+
+ QDomDocument doc;
+ doc.setContent( &in );
+
+ QDomElement de = doc.documentElement();
+ ASSERT( de.tagName() == "DCOP-IDL" );
+
+ QString base( argv[argpos] );
+ QString idl = base;
+
+ int pos = base.findRev( '.' );
+ if ( pos != -1 )
+ base = base.left( pos );
+
+ pos = idl.findRev('/');
+ if ( pos != -1 )
+ idl = idl.mid( pos+1 );
+
+ if ( generate_skel )
+ ;// generateSkel( idl, base + "_skel.java", de );
+
+ if ( generate_stub ) {
+ generateStubImpl( idl, package, base + "_stub.java", de );
+ }
+
+ return 0;
+}
diff --git a/dcopjava/dcopidl2java/main.h b/dcopjava/dcopidl2java/main.h
new file mode 100644
index 00000000..bc395af4
--- /dev/null
+++ b/dcopjava/dcopidl2java/main.h
@@ -0,0 +1,35 @@
+/*****************************************************************
+Copyright (c) 1999 Torben Weis <weis@kde.org>
+Copyright (c) 2000 Matthias Ettrich <ettrich@kde.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+******************************************************************/
+#include <qdom.h>
+#include <qstring.h>
+
+/**
+ * Writes the skeleton
+ */
+void generateSkel( const QString& idl, const QString& filename, QDomElement de );
+
+/**
+ * Writes the stub implementation
+ */
+void generateStubImpl( const QString& idl, const QString& package, const QString& filename, QDomElement de );
+
diff --git a/dcopjava/dcopidl2java/skel.cpp b/dcopjava/dcopidl2java/skel.cpp
new file mode 100644
index 00000000..55065dad
--- /dev/null
+++ b/dcopjava/dcopidl2java/skel.cpp
@@ -0,0 +1,322 @@
+/*****************************************************************
+Copyright (c) 1999 Torben Weis <weis@kde.org>
+Copyright (c) 2000 Matthias Ettrich <ettrich@kde.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+******************************************************************/
+#include <qdom.h>
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qstring.h>
+#include <qvaluelist.h>
+#include <qstringlist.h>
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "main.h"
+
+static int const primes[] =
+{
+ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
+ 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
+ 73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
+ 127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
+ 179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
+ 233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
+ 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
+ 353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
+ 419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
+ 467, 479, 487, 491, 499, 503, 509, 521, 523, 541,
+ 547, 557, 563, 569, 571, 577, 587, 593, 599, 601,0
+};
+
+
+struct Function
+{
+ Function(){};
+ Function( const QString& t, const QString& n, const QString&fn ) : type( t ), name( n ), fullName( fn ){}
+ QString type;
+ QString name;
+ QString fullName;
+};
+
+
+/**
+ * Writes the skeleton
+ */
+void generateSkel( const QString& idl, const QString& filename, QDomElement de )
+{
+ QFile skel( filename );
+ if ( !skel.open( IO_WriteOnly ) )
+ qFatal("Could not write to %s", filename.latin1() );
+
+ QTextStream str( &skel );
+
+ str << "/****************************************************************************" << endl;
+ str << "**" << endl;
+ str << "** DCOP Skeleton created by dcopidl2cpp from " << idl << endl;
+ str << "**" << endl;
+ str << "** WARNING! All changes made in this file will be lost!" << endl;
+ str << "**" << endl;
+ str << "*****************************************************************************/" << endl;
+ str << endl;
+
+ QDomElement e = de.firstChild().toElement();
+ if ( e.tagName() == "SOURCE" ) {
+ str << "#include \"" << e.firstChild().toText().data() << "\"" << endl << endl;
+ }
+
+ for( ; !e.isNull(); e = e.nextSibling().toElement() ) {
+ if ( e.tagName() == "CLASS" ) {
+ QDomElement n = e.firstChild().toElement();
+ ASSERT( n.tagName() == "NAME" );
+ QString className = n.firstChild().toText().data();
+ // find dcop parent ( rightmost super class )
+ QString DCOPParent;
+ QDomElement s = n.nextSibling().toElement();
+ for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
+ if ( s.tagName() == "SUPER" )
+ DCOPParent = s.firstChild().toText().data();
+ }
+
+ // get function table
+ QValueList<Function> functions;
+ s = n.nextSibling().toElement();
+ for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
+ if ( s.tagName() == "FUNC" ) {
+ QDomElement r = s.firstChild().toElement();
+ ASSERT( r.tagName() == "TYPE" );
+ QString funcType = r.firstChild().toText().data();
+ r = r.nextSibling().toElement();
+ ASSERT ( r.tagName() == "NAME" );
+ QString funcName = r.firstChild().toText().data();
+ QStringList argtypes;
+ QStringList argnames;
+ r = r.nextSibling().toElement();
+ for( ; !r.isNull(); r = r.nextSibling().toElement() ) {
+ ASSERT( r.tagName() == "ARG" );
+ QDomElement a = r.firstChild().toElement();
+ ASSERT( a.tagName() == "TYPE" );
+ argtypes.append( a.firstChild().toText().data() );
+ a = a.nextSibling().toElement();
+ if ( !a.isNull() ) {
+ ASSERT( a.tagName() == "NAME" );
+ argnames.append( a.firstChild().toText().data() );
+ } else {
+ argnames.append( QString::null );
+ }
+ }
+ funcName += '(';
+ QString fullFuncName = funcName;
+ bool first = TRUE;
+ QStringList::Iterator ittype = argtypes.begin();
+ QStringList::Iterator itname = argnames.begin();
+ while ( ittype != argtypes.end() && itname != argnames.end() ) {
+ if ( !first ) {
+ funcName += ',';
+ fullFuncName += ',';
+ }
+ first = FALSE;
+ funcName += *ittype;
+ fullFuncName += *ittype;
+ if ( ! (*itname).isEmpty() ) {
+ fullFuncName += ' ';
+ fullFuncName += *itname;
+ }
+ ++ittype;
+ ++itname;
+ }
+ funcName += ')';
+ fullFuncName += ')';
+ functions.append( Function( funcType, funcName, fullFuncName ) );
+ }
+ }
+
+ // create static tables
+
+ int fhash = functions.count() + 1;
+ for ( int i = 0; primes[i]; i++ ) {
+ if ( primes[i] > static_cast<int>(functions.count()) ) {
+ fhash = primes[i];
+ break;
+ }
+ }
+
+ str << "#include <kdatastream.h>" << endl;
+
+ bool useHashing = functions.count() > 7;
+ if ( useHashing ) {
+ str << "#include <qasciidict.h>" << endl;
+ str << "static const int " << className << "_fhash = " << fhash << ";" << endl;
+ }
+ str << "static const char* const " << className << "_ftable[" << functions.count() + 1 << "][3] = {" << endl;
+ for( QValueList<Function>::Iterator it = functions.begin(); it != functions.end(); ++it ){
+ str << " { \"" << (*it).type << "\", \"" << (*it).name << "\", \"" << (*it).fullName << "\" }," << endl;
+ }
+ str << " { 0, 0, 0 }" << endl;
+ str << "};" << endl;
+
+ str << endl;
+
+
+ // Write dispatcher
+ str << "bool " << className;
+ str << "::process(const QCString &fun, const QByteArray &data, QCString& replyType, QByteArray &replyData)" << endl;
+ str << "{" << endl;
+ if ( useHashing ) {
+ str << " static QAsciiDict<int>* fdict = 0;" << endl;
+
+ str << " if ( !fdict ) {" << endl;
+ str << "\tfdict = new QAsciiDict<int>( " << className << "_fhash, TRUE, FALSE );" << endl;
+ str << "\tfor ( int i = 0; " << className << "_ftable[i][1]; i++ )" << endl;
+ str << "\t fdict->insert( " << className << "_ftable[i][1], new int( i ) );" << endl;
+ str << " }" << endl;
+
+ str << " int* fp = fdict->find( fun );" << endl;
+ str << " switch ( fp?*fp:-1) {" << endl;
+ }
+ s = n.nextSibling().toElement();
+ int fcount = 0;
+ bool firstFunc = TRUE;
+ for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
+ if ( s.tagName() == "FUNC" ) {
+ QDomElement r = s.firstChild().toElement();
+ ASSERT( r.tagName() == "TYPE" );
+ QString funcType = r.firstChild().toText().data();
+ if ( funcType == "ASYNC" )
+ funcType = "void";
+ r = r.nextSibling().toElement();
+ ASSERT ( r.tagName() == "NAME" );
+ QString funcName = r.firstChild().toText().data();
+ QStringList args;
+ QStringList argtypes;
+ r = r.nextSibling().toElement();
+ for( ; !r.isNull(); r = r.nextSibling().toElement() ) {
+ ASSERT( r.tagName() == "ARG" );
+ QDomElement a = r.firstChild().toElement();
+ ASSERT( a.tagName() == "TYPE" );
+ argtypes.append( a.firstChild().toText().data() );
+ args.append( QString("arg" ) + QString::number( args.count() ) );
+ }
+ QString plainFuncName = funcName;
+ funcName += '(';
+ bool first = TRUE;
+ for( QStringList::Iterator argtypes_count = argtypes.begin(); argtypes_count != argtypes.end(); ++argtypes_count ){
+ if ( !first )
+ funcName += ',';
+ first = FALSE;
+ funcName += *argtypes_count;
+ }
+ funcName += ')';
+
+ if ( useHashing ) {
+ str << " case " << fcount << ": { // " << funcType << " " << funcName << endl;
+ } else {
+ if ( firstFunc )
+ str << " if ( fun == " << className << "_ftable[" << fcount << "][1] ) { // " << funcType << " " << funcName << endl;
+ else
+ str << " else if ( fun == " << className << "_ftable[" << fcount << "][1] ) { // " << funcType << " " << funcName << endl;
+ firstFunc = FALSE;
+ }
+ if ( !args.isEmpty() ) {
+ QStringList::Iterator ittypes = argtypes.begin();
+ QStringList::Iterator args_count;
+ for( args_count = args.begin(); args_count != args.end(); ++args_count ){
+ str << '\t'<< *ittypes << " " << *args_count << ";" << endl;
+ ++ittypes;
+ }
+ str << "\tQDataStream arg( data, IO_ReadOnly );" << endl;
+ for( args_count = args.begin(); args_count != args.end(); ++args_count ){
+ str << "\targ >> " << *args_count << ";" << endl;
+ }
+ }
+
+ str << "\treplyType = " << className << "_ftable[" << fcount++ << "][0]; " << endl;
+ if ( funcType == "void" ) {
+ str << '\t' << plainFuncName << '(';
+ } else {
+ str << "\tQDataStream _replyStream( replyData, IO_WriteOnly );" << endl;
+ str << "\t_replyStream << " << plainFuncName << '(';
+ }
+
+ first = TRUE;
+ for ( QStringList::Iterator args_count = args.begin(); args_count != args.end(); ++args_count ){
+ if ( !first )
+ str << ", ";
+ first = FALSE;
+ str << *args_count;
+ }
+ str << " );" << endl;
+ if (useHashing ) {
+ str << " } break;" << endl;
+ } else {
+ str << " }";
+ }
+ }
+ }
+ if ( useHashing ) {
+ str << " default: " << endl;
+ } else {
+ str << " else {" << endl;
+ }
+ if (!DCOPParent.isEmpty()) {
+ str << "\treturn " << DCOPParent << "::process( fun, data, replyType, replyData );" << endl;
+ } else {
+ str << "\treturn FALSE;" << endl;
+ }
+ str << " }" << endl;
+ str << " return TRUE;" << endl;
+ str << "}" << endl << endl;
+
+ str << "QCStringList " << className;
+ str << "::interfaces()" << endl;
+ str << "{" << endl;
+ if (!DCOPParent.isEmpty()) {
+ str << " QCStringList ifaces = " << DCOPParent << "::interfaces();" << endl;
+ } else {
+ str << " QCStringList ifaces;" << endl;
+ }
+ str << " ifaces += \"" << className << "\";" << endl;
+ str << " return ifaces;" << endl;
+ str << "}" << endl << endl;
+
+
+ str << "QCStringList " << className;
+ str << "::functions()" << endl;
+ str << "{" << endl;
+ if (!DCOPParent.isEmpty()) {
+ str << " QCStringList funcs = " << DCOPParent << "::functions();" << endl;
+ } else {
+ str << " QCStringList funcs;" << endl;
+ }
+ str << " for ( int i = 0; " << className << "_ftable[i][2]; i++ ) {" << endl;
+ str << "\tQCString func = " << className << "_ftable[i][0];" << endl;
+ str << "\tfunc += ' ';" << endl;
+ str << "\tfunc += " << className << "_ftable[i][2];" << endl;
+ str << "\tfuncs << func;" << endl;
+ str << " }" << endl;
+ str << " return funcs;" << endl;
+ str << "}" << endl << endl;
+ }
+ }
+
+ skel.close();
+}
diff --git a/dcopjava/dcopidl2java/stubimpl.cpp b/dcopjava/dcopidl2java/stubimpl.cpp
new file mode 100644
index 00000000..8d15fe7a
--- /dev/null
+++ b/dcopjava/dcopidl2java/stubimpl.cpp
@@ -0,0 +1,312 @@
+/*****************************************************************
+Copyright (c) 1999 Torben Weis <weis@kde.org>
+Copyright (c) 2000 Matthias Ettrich <ettrich@kde.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+******************************************************************/
+#include <qdom.h>
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qstring.h>
+#include <qregexp.h>
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "main.h"
+
+
+QString javaType(QString type)
+{
+ if (type == "bool")
+ return "boolean";
+ if (type == "QString")
+ return "String";
+ if (type == "QCString")
+ return "String";
+ if (type == "QStringList")
+ return "String[]";
+ if (type == "short int")
+ return "short";
+ if (type == "long int")
+ return "int";
+
+ return type;
+}
+
+
+QString javaRightAttribute(QString attr)
+{
+ if (attr == "&")
+ return QString::null;
+
+ return "!!!NOT IMPLEMENTED: " + attr;
+}
+
+
+QString javaLeftAttribute(QString attr)
+{
+ if (attr == "const")
+ return QString::null;
+
+ return "!!!NOT IMPLEMENTED: " + attr;
+}
+
+
+QString javaQualifier(QString qual)
+{
+ if (qual == "const")
+ return QString::null;
+
+ return "!!!NOT IMPLEMENTED: " + qual;
+}
+
+
+QString underscore(QString in)
+{
+ return in.replace(QRegExp(" "), "_");
+}
+
+
+QString defValue(QString type)
+{
+ if (type == "bool")
+ return "false";
+ if (type == "QString")
+ return "null";
+ if (type == "QStringList")
+ return "null";
+ if (type == "DCOPRef")
+ return "null";
+ if (type == "QCString")
+ return "null";
+
+ return "0";
+}
+
+
+/**
+ * Writes the stub implementation
+ */
+void generateStubImpl( const QString& idl, const QString& package, const QString& filename, QDomElement de )
+{
+ QFile impl( filename );
+ if ( !impl.open( IO_WriteOnly ) )
+ qFatal("Could not write to %s", filename.latin1() );
+
+ QTextStream str( &impl );
+
+ str << "/****************************************************************************" << endl;
+ str << "**" << endl;
+ str << "** DCOP Stub Implementation created by dcopidl2java from " << idl << endl;
+ str << "**" << endl;
+ str << "** WARNING! All changes made in this file will be lost!" << endl;
+ str << "**" << endl;
+ str << "*****************************************************************************/" << endl;
+ str << endl;
+
+ if (!package.isEmpty())
+ str << endl << "package " << package << ";" << endl << endl;
+
+ str << endl << "import java.io.*;" << endl;
+ str << "import org.kde.DCOP.*;" << endl;
+ str << endl << endl;
+
+ QDomElement e = de.firstChild().toElement();
+ for( ; !e.isNull(); e = e.nextSibling().toElement() ) {
+ if ( e.tagName() == "CLASS" ) {
+ QDomElement n = e.firstChild().toElement();
+ ASSERT( n.tagName() == "NAME" );
+ QString className = n.firstChild().toText().data() + "_stub";
+
+ // find dcop parent ( rightmost super class )
+ QString DCOPParent;
+ QDomElement s = n.nextSibling().toElement();
+ for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
+ if ( s.tagName() == "SUPER" )
+ DCOPParent = s.firstChild().toText().data();
+ }
+
+ // Start class definition
+ str << "class " << className;
+
+ if ( DCOPParent.isEmpty() || DCOPParent == "DCOPObject" )
+ str << " extends Stub" << endl;
+ else
+ str << " extends " << DCOPParent << endl;
+
+ str << "{" << endl;
+
+ // Write constructor
+ str << " public " << className << "(String app, String obj)" << endl;
+ str << " {" << endl << " super(app, obj);" << endl << " }" << endl;
+ str << endl;
+
+ // Write marshalling code
+ s = e.firstChild().toElement();
+ for( ; !s.isNull(); s = s.nextSibling().toElement() ) {
+ if ( s.tagName() == "FUNC" ) {
+ QDomElement r = s.firstChild().toElement();
+ ASSERT( r.tagName() == "TYPE" );
+ QString result = r.firstChild().toText().data();
+ str << " public ";
+ bool async = result == "ASYNC";
+ if ( async)
+ result = "void";
+ if ( r.hasAttribute( "qleft" ) )
+ str << " " << javaLeftAttribute(r.attribute("qleft")) << " ";
+ str << javaType(result);
+ if ( r.hasAttribute( "qright" ) )
+ str << " " << javaRightAttribute(r.attribute("qright")) << " ";
+ else
+ str << " ";
+
+ r = r.nextSibling().toElement();
+ ASSERT ( r.tagName() == "NAME" );
+ QString funcName = r.firstChild().toText().data();
+ str << funcName << "(";
+
+ QStringList args;
+ QStringList argtypes;
+ bool first = TRUE;
+ r = r.nextSibling().toElement();
+ for( ; !r.isNull(); r = r.nextSibling().toElement() ) {
+ if ( !first )
+ str << ", ";
+ first = FALSE;
+ ASSERT( r.tagName() == "ARG" );
+ QDomElement a = r.firstChild().toElement();
+ ASSERT( a.tagName() == "TYPE" );
+ if ( a.hasAttribute( "qleft" ) )
+ str << javaLeftAttribute(a.attribute("qleft")) << " ";
+ argtypes.append(a.firstChild().toText().data());
+ str << javaType(argtypes.last());
+ if ( a.hasAttribute( "qright" ) )
+ str << javaRightAttribute(a.attribute("qright")) << " ";
+ else
+ str << " ";
+ args.append(QString("arg") + QString::number(args.count())) ;
+ str << args.last();
+ }
+ str << ")";
+
+ if ( s.hasAttribute("qual") )
+ str << " " << javaQualifier(s.attribute("qual"));
+ str << endl;
+
+ str << " {" << endl ;
+
+ funcName += "(";
+ first = TRUE;
+ for( QStringList::Iterator it = argtypes.begin(); it != argtypes.end(); ++it ){
+ if ( !first )
+ funcName += ",";
+ first = FALSE;
+ funcName += *it;
+ }
+ funcName += ")";
+
+ if ( async ) {
+ str << " ByteArrayOutputStream bs = new ByteArrayOutputStream();" << endl;
+ if ( !args.isEmpty() ) {
+ str << " DataOutputStream os = new DataOutputStream(bs);" << endl;
+ str << " try" << endl;
+ str << " {" << endl;
+
+ QStringList::Iterator itt, ita;
+ for (itt = argtypes.begin(), ita = args.begin(); itt != argtypes.end(); ++itt, ++ita)
+ str << " write_" << *itt << "(os, " << *ita << ");" << endl;
+ }
+ str << " client().send(app(), obj(), \"" << funcName << "\", bs.toByteArray());" << endl;
+ str << " setStatus(CallSucceeded);" << endl;
+ if (!args.isEmpty())
+ {
+ str << " }" << endl;
+ str << " catch (java.io.IOException e)" << endl;
+ str << " {" << endl;
+ str << " callFailed();" << endl;
+ str << " }" << endl;
+ }
+ } else {
+
+ if ( result != "void" )
+ str << " " << javaType(result) << " result = " << defValue(result) << ";" << endl;
+
+ str << " ByteArrayOutputStream data = new ByteArrayOutputStream();" << endl;
+
+ if ( !args.isEmpty() ) {
+ str << " DataOutputStream os = new DataOutputStream(data);" << endl;
+ str << " try" << endl;
+ str << " {" << endl;
+
+ QStringList::Iterator itt, ita;
+ for (itt = argtypes.begin(), ita = args.begin(); itt != argtypes.end(); ++itt, ++ita)
+ str << " write_" << underscore(*itt) << "(os, " << *ita << ");" << endl;
+
+ }
+
+ str << " Response response = client().call(app(), obj(), \"" << funcName << "\", data.toByteArray(), false);" << endl;
+ str << " if (response.returnValue)" << endl;
+ str << " {" << endl;
+ if ( result != "void" ) {
+ str << " if (response.returnType.equals(\"" << result << "\"))" << endl;
+ str << " {" << endl;
+ str << " ByteArrayInputStream bi = new ByteArrayInputStream(response.returnData);" << endl;
+ str << " DataInputStream is = new DataInputStream(bi);" << endl;
+ str << " try" << endl;
+ str << " {" << endl;
+ str << " result = read_" << underscore(result) << "(is);" << endl;
+ str << " setStatus( CallSucceeded );" << endl;
+ str << " }" << endl;
+ str << " catch (java.io.IOException e)" << endl;
+ str << " {" << endl;
+ str << " callFailed();" << endl;
+ str << " }" << endl;
+ str << " }" << endl;
+ str << " else" << endl;
+ str << " callFailed();" << endl;
+ } else {
+ str << " setStatus(CallSucceeded);" << endl;
+ }
+ str << " }" << endl;
+ str << " else " << endl;
+ str << " callFailed();" << endl;
+
+
+ if (!args.isEmpty())
+ {
+ str << " }" << endl;
+ str << " catch (java.io.IOException e)" << endl;
+ str << " {" << endl;
+ str << " callFailed();" << endl;
+ str << " }" << endl;
+ }
+
+ if ( result != "void" )
+ str << " return result;" << endl;
+ }
+ str << " }" << endl << endl;
+ }
+ }
+ str << "}" << endl;
+ }
+ }
+ impl.close();
+}
diff --git a/dcopjava/tests/Makefile.am b/dcopjava/tests/Makefile.am
new file mode 100644
index 00000000..847d3c53
--- /dev/null
+++ b/dcopjava/tests/Makefile.am
@@ -0,0 +1,17 @@
+INCLUDES = $(all_includes)
+
+check_PROGRAMS = server test.class
+
+server_SOURCES = main.cpp test.skel test_impl.cpp
+server_LDFLAGS = $(all_libraries)
+server_LDADD = $(LIB_KDECORE)
+
+# test_class_SOURCES = test.java
+
+test.class: test.java test_stub.java
+ $(JAVAC) -classpath $(kde_libraries)/java:. test.java
+
+test_stub.java: test.h test.kidl
+ dcopidl2java test.kidl
+
+CLEANFILES = test_stub.java test_stub.class
diff --git a/dcopjava/tests/main.cpp b/dcopjava/tests/main.cpp
new file mode 100644
index 00000000..2bdb0547
--- /dev/null
+++ b/dcopjava/tests/main.cpp
@@ -0,0 +1,17 @@
+#include <kapplication.h>
+#include <dcopclient.h>
+
+
+#include "test_impl.h"
+
+
+int main(int argc, char *argv[])
+{
+ KApplication app(argc, argv, "test-server", false, false);
+
+ app.dcopClient()->registerAs("test-server", false);
+
+ test_impl *t = new test_impl;
+
+ return app.exec();
+}
diff --git a/dcopjava/tests/test.h b/dcopjava/tests/test.h
new file mode 100644
index 00000000..5f215ce7
--- /dev/null
+++ b/dcopjava/tests/test.h
@@ -0,0 +1,46 @@
+#ifndef _TEST_H_
+#define _TEST_H_
+
+
+#include <qstring.h>
+#include <qstringlist.h>
+
+
+#include <dcopobject.h>
+#include <dcopref.h>
+
+
+class test : virtual public DCOPObject
+{
+ K_DCOP
+
+public:
+
+k_dcop:
+
+ virtual void noArg() = 0;
+ virtual ASYNC asyncNoArg() = 0;
+
+ virtual void oneArg(bool val) = 0;
+ virtual bool returnFalse() = 0;
+ virtual bool returnTrue() = 0;
+
+ virtual short shortArg(short in) = 0;
+ virtual int intArg(int in) = 0;
+ virtual long longArg(long in) = 0;
+
+ virtual float floatArg(float in) = 0;
+ virtual double doubleArg(double in) = 0;
+
+ virtual QString stringArg(QString in) = 0;
+ virtual QStringList stringListArg(QStringList in) = 0;
+
+ virtual QCString cstringArg(QCString in) = 0;
+
+ virtual DCOPRef DCOPRefArg(DCOPRef in) = 0;
+
+};
+
+
+
+#endif
diff --git a/dcopjava/tests/test.java b/dcopjava/tests/test.java
new file mode 100644
index 00000000..72a40b95
--- /dev/null
+++ b/dcopjava/tests/test.java
@@ -0,0 +1,78 @@
+import org.kde.DCOP.*;
+
+
+class test
+{
+
+ public static void main(String[] argv)
+ {
+ test_stub test = new test_stub("test-server", "test");
+
+ System.out.println("Calling server without args:");
+ test.noArg();
+ System.out.println("");
+
+ System.out.println("Calling server asynchronously without args:");
+ test.asyncNoArg();
+ System.out.println("");
+
+ System.out.println("Calling server with one argument: bool=true:");
+ test.oneArg(true);
+ System.out.println("");
+
+ System.out.println("Calling server with one argument: bool=false:");
+ test.oneArg(false);
+ System.out.println("");
+
+ System.out.println("Calling server: returnFalse");
+ boolean ret = test.returnFalse();
+ System.out.print("Returned: ");
+ if (ret)
+ System.out.println("True");
+ else
+ System.out.println("False");
+ System.out.println();
+
+ System.out.println("Calling server: returnTrue");
+ ret = test.returnTrue();
+ System.out.print("Returned: ");
+ if (ret)
+ System.out.println("True");
+ else
+ System.out.println("False");
+ System.out.println();
+
+ System.out.println("Calling server: short");
+ System.out.println(test.shortArg((short)(51)));
+
+ System.out.println("Calling server: int");
+ System.out.println(test.intArg(512));
+
+ System.out.println("Calling server: long");
+ System.out.println(test.longArg(999999));
+
+ System.out.println("Calling server: float");
+ System.out.println(test.floatArg(5.1212f));
+
+ System.out.println("Calling server: double");
+ System.out.println(test.doubleArg(0.001122));
+
+ System.out.println("Calling server: String");
+ System.out.println(test.stringArg("Hallo Server"));
+
+ String[] in = { "alpha", "beta", "gamma", "delta" };
+ System.out.println("Calling server: String[]");
+ String[] out = test.stringListArg(in);
+ for (int i=0; i<out.length; ++i)
+ System.out.println(out[i]);
+
+ System.out.println("Calling server: CString");
+ System.out.println(test.cstringArg("Hallo Server"));
+
+ DCOPRef rin = new DCOPRef("app", "obj", "typ");
+ System.out.println("Calling server: DCOPRef");
+ DCOPRef rout = test.DCOPRefArg(rin);
+ System.out.println("Reference: " + rout.app() + ", " +
+ rout.object() + ", " + rout.type());
+ }
+}
diff --git a/dcopjava/tests/test_impl.cpp b/dcopjava/tests/test_impl.cpp
new file mode 100644
index 00000000..c220b3f8
--- /dev/null
+++ b/dcopjava/tests/test_impl.cpp
@@ -0,0 +1,108 @@
+#include <stream.h>
+#include <stdio.h>
+
+
+#include "test_impl.h"
+
+
+void test_impl::noArg()
+{
+ printf("SERVER: noArg() called\n");
+}
+
+
+void test_impl::asyncNoArg()
+{
+ printf("SERVER: asyncNoArg() called\n");
+}
+
+
+void test_impl::oneArg(bool b)
+{
+ printf("SERVER: oneArg(");
+ printf(b ? "true" : "false");
+ printf(") called\n");
+}
+
+
+bool test_impl::returnFalse()
+{
+ printf("SERVER: returnFalse() called\n");
+ return false;
+}
+
+
+bool test_impl::returnTrue()
+{
+ printf("SERVER: returnTrue() called\n");
+ return true;
+}
+
+
+short test_impl::shortArg(short in)
+{
+ cout << "SERVER: short in: " << in << endl;
+ return 123;
+}
+
+
+int test_impl::intArg(int in)
+{
+ cout << "SERVER: int in: " << in << endl;
+ return 123456;
+}
+
+
+long test_impl::longArg(long in)
+{
+ cout << "SERVER: long in: " << in << endl;
+ return 1234567890;
+}
+
+
+float test_impl::floatArg(float in)
+{
+ cout << "SERVER: float in: " << in << endl;
+ return 12.34;
+}
+
+
+double test_impl::doubleArg(double in)
+{
+ cout << "SERVER: double in: " << in << endl;
+ return 12.12313123;
+}
+
+
+QString test_impl::stringArg(QString in)
+{
+ cout << "SERVER: QString in: " << in << endl;
+ return "Hello Java";
+}
+
+
+QCString test_impl::cstringArg(QCString in)
+{
+ cout << "SERVER: QCString in: " << in << endl;
+ return "Hello Java";
+}
+
+
+QStringList test_impl::stringListArg(QStringList in)
+{
+ cout << "SERVER: QStringList in: ";
+ for (uint i=0; i<in.count(); ++i)
+ cout << in[i] << ", ";
+ cout << endl;
+ QStringList result;
+ result << "one" << "two" << "three";
+ return result;
+}
+
+
+DCOPRef test_impl::DCOPRefArg(DCOPRef in)
+{
+ cout << "SERVER: DCOPRef in: " << in.app() << ", "
+ << in.object() << ", " << in.type() << endl;
+ return DCOPRef("application", "object", "type");
+}
diff --git a/dcopjava/tests/test_impl.h b/dcopjava/tests/test_impl.h
new file mode 100644
index 00000000..61986819
--- /dev/null
+++ b/dcopjava/tests/test_impl.h
@@ -0,0 +1,38 @@
+#include "test.h"
+
+
+class test_impl : virtual public test
+{
+public:
+
+ test_impl() : DCOPObject("test") {};
+
+ void noArg();
+
+ void asyncNoArg();
+
+ void oneArg(bool b);
+
+ bool returnFalse();
+
+ bool returnTrue();
+
+ short shortArg(short in);
+
+ int intArg(int in);
+
+ long longArg(long in);
+
+ float floatArg(float in);
+
+ double doubleArg(double in);
+
+ QString stringArg(QString in);
+
+ QCString cstringArg(QCString in);
+
+ QStringList stringListArg(QStringList in);
+
+ DCOPRef DCOPRefArg(DCOPRef in);
+
+};