fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / jurt / source / pipe / wrapper / wrapper.c
blob632b19afa08ac8a7f5a08da95141dfba34f84cb7
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>
24 #include <windows.h>
26 #include "jni.h"
27 #include "sal/types.h"
30 static HMODULE module = NULL;
31 static HINSTANCE hInstDLL = NULL;
32 static CRITICAL_SECTION CriticalSection;
34 void InitWrapper(void) {
35 #define MAXPATH 512
36 wchar_t path[MAXPATH];
37 DWORD size;
39 size = GetModuleFileNameW(hInstDLL, path, MAXPATH);
40 if (size == 0) {
41 abort();
43 path[size - 5] = L'x'; /* ...\jpipe.dll -> ...\jpipx.dll */
44 module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
45 if (module == NULL) {
46 abort();
50 static FARPROC getFunction(char const * name)
53 EnterCriticalSection(&CriticalSection);
55 if(module == NULL)
56 InitWrapper();
58 LeaveCriticalSection(&CriticalSection);
61 return GetProcAddress(module, name);
64 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
65 (void) lpvReserved;
67 if (fdwReason == DLL_PROCESS_ATTACH)
69 InitializeCriticalSection(&CriticalSection);
70 hInstDLL = hinstDLL;
73 return TRUE;
76 SAL_DLLPUBLIC_EXPORT void JNICALL
77 Java_com_sun_star_lib_connections_pipe_PipeConnection_createJNI(
78 JNIEnv * env, jobject obj_this, jstring name)
80 (*(void (*)(JNIEnv *, jobject, jstring))
81 getFunction("PipeConnection_create"))(env, obj_this, name);
84 SAL_DLLPUBLIC_EXPORT void JNICALL
85 Java_com_sun_star_lib_connections_pipe_PipeConnection_closeJNI(
86 JNIEnv * env, jobject obj_this)
88 (*(void (*)(JNIEnv *, jobject))
89 getFunction("PipeConnection_close"))(env, obj_this);
92 SAL_DLLPUBLIC_EXPORT jint JNICALL
93 Java_com_sun_star_lib_connections_pipe_PipeConnection_readJNI(
94 JNIEnv * env, jobject obj_this, jobjectArray buffer, jint len)
96 return (*(jint (*)(JNIEnv *, jobject, jobjectArray, jint))
97 getFunction("PipeConnection_read"))(env, obj_this, buffer, len);
100 SAL_DLLPUBLIC_EXPORT void JNICALL
101 Java_com_sun_star_lib_connections_pipe_PipeConnection_writeJNI(
102 JNIEnv * env, jobject obj_this, jbyteArray buffer)
104 (*(void (*)(JNIEnv *, jobject, jbyteArray))
105 getFunction("PipeConnection_write"))(env, obj_this, buffer);
108 SAL_DLLPUBLIC_EXPORT void JNICALL
109 Java_com_sun_star_lib_connections_pipe_PipeConnection_flushJNI(
110 JNIEnv * env, jobject obj_this)
112 (*(void (*)(JNIEnv *, jobject))
113 getFunction("PipeConnection_flush"))(env, obj_this);
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */