Changeset 5487:882b4283f8d7 in roaraudio


Ignore:
Timestamp:
04/30/12 03:12:01 (9 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

support getting plugin by name

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/plugincontainer.h

    r5437 r5487  
    5858int roar_plugincontainer_unref(struct roar_plugincontainer * cont); 
    5959 
    60 /* 
    61  * stuff we still need: 
    62  * object creation, get plugin handle. 
     60/* Get a lhandle by name of the loaded plugin 
    6361 */ 
     62struct roar_dl_lhandle * roar_plugincontainer_get_lhandle_by_name (struct roar_plugincontainer * cont, 
     63                                                                   const char * name); 
    6464 
    6565// plugin loading and unloading: 
  • libroar/plugincontainer.c

    r5441 r5487  
    233233} 
    234234 
     235struct roar_dl_lhandle * roar_plugincontainer_get_lhandle_by_name (struct roar_plugincontainer * cont, 
     236                                                                   const char * name) { 
     237 const struct roar_dl_libraryname * libname; 
     238 size_t i; 
     239 
     240 if ( cont == NULL || name == NULL ) { 
     241  roar_err_set(ROAR_ERROR_FAULT); 
     242  return NULL; 
     243 } 
     244 
     245 for (i = 0; i < MAX_PLUGINS; i++) { 
     246  if ( cont->handle[i] == NULL ) 
     247   continue; 
     248  libname = roar_dl_getlibname(cont->handle[i]); 
     249  if ( libname == NULL ) 
     250   continue; 
     251 
     252  if ( !strcmp(libname->name, name) ) { 
     253   if ( roar_dl_ref(cont->handle[i]) == -1 ) 
     254    return NULL; 
     255 
     256   return cont->handle[i]; 
     257  } 
     258 } 
     259 
     260 roar_err_set(ROAR_ERROR_NOENT); 
     261 return NULL; 
     262} 
     263 
    235264// plugin loading and unloading: 
    236265int roar_plugincontainer_load(struct roar_plugincontainer * cont, const char * name, struct roar_dl_librarypara * para) { 
     
    304333 
    305334int roar_plugincontainer_unload(struct roar_plugincontainer * cont, const char * name) { 
    306  const struct roar_dl_libraryname * libname; 
    307  size_t i; 
     335 struct roar_dl_lhandle * lhandle; 
    308336 
    309337 if ( cont == NULL || name == NULL ) { 
     
    312340 } 
    313341 
    314  for (i = 0; i < MAX_PLUGINS; i++) { 
    315   if ( cont->handle[i] == NULL ) 
    316    continue; 
    317   libname = roar_dl_getlibname(cont->handle[i]); 
    318   if ( libname == NULL ) 
    319    continue; 
    320  
    321   if ( !strcmp(libname->name, name) ) 
    322    return roar_plugincontainer_unload_lhandle(cont, cont->handle[i]); 
    323  } 
    324  
    325  roar_err_set(ROAR_ERROR_NOENT); 
    326  return -1; 
     342 lhandle = roar_plugincontainer_get_lhandle_by_name(cont, name); 
     343 if ( lhandle == NULL ) 
     344  return -1; 
     345 
     346 roar_dl_unref(lhandle); // we can do this early here as the handle stay valid in the container's array. 
     347 
     348 return roar_plugincontainer_unload_lhandle(cont, lhandle); 
    327349} 
    328350 
Note: See TracChangeset for help on using the changeset viewer.