Changeset 4934:a88414aa5705 in roaraudio for roard/rolestack.c
- Timestamp:
- 05/09/11 01:39:41 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roard/rolestack.c
r4932 r4934 26 26 #include "roard.h" 27 27 28 #define STACKSIZE 16 29 30 static struct rolestack g_rolestack[STACKSIZE]; 31 32 void rolestack_init(void) { 33 int i; 34 35 for (i = 0; i < STACKSIZE; i++) { 36 g_rolestack[i].index = i; 37 g_rolestack[i].role = ROAR_ROLE_UNKNOWN; 38 g_rolestack[i].action = RS_MIX; 39 } 40 41 g_rolestack[0].role = ROAR_ROLE_NONE; 42 } 43 44 void print_rolestack(void) { 45 int i; 46 47 printf("Index Role Action\n"); 48 printf("-----------------------------\n"); 49 for (i = 0; i < STACKSIZE && g_rolestack[i].role != ROAR_ROLE_UNKNOWN; i++) { 50 printf("%-5i %-16s %s\n", g_rolestack[i].index, 51 roar_role2str(g_rolestack[i].role), rolestack_action2str(g_rolestack[i].action)); 52 } 53 } 54 55 const struct rolestack * rolestack_get_role(int role) { 56 int i; 57 58 ROAR_DBG("rolestack_get_role(role=%i) = ?", role); 59 60 if ( role == -1 ) 61 return &(g_rolestack[0]); 62 63 for (i = STACKSIZE - 1; i >= 0; i--) 64 if ( g_rolestack[i].role == role ) 65 return &(g_rolestack[i]); 66 67 return &(g_rolestack[0]); 68 } 69 70 int rolestack_push(const struct rolestack * role) { 71 int i; 72 73 for (i = 0; i < STACKSIZE; i++) { 74 if ( g_rolestack[i].role == ROAR_ROLE_UNKNOWN ) { 75 memcpy(&(g_rolestack[i]), role, sizeof(g_rolestack[i])); 76 g_rolestack[i].index = i; 77 return 0; 78 } 79 } 80 81 roar_err_set(ROAR_ERROR_NOMEM); 82 return -1; 83 } 84 85 enum rs_action rolestack_str2action(const char * str) { 86 if ( str == NULL ) { 87 roar_err_set(ROAR_ERROR_FAULT); 88 return -1; 89 } 90 91 if (!strcasecmp(str, "mix")) { 92 return RS_MIX; 93 } else if (!strcasecmp(str, "kick")) { 94 return RS_KICK; 95 } else if (!strcasecmp(str, "mute")) { 96 return RS_MUTE; 97 } else if (!strcasecmp(str, "pause")) { 98 return RS_PAUSE; 99 } 100 101 return RS_ERROR; 102 } 103 104 const char * rolestack_action2str(enum rs_action action) { 105 switch (action) { 106 case RS_ERROR: return "(error)"; break; 107 case RS_MIX: return "mix"; break; 108 case RS_MUTE: return "mute"; break; 109 case RS_PAUSE: return "pause"; break; 110 case RS_KICK: return "kick"; break; 111 } 112 113 return "(unknown)"; 114 } 115 116 const struct rolestack * rolestack_parse(const char * str) { 117 static struct rolestack ret; 118 char * role, * action; 119 120 if ( str == NULL ) { 121 roar_err_set(ROAR_ERROR_FAULT); 122 return NULL; 123 } 124 125 role = roar_mm_strdup(str); 126 if ( role == NULL ) 127 return NULL; 128 129 if ( (action = strstr(role, ":")) == NULL ) { 130 roar_mm_free(role); 131 roar_err_set(ROAR_ERROR_BADMSG); 132 return NULL; 133 } 134 135 *action = 0; 136 action++; 137 138 ret.index = -1; 139 ret.role = roar_str2role(role); 140 ret.action = rolestack_str2action(action); 141 142 roar_mm_free(role); 143 144 if ( ret.role == -1 || ret.action == RS_ERROR ) { 145 roar_err_set(ROAR_ERROR_BADMSG); 146 return NULL; 147 } 148 149 return &ret; 150 } 151 28 152 //ll
Note: See TracChangeset
for help on using the changeset viewer.