Changeset 3362:2bf10ee217b5 in roaraudio


Ignore:
Timestamp:
02/08/10 16:36:13 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

support plugin sched events

Location:
roard
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • roard/include/plugins.h

    r3354 r3362  
    2828#include <roaraudio.h> 
    2929 
     30struct roard_plugins_sched { 
     31 int (*init)(void); 
     32 int (*free)(void); 
     33 int (*update)(void); 
     34}; 
     35 
    3036int plugins_preinit  (void); 
    3137int plugins_init     (void); 
    3238int plugins_free     (void); 
     39int plugins_update   (void); 
    3340 
    3441int plugins_load     (const char * filename); 
     42 
     43int plugins_reg_sched(struct roard_plugins_sched * sched); 
    3544 
    3645#endif 
  • roard/loop.c

    r3358 r3362  
    112112*/ 
    113113 
     114  if ( plugins_update() == -1 ) 
     115   alive = 0; 
    114116 
    115117  ROAR_DBG("main_loop(*): sending output data..."); 
  • roard/plugins.c

    r3357 r3362  
    2727#define MAX_PLUGINS    8 
    2828 
    29 static struct roar_dl_lhandle * g_plugins[MAX_PLUGINS]; 
     29static struct _roard_plugin { 
     30 struct roar_dl_lhandle     * lhandle; 
     31 struct roard_plugins_sched * sched; 
     32} g_plugins[MAX_PLUGINS]; 
     33static struct _roard_plugin * _pp = NULL; 
    3034 
    31 static struct roar_dl_lhandle ** _find_free(void) { 
     35static struct _roard_plugin * _find_free(void) { 
    3236 int i; 
    3337 
    3438 for (i = 0; i < MAX_PLUGINS; i++) { 
    35   if ( g_plugins[i] == NULL ) 
     39  if ( g_plugins[i].lhandle == NULL ) { 
     40   memset(&(g_plugins[i]), 0, sizeof(struct _roard_plugin)); 
    3641   return &(g_plugins[i]); 
     42  } 
    3743 } 
    3844 
     
    5056 
    5157 for (i = 0; i < MAX_PLUGINS; i++) { 
    52   if ( g_plugins[i] != NULL ) { 
    53    roar_dl_ra_init(g_plugins[i], NULL); 
     58  if ( g_plugins[i].lhandle != NULL ) { 
     59   _pp = &(g_plugins[i]); 
     60 
     61   roar_dl_ra_init(g_plugins[i].lhandle, NULL); 
     62 
     63   if ( g_plugins[i].sched->init != NULL ) 
     64    g_plugins[i].sched->init(); 
     65 
     66   _pp = NULL; 
    5467  } 
    5568 } 
     
    6275 
    6376 for (i = 0; i < MAX_PLUGINS; i++) { 
    64   if ( g_plugins[i] != NULL ) { 
    65    roar_dl_close(g_plugins[i]); 
     77  if ( g_plugins[i].lhandle != NULL ) { 
     78   if ( g_plugins[i].sched->free != NULL ) 
     79    g_plugins[i].sched->free(); 
     80 
     81   roar_dl_close(g_plugins[i].lhandle); 
    6682  } 
    6783 } 
     
    7086} 
    7187 
     88int plugins_update   (void) { 
     89 int ret = 0; 
     90 int i; 
     91 
     92 for (i = 0; i < MAX_PLUGINS; i++) 
     93  if ( g_plugins[i].lhandle != NULL ) 
     94   if ( g_plugins[i].sched->update != NULL ) 
     95    if ( g_plugins[i].sched->update() == -1 ) 
     96     ret = -1; 
     97 
     98 return ret; 
     99} 
     100 
    72101int plugins_load  (const char * filename) { 
    73  struct roar_dl_lhandle ** next = _find_free(); 
     102 struct _roard_plugin * next = _find_free(); 
    74103 
    75104 if ( next == NULL ) 
    76105  return -1; 
    77106 
    78  *next = roar_dl_open(filename, -1, 0 /* we delay this until plugins_init() */); 
    79  if ( *next == NULL ) 
     107 next->lhandle = roar_dl_open(filename, -1, 0 /* we delay this until plugins_init() */); 
     108 if ( next->lhandle == NULL ) 
    80109  return -1; 
    81110 
     
    83112} 
    84113 
     114int plugins_reg_sched(struct roard_plugins_sched * sched) { 
     115 if ( _pp == NULL ) 
     116  return -1; 
     117 
     118 _pp->sched = sched; 
     119 
     120 return 0; 
     121} 
     122 
    85123//ll 
Note: See TracChangeset for help on using the changeset viewer.