xref: /aoo42x/main/jurt/source/pipe/wrapper/wrapper.c (revision 6229858e)
15fa9200eSAndrew Rist /**************************************************************
25fa9200eSAndrew Rist  *
35fa9200eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45fa9200eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55fa9200eSAndrew Rist  * distributed with this work for additional information
65fa9200eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75fa9200eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
85fa9200eSAndrew Rist  * "License"); you may not use this file except in compliance
95fa9200eSAndrew Rist  * with the License.  You may obtain a copy of the License at
105fa9200eSAndrew Rist  *
115fa9200eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
125fa9200eSAndrew Rist  *
135fa9200eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
145fa9200eSAndrew Rist  * software distributed under the License is distributed on an
155fa9200eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165fa9200eSAndrew Rist  * KIND, either express or implied.  See the License for the
175fa9200eSAndrew Rist  * specific language governing permissions and limitations
185fa9200eSAndrew Rist  * under the License.
195fa9200eSAndrew Rist  *
205fa9200eSAndrew Rist  *************************************************************/
215fa9200eSAndrew Rist 
225fa9200eSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "sal/config.h"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <stddef.h>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <Windows.h>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "jni.h"
31cdf0e10cSrcweir #include "sal/types.h"
32cdf0e10cSrcweir 
33*6229858eSDamjan Jovanovic static HMODULE module;
34cdf0e10cSrcweir 
getFunction(char const * name)35*6229858eSDamjan Jovanovic static FARPROC getFunction(char const * name) {
36cdf0e10cSrcweir     return GetProcAddress(module, name);
37cdf0e10cSrcweir }
38cdf0e10cSrcweir 
DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)39cdf0e10cSrcweir BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
40cdf0e10cSrcweir     (void) lpvReserved;
41*6229858eSDamjan Jovanovic     if (fdwReason == DLL_PROCESS_ATTACH) {
42*6229858eSDamjan Jovanovic         wchar_t path[32767];
43*6229858eSDamjan Jovanovic         DWORD size;
44*6229858eSDamjan Jovanovic         size = GetModuleFileNameW(hinstDLL, path, 32767);
45*6229858eSDamjan Jovanovic         if (size == 0) {
46*6229858eSDamjan Jovanovic             return FALSE;
47*6229858eSDamjan Jovanovic         }
48*6229858eSDamjan Jovanovic         path[size - 5] = L'x'; /* ...\jpipe.dll -> ...\jpipx.dll */
49*6229858eSDamjan Jovanovic         module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
50*6229858eSDamjan Jovanovic         if (module == NULL) {
51*6229858eSDamjan Jovanovic             return FALSE;
52*6229858eSDamjan Jovanovic         }
53cdf0e10cSrcweir     }
54cdf0e10cSrcweir     return TRUE;
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void JNICALL
Java_com_sun_star_lib_connections_pipe_PipeConnection_createJNI(JNIEnv * env,jobject obj_this,jstring name)58cdf0e10cSrcweir Java_com_sun_star_lib_connections_pipe_PipeConnection_createJNI(
59cdf0e10cSrcweir     JNIEnv * env, jobject obj_this, jstring name)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     (*(void (*)(JNIEnv *, jobject, jstring))
62cdf0e10cSrcweir      getFunction("PipeConnection_create"))(env, obj_this, name);
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void JNICALL
Java_com_sun_star_lib_connections_pipe_PipeConnection_closeJNI(JNIEnv * env,jobject obj_this)66cdf0e10cSrcweir Java_com_sun_star_lib_connections_pipe_PipeConnection_closeJNI(
67cdf0e10cSrcweir     JNIEnv * env, jobject obj_this)
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     (*(void (*)(JNIEnv *, jobject))
70cdf0e10cSrcweir      getFunction("PipeConnection_close"))(env, obj_this);
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT jint JNICALL
Java_com_sun_star_lib_connections_pipe_PipeConnection_readJNI(JNIEnv * env,jobject obj_this,jobjectArray buffer,jint len)74cdf0e10cSrcweir Java_com_sun_star_lib_connections_pipe_PipeConnection_readJNI(
75cdf0e10cSrcweir     JNIEnv * env, jobject obj_this, jobjectArray buffer, jint len)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     return (*(jint (*)(JNIEnv *, jobject, jobjectArray, jint))
78cdf0e10cSrcweir             getFunction("PipeConnection_read"))(env, obj_this, buffer, len);
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void JNICALL
Java_com_sun_star_lib_connections_pipe_PipeConnection_writeJNI(JNIEnv * env,jobject obj_this,jbyteArray buffer)82cdf0e10cSrcweir Java_com_sun_star_lib_connections_pipe_PipeConnection_writeJNI(
83cdf0e10cSrcweir     JNIEnv * env, jobject obj_this, jbyteArray buffer)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir     (*(void (*)(JNIEnv *, jobject, jbyteArray))
86cdf0e10cSrcweir      getFunction("PipeConnection_write"))(env, obj_this, buffer);
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void JNICALL
Java_com_sun_star_lib_connections_pipe_PipeConnection_flushJNI(JNIEnv * env,jobject obj_this)90cdf0e10cSrcweir Java_com_sun_star_lib_connections_pipe_PipeConnection_flushJNI(
91cdf0e10cSrcweir     JNIEnv * env, jobject obj_this)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     (*(void (*)(JNIEnv *, jobject))
94cdf0e10cSrcweir      getFunction("PipeConnection_flush"))(env, obj_this);
95cdf0e10cSrcweir }
96