1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
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)
{
TTQString name(env->GetStringUTFChars(appName, 0));
kdDebug() << "javadcop::registerAs(\"" << name << "\") called" << endl;
TTQString 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)
{
TTQString _remApp(env->GetStringUTFChars(remApp, 0));
TTQString _remObj(env->GetStringUTFChars(remObj, 0));
TTQString _remFun(env->GetStringUTFChars(remFun, 0));
TTQString _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());
}
TTQByteArray byteArray(JNIEnv *env, jbyteArray a)
{
jsize len = env->GetArrayLength(a);
TTQByteArray _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)
{
TTQString _remApp(env->GetStringUTFChars(remApp, 0));
TTQString _remObj(env->GetStringUTFChars(remObj, 0));
TTQString _remFun(env->GetStringUTFChars(remFun, 0));
TTQByteArray _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)
{
TTQString _remApp(env->GetStringUTFChars(remApp, 0));
TTQString _remObj(env->GetStringUTFChars(remObj, 0));
TTQString _remFun(env->GetStringUTFChars(remFun, 0));
TTQByteArray _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;
TTQCString _retType;
TTQByteArray _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 TTQCString _remApp(env->GetStringUTFChars(remApp, 0));
kdDebug() << "javadcop::isApplicationRegistered() called" << endl;
return client::instance()->isApplicationRegistered(_remApp);
}
|