Hi again, as we in our work target a large number of possible hardware platforms with various OS and software versions we can not be sure about paths for DirectFB modules. Even if we deliver necessary DirectFB libraries and modules with our software the customers may want to place the software package in very different locations than we thought about. Since DirectFB uses a hard coded path to the module directory this causes problems.
Attached there is a patch containing code that we have used to solve this for some time. It iterates through the LD_LIBRARY_PATH and searches each element there for a directfb folder. If it is found this is used when loading modules. Is there any other way to gain the same functionality already? If not, would it be possible to add something like this to future versions? I think this functionality is very positive for users like us, since target devices look very different. With best regards, Anders Karlsson <[EMAIL PROTECTED]>
diff -rupN DirectFB-1.2.3.orig/lib/direct/modules.c DirectFB-1.2.3/lib/direct/modules.c --- DirectFB-1.2.3.orig/lib/direct/modules.c 2008-06-02 08:07:44.000000000 +0200 +++ DirectFB-1.2.3/lib/direct/modules.c 2008-09-30 16:40:23.000000000 +0200 @@ -39,6 +39,9 @@ #include <direct/messages.h> #include <direct/modules.h> +#include <stdlib.h> +#include <string.h> + #ifdef PIC #define DYNAMIC_LINKING #endif @@ -47,6 +50,73 @@ #include <dlfcn.h> #endif +char *find_module_directory(const char *p) +{ + static char *path = NULL; + // The directory name we will be looking for. + char *target = NULL; +#if defined D_DEBUG_ENABLED && D_DEBUG_ENABLED == 1 + target = "/directfb-1.2-0-debug/"; +#else + target = "/directfb-1.2-0/"; +#endif // D_DEBUG_ENABLED == 1 + char *ld_lib_path = getenv("LD_LIBRARY_PATH"); + int go = 1, found = 0; + char *cur_path = ld_lib_path; + int cur_path_len = 0; + while (go) { + char *next_colon = strchr(cur_path, ':'); + if (!next_colon) { + // Don't look for another path after the current one, this is the last one. + go = 0; + next_colon = cur_path + strlen(cur_path); + } + cur_path_len = next_colon - cur_path; + + // No use checking an empty path. + if (cur_path_len > 0) { + char *target_path = NULL; + target_path = D_CALLOC(cur_path_len + strlen(target) + strlen(p) + 1, 1); + strncpy(target_path, cur_path, cur_path_len); + target_path[cur_path_len] = '\0'; + strcat(target_path, target); + strcat(target_path, p); + + // Go through the files in this directory, looking for the directfb directory. + DIR *cur_dir = opendir(target_path); + if (cur_dir) { + found = 1; + go = 0; + closedir(cur_dir); + } + D_FREE(target_path); + } + + if (go) { + cur_path += cur_path_len+1; + } + } + + static char *ret = NULL; + if (found) { + if (ret) { + D_FREE(ret); + ret = NULL; + } + ret = D_CALLOC(cur_path_len + strlen(target) + strlen(p) + 1, 1); + strncpy(ret, cur_path, cur_path_len); + ret[cur_path_len] = '\0'; + strcat(ret, target); + strcat(ret, p); + + return ret; + } + + D_PERROR("Direct/Modules: Could not find module directory in path!\n"); + return NULL; +} + + D_DEBUG_DOMAIN( Direct_Modules, "Direct/Modules", "Module loading and registration" ); /******************************************************************************/ diff -rupN DirectFB-1.2.3.orig/lib/direct/modules.h DirectFB-1.2.3/lib/direct/modules.h --- DirectFB-1.2.3.orig/lib/direct/modules.h 2008-06-02 08:07:44.000000000 +0200 +++ DirectFB-1.2.3/lib/direct/modules.h 2008-09-30 16:40:25.000000000 +0200 @@ -78,6 +78,8 @@ struct __D_DirectModuleDir { loading: NULL \ } +char *find_module_directory( const char *p ); + int direct_modules_explore_directory( DirectModuleDir *directory ); void direct_modules_register( DirectModuleDir *directory, diff -rupN DirectFB-1.2.3.orig/src/core/gfxcard.c DirectFB-1.2.3/src/core/gfxcard.c --- DirectFB-1.2.3.orig/src/core/gfxcard.c 2008-07-09 20:35:59.000000000 +0200 +++ DirectFB-1.2.3/src/core/gfxcard.c 2008-09-30 16:45:29.000000000 +0200 @@ -198,7 +198,11 @@ dfb_graphics_core_initialize( CoreDFB } /* Build a list of available drivers. */ - direct_modules_explore_directory( &dfb_graphics_drivers ); + dfb_graphics_drivers.path = find_module_directory("gfxdrivers"); + if (dfb_graphics_drivers.path) { + direct_modules_explore_directory( &dfb_graphics_drivers ); + } + dfb_graphics_drivers.path = NULL; /* Load driver */ if (dfb_system_caps() & CSCAPS_ACCELERATION) diff -rupN DirectFB-1.2.3.orig/src/core/input.c DirectFB-1.2.3/src/core/input.c --- DirectFB-1.2.3.orig/src/core/input.c 2008-07-25 16:10:08.000000000 +0200 +++ DirectFB-1.2.3/src/core/input.c 2008-09-30 16:47:52.000000000 +0200 @@ -29,7 +29,6 @@ #include <config.h> #include <stdio.h> -#include <stdlib.h> #include <unistd.h> #include <sys/types.h> @@ -376,8 +375,12 @@ dfb_input_core_initialize( CoreDFB data->core = core; data->shared = shared; - - direct_modules_explore_directory( &dfb_input_modules ); + // Find the path that contains the input driver modules. + dfb_input_modules.path = find_module_directory("inputdrivers"); + if (dfb_input_modules.path) { + direct_modules_explore_directory( &dfb_input_modules ); + } + dfb_input_modules.path = NULL; init_devices( core ); diff -rupN DirectFB-1.2.3.orig/src/core/system.c DirectFB-1.2.3/src/core/system.c --- DirectFB-1.2.3.orig/src/core/system.c 2008-06-02 08:07:44.000000000 +0200 +++ DirectFB-1.2.3/src/core/system.c 2008-09-30 16:47:57.000000000 +0200 @@ -270,7 +270,12 @@ dfb_system_lookup() { DirectLink *l; - direct_modules_explore_directory( &dfb_core_systems ); + // Find the path that contains the systems modules. + dfb_core_systems.path = find_module_directory("systems"); + if (dfb_core_systems.path) { + direct_modules_explore_directory( &dfb_core_systems ); + } + dfb_core_systems.path = NULL; direct_list_foreach( l, dfb_core_systems.entries ) { DirectModuleEntry *module = (DirectModuleEntry*) l; diff -rupN DirectFB-1.2.3.orig/src/core/wm.c DirectFB-1.2.3/src/core/wm.c --- DirectFB-1.2.3.orig/src/core/wm.c 2008-08-19 11:25:16.000000000 +0200 +++ DirectFB-1.2.3/src/core/wm.c 2008-09-30 16:48:04.000000000 +0200 @@ -453,7 +453,12 @@ load_module( const char *name ) D_ASSERT( wm_local != NULL ); - direct_modules_explore_directory( &dfb_core_wm_modules ); + // Find the path that contains the input driver modules. + dfb_core_wm_modules.path = find_module_directory("wm"); + if (dfb_core_wm_modules.path) { + direct_modules_explore_directory( &dfb_core_wm_modules ); + } + dfb_core_wm_modules.path = NULL; direct_list_foreach( l, dfb_core_wm_modules.entries ) { DirectModuleEntry *module = (DirectModuleEntry*) l;
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ directfb-dev mailing list directfb-dev@directfb.org http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev