Changeset 5317:6b1045321fd6 in roaraudio for libroar


Ignore:
Timestamp:
12/01/11 19:38:56 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

updated plugin infrastructre

Location:
libroar
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • libroar/Makefile

    r5270 r5317  
    1111PASSWORD=passwordapi.o pinentry.o sshaskpass.o 
    1212CRYPTO=crypto.o random.o $(HASHES) crc.o 
    13 OBJS=libroar.o config.o debug.o error.o basic.o stream.o client.o simple.o auth.o socket.o ctl.o buffer.o meta.o file.o acl.o cdrom.o $(PASSWORD) $(VIO) stack.o slp.o nnode.o roardl.o roarx11.o beep.o proto.o env.o keyval.o vs.o ltm.o notify.o notify_proxy.o asyncctl.o enumdev.o serverinfo.o $(CRYPTO) authfile.o caps.o roarfloat.o base64.o trap.o memmgr.o time.o 
     13OBJS=libroar.o config.o debug.o error.o basic.o stream.o client.o simple.o auth.o socket.o ctl.o buffer.o meta.o file.o acl.o cdrom.o $(PASSWORD) $(VIO) stack.o slp.o nnode.o roardl.o plugincontainer.o roarx11.o beep.o proto.o env.o keyval.o vs.o ltm.o notify.o notify_proxy.o asyncctl.o enumdev.o serverinfo.o $(CRYPTO) authfile.o caps.o roarfloat.o base64.o trap.o memmgr.o time.o 
    1414 
    1515#DEFINES        = -DDEBUG 
  • libroar/roardl.c

    r5313 r5317  
    4141 
    4242struct roar_dl_lhandle { 
     43 size_t refc; // currently unused. 
     44 int flags; 
     45 char * libname; // only used for ROAR_DL_FLAG_STATIC. 
    4346 struct roar_dl_librarypara * para; 
    4447 struct roar_dl_libraryinst * lib; 
     
    4750  void *  global_data; 
    4851  void *  global_data_state; 
     52  struct roar_notify_core * notifycore; 
    4953 } context; 
    5054#if defined(ROAR_HAVE_LIBDL) 
     
    118122 para->refc--; 
    119123 
    120  if ( para->refc == 0 ) { 
    121   if ( para->args_store != NULL ) { 
    122    roar_mm_free(para->args_store); 
    123    roar_mm_free(para->argv); 
    124   } 
    125   roar_mm_free(para); 
    126  } 
     124 if ( para->refc ) 
     125  return 0; 
     126 
     127 if ( para->notifycore != NULL ) 
     128  roar_notify_core_unref(para->notifycore); 
     129 
     130 if ( para->args_store != NULL ) { 
     131  roar_mm_free(para->args_store); 
     132  roar_mm_free(para->argv); 
     133 } 
     134 
     135 roar_mm_free(para); 
    127136 
    128137 return 0; 
     
    165174#if defined(ROAR_HAVE_LIBDL) 
    166175static void * _roardl2ldl (struct roar_dl_lhandle * lhandle) { 
    167  if ( lhandle == ROAR_DL_HANDLE_DEFAULT ) 
     176 ROAR_DBG("_roardl2ldl(lhandle=%p) = ?", lhandle); 
     177 
     178 if ( lhandle == ROAR_DL_HANDLE_DEFAULT ) { 
     179  ROAR_DBG("_roardl2ldl(lhandle=%p) = %p", lhandle, (void*)RTLD_DEFAULT); 
    168180  return RTLD_DEFAULT; 
    169  
    170  if ( lhandle == ROAR_DL_HANDLE_NEXT ) 
     181 } 
     182 
     183 if ( lhandle == ROAR_DL_HANDLE_NEXT ) { 
     184  ROAR_DBG("_roardl2ldl(lhandle=%p) = %p", lhandle, (void*)RTLD_NEXT); 
    171185  return RTLD_NEXT; 
    172  
     186 } 
     187 
     188 ROAR_DBG("_roardl2ldl(lhandle=%p) = %p", lhandle, (void*)(lhandle->handle)); 
    173189 return lhandle->handle; 
    174190} 
     
    178194                                      int ra_init, struct roar_dl_librarypara * para) { 
    179195 struct roar_dl_lhandle * ret = NULL; 
     196#if defined(ROAR_HAVE_LIBDL) 
     197#ifdef RTLD_DEEPBIND 
     198 int libdl_flags = RTLD_NOW|RTLD_DEEPBIND; 
     199#else 
     200 int libdl_flags = RTLD_NOW; 
     201#endif 
     202#endif 
    180203 int err; 
    181204 
    182  // early errors just return. 
    183  
    184  if ( flags != ROAR_DL_FLAG_DEFAUTS ) { 
    185   roar_err_set(ROAR_ERROR_NOTSUP); 
    186   return NULL; 
    187  } 
     205 if ( flags == ROAR_DL_FLAG_DEFAULTS ) 
     206  flags = ROAR_DL_FLAG_NONE; 
    188207 
    189208 if ( (ret = roar_mm_malloc(sizeof(struct roar_dl_lhandle))) == NULL ) 
     
    194213 roar_err_initstore(&(ret->context.error_state)); 
    195214 
    196 #if defined(ROAR_HAVE_LIBDL) 
    197  flags  = RTLD_NOW; 
    198  
    199 #ifdef RTLD_DEEPBIND 
    200  flags |= RTLD_DEEPBIND; 
    201 #endif 
    202  
    203  ret->handle = dlopen(filename, flags); 
    204  
    205  if ( ret->handle == NULL ) { 
     215 ret->flags = flags; 
     216 
     217 if ( flags & ROAR_DL_FLAG_STATIC ) { 
     218  if ( filename == NULL ) { 
     219   ret->libname = NULL; 
     220  } else { 
     221   ret->libname = roar_mm_strdup(filename); 
     222  } 
     223 } else { 
     224#if defined(ROAR_HAVE_LIBDL) 
     225  ret->handle = dlopen(filename, libdl_flags); 
     226 
     227  if ( ret->handle == NULL ) { 
     228   ROAR_DBG("roar_dl_open(filename='%s', flags=%i, ra_init=%i, para=%p): Can not load library: %s", filename, flags, ra_init, para, roar_dl_errstr(ret)); 
     229   roar_mm_free(ret); 
     230   return NULL; 
     231  } 
     232#else 
    206233  roar_mm_free(ret); 
    207   return NULL; 
    208  } 
    209 #else 
    210  roar_mm_free(ret); 
    211  roar_err_set(ROAR_ERROR_NOSYS); 
    212  return NULL; 
    213 #endif 
     234  roar_err_set(ROAR_ERROR_NOSYS); 
     235  return NULL; 
     236#endif 
     237 } 
    214238 
    215239 ret->para = para; 
     
    220244   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)); 
    221245#if defined(ROAR_HAVE_LIBDL) 
    222    dlclose(ret->handle); 
     246   if ( ret->handle != NULL ) 
     247    dlclose(ret->handle); 
    223248#endif 
    224249   roar_mm_free(ret); 
     
    242267 } 
    243268 
    244  if ( lhandle->lib != NULL && lhandle->lib->unload != NULL ) 
     269 if ( lhandle->lib != NULL && lhandle->lib->unload != NULL ) { 
     270  roar_dl_context_restore(lhandle); 
    245271  lhandle->lib->unload(lhandle->para, lhandle->lib); 
    246  
    247 #if defined(ROAR_HAVE_LIBDL) 
    248  ret = dlclose(_roardl2ldl(lhandle)); 
     272  roar_dl_context_store(lhandle); 
     273 } 
     274 
     275#if defined(ROAR_HAVE_LIBDL) 
     276 if ( lhandle->handle == NULL ) { 
     277  ret = 0; 
     278 } else { 
     279  ret = dlclose(_roardl2ldl(lhandle)); 
     280 } 
    249281#else 
    250282 ret = -1; 
     
    257289  roar_dl_para_unref(lhandle->para); 
    258290 
     291 if ( lhandle->libname != NULL ) 
     292  roar_mm_free(lhandle->libname); 
     293 
    259294 roar_mm_free(lhandle); 
    260295 
     
    268303 (void)type; 
    269304 
     305 ROAR_DBG("roar_dl_getsym(lhandle=%p, sym='%s', type=%i): errno=%s, dlerror()='%s'", lhandle, sym, type, ret, strerror(errno), dlerror()); 
    270306 ROAR_DBG("roar_dl_getsym(lhandle=%p, sym='%s', type=%i) = %p", lhandle, sym, type, ret); 
    271307 
    272308 return ret; 
    273309#else 
     310 ROAR_DBG("roar_dl_getsym(lhandle=%p, sym='%s', type=%i) = NULL // errno=NOSYS", lhandle, sym, type, ret); 
     311 roar_err_set(ROAR_ERROR_NOSYS); 
    274312 return NULL; 
    275313#endif 
     
    283321 struct roar_dl_libraryinst * (*func)(struct roar_dl_librarypara * para); 
    284322 struct roar_dl_libraryinst * lib; 
     323 struct roar_dl_lhandle     * getsymhandle = lhandle; 
    285324 void * global_data_state = NULL; 
    286325 int i; 
     
    290329   return -1; 
    291330 } else { 
     331  if ( prefix == NULL ) 
     332   prefix = lhandle->libname; 
     333 
    292334  if ( para == NULL ) 
    293335   para = lhandle->para; 
     336 
     337  if ( lhandle->flags & ROAR_DL_FLAG_STATIC ) 
     338   getsymhandle = ROAR_DL_HANDLE_DEFAULT; 
    294339 } 
    295340 
     
    303348 ROAR_DBG("roar_dl_ra_init(lhandle=%p, prefix='%s'): name='%s'", lhandle, prefix, name); 
    304349 
    305  if ( (func = roar_dl_getsym(lhandle, name, -1)) == NULL ) 
    306   return -1; 
     350 if ( (func = roar_dl_getsym(getsymhandle, name, -1)) == NULL ) { 
     351  ROAR_DBG("roar_dl_ra_init(lhandle=%p, prefix='%s') = -1", lhandle, prefix); 
     352  return -1; 
     353 } 
    307354 
    308355 ROAR_DBG("roar_dl_ra_init(lhandle=%p, prefix='%s'): func=%p", lhandle, prefix, func); 
     
    416463 struct roar_error_state error_state; 
    417464 
     465 ROAR_DBG("roar_dl_context_restore(lhandle=%p) = ?", lhandle); 
     466 
    418467 if ( (void*)lhandle < (void*)128 ) { 
     468  ROAR_DBG("roar_dl_context_restore(lhandle=%p) = -1 // errno=NOTSUP", lhandle); 
    419469  roar_err_set(ROAR_ERROR_NOTSUP); 
    420470  return -1; 
     
    426476 
    427477 if ( lhandle->lib->global_data_pointer != NULL ) { 
     478  ROAR_DBG("roar_dl_context_restore(lhandle=%p): gptr(%p): %p -> %p", lhandle, 
     479           lhandle->lib->global_data_pointer, *(lhandle->lib->global_data_pointer), lhandle->context.global_data); 
    428480  lhandle->context.global_data_state = *(lhandle->lib->global_data_pointer); 
    429481  *(lhandle->lib->global_data_pointer) = lhandle->context.global_data; 
    430482 } 
    431483 
     484 if ( lhandle->para->notifycore != NULL ) 
     485  lhandle->context.notifycore = roar_notify_core_swap_global(lhandle->para->notifycore); 
     486 
     487 ROAR_DBG("roar_dl_context_restore(lhandle=%p) = 0", lhandle); 
    432488 return 0; 
    433489} 
     
    436492 struct roar_error_state error_state; 
    437493 
     494 ROAR_DBG("roar_dl_context_store(lhandle=%p) = ?", lhandle); 
     495 
    438496 if ( (void*)lhandle < (void*)128 ) { 
     497  ROAR_DBG("roar_dl_context_store(lhandle=%p) = -1 // errno=NOTSUP", lhandle); 
    439498  roar_err_set(ROAR_ERROR_NOTSUP); 
    440499  return -1; 
    441500 } 
    442501 
     502 if ( lhandle->para->notifycore != NULL ) { 
     503  roar_notify_core_unref(roar_notify_core_swap_global(lhandle->context.notifycore)); 
     504  roar_notify_core_unref(lhandle->context.notifycore); 
     505  lhandle->context.notifycore = NULL; 
     506 } 
     507 
    443508 if ( lhandle->lib->global_data_pointer != NULL ) { 
     509  ROAR_DBG("roar_dl_context_store(lhandle=%p): gptr(%p): %p -> %p", lhandle, 
     510           lhandle->lib->global_data_pointer, *(lhandle->lib->global_data_pointer), lhandle->context.global_data_state); 
    444511  *(lhandle->lib->global_data_pointer) = lhandle->context.global_data_state; 
    445512 } 
     
    449516 lhandle->context.error_state = error_state; 
    450517 
     518 ROAR_DBG("roar_dl_context_store(lhandle=%p) = 0", lhandle); 
    451519 return 0; 
    452520} 
    453521 
     522int                      roar_dl_appsched_trigger(struct roar_dl_lhandle * lhandle, enum roar_dl_appsched_trigger trigger) { 
     523 int ret; 
     524 
     525 if ( (void*)lhandle < (void*)128 ) { 
     526  roar_err_set(ROAR_ERROR_NOTSUP); 
     527  return -1; 
     528 } 
     529 
     530 if ( lhandle->lib->appsched == NULL ) { 
     531  roar_err_set(ROAR_ERROR_NOENT); 
     532  return -1; 
     533 } 
     534 
     535 switch (trigger) { 
     536#define _trig(lname,uname) \ 
     537  case ROAR_DL_APPSCHED_ ## uname :             \ 
     538    if ( lhandle->lib->appsched->lname == NULL ) {   \ 
     539     roar_err_set(ROAR_ERROR_NOENT);            \ 
     540     return -1;                                 \ 
     541    }                                           \ 
     542    roar_dl_context_restore(lhandle);           \ 
     543    ret = lhandle->lib->appsched->lname(lhandle->para); \ 
     544    roar_dl_context_store(lhandle);             \ 
     545    return ret;                                 \ 
     546   break; 
     547  _trig(init, INIT); 
     548  _trig(free, FREE); 
     549  _trig(update, UPDATE); 
     550 } 
     551 
     552 roar_err_set(ROAR_ERROR_BADRQC); 
     553 return -1; 
     554} 
     555 
    454556//ll 
Note: See TracChangeset for help on using the changeset viewer.