summaryrefslogtreecommitdiffstats
path: root/dcopjava/binding/org/trinitydesktop
diff options
context:
space:
mode:
Diffstat (limited to 'dcopjava/binding/org/trinitydesktop')
-rw-r--r--dcopjava/binding/org/trinitydesktop/DCOP/Client.java63
-rw-r--r--dcopjava/binding/org/trinitydesktop/DCOP/DCOPRef.java30
-rw-r--r--dcopjava/binding/org/trinitydesktop/DCOP/Makefile.am9
-rw-r--r--dcopjava/binding/org/trinitydesktop/DCOP/Response.java9
-rw-r--r--dcopjava/binding/org/trinitydesktop/DCOP/Stub.java193
-rw-r--r--dcopjava/binding/org/trinitydesktop/Makefile.am1
6 files changed, 305 insertions, 0 deletions
diff --git a/dcopjava/binding/org/trinitydesktop/DCOP/Client.java b/dcopjava/binding/org/trinitydesktop/DCOP/Client.java
new file mode 100644
index 00000000..f8e87f72
--- /dev/null
+++ b/dcopjava/binding/org/trinitydesktop/DCOP/Client.java
@@ -0,0 +1,63 @@
+package org.trinitydesktop.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/trinitydesktop/DCOP/DCOPRef.java b/dcopjava/binding/org/trinitydesktop/DCOP/DCOPRef.java
new file mode 100644
index 00000000..65e5e039
--- /dev/null
+++ b/dcopjava/binding/org/trinitydesktop/DCOP/DCOPRef.java
@@ -0,0 +1,30 @@
+package org.trinitydesktop.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/trinitydesktop/DCOP/Makefile.am b/dcopjava/binding/org/trinitydesktop/DCOP/Makefile.am
new file mode 100644
index 00000000..975d2826
--- /dev/null
+++ b/dcopjava/binding/org/trinitydesktop/DCOP/Makefile.am
@@ -0,0 +1,9 @@
+class_DATA = DCOPRef.class Response.class Client.class Stub.class
+classdir = $(kde_libraries)/java/org/trinitydesktop/DCOP
+
+SUFFIXES = .java .class
+
+.java.class:
+ CLASSPATH=$(top_srcdir)/dcopjava/binding $(JAVAC) -d ../../../ -cp ../../../ $(top_srcdir)/dcopjava/binding/org/trinitydesktop/DCOP/$*.java
+
+CLEANFILES = $(class_DATA)
diff --git a/dcopjava/binding/org/trinitydesktop/DCOP/Response.java b/dcopjava/binding/org/trinitydesktop/DCOP/Response.java
new file mode 100644
index 00000000..aca9fc61
--- /dev/null
+++ b/dcopjava/binding/org/trinitydesktop/DCOP/Response.java
@@ -0,0 +1,9 @@
+package org.trinitydesktop.DCOP;
+
+
+public class Response
+{
+ public boolean returnValue;
+ public String returnType;
+ public byte[] returnData;
+}
diff --git a/dcopjava/binding/org/trinitydesktop/DCOP/Stub.java b/dcopjava/binding/org/trinitydesktop/DCOP/Stub.java
new file mode 100644
index 00000000..0a23543a
--- /dev/null
+++ b/dcopjava/binding/org/trinitydesktop/DCOP/Stub.java
@@ -0,0 +1,193 @@
+package org.trinitydesktop.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/trinitydesktop/Makefile.am b/dcopjava/binding/org/trinitydesktop/Makefile.am
new file mode 100644
index 00000000..4e9d266d
--- /dev/null
+++ b/dcopjava/binding/org/trinitydesktop/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = DCOP