Changeset 5275:811818eb5b81 in roaraudio for roard/plugins.c


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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roard/plugins.c

    r4708 r5275  
    3131 struct roar_dl_lhandle     * lhandle; 
    3232 struct roard_plugins_sched * sched; 
     33 int protocols[MAX_PROTOS]; 
    3334} g_plugins[MAX_PLUGINS]; 
    3435static struct _roard_plugin * _pp = NULL; 
     
    5354} 
    5455 
     56static void inline plugins_delete(struct _roard_plugin * plugin) { 
     57 int i; 
     58 
     59 if ( plugin->sched != NULL ) 
     60  if ( plugin->sched->free != NULL ) 
     61   plugin->sched->free(); 
     62 
     63 for (i = 0; i < MAX_PROTOS; i++) { 
     64  if ( plugin->protocols[i] != -1 ) { 
     65   clients_unregister_proto(plugin->protocols[i]); 
     66  } 
     67 } 
     68 
     69 roar_dl_close(plugin->lhandle); 
     70 memset(plugin, 0, sizeof(struct _roard_plugin)); 
     71 plugin->lhandle = NULL; 
     72} 
     73 
    5574int plugins_init  (void) { 
    5675 int i; 
     
    6281   _pp->sched = NULL; 
    6382 
    64    roar_dl_ra_init(g_plugins[i].lhandle, NULL); 
     83   if ( roar_dl_ra_init(g_plugins[i].lhandle, NULL, NULL) == -1 ) { 
     84    ROAR_WARN("plugins_init(void): Can not RA init lib at %p: %s", g_plugins[i].lhandle, roar_error2str(roar_error)); 
     85    plugins_delete(&(g_plugins[i])); 
     86    continue; 
     87   } 
    6588 
    6689   if ( g_plugins[i].sched != NULL ) 
     
    80103 for (i = 0; i < MAX_PLUGINS; i++) { 
    81104  if ( g_plugins[i].lhandle != NULL ) { 
    82    if ( g_plugins[i].sched != NULL ) 
    83     if ( g_plugins[i].sched->free != NULL ) 
    84      g_plugins[i].sched->free(); 
    85  
    86    roar_dl_close(g_plugins[i].lhandle); 
     105   plugins_delete(&(g_plugins[i])); 
    87106  } 
    88107 } 
     
    105124} 
    106125 
    107 int plugins_load  (const char * filename) { 
     126int plugins_load  (const char * filename, const char * args) { 
    108127 struct _roard_plugin * next = _find_free(); 
     128 struct roar_dl_librarypara * para; 
     129 int i; 
    109130 
    110131 if ( next == NULL ) 
    111132  return -1; 
    112133 
    113  next->lhandle = roar_dl_open(filename, -1, 0 /* we delay this until plugins_init() */); 
     134 for (i = 0; i < MAX_PROTOS; i++) 
     135  next->protocols[i] = -1; 
     136 
     137 if ( (para = roar_dl_para_new(args, NULL, ROARD_DL_APPNAME, ROARD_DL_ABIVERSION)) == NULL ) { 
     138  ROAR_WARN("Can not load plugin (allocate para set): %s: %s", filename, roar_error2str(roar_error)); 
     139  return -1; 
     140 } 
     141 
     142 next->lhandle = roar_dl_open(filename, ROAR_DL_FLAG_DEFAUTS, 0 /* we delay this until plugins_init() */, para); 
     143 roar_dl_para_unref(para); 
     144 
    114145 if ( next->lhandle == NULL ) { 
    115146  ROAR_ERR("plugins_load(filename='%s'): can not load plugin: %s", filename, roar_dl_errstr(NULL)); 
     
    130161 
    131162int plugins_reg_proto(struct roard_proto         * proto) { 
     163 int i; 
     164 
    132165 if ( _pp == NULL ) 
    133166  return -1; 
     167 
     168 for (i = 0; i < MAX_PROTOS; i++) { 
     169  if ( _pp->protocols[i] == -1 ) { 
     170   _pp->protocols[i] = proto->proto; 
     171   break; 
     172  } 
     173 } 
     174 
     175 if ( i == MAX_PROTOS ) { 
     176  roar_err_set(ROAR_ERROR_NOMEM); 
     177  return -1; 
     178 } 
    134179 
    135180 return clients_register_proto(proto); 
Note: See TracChangeset for help on using the changeset viewer.