OpenMAXBellagio  0.9.3
omx_create_loaders_linux.c
Go to the documentation of this file.
1 
28 #define _GNU_SOURCE
29 #include <stdlib.h>
30 #include <dlfcn.h>
31 #include <dirent.h>
32 #include <string.h>
33 #include "component_loader.h"
34 #include "omx_create_loaders.h"
36 #include "common.h"
37 
38 #define OMX_LOADERS_FILENAME ".omxloaders"
39 
40 #ifndef OMX_LOADERS_DIRNAME
41 #define OMX_LOADERS_DIRNAME "/usr/lib/omxloaders/"
42 #endif
43 
44 #ifndef INSTALL_PATH_STR
45 #define INSTALL_PATH_STR "/usr/local/lib/bellagio"
46 #endif
47 
59  // load component loaders
60  BOSA_COMPONENTLOADER *loader;
61  DIR *dirp_name;
62  struct dirent *dp;
63  void *handle;
64  void *functionPointer;
65  void (*fptr)(BOSA_COMPONENTLOADER *loader);
66  char *libraryFileName = NULL;
67  FILE *loaderFP;
68  char *omxloader_registry_filename;
69  int onlyDefault = 0;
70  int index_readline;
71  int isFileExisting = 0;
72  int isDirExisting = 0;
73 
74  omxloader_registry_filename = loadersRegistryGetFilename(OMX_LOADERS_FILENAME);
75 
76  isFileExisting = exists(omxloader_registry_filename);
77 
78  isDirExisting = exists(OMX_LOADERS_DIRNAME);
79 
80  /* test the existence of the file */
81  if (!isDirExisting && !isFileExisting) {
82  onlyDefault = 1;
83  }
84 
85  if (onlyDefault) {
86  loader = calloc(1, sizeof(BOSA_COMPONENTLOADER));
87  if (loader == NULL) {
88  DEBUG(DEB_LEV_ERR, "not enough memory for this loader\n");
90  }
93  return 0;
94  }
95  if (isFileExisting) {
96  loaderFP = fopen(omxloader_registry_filename, "r");
97  // dlopen all loaders defined in .omxloaders file
98  libraryFileName = malloc(MAX_LINE_LENGTH);
99  while(1) {
100  index_readline = 0;
101  while(index_readline < MAX_LINE_LENGTH) {
102  *(libraryFileName + index_readline) = fgetc(loaderFP);
103  if ((*(libraryFileName + index_readline) == '\n') || (*(libraryFileName + index_readline) == '\0')) {
104  break;
105  }
106  index_readline++;
107  }
108  *(libraryFileName + index_readline) = '\0';
109  if ((index_readline >= MAX_LINE_LENGTH) || (index_readline == 0)) {
110  break;
111  }
112 
113  handle = dlopen(libraryFileName, RTLD_NOW);
114 
115  if (!handle) {
116  DEBUG(DEB_LEV_ERR, "library %s dlopen error: %s\n", libraryFileName, dlerror());
117  continue;
118  }
119 
120  if ((functionPointer = dlsym(handle, "setup_component_loader")) == NULL) {
121  DEBUG(DEB_LEV_ERR, "the library %s is not compatible - %s\n", libraryFileName, dlerror());
122  continue;
123  }
124  fptr = functionPointer;
125 
126  loader = calloc(1, sizeof(BOSA_COMPONENTLOADER));
127 
128  if (loader == NULL) {
129  DEBUG(DEB_LEV_ERR, "not enough memory for this loader\n");
131  }
132 
133  /* setup the function pointers */
134  (*fptr)(loader);
135 
136  /* add loader to core */
137  BOSA_AddComponentLoader(loader);
138  }
139  if (libraryFileName) {
140  free(libraryFileName);
141  }
142  fclose(loaderFP);
143  }
144 
145  if (isDirExisting) {
146  dirp_name = opendir(OMX_LOADERS_DIRNAME);
147  while ((dp = readdir(dirp_name)) != NULL) {
148  int len = strlen(dp->d_name);
149  if(len >= 3) {
150  if(strncmp(dp->d_name+len-3, ".so", 3) == 0){
151  char lib_absolute_path[strlen(OMX_LOADERS_DIRNAME) + len + 1];
152  strcpy(lib_absolute_path, OMX_LOADERS_DIRNAME);
153  strcat(lib_absolute_path, dp->d_name);
154  handle = dlopen(lib_absolute_path, RTLD_NOW);
155  if (!handle) {
156  DEBUG(DEB_LEV_ERR, "library %s dlopen error: %s\n", lib_absolute_path, dlerror());
157  continue;
158  }
159  if ((functionPointer = dlsym(handle, "setup_component_loader")) == NULL) {
160  DEBUG(DEB_LEV_ERR, "the library %s is not compatible - %s\n", lib_absolute_path, dlerror());
161  continue;
162  }
163  fptr = functionPointer;
164  loader = calloc(1, sizeof(BOSA_COMPONENTLOADER));
165  if (loader == NULL) {
166  DEBUG(DEB_LEV_ERR, "not enough memory for this loader\n");
168  }
169  /* setup the function pointers */
170  (*fptr)(loader);
171  /* add loader to core */
172  BOSA_AddComponentLoader(loader);
173  }
174  }
175  }
176  closedir(dirp_name);
177  }
178  /* add the ST static component loader */
179  loader = calloc(1, sizeof(BOSA_COMPONENTLOADER));
180  if (loader == NULL) {
181  DEBUG(DEB_LEV_ERR, "not enough memory for this loader\n");
183  }
185  BOSA_AddComponentLoader(loader);
186 
187  free(omxloader_registry_filename);
188 
189  return 0;
190 }
#define OMX_LOADERS_DIRNAME
char * loadersRegistryGetFilename(char *registry_name)
Definition: common.c:119
void st_static_setup_component_loader(BOSA_COMPONENTLOADER *st_static_loader)
The initialization of the ST specific component loader.
int createComponentLoaders()
OMX_ERRORTYPE BOSA_AddComponentLoader(BOSA_COMPONENTLOADER *pLoader)
Definition: omxcore.c:64
OMX_HANDLETYPE handle
#define DEBUG(n, fmt, args...)
#define OMX_LOADERS_FILENAME
Component loader entry points.
#define DEB_LEV_ERR
int exists(const char *fname)
Definition: common.c:194
#define MAX_LINE_LENGTH
Definition: common.h:30

Generated for OpenMAX Bellagio rel. 0.9.3 by  doxygen 1.5.1
SourceForge.net Logo