|
OpenMAXBellagio 0.9.3
|
00001 00028 #define _GNU_SOURCE 00029 #include <stdlib.h> 00030 #include <dlfcn.h> 00031 #include <dirent.h> 00032 #include <string.h> 00033 #include "component_loader.h" 00034 #include "omx_create_loaders.h" 00035 #include "st_static_component_loader.h" 00036 #include "common.h" 00037 00038 #define OMX_LOADERS_FILENAME ".omxloaders" 00039 00040 #ifndef OMX_LOADERS_DIRNAME 00041 #define OMX_LOADERS_DIRNAME "/usr/lib/omxloaders/" 00042 #endif 00043 00044 #ifndef INSTALL_PATH_STR 00045 #define INSTALL_PATH_STR "/usr/local/lib/bellagio" 00046 #endif 00047 00058 int createComponentLoaders() { 00059 // load component loaders 00060 BOSA_COMPONENTLOADER *loader; 00061 DIR *dirp_name; 00062 struct dirent *dp; 00063 void *handle; 00064 void *functionPointer; 00065 void (*fptr)(BOSA_COMPONENTLOADER *loader); 00066 char *libraryFileName = NULL; 00067 FILE *loaderFP; 00068 char *omxloader_registry_filename; 00069 int onlyDefault = 0; 00070 int index_readline; 00071 int isFileExisting = 0; 00072 int isDirExisting = 0; 00073 00074 omxloader_registry_filename = loadersRegistryGetFilename(OMX_LOADERS_FILENAME); 00075 00076 isFileExisting = exists(omxloader_registry_filename); 00077 00078 isDirExisting = exists(OMX_LOADERS_DIRNAME); 00079 00080 /* test the existence of the file */ 00081 if (!isDirExisting && !isFileExisting) { 00082 onlyDefault = 1; 00083 } 00084 00085 if (onlyDefault) { 00086 loader = calloc(1, sizeof(BOSA_COMPONENTLOADER)); 00087 if (loader == NULL) { 00088 DEBUG(DEB_LEV_ERR, "not enough memory for this loader\n"); 00089 return OMX_ErrorInsufficientResources; 00090 } 00091 st_static_setup_component_loader(loader); 00092 BOSA_AddComponentLoader(loader); 00093 return 0; 00094 } 00095 if (isFileExisting) { 00096 loaderFP = fopen(omxloader_registry_filename, "r"); 00097 // dlopen all loaders defined in .omxloaders file 00098 libraryFileName = malloc(MAX_LINE_LENGTH); 00099 while(1) { 00100 index_readline = 0; 00101 while(index_readline < MAX_LINE_LENGTH) { 00102 *(libraryFileName + index_readline) = fgetc(loaderFP); 00103 if ((*(libraryFileName + index_readline) == '\n') || (*(libraryFileName + index_readline) == '\0')) { 00104 break; 00105 } 00106 index_readline++; 00107 } 00108 *(libraryFileName + index_readline) = '\0'; 00109 if ((index_readline >= MAX_LINE_LENGTH) || (index_readline == 0)) { 00110 break; 00111 } 00112 00113 handle = dlopen(libraryFileName, RTLD_NOW); 00114 00115 if (!handle) { 00116 DEBUG(DEB_LEV_ERR, "library %s dlopen error: %s\n", libraryFileName, dlerror()); 00117 continue; 00118 } 00119 00120 if ((functionPointer = dlsym(handle, "setup_component_loader")) == NULL) { 00121 DEBUG(DEB_LEV_ERR, "the library %s is not compatible - %s\n", libraryFileName, dlerror()); 00122 continue; 00123 } 00124 fptr = functionPointer; 00125 00126 loader = calloc(1, sizeof(BOSA_COMPONENTLOADER)); 00127 00128 if (loader == NULL) { 00129 DEBUG(DEB_LEV_ERR, "not enough memory for this loader\n"); 00130 return OMX_ErrorInsufficientResources; 00131 } 00132 00133 /* setup the function pointers */ 00134 (*fptr)(loader); 00135 00136 /* add loader to core */ 00137 BOSA_AddComponentLoader(loader); 00138 } 00139 if (libraryFileName) { 00140 free(libraryFileName); 00141 } 00142 fclose(loaderFP); 00143 } 00144 00145 if (isDirExisting) { 00146 dirp_name = opendir(OMX_LOADERS_DIRNAME); 00147 while ((dp = readdir(dirp_name)) != NULL) { 00148 int len = strlen(dp->d_name); 00149 if(len >= 3) { 00150 if(strncmp(dp->d_name+len-3, ".so", 3) == 0){ 00151 char lib_absolute_path[strlen(OMX_LOADERS_DIRNAME) + len + 1]; 00152 strcpy(lib_absolute_path, OMX_LOADERS_DIRNAME); 00153 strcat(lib_absolute_path, dp->d_name); 00154 handle = dlopen(lib_absolute_path, RTLD_NOW); 00155 if (!handle) { 00156 DEBUG(DEB_LEV_ERR, "library %s dlopen error: %s\n", lib_absolute_path, dlerror()); 00157 continue; 00158 } 00159 if ((functionPointer = dlsym(handle, "setup_component_loader")) == NULL) { 00160 DEBUG(DEB_LEV_ERR, "the library %s is not compatible - %s\n", lib_absolute_path, dlerror()); 00161 continue; 00162 } 00163 fptr = functionPointer; 00164 loader = calloc(1, sizeof(BOSA_COMPONENTLOADER)); 00165 if (loader == NULL) { 00166 DEBUG(DEB_LEV_ERR, "not enough memory for this loader\n"); 00167 return OMX_ErrorInsufficientResources; 00168 } 00169 /* setup the function pointers */ 00170 (*fptr)(loader); 00171 /* add loader to core */ 00172 BOSA_AddComponentLoader(loader); 00173 } 00174 } 00175 } 00176 closedir(dirp_name); 00177 } 00178 /* add the ST static component loader */ 00179 loader = calloc(1, sizeof(BOSA_COMPONENTLOADER)); 00180 if (loader == NULL) { 00181 DEBUG(DEB_LEV_ERR, "not enough memory for this loader\n"); 00182 return OMX_ErrorInsufficientResources; 00183 } 00184 st_static_setup_component_loader(loader); 00185 BOSA_AddComponentLoader(loader); 00186 00187 free(omxloader_registry_filename); 00188 00189 return 0; 00190 }