23#include <rtl/byteseq.h>
24#include <rtl/byteseq.hxx>
27#include <uno/threadpool.h>
42 jmethodID theExecute, uno_ThreadPool thePool):
43 virtualMachine(
std::move(theVirtualMachine)), execute(theExecute), pool(thePool) {}
51 Job(Pool * thePool, jobject theJob): pool(thePool), job(theJob) {}
57void throwOutOfMemory(JNIEnv * env) {
58 jclass c =
env->FindClass(
"java/lang/OutOfMemoryError");
69 Job * job =
static_cast< Job *
>(data);
76 env->CallObjectMethod(job->job, job->pool->execute);
77 env->DeleteGlobalRef(job->job);
87extern "C" SAL_JNI_EXPORT jbyteArray JNICALL
94 rtl::ByteSequence seq(s);
95 rtl_byte_sequence_release(s);
96 sal_Int32
n = seq.getLength();
97 jbyteArray
a =
env->NewByteArray(
n);
102 void *
p =
env->GetPrimitiveArrayCritical(
a,
nullptr);
106 memcpy(
p, seq.getConstArray(),
n);
108 env->ReleasePrimitiveArrayCritical(
a,
p, 0);
112extern "C" SAL_JNI_EXPORT jlong JNICALL
117 if (
env->GetJavaVM(&vm) != JNI_OK) {
118 jclass c =
env->FindClass(
"java/lang/RuntimeException");
120 env->ThrowNew(c,
"JNI GetJavaVM failed");
124 jclass c =
env->FindClass(
"com/sun/star/lib/uno/environments/remote/Job");
128 jmethodID execute =
env->GetMethodID(c,
"execute",
"()Ljava/lang/Object;");
129 if (execute ==
nullptr) {
133 return reinterpret_cast< jlong
>(
new Pool(
136 }
catch (
const std::bad_alloc &) {
137 throwOutOfMemory(
env);
142extern "C" SAL_JNI_EXPORT
void JNICALL
144 SAL_UNUSED_PARAMETER JNIEnv *, SAL_UNUSED_PARAMETER jclass, jlong pool)
150extern "C" SAL_JNI_EXPORT jobject JNICALL
156 reinterpret_cast< Pool *
>(pool)->pool,
157 reinterpret_cast< void **
>(&job));
158 if (job ==
nullptr) {
161 jobject ref =
env->NewLocalRef(job);
162 env->DeleteGlobalRef(job);
166extern "C" SAL_JNI_EXPORT
void JNICALL
168 SAL_UNUSED_PARAMETER JNIEnv *, SAL_UNUSED_PARAMETER jclass, jlong pool)
174extern "C" SAL_JNI_EXPORT
void JNICALL
176 JNIEnv * env, SAL_UNUSED_PARAMETER jclass, jlong pool, jbyteArray threadId,
179 void * s =
env->GetPrimitiveArrayCritical(threadId,
nullptr);
183 rtl::ByteSequence seq(
184 static_cast< sal_Int8 *
>(s),
env->GetArrayLength(threadId));
188 env->ReleasePrimitiveArrayCritical(threadId, s, JNI_ABORT);
189 Pool *
p =
reinterpret_cast< Pool *
>(pool);
190 jobject ref =
env->NewGlobalRef(job);
191 if (ref ==
nullptr) {
196 j =
new(std::nothrow) Job(
p, ref);
198 env->DeleteGlobalRef(ref);
199 throwOutOfMemory(
env);
204 p->pool, seq.getHandle(),
205 request ?
static_cast< void *
>(j) :
static_cast< void *
>(ref),
209extern "C" SAL_JNI_EXPORT
void JNICALL
211 SAL_UNUSED_PARAMETER JNIEnv *, SAL_UNUSED_PARAMETER jclass, jlong pool)
217extern "C" SAL_JNI_EXPORT
void JNICALL
219 SAL_UNUSED_PARAMETER JNIEnv *, SAL_UNUSED_PARAMETER jclass, jlong pool)
222 Pool *
p =
reinterpret_cast< Pool *
>(pool);
JNIEnv * getEnvironment() const
const css::uno::Reference< css::xml::crypto::XSecurityEnvironment > & env
SAL_JNI_EXPORT jobject JNICALL Java_com_sun_star_lib_uno_environments_remote_NativeThreadPool_enter(JNIEnv *env, SAL_UNUSED_PARAMETER jclass, jlong pool) SAL_THROW_EXTERN_C()
static void executeRequest(void *data)
SAL_JNI_EXPORT jbyteArray JNICALL Java_com_sun_star_lib_uno_environments_remote_NativeThreadPool_threadId(JNIEnv *env, SAL_UNUSED_PARAMETER jclass) SAL_THROW_EXTERN_C()
SAL_JNI_EXPORT void JNICALL Java_com_sun_star_lib_uno_environments_remote_NativeThreadPool_detach(SAL_UNUSED_PARAMETER JNIEnv *, SAL_UNUSED_PARAMETER jclass, jlong pool) SAL_THROW_EXTERN_C()
SAL_JNI_EXPORT void JNICALL Java_com_sun_star_lib_uno_environments_remote_NativeThreadPool_dispose(SAL_UNUSED_PARAMETER JNIEnv *, SAL_UNUSED_PARAMETER jclass, jlong pool) SAL_THROW_EXTERN_C()
SAL_JNI_EXPORT jlong JNICALL Java_com_sun_star_lib_uno_environments_remote_NativeThreadPool_create(JNIEnv *env, SAL_UNUSED_PARAMETER jclass) SAL_THROW_EXTERN_C()
SAL_JNI_EXPORT void JNICALL Java_com_sun_star_lib_uno_environments_remote_NativeThreadPool_putJob(JNIEnv *env, SAL_UNUSED_PARAMETER jclass, jlong pool, jbyteArray threadId, jobject job, jboolean request, jboolean oneWay) SAL_THROW_EXTERN_C()
SAL_JNI_EXPORT void JNICALL Java_com_sun_star_lib_uno_environments_remote_NativeThreadPool_destroy(SAL_UNUSED_PARAMETER JNIEnv *, SAL_UNUSED_PARAMETER jclass, jlong pool) SAL_THROW_EXTERN_C()
SAL_JNI_EXPORT void JNICALL Java_com_sun_star_lib_uno_environments_remote_NativeThreadPool_attach(SAL_UNUSED_PARAMETER JNIEnv *, SAL_UNUSED_PARAMETER jclass, jlong pool) SAL_THROW_EXTERN_C()
void SAL_CALL uno_releaseIdFromCurrentThread() SAL_THROW_EXTERN_C()
void SAL_CALL uno_getIdOfCurrentThread(sal_Sequence **ppThreadId) SAL_THROW_EXTERN_C()
void SAL_CALL uno_threadpool_enter(uno_ThreadPool hPool, void **ppJob) SAL_THROW_EXTERN_C()
uno_ThreadPool SAL_CALL uno_threadpool_create() SAL_THROW_EXTERN_C()
void SAL_CALL uno_threadpool_detach(SAL_UNUSED_PARAMETER uno_ThreadPool) SAL_THROW_EXTERN_C()
void SAL_CALL uno_threadpool_putJob(uno_ThreadPool hPool, sal_Sequence *pThreadId, void *pJob, void(SAL_CALL *doRequest)(void *pThreadSpecificData), sal_Bool bIsOneway) SAL_THROW_EXTERN_C()
void SAL_CALL uno_threadpool_attach(uno_ThreadPool hPool) SAL_THROW_EXTERN_C()
void SAL_CALL uno_threadpool_destroy(uno_ThreadPool hPool) SAL_THROW_EXTERN_C()
void SAL_CALL uno_threadpool_dispose(uno_ThreadPool hPool) SAL_THROW_EXTERN_C()
#define SAL_THROW_EXTERN_C()