summaryrefslogtreecommitdiffstats
path: root/dcopjava/binding
diff options
context:
space:
mode:
Diffstat (limited to 'dcopjava/binding')
-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
9 files changed, 533 insertions, 0 deletions
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