Changeset 4934:a88414aa5705 in roaraudio
- Timestamp:
- 05/09/11 01:39:41 (13 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
ChangeLog
r4930 r4934 6 6 * Some cleanup of roarclients to fix ckport warnings. 7 7 * Fixed warning on FreeBSD about tempfile in ast2roar (Closes: #47) 8 * Added support for role based handling in roard (Closes: #49) 8 9 9 10 v. 0.4beta5 - Tue Apr 26 2011 08:42 CEST -
roard/include/rolestack.h
r4932 r4934 29 29 #include <roaraudio.h> 30 30 31 enum rs_action { 32 RS_ERROR = -1, 33 RS_MIX = 0, 34 RS_KICK, 35 RS_MUTE, 36 RS_PAUSE 37 }; 38 39 struct rolestack { 40 int index; 41 int role; 42 enum rs_action action; 43 }; 44 45 void rolestack_init(void); 46 void print_rolestack(void); 47 48 const struct rolestack * rolestack_get_role(int role); 49 int rolestack_push(const struct rolestack * role); 50 51 enum rs_action rolestack_str2action(const char * str); 52 const char * rolestack_action2str(enum rs_action action); 53 54 const struct rolestack * rolestack_parse(const char * str); 55 31 56 #endif 32 57 -
roard/roard.c
r4924 r4934 248 248 " a flag as default or remove it from the default\n" 249 249 ); 250 printf("\nStream Options:\n\n"); 251 printf( 252 " --list-rolestack - Show the current role stack\n" 253 " --rolestack-push R:A - Add a rule for role R with action A on top\n" 254 " of the role stack.\n" 255 ); 250 256 251 257 printf("\nOutput Options:\n\n"); … … 1332 1338 struct roar_audio_info sa, max_sa; 1333 1339 struct roard_config config; 1340 const struct rolestack * rolestack; 1334 1341 #ifdef ROAR_HAVE_FORK 1335 1342 int daemon = 0; … … 1461 1468 #endif 1462 1469 1470 rolestack_init(); 1471 1463 1472 if ( auth_init() == -1 ) { 1464 1473 ROAR_ERR("Can not init auth subsystem!"); … … 1712 1721 return 1; 1713 1722 } 1723 1724 } else if ( strcmp(k, "--list-rolestack") == 0 ) { 1725 print_rolestack(); 1726 return 0; 1727 } else if ( strcmp(k, "--rolestack-push") == 0 ) { 1728 _CKHAVEARGS(1); 1729 if ( (rolestack = rolestack_parse(argv[++i])) == NULL ) { 1730 ROAR_ERR("Can not parse rolestack request: %s", roar_error2str(roar_error)); 1731 } else { 1732 if ( rolestack_push(rolestack) == -1 ) { 1733 ROAR_ERR("Can not push request to rolestack: %s", roar_error2str(roar_error)); 1734 } 1735 } 1714 1736 1715 1737 } else if ( strcmp(k, "--list-aiprofiles") == 0 ) { -
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 -
roard/streams.c
r4896 r4934 33 33 int streams_recsource_id = -1; 34 34 35 static const struct rolestack * streams_rolestack = NULL; 36 static int streams_role_num = 0; 37 38 35 39 static void _streams_change_state(struct roar_stream_server * s, const int new, const char * func) { 36 40 register int id = ROAR_STREAM(s)->id; … … 122 126 int streams_init (void) { 123 127 int i; 128 129 streams_rolestack = rolestack_get_role(-1); // get default 124 130 125 131 for (i = 0; i < ROAR_STREAMS_MAX; i++) … … 263 269 roar_notify_core_emit_snoargs(ROAR_OE_BASICS_DELETE, -1, id, ROAR_OT_STREAM); 264 270 271 streams_set_role(id, -1); 272 265 273 prim = s->primary; 266 274 … … 513 521 } 514 522 523 static int streams_set_role_handle(int id) { 524 switch (streams_rolestack->action) { 525 case RS_ERROR: /* nothing to do */; break; 526 case RS_MIX: /* nothing to do */; break; 527 case RS_KICK: streams_delete(id); break; 528 case RS_MUTE: streams_set_flag(id, ROAR_FLAG_MUTE); break; 529 case RS_PAUSE: streams_set_flag(id, ROAR_FLAG_PAUSE); break; 530 } 531 return 0; 532 } 533 515 534 int streams_set_role (int id, int role) { 516 535 struct roar_stream_server * ss; 536 const struct rolestack * rs; 537 int old_role; 538 int i; 539 540 ROAR_DBG("streams_set_role(id=%i, role=%i) = ?", id, role); 517 541 518 542 _CHECK_SID(id); … … 521 545 return -1; 522 546 547 old_role = ss->role; 523 548 ss->role = role; 524 549 550 ROAR_DBG("streams_set_role(id=%i, role=%i) = ?", id, role); 551 552 if ( ROAR_STREAM(ss)->dir != ROAR_DIR_PLAY ) 553 return 0; 554 555 ROAR_DBG("streams_set_role(id=%i, role=%i) = ?", id, role); 556 557 if ( old_role == role ) 558 return 0; 559 560 if ( old_role != role && old_role != -1 && role != -1 ) { 561 streams_set_role(id, -1); 562 streams_set_role(id, role); 563 } 564 565 ROAR_DBG("streams_set_role(id=%i, role=%i) = ?", id, role); 566 567 if ( ss->role != -1 && ss->role == streams_rolestack->role ) { 568 ROAR_DBG("streams_set_role(id=%i, role=%i) = ?", id, role); 569 570 streams_role_num--; 571 if ( streams_role_num == 0 ) { 572 streams_rolestack = rolestack_get_role(-1); // get default 573 for (i = 0; i < ROAR_STREAMS_MAX; i++) { 574 if ( (ss = g_streams[i]) == NULL ) 575 continue; 576 if ( ROAR_STREAM(ss)->dir != ROAR_DIR_PLAY ) 577 continue; 578 if ( ss->role == -1 ) 579 continue; 580 rs = rolestack_get_role(ss->role); 581 if ( rs->index > streams_rolestack->role ) { 582 streams_rolestack = rs; 583 } 584 } 585 for (i = 0; i < ROAR_STREAMS_MAX; i++) { 586 if ( (ss = g_streams[i]) == NULL ) 587 continue; 588 if ( ROAR_STREAM(ss)->dir != ROAR_DIR_PLAY ) 589 continue; 590 if ( ss->role == streams_rolestack->role ) 591 streams_role_num++; 592 } 593 } 594 } else if ( role != -1 ) { 595 ROAR_DBG("streams_set_role(id=%i, role=%i) = ?", id, role); 596 597 rs = rolestack_get_role(role); 598 ROAR_DBG("streams_set_role(id=%i, role=%i): rs->index=%i, streams_rolestack->index=%i", id, role, rs->index, streams_rolestack->index); 599 if ( rs->index == streams_rolestack->index ) { 600 ROAR_DBG("streams_set_role(id=%i, role=%i): rs->index=%i, streams_rolestack->index=%i", id, role, rs->index, streams_rolestack->index); 601 streams_role_num++; 602 } else if ( rs->index > streams_rolestack->index ) { 603 ROAR_DBG("streams_set_role(id=%i, role=%i): rs=%p{.index=%i, .action=%s}", id, role, rs, rs->index, rolestack_action2str(rs->action)); 604 streams_role_num = 1; 605 streams_rolestack = rs; 606 for (i = 0; i < ROAR_STREAMS_MAX; i++) { 607 if ( (ss = g_streams[i]) == NULL ) 608 continue; 609 if ( ROAR_STREAM(ss)->dir != ROAR_DIR_PLAY ) 610 continue; 611 rs = rolestack_get_role(ss->role); 612 ROAR_DBG("streams_set_role(id=%i, role=%i): i=%i, rs->index=%i, streams_rolestack->index=%i", id, role, i, rs->index, streams_rolestack->index); 613 if ( rs->index < streams_rolestack->index ) 614 streams_set_role_handle(i); 615 } 616 } else { 617 ROAR_DBG("streams_set_role(id=%i, role=%i): streams_rolestack->action=%s", id, role, rolestack_action2str(streams_rolestack->action)); 618 streams_set_role_handle(id); 619 } 620 } 621 622 ROAR_DBG("streams_set_role(id=%i, role=%i) = 0", id, role); 525 623 return 0; 526 624 }
Note: See TracChangeset
for help on using the changeset viewer.