Changeset 4552:47a0412f706d in roaraudio


Ignore:
Timestamp:
10/25/10 14:03:43 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

implemented flag toggling and flag protection

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r4548 r4552  
    1414        * Added new test system RAT 
    1515        * Added support for single sink mode (Closes: #25) 
     16        * Implemented atomic flag toggling and flag protection. 
    1617 
    1718v. 0.4beta0 - Fri Oct 01 2010 13:36 CEST 
  • roarclients/roarctl.c

    r4536 r4552  
    9797        "                            separated list of flags.\n" 
    9898        "  unflag ID FLAGS         - Unsets flags on a stream. See flag.\n" 
     99        "  toogleflag ID FLAGS     - Toggels flags on a stream. See flag.\n" 
     100        "  protectflag ID FLAGS    - Protects flags on a stream. Those flags can not be\n" 
     101        "                            changed anymore after the they got protected. See flag.\n" 
    99102        "\n" 
    100103        "  kick TYPE ID            - Kicks object of TYPE with id ID\n" 
     
    926929} 
    927930 
    928 int set_flags (struct roar_connection * con, int id, int reset, char * flags) { 
    929  int f = ROAR_FLAG_NONE; 
     931int set_flags (struct roar_connection * con, int id, int action, char * flags) { 
     932 uint32_t f = ROAR_FLAG_NONE; 
    930933 char * c; 
    931934 struct roar_stream s[1]; 
     
    976979 } 
    977980 
    978  return roar_stream_set_flags(con, s, f, reset); 
     981 return roar_stream_set_flags2(con, s, f, action); 
    979982} 
    980983 
     
    11911194   } 
    11921195   i++; 
     1196  } else if ( !strcmp(k, "toggleflag") ) { 
     1197   i++; 
     1198   if ( set_flags(&con, atoi(argv[i]), ROAR_TOGGLE_FLAG, argv[i+1]) == -1 ) { 
     1199    fprintf(stderr, "Error: can not toggle flags\n"); 
     1200   } else { 
     1201    printf("flags changed\n"); 
     1202   } 
     1203   i++; 
     1204  } else if ( !strcmp(k, "protectflag") ) { 
     1205   i++; 
     1206   if ( set_flags(&con, atoi(argv[i]), ROAR_NOOP_FLAG|ROAR_PROTECT_FLAG, argv[i+1]) == -1 ) { 
     1207    fprintf(stderr, "Error: can not protect flags\n"); 
     1208   } else { 
     1209    printf("flags protected\n"); 
     1210   } 
     1211   i++; 
    11931212  } else if ( !strcmp(k, "metaset") ) { 
    11941213   i++; 
  • roard/include/streams.h

    r4550 r4552  
    162162int streams_get_flag     (int id, uint32_t flag); 
    163163 
     164int streams_protect_flag (int id, uint32_t flag); 
     165 
    164166int streams_set_name     (int id, char * name); 
    165167char * streams_get_name  (int id); 
  • roard/req.c

    r4539 r4552  
    10731073 
    10741074int req_on_set_stream_para (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) { 
     1075 struct roar_stream_server * ss; 
    10751076 uint16_t * d = (uint16_t *) mes->data; 
    1076  uint32_t tmp; 
     1077 uint32_t tmp, tmp2, flagstore; 
     1078 int protect = 0; 
    10771079 int i; 
    10781080 
     
    11071109    tmp |= d[3]; 
    11081110 
    1109     if ( d[2] == ROAR_RESET_FLAG ) { 
    1110      if ( streams_reset_flag(mes->stream, tmp) == -1 ) 
    1111       return -1; 
    1112     } else { 
    1113      if ( streams_set_flag(mes->stream, tmp) == -1 ) 
    1114       return -1; 
    1115     } 
     1111    if ( d[2] & ROAR_PROTECT_FLAG ) { 
     1112     protect = 1; 
     1113     d[2] -= ROAR_PROTECT_FLAG; 
     1114    } 
     1115 
     1116    switch (d[2]) { 
     1117     case ROAR_SET_FLAG: 
     1118       if ( streams_set_flag(mes->stream, tmp) == -1 ) 
     1119        return -1; 
     1120      break; 
     1121     case ROAR_RESET_FLAG: 
     1122       if ( streams_reset_flag(mes->stream, tmp) == -1 ) 
     1123        return -1; 
     1124      break; 
     1125     case ROAR_NOOP_FLAG: 
     1126      break; 
     1127     case ROAR_TOGGLE_FLAG: 
     1128       if ( streams_get(mes->stream, &ss) == -1 ) 
     1129        return -1; 
     1130 
     1131       flagstore = ss->flags; 
     1132 
     1133       tmp2 = flagstore & tmp; // those are the flags we need to reset. 
     1134       ROAR_DBG("req_on_set_stream_para(*): tmp2=0x%.8lx", (long int)tmp2); 
     1135       if ( tmp2 ) 
     1136        if ( streams_reset_flag(mes->stream, tmp2) == -1 ) 
     1137         return -1; 
     1138 
     1139       tmp2 = (flagstore ^ tmp) & tmp; // those are the flags we need to set. 
     1140       ROAR_DBG("req_on_set_stream_para(*): tmp2=0x%.8lx", (long int)tmp2); 
     1141       if ( tmp2 ) 
     1142        if ( streams_set_flag(mes->stream, tmp2) == -1 ) 
     1143         return -1; 
     1144      break; 
     1145     default: 
     1146       return -1; 
     1147      break; 
     1148    } 
     1149 
     1150   ROAR_DBG("req_on_set_stream_para(*): protect=%i", protect); 
     1151   if ( protect ) 
     1152    if ( streams_protect_flag(mes->stream, tmp) == -1 ) 
     1153     return -1; 
     1154 
    11161155   break; 
    11171156  case ROAR_STREAM_PARA_CHANMAP: 
  • roard/streams.c

    r4550 r4552  
    896896  flag |= ROAR_FLAG_PRIMARY; 
    897897 
     898 
     899 // check if flags we are going to change are protected: 
     900 if ( g_streams[id]->flags_protection & flag ) 
     901  return -1; 
     902 
     903 
    898904 if ( flag & ROAR_FLAG_MMAP ) { 
    899905  if ( streams_set_mmap(id, 0) == -1 ) { 
     
    984990 _CHECK_SID(id); 
    985991 
     992 // check if flags we are going to change are protected: 
     993 if ( g_streams[id]->flags_protection & flag ) 
     994  return -1; 
     995 
    986996 if ( g_streams[id]->flags & ROAR_FLAG_IMMUTABLE ) { 
    987997  flag |= ROAR_FLAG_PRIMARY; 
     
    10321042 
    10331043 return g_streams[id]->flags & flag ? 1 : 0; 
     1044} 
     1045 
     1046int streams_protect_flag (int id, uint32_t flag) { 
     1047 _CHECK_SID(id); 
     1048 
     1049 g_streams[id]->flags_protection |= flag; 
     1050 
     1051 return 0; 
    10341052} 
    10351053 
Note: See TracChangeset for help on using the changeset viewer.