Changeset 5567:6ecf012d7063 in roaraudio for roard/plugins.c


Ignore:
Timestamp:
07/16/12 17:02:17 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

roard now tries to auto load missing protocols as plugins (Closes: #275)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roard/plugins.c

    r5427 r5567  
    3535static struct _roard_plugin * _pp = NULL; 
    3636 
     37static int _plugins_inited = 0; 
     38 
    3739static struct _roard_plugin * _find_free(void) { 
    3840 int i; 
     
    7880} 
    7981 
     82static int plugins_init_one(struct _roard_plugin * plugin) { 
     83 if ( plugin == NULL ) 
     84  return -1; 
     85 
     86 _pp = plugin; 
     87 _pp->sched = NULL; 
     88 
     89 if ( roar_dl_ra_init(plugin->lhandle, NULL, NULL) == -1 ) { 
     90  ROAR_WARN("plugins_init(void): Can not RA init lib at %p: %s", plugin->lhandle, roar_error2str(roar_error)); 
     91  plugins_delete(plugin); 
     92  return -1; 
     93 } 
     94 
     95 if ( plugin->sched != NULL ) { 
     96  if ( plugin->sched->init != NULL ) { 
     97   roar_dl_context_restore(plugin->lhandle); 
     98   plugin->sched->init(); 
     99   roar_dl_context_store(plugin->lhandle); 
     100  } 
     101 } 
     102 
     103 roar_dl_appsched_trigger(plugin->lhandle, ROAR_DL_APPSCHED_INIT); 
     104 
     105 _pp = NULL; 
     106 
     107 return 0; 
     108} 
     109 
    80110int plugins_init  (void) { 
    81  int i; 
     111 size_t i; 
     112 
     113 if ( _plugins_inited ) { 
     114  roar_err_set(ROAR_ERROR_BUSY); 
     115  return -1; 
     116 } 
    82117 
    83118 for (i = 0; i < MAX_PLUGINS; i++) { 
    84119  if ( g_plugins[i].lhandle != NULL ) { 
    85    _pp = &(g_plugins[i]); 
    86  
    87    _pp->sched = NULL; 
    88  
    89    if ( roar_dl_ra_init(g_plugins[i].lhandle, NULL, NULL) == -1 ) { 
    90     ROAR_WARN("plugins_init(void): Can not RA init lib at %p: %s", g_plugins[i].lhandle, roar_error2str(roar_error)); 
    91     plugins_delete(&(g_plugins[i])); 
    92     continue; 
    93    } 
    94  
    95    if ( g_plugins[i].sched != NULL ) { 
    96     if ( g_plugins[i].sched->init != NULL ) { 
    97      roar_dl_context_restore(g_plugins[i].lhandle); 
    98      g_plugins[i].sched->init(); 
    99      roar_dl_context_store(g_plugins[i].lhandle); 
    100     } 
    101    } 
    102  
    103    roar_dl_appsched_trigger(g_plugins[i].lhandle, ROAR_DL_APPSCHED_INIT); 
    104  
    105    _pp = NULL; 
    106   } 
    107  } 
     120   plugins_init_one(&(g_plugins[i])); 
     121  } 
     122 } 
     123 
     124 _plugins_inited = 1; 
    108125 
    109126 return 0; 
     
    169186 } 
    170187 
     188 if ( _plugins_inited ) 
     189  return plugins_init_one(next); 
     190 
    171191 return 0; 
    172192} 
Note: See TracChangeset for help on using the changeset viewer.