omx_create_loaders_linux.c

Go to the documentation of this file.
00001 
00031 #define _GNU_SOURCE
00032 #include <stdlib.h>
00033 #include <dlfcn.h>
00034 #include <string.h>
00035 #include "component_loader.h"
00036 #include "omx_create_loaders.h"
00037 #include "omxcore.h"
00038 #include "st_static_component_loader.h"
00039 
00040 int 
00041 createComponentLoaders()
00042 {
00043     // load component loaders
00044     BOSA_COMPONENTLOADER *loader;
00045     void *handle;
00046     void *functionPointer;
00047     void (*fptr)(BOSA_COMPONENTLOADER *loader);
00048     char loaderFile[200];
00049     char *libraryFileName = NULL;
00050     FILE *loaderFP;
00051     size_t len = 0;
00052     int read;
00053     
00054     /* add the ST static component loader */
00055     st_static_InitComponentLoader();
00056     BOSA_AddComponentLoader(st_static_loader);
00057     
00058     // open file containing loader library names ($HOME/.omxloaders)
00059     DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00060     memset(loaderFile, 0, sizeof(loaderFile));
00061     strcat(loaderFile, getenv("HOME"));
00062     strcat(loaderFile, "/.omxloaders");
00063 
00064     loaderFP = fopen(loaderFile, "r");
00065     if (loaderFP == NULL)
00066     {
00067         //DEBUG(DEB_LEV_ERR, "Could not open .omxloaders file\n");
00068         return -1;
00069     }
00070     
00071     // dlopen all loaders defined in .omxloaders file
00072     while((read = getline(&libraryFileName, &len, loaderFP)) != -1) 
00073     {
00074         // strip delimeter, the dlopen doesn't like it
00075         if(libraryFileName[read-1] == '\n')
00076             libraryFileName[read-1] = 0;
00077             
00078         handle = dlopen(libraryFileName, RTLD_NOW);
00079         
00080         if (!handle)
00081         {
00082             DEBUG(DEB_LEV_ERR, "library %s dlopen error: %s\n", libraryFileName, dlerror());
00083             exit(1);
00084         }
00085 
00086         if ((functionPointer = dlsym(handle, "setup_component_loader")) == NULL)
00087         {
00088                 DEBUG(DEB_LEV_ERR, "the library %s is not compatible - %s\n", libraryFileName, dlerror());
00089                 exit(1);
00090         }
00091         fptr = functionPointer;
00092 
00093         loader = (BOSA_COMPONENTLOADER *) calloc(1, sizeof(BOSA_COMPONENTLOADER));
00094 
00095         if (loader == NULL) 
00096         {
00097                 DEBUG(DEB_LEV_ERR, "not enough memory for this loader\n");
00098                 exit(1);
00099         }
00100 
00101         /* setup the function pointers */
00102         (*fptr)(loader);
00103 
00104         /* add loader to core */
00105         BOSA_AddComponentLoader(loader);
00106     }
00107 
00108     if (libraryFileName)
00109     {
00110         free(libraryFileName);
00111     }
00112     
00113     fclose(loaderFP);
00114 
00115     return 0;
00116 }

Generated for OpenMAX Bellagio rel. 0.3.5-svn by  doxygen 1.5.1
SourceForge.net Logo