Changeset 5312:27ec111dc8c5 in roaraudio


Ignore:
Timestamp:
11/30/11 01:05:41 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added support for seperate contextes for roardl/plugins. Currently incudes error state and a global per handle data segment. This does not work for statically linked librarys (yet). support for per-context notify core needs to be added/completed.

Files:
11 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/error.h

    r5286 r5312  
    113113void   roar_err_to_errno(void); 
    114114 
     115// Resets the stored state to 'no error' state. This can be used 
     116// to init the state. 
     117int    roar_err_initstore(struct roar_error_state * state); 
     118 
    115119// store a error state (both libroar and system) 
    116120// returnes the error or ROAR_ERROR_NONE on success so it does not alter gloabl error state. 
  • include/libroar/roardl.h

    r5275 r5312  
    148148 int    (*func[ROAR_DL_FN_MAX])(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib); 
    149149 struct roar_dl_libraryname * libname; 
     150 size_t  global_data_len; 
     151 void *  global_data_init; 
     152 void ** global_data_pointer; 
    150153}; 
    151154 
     155// parameter functions: 
    152156struct roar_dl_librarypara * roar_dl_para_new(const char * args, void * binargv, 
    153157                                              const char * appname, const char * abiversion); 
     
    157161                                         const char * appname, const char * abiversion); 
    158162 
     163// 'core' dynamic loader functions. 
    159164struct roar_dl_lhandle * roar_dl_open   (const char * filename, int flags, 
    160165                                         int ra_init, struct roar_dl_librarypara * para); 
     
    169174const char *             roar_dl_errstr (struct roar_dl_lhandle * lhandle); 
    170175 
     176// getting meta data: 
    171177struct roar_dl_librarypara       * roar_dl_getpara(struct roar_dl_lhandle * lhandle); 
    172178const struct roar_dl_libraryname * roar_dl_getlibname(struct roar_dl_lhandle * lhandle); 
     179 
     180// context switching: 
     181// _restore() is to switch from main to library context. _store() is to store library context 
     182// and switch back to main context. 
     183int                      roar_dl_context_restore(struct roar_dl_lhandle * lhandle); 
     184int                      roar_dl_context_store(struct roar_dl_lhandle * lhandle); 
    173185 
    174186#endif 
  • libroar/error.c

    r5295 r5312  
    866866} 
    867867 
     868// Resets the stored state to 'no error' state. This can be used 
     869// to init the state. 
     870int    roar_err_initstore(struct roar_error_state * state) { 
     871 struct roar_error_state curstate; 
     872 
     873 if ( state == NULL ) { 
     874  roar_err_set(ROAR_ERROR_FAULT); 
     875  return -1; 
     876 } 
     877 
     878 roar_err_store(&curstate); 
     879 roar_err_clear_all(); 
     880 roar_err_store(state); 
     881 roar_err_restore(&curstate); 
     882 
     883 return -1; 
     884} 
    868885 
    869886// store a error state (both libroar and system) 
  • libroar/roardl.c

    r5275 r5312  
    4343 struct roar_dl_librarypara * para; 
    4444 struct roar_dl_libraryinst * lib; 
     45 struct { 
     46  struct roar_error_state error_state; 
     47  void *  global_data; 
     48  void *  global_data_state; 
     49 } context; 
    4550#if defined(ROAR_HAVE_LIBDL) 
    4651 void * handle; 
     
    187192 memset(ret, 0, sizeof(struct roar_dl_lhandle)); 
    188193 
     194 roar_err_initstore(&(ret->context.error_state)); 
     195 
    189196#if defined(ROAR_HAVE_LIBDL) 
    190197 flags  = RTLD_NOW; 
     
    243250 ret = -1; 
    244251#endif 
     252 
     253 if ( lhandle->context.global_data != NULL ) 
     254  roar_mm_free(lhandle->context.global_data); 
    245255 
    246256 if ( lhandle->para != NULL ) 
     
    273283 struct roar_dl_libraryinst * (*func)(struct roar_dl_librarypara * para); 
    274284 struct roar_dl_libraryinst * lib; 
     285 void * global_data_state = NULL; 
    275286 int i; 
    276287 
     
    310321 if ( !((void*)lhandle < (void*)128) ) { 
    311322  lhandle->lib = lib; 
     323 
     324  if ( lib->global_data_len ) { 
     325   lhandle->context.global_data = roar_mm_malloc(lib->global_data_len); 
     326   if ( lhandle->context.global_data == NULL ) 
     327    return -1; 
     328 
     329   if ( lib->global_data_init == NULL ) { 
     330    memset(lhandle->context.global_data, 0, lib->global_data_len); 
     331   } else { 
     332    memcpy(lhandle->context.global_data, lib->global_data_init, lib->global_data_len); 
     333   } 
     334  } 
     335 } 
     336 
     337 if ( lib->global_data_pointer != NULL ) { 
     338  global_data_state = *(lib->global_data_pointer); 
     339  if ( !((void*)lhandle < (void*)128) ) { 
     340   *(lib->global_data_pointer) = lib->global_data_init; 
     341  } else { 
     342   *(lib->global_data_pointer) = lhandle->context.global_data; 
     343  } 
    312344 } 
    313345 
     
    315347  if ( lib->func[i] != NULL ) 
    316348   lib->func[i](para, lib); 
     349 } 
     350 
     351 if ( lib->global_data_pointer != NULL ) { 
     352  *(lib->global_data_pointer) = global_data_state; 
    317353 } 
    318354 
     
    375411} 
    376412 
     413int                      roar_dl_context_restore(struct roar_dl_lhandle * lhandle) { 
     414 struct roar_error_state error_state; 
     415 
     416 if ( (void*)lhandle < (void*)128 ) { 
     417  roar_err_set(ROAR_ERROR_NOTSUP); 
     418  return -1; 
     419 } 
     420 
     421 roar_err_store(&error_state); 
     422 roar_err_restore(&(lhandle->context.error_state)); 
     423 lhandle->context.error_state = error_state; 
     424 
     425 if ( lhandle->lib->global_data_pointer != NULL ) { 
     426  lhandle->context.global_data_state = *(lhandle->lib->global_data_pointer); 
     427  *(lhandle->lib->global_data_pointer) = lhandle->context.global_data; 
     428 } 
     429 
     430 return 0; 
     431} 
     432 
     433int                      roar_dl_context_store(struct roar_dl_lhandle * lhandle) { 
     434 struct roar_error_state error_state; 
     435 
     436 if ( (void*)lhandle < (void*)128 ) { 
     437  roar_err_set(ROAR_ERROR_NOTSUP); 
     438  return -1; 
     439 } 
     440 
     441 if ( lhandle->lib->global_data_pointer != NULL ) { 
     442  *(lhandle->lib->global_data_pointer) = lhandle->context.global_data_state; 
     443 } 
     444 
     445 roar_err_store(&error_state); 
     446 roar_err_restore(&(lhandle->context.error_state)); 
     447 lhandle->context.error_state = error_state; 
     448 
     449 return 0; 
     450} 
     451 
    377452//ll 
  • plugins/roard/protocol-irc.c

    r5310 r5312  
    865865 
    866866static struct roard_proto proto[1] = { 
    867  {ROAR_PROTO_IRC, ROAR_SUBSYS_NONE, "Internet Relay Chat", new_client, check_client, NULL, NULL} 
     867 {ROAR_PROTO_IRC, ROAR_SUBSYS_NONE, "Internet Relay Chat", NULL, new_client, check_client, NULL, NULL} 
    868868}; 
    869869 
  • plugins/universal/protocol-daytime.c

    r5303 r5312  
    5959 
    6060static struct roard_proto proto[1] = { 
    61  {ROAR_PROTO_DAYTIME, ROAR_SUBSYS_NONE, "The Internet daytime protocol", new_client, NULL, NULL, flushed_client} 
     61 {ROAR_PROTO_DAYTIME, ROAR_SUBSYS_NONE, "The Internet daytime protocol", NULL, new_client, NULL, NULL, flushed_client} 
    6262}; 
    6363 
  • plugins/universal/protocol-discard.c

    r5275 r5312  
    4242 
    4343static struct roard_proto proto[1] = { 
    44  {ROAR_PROTO_DISCARD, ROAR_SUBSYS_NONE, "Discard all data send to the server", NULL, check_client, NULL, NULL} 
     44 {ROAR_PROTO_DISCARD, ROAR_SUBSYS_NONE, "Discard all data send to the server", NULL, NULL, check_client, NULL, NULL} 
    4545}; 
    4646 
  • plugins/universal/protocol-echo.c

    r5303 r5312  
    5757 
    5858static struct roard_proto proto[1] = { 
    59  {ROAR_PROTO_ECHO, ROAR_SUBSYS_NONE, "Send all data send to the server back to the client", NULL, check_client, NULL, NULL} 
     59 {ROAR_PROTO_ECHO, ROAR_SUBSYS_NONE, "Send all data send to the server back to the client", NULL, NULL, check_client, NULL, NULL} 
    6060}; 
    6161 
  • roard/clients.c

    r5304 r5312  
    3838#ifndef ROAR_WITHOUT_DCOMP_EMUL_ESD 
    3939#ifdef ROAR_HAVE_H_ESD 
    40  {ROAR_PROTO_ESOUND, ROAR_SUBSYS_WAVEFORM, "EsounD emulation", NULL, emul_esd_check_client, NULL, NULL}, 
     40 {ROAR_PROTO_ESOUND, ROAR_SUBSYS_WAVEFORM, "EsounD emulation", NULL, NULL, emul_esd_check_client, NULL, NULL}, 
    4141#endif 
    4242#endif 
    4343#ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY 
    44  {ROAR_PROTO_RPLAY, ROAR_SUBSYS_WAVEFORM, "RPlay emulation", NULL, emul_rplay_check_client, NULL, NULL}, 
     44 {ROAR_PROTO_RPLAY, ROAR_SUBSYS_WAVEFORM, "RPlay emulation", NULL, NULL, emul_rplay_check_client, NULL, NULL}, 
    4545#endif 
    4646#ifndef ROAR_WITHOUT_DCOMP_EMUL_GOPHER 
    47  {ROAR_PROTO_GOPHER, ROAR_SUBSYS_WAVEFORM, "The Internet Gopher Protocol", NULL, emul_gopher_check_client, NULL, emul_gopher_flushed_client}, 
    48 #endif 
    49  {-1, 0, NULL, NULL, NULL, NULL, NULL} 
     47 {ROAR_PROTO_GOPHER, ROAR_SUBSYS_WAVEFORM, "The Internet Gopher Protocol", NULL, NULL, emul_gopher_check_client, NULL, emul_gopher_flushed_client}, 
     48#endif 
     49 {-1, 0, NULL, NULL, NULL, NULL, NULL, NULL} 
    5050}; 
    5151 
     
    647647     if ( g_proto[i].proto == c->proto ) { 
    648648      roar_vio_open_fh_socket(&vio, clients_get_fh(id)); 
     649      if ( g_proto[i].lhandle != NULL ) 
     650       roar_dl_context_restore(g_proto[i].lhandle); 
    649651      rv = g_proto[i].check_client(id, &vio); 
     652      if ( g_proto[i].lhandle != NULL ) 
     653       roar_dl_context_store(g_proto[i].lhandle); 
    650654     } 
    651655    } 
     
    686690 
    687691 if ( p->flush_client != NULL ) { 
     692  if ( p->lhandle != NULL ) 
     693   roar_dl_context_restore(p->lhandle); 
    688694  return p->flush_client(id, &vio); 
     695  if ( p->lhandle != NULL ) 
     696   roar_dl_context_store(p->lhandle); 
    689697 } 
    690698 
     
    716724 if ( cs->outbuf == NULL ) { 
    717725  if ( p->flushed_client != NULL ) { 
     726   if ( p->lhandle != NULL ) 
     727    roar_dl_context_restore(p->lhandle); 
    718728   return p->flushed_client(id, &vio); 
     729   if ( p->lhandle != NULL ) 
     730    roar_dl_context_store(p->lhandle); 
    719731  } 
    720732 } 
     
    813825 
    814826// proto support 
    815 int clients_register_proto(struct roard_proto * proto) { 
     827int clients_register_proto(struct roard_proto * proto, struct roar_dl_lhandle * lhandle) { 
    816828 const size_t len = sizeof(g_proto)/sizeof(*g_proto); 
    817829 size_t i; 
     
    829841 
    830842 memcpy(&(g_proto[i]), proto, sizeof(*g_proto)); 
     843 
     844 g_proto[i].lhandle = lhandle; 
    831845 
    832846 return 0; 
  • roard/include/client.h

    r5301 r5312  
    7878 int subsystems; 
    7979 const char * description; 
     80 struct roar_dl_lhandle * lhandle; 
    8081 int (*new_client)(int client, struct roar_vio_calls * vio, struct roard_listen * lsock); 
    8182 int (*check_client)(int client, struct roar_vio_calls * vio); 
     
    116117 
    117118// proto support 
    118 int clients_register_proto  (struct roard_proto * proto); 
     119int clients_register_proto  (struct roard_proto * proto, struct roar_dl_lhandle * lhandle); 
    119120int clients_unregister_proto(int proto); 
    120121void print_protolist        (enum output_format format); 
  • roard/plugins.c

    r5275 r5312  
    5757 int i; 
    5858 
    59  if ( plugin->sched != NULL ) 
    60   if ( plugin->sched->free != NULL ) 
     59 if ( plugin->sched != NULL ) { 
     60  if ( plugin->sched->free != NULL ) { 
     61   roar_dl_context_restore(plugin->lhandle); 
    6162   plugin->sched->free(); 
     63   roar_dl_context_store(plugin->lhandle); 
     64  } 
     65 } 
    6266 
    6367 for (i = 0; i < MAX_PROTOS; i++) { 
     
    8791   } 
    8892 
    89    if ( g_plugins[i].sched != NULL ) 
    90     if ( g_plugins[i].sched->init != NULL ) 
     93   if ( g_plugins[i].sched != NULL ) { 
     94    if ( g_plugins[i].sched->init != NULL ) { 
     95     roar_dl_context_restore(g_plugins[i].lhandle); 
    9196     g_plugins[i].sched->init(); 
     97     roar_dl_context_store(g_plugins[i].lhandle); 
     98    } 
     99   } 
    92100 
    93101   _pp = NULL; 
     
    114122 int i; 
    115123 
    116  for (i = 0; i < MAX_PLUGINS; i++) 
    117   if ( g_plugins[i].lhandle != NULL ) 
    118    if ( g_plugins[i].sched != NULL ) 
    119     if ( g_plugins[i].sched->update != NULL ) 
     124 for (i = 0; i < MAX_PLUGINS; i++) { 
     125  if ( g_plugins[i].lhandle != NULL ) { 
     126   if ( g_plugins[i].sched != NULL ) { 
     127    if ( g_plugins[i].sched->update != NULL ) { 
     128     roar_dl_context_restore(g_plugins[i].lhandle); 
    120129     if ( g_plugins[i].sched->update() == -1 ) 
    121130      ret = -1; 
     131     roar_dl_context_store(g_plugins[i].lhandle); 
     132    } 
     133   } 
     134  } 
     135 } 
    122136 
    123137 return ret; 
     
    178192 } 
    179193 
    180  return clients_register_proto(proto); 
     194 return clients_register_proto(proto, _pp->lhandle); 
    181195} 
    182196 
Note: See TracChangeset for help on using the changeset viewer.