Changeset 4326:c53e2ed183a2 in roaraudio


Ignore:
Timestamp:
09/08/10 01:30:26 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

use new roar_client_server struct for clients in roard

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/client.h

    r3718 r4326  
    3939#include "libroar.h" 
    4040 
     41#define ROAR_CLIENT(x) ((struct roar_client*)(x)) 
     42 
    4143struct roar_client { 
    4244 int fh; /* controll connection */ 
  • roard/clients.c

    r4325 r4326  
    5151 int i; 
    5252 int s; 
     53 struct roar_client_server * ns; 
    5354 struct roar_client * n; 
    5455 
    5556 for (i = 0; i < ROAR_CLIENTS_MAX; i++) { 
    5657  if ( g_clients[i] == NULL ) { 
    57    n = roar_mm_malloc(sizeof(struct roar_client)); 
     58   ns = roar_mm_malloc(sizeof(struct roar_client_server)); 
     59   n = ROAR_CLIENT(ns); 
     60 
     61   memset(ns, 0, sizeof(struct roar_client_server)); 
     62 
    5863   if ( n != NULL ) { 
    5964    n->pid    = -1; 
     
    7984    } 
    8085 
    81     g_clients[i] = n; 
     86    g_clients[i] = ns; 
    8287 
    8388    counters_inc(clients, 1); 
     
    134139 _CHECK_CID(id); 
    135140 
    136  if (g_clients[id]->execed != -1) { 
     141 if (ROAR_CLIENT(g_clients[id])->execed != -1) { 
    137142//  return streams_delete(g_clients[id]->execed); 
    138   g_clients[id]->execed = -1; 
     143  ROAR_CLIENT(g_clients[id])->execed = -1; 
    139144  close_client_fh = 0; 
    140145 } 
    141146 
    142147 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { 
    143   streams_delete(g_clients[id]->streams[i]); 
    144  } 
    145  
    146  if ( g_clients[id]->fh != -1 && close_client_fh ) 
    147   close(g_clients[id]->fh); 
    148  
    149  roar_nnode_free(&(g_clients[id]->nnode)); 
     148  streams_delete(ROAR_CLIENT(g_clients[id])->streams[i]); 
     149 } 
     150 
     151 if ( ROAR_CLIENT(g_clients[id])->fh != -1 && close_client_fh ) 
     152  close(ROAR_CLIENT(g_clients[id])->fh); 
     153 
     154 roar_nnode_free(&(ROAR_CLIENT(g_clients[id])->nnode)); 
    150155 
    151156 roar_mm_free(g_clients[id]); 
     
    163168 _CHECK_CID(id); 
    164169 
    165  c = g_clients[id]; 
     170 c = ROAR_CLIENT(g_clients[id]); 
    166171 
    167172 if ( c->fh == -1 ) { 
     
    170175 } 
    171176 
    172  if (nocheck_exec || g_clients[id]->execed != -1) { 
     177 if (nocheck_exec || c->execed != -1) { 
    173178  close(c->fh); 
    174179  c->fh = -1; 
     
    182187 _CHECK_CID(id); 
    183188 
    184  *client = g_clients[id]; 
     189 *client = ROAR_CLIENT(g_clients[id]); 
    185190 
    186191 if ( *client == NULL ) 
     
    199204 _CHECK_CID(id); 
    200205 
    201  if ( (c = g_clients[id]) == NULL ) 
     206 if ( (c = ROAR_CLIENT(g_clients[id])) == NULL ) 
    202207  return -1; 
    203208 
     
    226231 _CHECK_CID(id); 
    227232 
    228  return g_clients[id]->fh; 
     233 return ROAR_CLIENT(g_clients[id])->fh; 
    229234} 
    230235 
     
    232237 _CHECK_CID(id); 
    233238 
    234  g_clients[id]->pid = pid; 
     239 ROAR_CLIENT(g_clients[id])->pid = pid; 
    235240 
    236241 return 0; 
     
    240245 _CHECK_CID(id); 
    241246 
    242  g_clients[id]->uid = uid; 
     247 ROAR_CLIENT(g_clients[id])->uid = uid; 
    243248 
    244249 return 0; 
     
    248253 _CHECK_CID(id); 
    249254 
    250  g_clients[id]->gid = gid; 
     255 ROAR_CLIENT(g_clients[id])->gid = gid; 
    251256 
    252257 return 0; 
     
    267272 } 
    268273 
    269  g_clients[id]->proto     = proto; 
    270  g_clients[id]->byteorder = byteorder; 
     274 ROAR_CLIENT(g_clients[id])->proto     = proto; 
     275 ROAR_CLIENT(g_clients[id])->byteorder = byteorder; 
    271276 
    272277 return 0; 
     
    277282int clients_check_all (void) { 
    278283#ifdef ROAR_HAVE_SELECT 
     284 struct roar_client * c; 
    279285 struct timeval tv; 
    280286 fd_set r, e; 
     
    298304 
    299305 for (i = 0; i < ROAR_CLIENTS_MAX; i++) { 
    300   if ( g_clients[i] == NULL ) 
     306  if ( (c = ROAR_CLIENT(g_clients[i])) == NULL ) 
    301307   continue; 
    302308 
    303   if ( (fh = g_clients[i]->fh) != -1 ) { 
     309  if ( (fh = c->fh) != -1 ) { 
    304310   have++; 
    305311 
     
    316322 
    317323  for (j = 0; j < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; j++) { 
    318    if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) { 
    319     ROAR_DBG("clients_check_all(*): g_clients[i=%i]->streams[j=%i] = %i, fh = %i", i, j, g_clients[i]->streams[j], fh); 
     324   if ( (fh = streams_get_fh(c->streams[j])) != -1 ) { 
     325    ROAR_DBG("clients_check_all(*): g_clients[i=%i]->streams[j=%i] = %i, fh = %i", i, j, c->streams[j], fh); 
    320326    if ( fh > -1 ) { 
    321327     FD_SET(fh, &r); 
     
    324330      max_fh = fh; 
    325331    } else if ( fh == -2 ) { 
    326      streams_check(g_clients[i]->streams[j]); 
     332     streams_check(c->streams[j]); 
    327333    } 
    328334 
     
    334340  if ( !have_stream && have_streamless < MAX_STREAMLESS ) { 
    335341   streamless[have_streamless  ].id = i; 
    336    if ( (streamless[have_streamless++].fh = g_clients[i]->fh) == -1 ) 
     342   if ( (streamless[have_streamless++].fh = c->fh) == -1 ) 
    337343    have_streamless--; 
    338344  } 
     
    347353 
    348354 for (i = 0; i < ROAR_CLIENTS_MAX; i++) { 
    349   if ( g_clients[i] == NULL ) 
     355  if ( (c = ROAR_CLIENT(g_clients[i])) == NULL ) 
    350356   continue; 
    351357 
    352   if ( (fh = g_clients[i]->fh) != -1 ) { 
     358  if ( (fh = c->fh) != -1 ) { 
    353359   if ( FD_ISSET(fh, &r) ) { 
    354     if ( g_clients[i]->execed == -1 ) { 
     360    if ( c->execed == -1 ) { 
    355361     clients_check(i); 
    356      if ( g_clients[i] != NULL && g_clients[i]->execed != -1 ) { 
     362     if ( g_clients[i] != NULL && ROAR_CLIENT(g_clients[i])->execed != -1 ) { 
    357363      FD_CLR(fh, &r); 
    358364     } 
     
    370376  } 
    371377 
    372   if ( g_clients[i] == NULL ) 
     378  if ( (c = ROAR_CLIENT(g_clients[i])) == NULL ) 
    373379   continue; 
    374380 
     
    379385 
    380386   //ROAR_WARN("clients_check_all(*): client=%i: client exists", i); 
    381    ROAR_DBG("clients_check_all(*): client=%i, stream=%i: id=%i", i, j, g_clients[i]->streams[j]); 
    382  
    383    if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) { 
     387   ROAR_DBG("clients_check_all(*): client=%i, stream=%i: id=%i", i, j, c->streams[j]); 
     388 
     389   if ( (fh = streams_get_fh(c->streams[j])) != -1 ) { 
    384390    ROAR_DBG("clients_check_all(*): client=%i, stream=%i: fh=%i", i, j, fh); 
    385391    if ( fh > -1 && FD_ISSET(fh, &r) ) { 
    386      streams_check(g_clients[i]->streams[j]); 
     392     streams_check(c->streams[j]); 
    387393    } 
    388394   } 
     
    399405 
    400406   for (i = 0; i < have_streamless; i++) { 
    401     if ( ! g_clients[j = streamless[i].id] ) 
     407    if ( g_clients[j = streamless[i].id] == NULL ) 
    402408     continue; 
    403409 
    404     if ( g_clients[j]->execed != -1 ) 
     410    if ( ROAR_CLIENT(g_clients[j])->execed != -1 ) 
    405411     continue; 
    406412 
     
    433439 
    434440int clients_check     (int id) { 
     441 struct roar_client   * c; 
    435442 struct roar_message    m; 
    436443 struct roar_connection con; 
     
    444451 _CHECK_CID(id); 
    445452 
    446  if ( g_clients[id]->fh == -1 ) 
     453 c = ROAR_CLIENT(g_clients[id]); 
     454 
     455 if ( c->fh == -1 ) 
    447456  return -1; 
    448457 
    449  roar_connect_fh(&con, g_clients[id]->fh); 
    450  
    451  switch (g_clients[id]->proto) { 
     458 roar_connect_fh(&con, c->fh); 
     459 
     460 switch (c->proto) { 
    452461  case ROAR_PROTO_ROARAUDIO: 
    453462    r = roar_recv_message(&con, &m, &data); 
     
    554563*/ 
    555564 
    556   ROAR_DBG("clients_send_mon(*): client=%i, execed=%i", i, g_clients[i]->execed); 
     565  ROAR_DBG("clients_send_mon(*): client=%i, execed=%i", i, ROAR_CLIENT(g_clients[i])->execed); 
    557566 
    558567/* 
     
    563572    //if ( (fh = streams_get_fh(g_clients[i]->streams[j])) != -1 ) { 
    564573    ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> ?", i, j); 
    565     if ( g_clients[i]->streams[j] != -1 ) { 
    566      ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> %i", i, j, g_clients[i]->streams[j]); 
    567      streams_send_mon(g_clients[i]->streams[j]); 
     574    if ( ROAR_CLIENT(g_clients[i])->streams[j] != -1 ) { 
     575     ROAR_DBG("clients_send_mon(*): client=%i, stream=%i -> %i", i, j, ROAR_CLIENT(g_clients[i])->streams[j]); 
     576     streams_send_mon(ROAR_CLIENT(g_clients[i])->streams[j]); 
    568577 
    569578     // the client may be deleted here, check if it still exists: 
     
    587596 
    588597int clients_send_filter(struct roar_audio_info * sa, uint32_t pos) { 
     598 struct roar_client * c; 
    589599 int i; 
    590600 int fh; 
    591601 
    592602 for (i = 0; i < ROAR_CLIENTS_MAX; i++) { 
    593   if ( g_clients[i] == NULL ) 
     603  if ( (c = ROAR_CLIENT(g_clients[i])) == NULL ) 
    594604   continue; 
    595605 
    596   if ( (fh = g_clients[i]->fh) == -1 ) 
     606  if ( (fh = c->fh) == -1 ) 
    597607   continue; 
    598608 
    599   if ( g_clients[i]->execed == -1 ) { 
     609  if ( c->execed == -1 ) { 
    600610   // TODO: add some code to send a message to the client insetd of the raw data. 
    601611  } else { 
    602612//   streams_check(g_clients[i]->execed); 
    603    streams_send_filter(g_clients[i]->execed); 
     613   streams_send_filter(c->execed); 
    604614//   if ( streams_send_mon(g_clients[i]->execed) == -1 ) 
    605615//    clients_delete(i); // delete client in case we could not write 
     
    611621 
    612622int client_stream_exec   (int client, int stream) { 
     623 struct roar_client * c; 
    613624 int i; 
    614625 int fh; 
     
    623634#endif 
    624635 
     636 c = ROAR_CLIENT(g_clients[client]); 
     637 
    625638 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { 
    626   if ( g_clients[client]->streams[i] == stream ) { 
    627    g_clients[client]->execed = stream; 
     639  if ( c->streams[i] == stream ) { 
     640   c->execed = stream; 
    628641   if ( streams_is_ready(stream) == 0 ) { 
    629     streams_set_fh(stream, g_clients[client]->fh); 
     642    streams_set_fh(stream, c->fh); 
    630643    streams_set_socktype(stream, ROAR_SOCKET_TYPE_GENSTR); 
    631644   } else { 
    632645    ROAR_DBG("client_stream_exec(client=%i, stream=%i): fh=?", client, stream); 
    633     if ( (fh = g_clients[client]->fh) != -1 ) { 
     646    if ( (fh = c->fh) != -1 ) { 
    634647     close(fh); 
    635      g_clients[client]->fh = -1; 
     648     c->fh = -1; 
    636649    } 
    637650   } 
     
    653666 
    654667 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { 
    655   if ( g_clients[client]->streams[i] == stream ) { 
     668  if ( ROAR_CLIENT(g_clients[client])->streams[i] == stream ) { 
    656669   ROAR_DBG("client_stream_set_fh(client=%i, stream=%i, fh=%i): stream found, index %i", client, stream, fh, i); 
    657670   return streams_set_fh(stream, fh); 
     
    669682 
    670683 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { 
    671   if ( g_clients[client]->streams[i] == -1 ) { 
    672    g_clients[client]->streams[i] = stream; 
     684  if ( ROAR_CLIENT(g_clients[client])->streams[i] == -1 ) { 
     685   ROAR_CLIENT(g_clients[client])->streams[i] = stream; 
    673686   streams_set_client(stream, client); 
    674687   return 0; 
     
    685698 
    686699 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { 
    687   if ( g_clients[client]->streams[i] == stream ) { 
    688    g_clients[client]->streams[i] = -1; 
    689  
    690    if ( stream == g_clients[client]->execed ) { 
     700  if ( ROAR_CLIENT(g_clients[client])->streams[i] == stream ) { 
     701   ROAR_CLIENT(g_clients[client])->streams[i] = -1; 
     702 
     703   if ( stream == ROAR_CLIENT(g_clients[client])->execed ) { 
    691704    ROAR_DBG("client_stream_delete(client=%i, stream=%i): stream is execed one, deleting client!", client, stream); 
    692705    clients_delete(client); 
  • roard/include/client.h

    r3927 r4326  
    4747*/ 
    4848 
    49 struct roar_client * g_clients[ROAR_CLIENTS_MAX]; 
     49struct roar_client_server { 
     50 struct roar_client _client; 
     51} * g_clients[ROAR_CLIENTS_MAX]; 
    5052 
    5153 
Note: See TracChangeset for help on using the changeset viewer.