Changeset 5065:18cdc8c3a1ab in roaraudio


Ignore:
Timestamp:
06/18/11 04:07:49 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added roar_clock_gettime()

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/roarfeatures.h

    r5010 r5065  
    4848#define ROAR_FT_FUNC_PANIC 
    4949#define ROAR_FT_FUNC_RESET 
     50#define ROAR_FT_FUNC_CLOCK_GETTIME 
    5051#define ROAR_FT_FEATURE_VS 
    5152#define ROAR_FT_FEATURE_VS_FILE 
  • include/libroar/roartime.h

    r5031 r5065  
    5151int roar_get_time  (struct roar_connection * con, struct roar_time * time); 
    5252 
     53int roar_clock_gettime(struct roar_time * rt, int clock); 
     54 
    5355#endif 
    5456 
  • include/roaraudio/proto.h

    r5031 r5065  
    195195#define ROAR_ITST_UIURL             10 
    196196 
     197// IDs for diffrent clocks: 
     198#define ROAR_CLOCK_DEFAULT          -2 
     199#define ROAR_CLOCK_UNKNOWN          -1 
     200#define ROAR_CLOCK_REALTIME          1 
     201#define ROAR_CLOCK_MONOTONIC         2 
     202#define ROAR_CLOCK_UPTIME            3 
     203 
    197204// old: do not use. 
    198205struct roar_timeofday { 
  • libroar/time.c

    r5031 r5065  
    5757 
    5858 if ( time->c_drift == 0 ) { 
    59   mes->datalen -= 4; 
     59  mes->datalen -= 8; 
    6060  if ( time->c_freq == 0 ) { 
    61    mes->datalen -= 4; 
     61   mes->datalen -= 8; 
    6262   if ( time->t_ssec == 0 ) { 
    63     mes->datalen -= 4; 
     63    mes->datalen -= 8; 
    6464   } 
    6565  } 
     
    140140} 
    141141 
     142int roar_clock_gettime(struct roar_time * rt, int clock) { 
     143#ifdef ROAR_HAVE_GETTIMEOFDAY 
     144 struct timeval tv; 
     145#elif defined(ROAR_HAVE_TIME) 
     146 time_t now; 
     147#endif 
     148 
     149 if ( rt == NULL ) { 
     150  roar_err_set(ROAR_ERROR_FAULT); 
     151  return -1; 
     152 } 
     153 
     154 memset(rt, 0, sizeof(struct roar_time)); 
     155 
     156 if ( clock == ROAR_CLOCK_DEFAULT ) 
     157  clock = ROAR_CLOCK_REALTIME; 
     158 
     159 switch (clock) { 
     160  case ROAR_CLOCK_REALTIME: 
     161#ifdef ROAR_HAVE_GETTIMEOFDAY 
     162    if ( gettimeofday(&tv, NULL) == -1 ) { 
     163     roar_err_from_errno(); 
     164     return -1; 
     165    } 
     166    rt->t_sec  = tv.tv_sec; 
     167    rt->t_ssec = (uint64_t)tv.tv_usec * (uint64_t)18446744073709ULL; 
     168    rt->c_freq = 1000LLU; 
     169#elif defined(ROAR_HAVE_TIME) 
     170    now = time(NULL); 
     171    rt->t_sec  = now; 
     172    rt->c_freq = 1000000000LLU; 
     173#else 
     174    roar_err_set(ROAR_ERROR_NOTSUP); 
     175    return -1; 
     176#endif 
     177    return 0; 
     178   break; 
     179 } 
     180 
     181 roar_err_set(ROAR_ERROR_NOTSUP); 
     182 return -1; 
     183} 
     184 
    142185//ll 
  • roarclients/roarctl.c

    r5031 r5065  
    249249 
    250250 if ( roar_get_time(con, &time) == -1 ) { 
    251   fprintf(stderr, "Error: can not get server time\n"); 
     251  fprintf(stderr, "Error: can not get server time: %s\n", roar_error2str(roar_error)); 
    252252  return; 
    253253 } 
  • roard/req.c

    r5031 r5065  
    683683 
    684684int req_on_gettimeofday (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) { 
    685 #if defined(ROAR_HAVE_GETTIMEOFDAY) || defined(ROAR_HAVE_TIME) 
    686685 struct roar_time curtime; 
    687 #ifdef ROAR_HAVE_GETTIMEOFDAY 
    688  struct timeval tv; 
    689 #elif defined(ROAR_HAVE_TIME) 
    690  time_t now = time(NULL); 
    691 #endif 
    692686 
    693687 ROAR_DBG("req_on_gettimeofday(client=%i, mes=%p, data=%p, flags=%p) = ?", client, mes, data, flags); 
     
    713707 ROAR_DBG("req_on_gettimeofday(client=%i, mes=%p, data=%p, flags=%p) = ?", client, mes, data, flags); 
    714708 
    715  memset(&curtime, 0, sizeof(curtime)); 
    716  
    717 #ifdef ROAR_HAVE_GETTIMEOFDAY 
    718  if ( gettimeofday(&tv, NULL) == -1 ) 
    719   return -1; 
    720  curtime.t_sec  = tv.tv_sec; 
    721  curtime.t_ssec = (uint64_t)tv.tv_usec * (uint64_t)18446744073709ULL; 
    722 #elif defined(ROAR_HAVE_TIME) 
    723  curtime.t_sec = now; 
    724 #endif 
     709 if ( roar_clock_gettime(&curtime, ROAR_CLOCK_REALTIME) == -1 ) 
     710  return -1; 
    725711 
    726712 if ( roar_time_to_msg(mes, &curtime) == -1 ) 
     
    732718 
    733719 return 0; 
    734 #else 
    735  return -1; 
    736 #endif 
    737720} 
    738721 
Note: See TracChangeset for help on using the changeset viewer.