Bump version to 6.4-15
[LibreOffice.git] / jurt / source / pipe / wrapper / wrapper.c
blob83e70dc6fb8434f2dd0fa5e48823d4305fd4eda3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <stddef.h>
23 #include <stdlib.h>
25 #define WIN32_LEAN_AND_MEAN
26 #include <windows.h>
28 #include <jni.h>
29 #include <sal/types.h>
32 static HMODULE module = NULL;
33 static HINSTANCE hInstDLL = NULL;
34 static CRITICAL_SECTION CriticalSection;
36 static void InitWrapper(void) {
37 #define MAXPATH 512
38 wchar_t path[MAXPATH];
39 DWORD size;
41 size = GetModuleFileNameW(hInstDLL, path, MAXPATH);
42 if (size == 0) {
43 abort();
45 path[size - 5] = L'x'; /* ...\jpipe.dll -> ...\jpipx.dll */
46 module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
47 if (module == NULL) {
48 abort();
52 static FARPROC getFunction(char const * name)
55 EnterCriticalSection(&CriticalSection);
57 if(module == NULL)
58 InitWrapper();
60 LeaveCriticalSection(&CriticalSection);
63 return GetProcAddress(module, name);
66 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
67 (void) lpvReserved;
69 if (fdwReason == DLL_PROCESS_ATTACH)
71 InitializeCriticalSection(&CriticalSection);
72 hInstDLL = hinstDLL;
75 return TRUE;
78 SAL_DLLPUBLIC_EXPORT void JNICALL
79 Java_com_sun_star_lib_connections_pipe_PipeConnection_createJNI(
80 JNIEnv * env, jobject obj_this, jstring name)
82 (*(void (*)(JNIEnv *, jobject, jstring))
83 getFunction("PipeConnection_create"))(env, obj_this, name);
86 SAL_DLLPUBLIC_EXPORT void JNICALL
87 Java_com_sun_star_lib_connections_pipe_PipeConnection_closeJNI(
88 JNIEnv * env, jobject obj_this)
90 (*(void (*)(JNIEnv *, jobject))
91 getFunction("PipeConnection_close"))(env, obj_this);
94 SAL_DLLPUBLIC_EXPORT jint JNICALL
95 Java_com_sun_star_lib_connections_pipe_PipeConnection_readJNI(
96 JNIEnv * env, jobject obj_this, jobjectArray buffer, jint len)
98 return (*(jint (*)(JNIEnv *, jobject, jobjectArray, jint))
99 getFunction("PipeConnection_read"))(env, obj_this, buffer, len);
102 SAL_DLLPUBLIC_EXPORT void JNICALL
103 Java_com_sun_star_lib_connections_pipe_PipeConnection_writeJNI(
104 JNIEnv * env, jobject obj_this, jbyteArray buffer)
106 (*(void (*)(JNIEnv *, jobject, jbyteArray))
107 getFunction("PipeConnection_write"))(env, obj_this, buffer);
110 SAL_DLLPUBLIC_EXPORT void JNICALL
111 Java_com_sun_star_lib_connections_pipe_PipeConnection_flushJNI(
112 JNIEnv * env, jobject obj_this)
114 (*(void (*)(JNIEnv *, jobject))
115 getFunction("PipeConnection_flush"))(env, obj_this);
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */