SDL_DirectFB_dyn.c (3654B)
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#include "../../SDL_internal.h" 22 23#if SDL_VIDEO_DRIVER_DIRECTFB 24 25#include "SDL_DirectFB_video.h" 26#include "SDL_DirectFB_dyn.h" 27 28#ifdef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC 29#include "SDL_name.h" 30#include "SDL_loadso.h" 31 32#define DFB_SYM(ret, name, args, al, func) ret (*name) args; 33static struct _SDL_DirectFB_Symbols 34{ 35 DFB_SYMS 36 const unsigned int *directfb_major_version; 37 const unsigned int *directfb_minor_version; 38 const unsigned int *directfb_micro_version; 39} SDL_DirectFB_Symbols; 40#undef DFB_SYM 41 42#define DFB_SYM(ret, name, args, al, func) ret name args { func SDL_DirectFB_Symbols.name al ; } 43DFB_SYMS 44#undef DFB_SYM 45 46static void *handle = NULL; 47 48int 49SDL_DirectFB_LoadLibrary(void) 50{ 51 int retval = 0; 52 53 if (handle == NULL) { 54 handle = SDL_LoadObject(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC); 55 if (handle != NULL) { 56 retval = 1; 57#define DFB_SYM(ret, name, args, al, func) if (!(SDL_DirectFB_Symbols.name = SDL_LoadFunction(handle, # name))) retval = 0; 58 DFB_SYMS 59#undef DFB_SYM 60 if (! 61 (SDL_DirectFB_Symbols.directfb_major_version = 62 SDL_LoadFunction(handle, "directfb_major_version"))) 63 retval = 0; 64 if (! 65 (SDL_DirectFB_Symbols.directfb_minor_version = 66 SDL_LoadFunction(handle, "directfb_minor_version"))) 67 retval = 0; 68 if (! 69 (SDL_DirectFB_Symbols.directfb_micro_version = 70 SDL_LoadFunction(handle, "directfb_micro_version"))) 71 retval = 0; 72 } 73 } 74 if (retval) { 75 const char *stemp = DirectFBCheckVersion(DIRECTFB_MAJOR_VERSION, 76 DIRECTFB_MINOR_VERSION, 77 DIRECTFB_MICRO_VERSION); 78 /* Version Check */ 79 if (stemp != NULL) { 80 fprintf(stderr, 81 "DirectFB Lib: Version mismatch. Compiled: %d.%d.%d Library %d.%d.%d\n", 82 DIRECTFB_MAJOR_VERSION, DIRECTFB_MINOR_VERSION, 83 DIRECTFB_MICRO_VERSION, 84 *SDL_DirectFB_Symbols.directfb_major_version, 85 *SDL_DirectFB_Symbols.directfb_minor_version, 86 *SDL_DirectFB_Symbols.directfb_micro_version); 87 retval = 0; 88 } 89 } 90 if (!retval) 91 SDL_DirectFB_UnLoadLibrary(); 92 return retval; 93} 94 95void 96SDL_DirectFB_UnLoadLibrary(void) 97{ 98 if (handle != NULL) { 99 SDL_UnloadObject(handle); 100 handle = NULL; 101 } 102} 103 104#else 105int 106SDL_DirectFB_LoadLibrary(void) 107{ 108 return 1; 109} 110 111void 112SDL_DirectFB_UnLoadLibrary(void) 113{ 114} 115#endif 116 117#endif /* SDL_VIDEO_DRIVER_DIRECTFB */