Changeset 3312:f425c2ff782d in roaraudio


Ignore:
Timestamp:
02/03/10 14:03:41 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

more general internal API, support to register types

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/vio_dstr.h

    r3309 r3312  
    174174char *  roar_vio_dstr_get_name(int type); 
    175175 
     176int     roar_vio_dstr_register_type(int   type, 
     177                                    char *name, 
     178                                    int (*setdef) (struct roar_vio_dstr_chain * cur, 
     179                                                   struct roar_vio_dstr_chain * next), 
     180                                    int (*openvio)(struct roar_vio_calls      * calls, 
     181                                                   struct roar_vio_calls      * dst, 
     182                                                   struct roar_vio_dstr_chain * cur)); 
     183 
    176184int     roar_vio_dstr_init_defaults (struct roar_vio_defaults * def, int type, int o_flags, mode_t o_mode); 
    177185int     roar_vio_dstr_init_defaults_c (struct roar_vio_defaults * def, int type, struct roar_vio_defaults * odef, int o_flags); 
  • libroar/vio_dstr.c

    r3311 r3312  
    3636 
    3737#ifndef ROAR_WITHOUT_VIO_DSTR 
    38 struct { 
     38struct _roar_vio_dstr_type { 
    3939 int    id; 
    4040 char * name; 
     
    212212} 
    213213 
    214 char *  roar_vio_dstr_get_name(int type) { 
     214struct _roar_vio_dstr_type * roar_vio_dstr_get_by_type (int type) { 
    215215 int i; 
    216216 
    217217 for (i = 0; _roar_vio_dstr_objs[i].id != ROAR_VIO_DSTR_OBJT_EOL; i++) { 
    218218  if ( _roar_vio_dstr_objs[i].id == type ) 
    219    return _roar_vio_dstr_objs[i].name; 
    220  } 
     219   return &(_roar_vio_dstr_objs[i]); 
     220 } 
     221 
     222 return NULL; 
     223} 
     224 
     225char *  roar_vio_dstr_get_name(int type) { 
     226 struct _roar_vio_dstr_type * ret; 
     227 
     228 if ( (ret = roar_vio_dstr_get_by_type(type)) != NULL ) 
     229  return ret->name; 
    221230 
    222231 if ( type == ROAR_VIO_DSTR_OBJT_EOL ) 
     
    224233 
    225234 return NULL; 
     235} 
     236 
     237int     roar_vio_dstr_register_type(int   type, 
     238                                    char *name, 
     239                                    int (*setdef) (struct roar_vio_dstr_chain * cur, 
     240                                                   struct roar_vio_dstr_chain * next), 
     241                                    int (*openvio)(struct roar_vio_calls      * calls, 
     242                                                   struct roar_vio_calls      * dst, 
     243                                                   struct roar_vio_dstr_chain * cur)) { 
     244 struct _roar_vio_dstr_type * ret; 
     245 
     246 if ( (ret = roar_vio_dstr_get_by_type(type)) == NULL ) /* we can currently not register new types */ 
     247  return -1; 
     248 
     249 
     250 // check if things are allready set, we do not want to allow overwrite here. 
     251 if ( setdef != NULL && ret->setdef != NULL ) 
     252  return -1; 
     253 
     254 if ( openvio != NULL && ret->openvio != NULL ) 
     255  return -1; 
     256 
     257 if ( setdef != NULL ) 
     258  ret->setdef = setdef; 
     259 
     260 if ( openvio != NULL ) 
     261  ret->openvio = openvio; 
     262 
     263 return 0; 
    226264} 
    227265 
Note: See TracChangeset for help on using the changeset viewer.