1 /* 2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #include <stdio.h> 27 #ifdef __WINDOWS__ 28 # include <stddef.h> 29 #else 30 # include <stdint.h> 31 #endif 32 33 #include "splashscreen.h" 34 35 extern void* SplashProcAddress(const char* name); /* in java_md.c */ 36 37 /* 38 * Prototypes of pointers to functions in splashscreen shared lib 39 */ 40 typedef int (*SplashLoadMemory_t)(void* pdata, int size); 41 typedef int (*SplashLoadFile_t)(const char* filename); 42 typedef void (*SplashInit_t)(void); 43 typedef void (*SplashClose_t)(void); 44 typedef void (*SplashSetFileJarName_t)(const char* fileName, 45 const char* jarName); 46 typedef void (*SplashSetScaleFactor_t)(float scaleFactor); 47 typedef char* (*SplashGetScaledImageName_t)(const char* fileName, 48 const char* jarName, float* scaleFactor); 49 50 /* 51 * This macro invokes a function from the shared lib. 52 * it locates a function with SplashProcAddress on demand. 53 * if SplashProcAddress fails, def value is returned. 54 * 55 * it is further wrapped with INVOKEV (works with functions which return 56 * void and INVOKE (for all other functions). INVOKEV looks a bit ugly, 57 * that's due being unable to return a value of type void in C. INVOKEV 58 * works around this by using semicolon instead of return operator. 59 */ 60 #define _INVOKE(name,def,ret) \ 61 static void* proc = NULL; \ 62 if (!proc) { proc = SplashProcAddress(#name); } \ 63 if (!proc) { return def; } \ 64 ret ((name##_t)proc) 65 66 #define INVOKE(name,def) _INVOKE(name,((intptr_t) def),return) 67 #define INVOKEP(name,def) _INVOKE(name,def,return) 68 #define INVOKEV(name) _INVOKE(name, ,;) 69 70 int DoSplashLoadMemory(void* pdata, int size) { 71 INVOKE(SplashLoadMemory, NULL)(pdata, size); 72 } 73 74 int DoSplashLoadFile(const char* filename) { 75 INVOKE(SplashLoadFile, NULL)(filename); 76 } 77 78 void DoSplashInit(void) { 79 INVOKEV(SplashInit)(); 80 } 81 82 void DoSplashClose(void) { 83 INVOKEV(SplashClose)(); 84 } 85 86 void DoSplashSetFileJarName(const char* fileName, const char* jarName) { 87 INVOKEV(SplashSetFileJarName)(fileName, jarName); 88 } 89 90 void DoSplashSetScaleFactor(float scaleFactor) { 91 INVOKEV(SplashSetScaleFactor)(scaleFactor); 92 } 93 94 char* DoSplashGetScaledImageName(const char* fileName, const char* jarName, 95 float* scaleFactor) { 96 INVOKEP(SplashGetScaledImageName, NULL)(fileName, jarName, scaleFactor); 97 } 98