Changeset 5576:a98545bcc3f1 in roaraudio for roard/plugins.c


Ignore:
Timestamp:
07/21/12 16:05:33 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Support a common protocol interface (Closes: #257)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roard/plugins.c

    r5567 r5576  
    3737static int _plugins_inited = 0; 
    3838 
     39static int plugin_callback(enum roar_dl_fnreg_action action, int fn, int subtype, const void * object, size_t objectlen, int version, int options, void * userdata, struct roar_dl_lhandle * lhandle); 
     40static const struct roar_dl_fnreg _plugin_callbacks = { 
     41 .fn = -1, 
     42 .subtype = -1, 
     43 .version = -1, 
     44 .callback = plugin_callback, 
     45 .userdata = NULL 
     46}; 
     47 
    3948static struct _roard_plugin * _find_free(void) { 
    4049 int i; 
     
    115124  return -1; 
    116125 } 
     126 
     127 roar_dl_register_fn(ROAR_DL_HANDLE_APPLICATION, ROAR_DL_FN_REGFN, ROAR_DL_FNREG_SUBTYPE, &_plugin_callbacks, ROAR_DL_FNREG_SIZE, ROAR_DL_FNREG_VERSION, ROAR_DL_FNREG_OPT_NONE); 
    117128 
    118129 for (i = 0; i < MAX_PLUGINS; i++) { 
     
    222233} 
    223234 
     235static int plugin_callback(enum roar_dl_fnreg_action action, int fn, int subtype, const void * object, size_t objectlen, int version, int options, void * userdata, struct roar_dl_lhandle * lhandle) { 
     236 
     237 ROAR_DBG("plugin_callback(action=%i, fn=%i, subtype=%i, object=%p, objectlen=%llu, version=%i, options=0x%x, userdata=%p, lhandle=%p) = ?", (int)action, fn, subtype, object, (long long unsigned int)objectlen, version, options, userdata, lhandle); 
     238 
     239 switch (fn) { 
     240  case ROAR_DL_FN_PROTO: 
     241    if ( subtype != ROAR_DL_PROTO_SUBTYPE ) { 
     242     ROAR_DBG("plugin_callback(action=%i, fn=%i, subtype=%i, object=%p, objectlen=%llu, version=%i, options=0x%x, userdata=%p, lhandle=%p) = -1 // error=TYPEMM", (int)action, fn, subtype, object, (long long unsigned int)objectlen, version, options, userdata, lhandle); 
     243 
     244     roar_err_set(ROAR_ERROR_TYPEMM); 
     245     return -1; 
     246    } 
     247    if ( objectlen != ROAR_DL_PROTO_SIZE ) { 
     248     ROAR_DBG("plugin_callback(action=%i, fn=%i, subtype=%i, object=%p, objectlen=%llu, version=%i, options=0x%x, userdata=%p, lhandle=%p) = -1 // error=BADLIB", (int)action, fn, subtype, object, (long long unsigned int)objectlen, version, options, userdata, lhandle); 
     249     roar_err_set(ROAR_ERROR_BADLIB); 
     250     return -1; 
     251    } 
     252    if ( version != ROAR_DL_PROTO_VERSION ) { 
     253     ROAR_DBG("plugin_callback(action=%i, fn=%i, subtype=%i, object=%p, objectlen=%llu, version=%i, options=0x%x, userdata=%p, lhandle=%p) = -1 // error=BADVERSION", (int)action, fn, subtype, object, (long long unsigned int)objectlen, version, options, userdata, lhandle); 
     254     roar_err_set(ROAR_ERROR_BADVERSION); 
     255     return -1; 
     256    } 
     257    switch (action) { 
     258     case ROAR_DL_FNREG: 
     259       return clients_register_proto_common(object, lhandle); 
     260      break; 
     261     case ROAR_DL_FNUNREG: 
     262       return clients_unregister_proto(((const struct roard_proto *)object)->proto); 
     263      break; 
     264    } 
     265   break; 
     266 } 
     267 
     268 ROAR_DBG("plugin_callback(action=%i, fn=%i, subtype=%i, object=%p, objectlen=%llu, version=%i, options=0x%x, userdata=%p, lhandle=%p) = -1 // error=NOTSUP", (int)action, fn, subtype, object, (long long unsigned int)objectlen, version, options, userdata, lhandle); 
     269 roar_err_set(ROAR_ERROR_NOTSUP); 
     270 return -1; 
     271} 
     272 
    224273//ll 
Note: See TracChangeset for help on using the changeset viewer.