Changeset 4836:684486ae8f9f in roaraudio for roarclients


Ignore:
Timestamp:
04/03/11 12:44:57 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

add --explain

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roarclients/roarvio.c

    r4835 r4836  
    2424 */ 
    2525 
     26int g_verbose = 0; 
     27#define ROAR_DBG_INFOVAR g_verbose 
     28 
    2629#include <roaraudio.h> 
    2730#include <errno.h> 
     
    3033enum action { 
    3134 READ, 
    32  WRITE 
     35 WRITE, 
     36 EXPLAIN 
    3337}; 
    3438 
     39 
    3540void usage (const char * progname) { 
     41} 
     42 
     43int do_explain (struct roar_vio_calls * cur) { 
     44 struct roar_sockname sockname; 
     45 int                  have_sockname; 
     46 int need_space, need_space2; 
     47 int level = 0; 
     48 int fh; 
     49 char * name; 
     50 const char * codec; 
     51 char * content_type; 
     52 
     53 while (cur != NULL) { 
     54  if ( roar_vio_ctl(cur, ROAR_VIO_CTL_GET_NAME, &name) == -1 ) 
     55   name = "UNKNOWN"; 
     56 
     57  if ( g_verbose ) { 
     58   if ( roar_vio_ctl(cur, ROAR_VIO_CTL_GET_MIMETYPE, &content_type) == -1 ) 
     59    content_type = "UNKNOWN"; 
     60 
     61   codec = roar_codec2str(roar_mime2codec(content_type)); 
     62 
     63   if ( roar_vio_ctl(cur, ROAR_VIO_CTL_GET_FH, &fh) == -1 ) 
     64    fh = -1; 
     65 
     66   if ( g_verbose > 1 ) { 
     67    if ( roar_vio_ctl(cur, ROAR_VIO_CTL_GET_PEERNAME, &sockname) == -1 ) { 
     68     have_sockname = 0; 
     69    } else { 
     70     have_sockname = 1; 
     71    } 
     72   } else { 
     73    have_sockname = 0; 
     74   } 
     75  } else { 
     76   content_type  = "UNKNOWN"; 
     77   codec         = "UNKNOWN"; 
     78   fh            = -1; 
     79   have_sockname = 0; 
     80  } 
     81 
     82  printf("%i: %s", level, name); 
     83  if ( fh != -1 || !!strcasecmp(codec, "UNKNOWN") || !!strcasecmp(content_type, "UNKNOWN") || have_sockname ) { 
     84   need_space = 0; 
     85   printf(" ("); 
     86   if ( fh != -1 ) { 
     87    printf("fh=%i", fh); 
     88    need_space = 1; 
     89   } 
     90 
     91   if ( have_sockname ) { 
     92    need_space2 = 0; 
     93    printf("%ssocket={", need_space ? ", " : ""); 
     94 
     95    need_space2 = 1; 
     96    switch (sockname.type) { 
     97     case ROAR_SOCKET_TYPE_UNIX:   printf("af=UNIX");   break; 
     98     case ROAR_SOCKET_TYPE_DECNET: printf("af=DECnet"); break; 
     99     case ROAR_SOCKET_TYPE_INET:   printf("af=INET");   break; 
     100     case ROAR_SOCKET_TYPE_INET6:  printf("af=INET6");  break; 
     101     default: 
     102       need_space2 = 0; 
     103      break; 
     104    } 
     105 
     106    if ( sockname.addr != NULL ) { 
     107     printf("%saddr=\"%s\"", need_space2 ? ", " : "", sockname.addr); 
     108     need_space2 = 1; 
     109    } 
     110 
     111    if ( sockname.port ) { 
     112     printf("%sport=%i", need_space2 ? ", " : "", sockname.port); 
     113     need_space2 = 1; 
     114    } 
     115 
     116    printf("}"); 
     117    need_space = 1; 
     118   } 
     119 
     120   if ( !!strcasecmp(codec, "UNKNOWN") ) { 
     121    printf("%scodec=%s", need_space ? ", " : "", codec); 
     122    need_space = 1; 
     123   } 
     124 
     125   if ( !!strcmp(content_type, "UNKNOWN") ) { 
     126    printf("%scontent-type=\"%s\"", need_space ? ", " : "", content_type); 
     127    need_space = 1; 
     128   } 
     129   printf(")"); 
     130  } 
     131  printf("\n"); 
     132 
     133  level++; 
     134 
     135  if ( have_sockname ) 
     136   if ( sockname.addr != NULL ) 
     137    roar_mm_free(sockname.addr); 
     138 
     139  if ( roar_vio_ctl(cur, ROAR_VIO_CTL_GET_NEXT, &cur) == -1 ) 
     140   cur = NULL; 
     141 } 
     142 
     143 return 0; 
    36144} 
    37145 
     
    44152 char * file = NULL; 
    45153 int o_flags = -1; 
     154 int ret = 0; 
    46155 
    47156 for (i = 1; i < argc; i++) { 
     
    55164  } else if ( !strcmp(k, "--write") ) { 
    56165   action = WRITE; 
     166  } else if ( !strcmp(k, "--explain") ) { 
     167   action = EXPLAIN; 
     168  } else if ( !strcmp(k, "--verbose") ) { 
     169   g_verbose++; 
    57170  } else if ( file == NULL ) { 
    58171   file = k; 
     
    71184 switch (action) { 
    72185  case READ: 
     186  case EXPLAIN: 
    73187    o_flags = O_RDONLY; 
    74188   break; 
     
    100214    roar_vio_copy_data(&vio, roar_stdin); 
    101215   break; 
     216  case EXPLAIN: 
     217    if ( do_explain(&vio) == -1 ) 
     218     ret = 4; 
     219   break; 
    102220 } 
    103221 
    104222 roar_vio_close(&vio); 
    105223 
    106  return 0; 
     224 return ret; 
    107225} 
    108226 
Note: See TracChangeset for help on using the changeset viewer.