Changeset 5275:811818eb5b81 in roaraudio for libroar


Ignore:
Timestamp:
11/19/11 22:54:26 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Improved plugin loader a lot (Closes: #190)

Location:
libroar
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libroar/roardl.c

    r5270 r5275  
    4040#endif 
    4141 
     42struct roar_dl_lhandle { 
     43 struct roar_dl_librarypara * para; 
     44 struct roar_dl_libraryinst * lib; 
     45#if defined(ROAR_HAVE_LIBDL) 
     46 void * handle; 
     47#endif 
     48}; 
     49 
     50 
     51struct roar_dl_librarypara * roar_dl_para_new(const char * args, void * binargv, 
     52                                              const char * appname, const char * abiversion) { 
     53 struct roar_dl_librarypara * ret = roar_mm_malloc(sizeof(struct roar_dl_librarypara)); 
     54 ssize_t argc; 
     55 int err; 
     56 
     57 if ( ret == NULL ) 
     58  return NULL; 
     59 
     60 memset(ret, 0, sizeof(struct roar_dl_librarypara)); 
     61 
     62 ret->version    = ROAR_DL_LIBPARA_VERSION; 
     63 ret->len        = sizeof(struct roar_dl_librarypara); 
     64 ret->refc       = 1; 
     65 ret->argc       = 0; 
     66 ret->argv       = NULL; 
     67 ret->args_store = NULL; 
     68 ret->binargv    = binargv; 
     69 ret->appname    = appname; 
     70 ret->abiversion = abiversion; 
     71 
     72 if ( args != NULL ) { 
     73  ret->args_store = roar_mm_strdup(args); 
     74  if ( ret->args_store == NULL ) { 
     75   err = roar_error; 
     76   roar_mm_free(ret); 
     77   roar_error = err; 
     78   return NULL; 
     79  } 
     80 
     81  argc = roar_keyval_split(&(ret->argv), ret->args_store, NULL, NULL, 0); 
     82  if ( argc == -1 ) { 
     83   err = roar_error; 
     84   roar_mm_free(ret->args_store); 
     85   roar_mm_free(ret); 
     86   roar_error = err; 
     87   return NULL; 
     88  } 
     89 
     90  ret->argc = argc; 
     91 } 
     92 
     93 return ret; 
     94} 
     95 
     96int roar_dl_para_ref                    (struct roar_dl_librarypara * para) { 
     97 if ( para == NULL ) { 
     98  roar_err_set(ROAR_ERROR_FAULT); 
     99  return -1; 
     100 } 
     101 
     102 para->refc++; 
     103 
     104 return 0; 
     105} 
     106 
     107int roar_dl_para_unref                  (struct roar_dl_librarypara * para) { 
     108 if ( para == NULL ) { 
     109  roar_err_set(ROAR_ERROR_FAULT); 
     110  return -1; 
     111 } 
     112 
     113 para->refc--; 
     114 
     115 if ( para->refc == 0 ) { 
     116  if ( para->args_store != NULL ) { 
     117   roar_mm_free(para->args_store); 
     118   roar_mm_free(para->argv); 
     119  } 
     120  roar_mm_free(para); 
     121 } 
     122 
     123 return 0; 
     124} 
     125int roar_dl_para_check_version          (struct roar_dl_librarypara * para, 
     126                                         const char * appname, const char * abiversion) { 
     127 if ( para == NULL ) { 
     128  roar_err_set(ROAR_ERROR_FAULT); 
     129  return -1; 
     130 } 
     131 
     132 // check if both appnames are NULL or non-NULL. 
     133 if ( (para->appname == NULL && appname != NULL) || (para->appname != NULL && appname == NULL) ) { 
     134  roar_err_set(ROAR_ERROR_BADVERSION); 
     135  return -1; 
     136 } 
     137 
     138 // check if the appname matches if given. 
     139 if ( para->appname != NULL && !!strcmp(para->appname, appname) ) { 
     140  roar_err_set(ROAR_ERROR_BADVERSION); 
     141  return -1; 
     142 } 
     143 
     144 // check if both ABI versions are NULL or non-NULL. 
     145 if ( (para->abiversion == NULL && abiversion != NULL) || (para->abiversion != NULL && abiversion == NULL) ) { 
     146  roar_err_set(ROAR_ERROR_BADVERSION); 
     147  return -1; 
     148 } 
     149 
     150 // check if the ABI versions matches if given. 
     151 if ( para->abiversion != NULL && !!strcmp(para->abiversion, abiversion) ) { 
     152  roar_err_set(ROAR_ERROR_BADVERSION); 
     153  return -1; 
     154 } 
     155 
     156 return 0; 
     157} 
     158 
     159 
    42160#if defined(ROAR_HAVE_LIBDL) 
    43161static void * _roardl2ldl (struct roar_dl_lhandle * lhandle) { 
     
    52170#endif 
    53171 
    54 struct roar_dl_lhandle * roar_dl_open(const char * filename, int flags, int ra_init) { 
     172struct roar_dl_lhandle * roar_dl_open(const char * filename, int flags, 
     173                                      int ra_init, struct roar_dl_librarypara * para) { 
    55174 struct roar_dl_lhandle * ret = NULL; 
     175 int err; 
    56176 
    57177 // early errors just return. 
    58178 
    59  if ( flags != ROAR_DL_FLAG_DEFAUTS ) 
    60   return NULL; 
     179 if ( flags != ROAR_DL_FLAG_DEFAUTS ) { 
     180  roar_err_set(ROAR_ERROR_NOTSUP); 
     181  return NULL; 
     182 } 
    61183 
    62184 if ( (ret = roar_mm_malloc(sizeof(struct roar_dl_lhandle))) == NULL ) 
     
    80202#else 
    81203 roar_mm_free(ret); 
     204 roar_err_set(ROAR_ERROR_NOSYS); 
    82205 return NULL; 
    83206#endif 
    84207 
    85  if ( ret == NULL ) 
    86   return NULL; 
     208 ret->para = para; 
    87209 
    88210 if ( ra_init ) { 
    89   roar_dl_ra_init(ret, NULL); 
    90  } 
     211  if ( roar_dl_ra_init(ret, NULL, para) == -1 ) { 
     212   err = roar_error; 
     213   ROAR_WARN("roar_dl_open(filename='%s', flags=%i, ra_init=%i, para=%p): Can not init RA lib: %s", filename, flags, ra_init, para, roar_error2str(err)); 
     214#if defined(ROAR_HAVE_LIBDL) 
     215   dlclose(ret->handle); 
     216#endif 
     217   roar_mm_free(ret); 
     218   roar_error = err; 
     219   return NULL; 
     220  } 
     221 } 
     222 
     223 if ( para != NULL ) 
     224  roar_dl_para_ref(para); 
    91225 
    92226 return ret; 
     
    96230 int ret = -1; 
    97231 
    98  if ( lhandle == ROAR_DL_HANDLE_DEFAULT ) 
    99   return -1; 
    100  if ( lhandle == ROAR_DL_HANDLE_NEXT ) 
    101   return -1; 
     232 if ( lhandle == ROAR_DL_HANDLE_DEFAULT || lhandle == ROAR_DL_HANDLE_NEXT ) { 
     233  roar_err_set(ROAR_ERROR_BADFH); 
     234  return -1; 
     235 } 
    102236 
    103237 if ( lhandle->lib != NULL && lhandle->lib->unload != NULL ) 
     
    110244#endif 
    111245 
     246 if ( lhandle->para != NULL ) 
     247  roar_dl_para_unref(lhandle->para); 
     248 
    112249 roar_mm_free(lhandle); 
    113250 
     
    129266} 
    130267 
    131 int                      roar_dl_ra_init(struct roar_dl_lhandle * lhandle, const char * prefix) { 
     268int                      roar_dl_ra_init(struct roar_dl_lhandle * lhandle, 
     269                                         const char * prefix, 
     270                                         struct roar_dl_librarypara * para) { 
    132271#define _SUFFIX "_roaraudio_library_init" 
    133272 char name[80] = _SUFFIX; 
    134273 struct roar_dl_libraryinst * (*func)(struct roar_dl_librarypara * para); 
    135274 struct roar_dl_libraryinst * lib; 
    136  struct roar_dl_librarypara * para = NULL; 
    137275 int i; 
    138276 
     
    141279   return -1; 
    142280 } else { 
    143   para = lhandle->para; 
     281  if ( para == NULL ) 
     282   para = lhandle->para; 
    144283 } 
    145284 
     
    181320} 
    182321 
    183 char *                  roar_dl_errstr(struct roar_dl_lhandle * lhandle) { 
     322const char * roar_dl_errstr(struct roar_dl_lhandle * lhandle) { 
    184323#if defined(ROAR_HAVE_LIBDL) 
    185324 (void)lhandle; 
     
    190329} 
    191330 
     331struct roar_dl_librarypara       * roar_dl_getpara(struct roar_dl_lhandle * lhandle) { 
     332 if ( (void*)lhandle < (void*)128 ) { 
     333  roar_err_set(ROAR_ERROR_NOTSUP); 
     334  return NULL; 
     335 } 
     336 
     337 if ( lhandle->para == NULL ) { 
     338  roar_err_set(ROAR_ERROR_NOENT); 
     339  return NULL; 
     340 } 
     341 
     342 if ( roar_dl_para_ref(lhandle->para) == -1 ) 
     343  return NULL; 
     344 
     345 return lhandle->para; 
     346} 
     347 
     348const struct roar_dl_libraryname * roar_dl_getlibname(struct roar_dl_lhandle * lhandle) { 
     349 if ( (void*)lhandle < (void*)128 ) { 
     350  roar_err_set(ROAR_ERROR_NOTSUP); 
     351  return NULL; 
     352 } 
     353 
     354 if ( lhandle->lib == NULL ) { 
     355  roar_err_set(ROAR_ERROR_BADLIB); 
     356  return NULL; 
     357 } 
     358 
     359 if ( lhandle->lib->libname == NULL ) { 
     360  roar_err_set(ROAR_ERROR_NOENT); 
     361  return NULL; 
     362 } 
     363 
     364 if ( lhandle->lib->libname->version != ROAR_DL_LIBNAME_VERSION ) { 
     365  roar_err_set(ROAR_ERROR_BADVERSION); 
     366  return NULL; 
     367 } 
     368 
     369 if ( lhandle->lib->libname->len != sizeof(struct roar_dl_libraryname) ) { 
     370  roar_err_set(ROAR_ERROR_HOLE); 
     371  return NULL; 
     372 } 
     373 
     374 return lhandle->lib->libname; 
     375} 
     376 
    192377//ll 
  • libroar/vio_dstr.c

    r5270 r5275  
    289289 
    290290static void _roar_vio_dstr_init_otherlibs (void) { 
    291  roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroardsp"); 
    292  roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroareio"); 
    293  roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroarlight"); 
    294  roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroarmidi"); 
     291 roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroardsp",   NULL); 
     292 roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroareio",   NULL); 
     293 roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroarlight", NULL); 
     294 roar_dl_ra_init(ROAR_DL_HANDLE_DEFAULT, "libroarmidi",  NULL); 
    295295} 
    296296 
Note: See TracChangeset for help on using the changeset viewer.