📄 rvtime.h
字号:
#if (0)
************************************************************************
Filename :
Description:
************************************************************************
Copyright (c) 2000 RADVision Inc.
************************************************************************
NOTICE:
This document contains information that is proprietary to RADVision LTD.
No part of this publication may be reproduced in any form whatsoever
without written prior approval by RADVision LTD..
RADVision LTD. reserves the right to revise this publication and make
changes without obligation to notify any person of such revisions or
changes.
************************************************************************
$Revision:$
$Date:$
$Author: Jay Davis$
************************************************************************
#endif
#ifndef RV_TIME_H
#define RV_TIME_H
#include <time.h>
#include "rvplatform.h"
#include "rvtypes.h"
/* Type definitions for all OS's */
/* Rvtime: seconds = signed 32 bit number */
/* RvTimespec: seconds = signed 32 bit number */
/* nanoseconds = signed 32 bit number */
/* RvTm: standard ANSII tm structure */
/* Hrtime: nanoseconds = signed 64 bit number */
/* RvNtpTime: seconds = unsigned 32 bit number */
/* fraction = unsigned 32 bit number */
/* RvNtpTime64: seconds & fraction = unsigned 64 bit number */
#if defined(RV_OS_SOLARIS)
typedef time_t RvTime;
typedef struct timespec RvTimespec;
typedef struct tm RvTm;
typedef hrtime_t RvHrtime;
typedef unsigned long long RvNtpTime64; /* 64 bit NTP number */
#endif /* Solaris */
#if defined(RV_OS_TRU64) || defined(RV_OS_HPUX)
#include <pthread.h>
typedef time_t RvTime;
typedef struct timespec RvTimespec;
typedef struct tm RvTm;
typedef long long RvHrtime;
typedef unsigned long long RvNtpTime64; /* 64 bit NTP number */
#endif /* Tru64 */
#if defined(RV_OS_REDHAT) || defined(RV_OS_VXWORKS) || defined(RV_OS_PSOS)
typedef time_t RvTime;
typedef struct timespec RvTimespec;
typedef struct tm RvTm;
typedef long long RvHrtime;
typedef unsigned long long RvNtpTime64; /* 64 bit NTP number */
#endif /* Redhat & VxWorks & PSOS */
#if defined(RV_OS_WIN32)
#include <windows.h>
typedef time_t RvTime;
typedef struct {
time_t tv_sec;
long tv_nsec;
} RvTimespec;
typedef struct tm RvTm;
typedef LONGLONG RvHrtime;
typedef ULONGLONG RvNtpTime64; /* 64 bit NTP number */
#endif /* Win32 */
#if defined(RV_OS_OSE)
typedef long RvTime; /* OSE had to make time_t unsigned */
typedef struct {
long tv_sec;
long tv_nsec;
} RvTimespec;
typedef struct tm RvTm;
typedef long long RvHrtime;
typedef unsigned long long RvNtpTime64; /* 64 bit NTP number */
#endif
#if defined(RV_OS_NUCLEUS)
typedef long RvTime; /* Diab base lib has time_t unsigned also */
typedef struct {
time_t tv_sec;
long tv_nsec;
} RvTimespec;
typedef struct tm RvTm;
typedef long long RvHrtime;
typedef unsigned long long RvNtpTime64; /* 64 bit NTP number */
#endif /* Nucleus */
/* size of character buffer required by rvTimeAsctime */
#define RV_TIME_ASCTIME_BUFSIZE 30
struct RvNtpTime_;
/* constants for telling conversion functions how to work */
#define RV_NTP_TIME_ABSOLUTE rvTrue
#define RV_NTP_TIME_RELATIVE rvFalse
/* Convenient constants */
#define RV_TIME_NSECPERUSEC 1000
#define RV_TIME_NSECPERMSEC 1000000
#define RV_TIME_NSECPERSEC 1000000000
#if defined(__cplusplus)
extern "C" {
#endif
/* Prototypes and macros */
RvBool rvTimeInit(void);
void rvTimeEnd(void);
/* Time aquisition: Standard wall time functions */
RvTime rvTimeGetEpochTime(RvTimespec *result);
RvTimespec *rvTimeGetTimeRes(RvTimespec *result);
RvBool rvTimeSetEpochTime(RvTimespec *curtime);
/* Time aquisition: High resolition linear time functions */
RvTimespec *rvTimeGetHires(RvTimespec *result);
RvHrtime rvTimeGetHrtime(void);
RvTimespec *rvTimeGetHrtimeRes(RvTimespec *result);
/* Time (seconds) functions */
RvTime rvTimeConvertTm(RvTm *t);
#if defined(RV_NO_MACAROS)
RvTime rvTimeConvertsecs(RvTimespec *t);
RvTime rvTimeSubtractSecs(RvTime newtime, RvTime oldtime);
RvTime rvTimeAddSecs(RvTime time1, RvTime time2);
#else
#define rvTimeConvertsecs(t) ((t)->tv_sec)
#define rvTimeSubtractSecs(newtime, oldtime) ((newtime) - (oldtime))
#define rvTimeAddSecs(time1, time2) ((time1) + (time2))
#endif
/* Hrtime (nanoseconds) functions */
RvHrtime rvTimeConvertHrtime(const RvTimespec *t);
#if defined(RV_NO_MACAROS)
RvHrtime rvTimeHrSubtract(RvHrtime newtime, RvHrtime oldtime);
RvHrtime rvTimeHrAdd(RvHrtime time1, RvHrtime time2);
#else
#define rvTimeHrSubtract(newtime, oldtime) ((newtime) - (oldtime))
#define rvTimeHrAdd(time1, time2) ((time1) + (time2))
#endif
/* Timespec (seconds & nanoseconds) functions */
#define rvTimespecConstruct(t) (rvTimespecCreate((t), 0UL, 0UL))
#define rvTimespecConstructCopy(t,s,a) (rvTimespecCreate((t), (s)->tv_sec, (s)->tv_nsec))
#define rvTimespecDestruct(t)
#define rvTimespecCopy(t,s) ((t)->tv_sec = (s)->tv_sec,(t)->tv_nsec = (s)->tv_nsec)
RvTimespec *rvTimespecCreate(RvTimespec *t, RvTime secs, long nanosecs);
struct RvNtpTime_* rvTimeConvertNTP(const RvTimespec *tp, struct RvNtpTime_ *ntime, RvBool relative);
RvTimespec *rvTimeSubtract(RvTimespec *result, const RvTimespec *newtime, const RvTimespec *oldtime);
RvTimespec *rvTimeAdd(RvTimespec *result, const RvTimespec *time1, const RvTimespec *time2);
#define rvTimespecSecs(t) ((long)((t)->tv_sec))
#define rvTimespecNsecs(t) ((long)((t)->tv_nsec))
/*$
{type:
{name: RvNtpTime}
{superpackage: Kernel}
{include: rvtime.h}
{description:
{p: This class represents time in NTP time format. NTP time is
represented as seconds since January 1st, 1900 in a 64-bit
fixed point number. 32 bits are used for the fraction part
of the fixed point number. This gives the time an approximate
resolution of 0.2328 nanoseconds and a span from year 1900
to year 2038. See IETF RFC 1305 "Network Time Protocol (Version 3)
Specification, Implementation and Analysis" for details on NTP
time.}
}
{attributes scope="private":
{attribute: {t: RvUint32} {n: secs }
{d: Seconds in NTP time.}}
{attribute: {t: RvUint32} {n: fraction }
{d: Fraction of seconds in NTP time.}}
}
{methods:
{method: RvNtpTime* rvNtpTimeConstruct(RvNtpTime* thisPtr, RvUint32 secs, RvUint32 fraction);}
{method: RvNtpTime* rvNtpTimeConstructCopy(RvNtpTime* thisPtr, const RvNtpTime* srcPtr, RvAllocator* allocatorPtr);}
{method: void rvNtpTimeDestruct(RvNtpTime* thisPtr);}
{method: void rvNtpTimeCopy(RvNtpTime* thisPtr, const RvNtpTime* srcPtr);}
{method: void rvNtpTimeSetSecs(RvNtpTime* thisPtr, RvUint32 seconds);}
{method: void rvNtpTimeSetFraction(RvNtpTime* thisPtr, RvUint32 fraction);}
{method: RvUint32 rvNtpTimeGetSecs(const RvNtpTime* thisPtr);}
{method: RvUint32 rvNtpTimeGetFraction(const RvNtpTime* thisPtr);}
{method: RvNtpTime* rvNtpTimeSubtract(RvNtpTime* result, const RvNtpTime* newtime, const RvNtpTime* oldtime);}
{method: RvNtpTime* rvNtpTimeAdd(RvNtpTime* result, const RvNtpTime* newtime, const RvNtpTime* oldtime);}
}
}
$*/
typedef struct RvNtpTime_ {
RvUint32 secs;
RvUint32 fraction;
} RvNtpTime;
/* Published RvNtpTime methods */
#define rvNtpTimeConstruct(t,s,f) (rvNtpTimeCreate((t), (s), (f)))
#define rvNtpTimeConstructCopy(t,s,a) (rvNtpTimeCreate((t), (s)->secs, (s)->fraction))
#define rvNtpTimeDestruct(t)
#define rvNtpTimeCopy(t,s) ((t)->secs = (s)->secs,(t)->fraction = (s)->fraction)
RvNtpTime* rvNtpTimeSubtract(RvNtpTime* result, const RvNtpTime* newtime, const RvNtpTime* oldtime);
RvNtpTime* rvNtpTimeAdd(RvNtpTime* result, const RvNtpTime* newtime, const RvNtpTime* oldtime);
#define rvNtpTimeSetSecs(t,s) (((t)->secs) = (s))
#define rvNtpTimeSetFraction(t,f) (((t)->fraction = (f)))
#define rvNtpTimeGetSecs(t) (((t)->secs))
#define rvNtpTimeGetFraction(t) (((t)->fraction))
/* Unpublished RvNtpTime methods (can change without warning)*/
RvNtpTime *rvNtpTimeCreate(RvNtpTime *ntime, unsigned long secs, unsigned long fraction);
RvTimespec *rvNtpTimeConvert(const RvNtpTime *ntime, RvTimespec *tp, RvBool relative);
RvNtpTime *rvNtpTimeAdd(RvNtpTime *result, const RvNtpTime *newtime, const RvNtpTime *oldtime);
RvNtpTime *rvNtpTimeBuild64(RvNtpTime *result, RvNtpTime64 ntime, int decimal);
RvNtpTime *rvNtpTimeChop(RvNtpTime *result, const RvNtpTime *ntime, int secbits, int fracbits);
RvNtpTime64 rvNtpTimeChop64(RvNtpTime *ntime, int secbits, int fracbits);
/* Calendar time (Tm) functions */
RvTm *rvTimeUTC(RvTime t, RvTm *result);
RvTm *rvTimeLocal(RvTime t, RvTm *result);
char *rvTimeAsctime(RvTm *t, char *buf, int bufsize);
int rvTimeStrTm(char *result, int maxsize, char *format, RvTm *t);
#if defined(__cplusplus)
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -