Main Page   Modules   Class Hierarchy   Data Structures   File List   Data Fields   Globals   Related Pages  

oscl_time.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
00003 
00004 //               O S C L _ T I M E   ( T I M E   F U N C T I O N S )
00005 
00006 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
00007 
00022 #ifndef OSCL_TIME_H_INCLUDED
00023 #define OSCL_TIME_H_INCLUDED
00024 
00025 // - - Inclusion - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00026 
00027 #ifndef OSCL_BASE_H_INCLUDED
00028 #include "oscl_base.h"
00029 #endif
00030 
00031 #ifndef OSCLCONFIG_TIME_H_INCLUDED
00032 #include "osclconfig_time.h"
00033 #endif
00034 
00035 #ifndef OSCL_INT64_UTILS_INCLUDED
00036 #include "oscl_int64_utils.h"
00037 #endif
00038 
00039 const int CTIME_BUFFER_SIZE = 26;
00040 
00041 const int PV8601TIME_BUFFER_SIZE = 21;
00042 const int ISO8601TIME_BUFFER_SIZE = 21;
00043 
00044 typedef char CtimeStrBuf[CTIME_BUFFER_SIZE];
00045 typedef char PV8601timeStrBuf[PV8601TIME_BUFFER_SIZE];
00046 typedef char ISO8601timeStrBuf[ISO8601TIME_BUFFER_SIZE];
00047 
00048 class TimeValue;  // Forward definition
00049 
00050 OSCL_IMPORT_REF void PV8601ToRFC822(PV8601timeStrBuf pv8601_buffer, CtimeStrBuf ctime_buffer);
00051 OSCL_IMPORT_REF void ISO8601ToRFC822(ISO8601timeStrBuf iso8601_buffer, CtimeStrBuf ctime_buffer);
00052 OSCL_IMPORT_REF void RFC822ToPV8601(CtimeStrBuf ctime_buffer, PV8601timeStrBuf);
00053 
00054 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00056 typedef enum { SECONDS = 0, MILLISECONDS = 1, MICROSECONDS = 2 } TimeUnits;
00057 
00058 const long USEC_PER_SEC = 1000000;
00059 const long MSEC_PER_SEC = 1000;
00060 
00062 static const long MapToSeconds[] = {1, 1000, 1000000};
00063 static const long MapToUSeconds[] = {1000000, 1000, 1};
00064 static const long MapTo100NanoSeconds[] = {10000000, 10000, 10};
00065 const uint32 unix_ntp_offset = 2208988800U;
00066 
00067 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00068 
00070 
00079 class NTPTime
00080 {
00081 
00082     private:
00083         uint64 timevalue;
00084 
00085     public:
00087         OSCL_COND_IMPORT_REF NTPTime();
00088 
00090         OSCL_COND_IMPORT_REF NTPTime(const NTPTime& src);
00091 
00093 
00094         OSCL_COND_IMPORT_REF NTPTime(const uint32 seconds);
00095 
00097 
00098         OSCL_COND_IMPORT_REF NTPTime(const int32 seconds);
00099 
00101 
00105         OSCL_COND_IMPORT_REF NTPTime(const TimeValue& t);
00106 
00108 
00109         OSCL_COND_IMPORT_REF NTPTime(const uint64 value);
00110 
00111 
00113 
00114         OSCL_COND_IMPORT_REF NTPTime& operator=(uint32 newval);
00115 
00117 
00118         OSCL_COND_IMPORT_REF NTPTime& operator=(uint64 newval);
00119 
00121 
00122         OSCL_COND_IMPORT_REF NTPTime& operator+=(uint64 val);
00123 
00125 
00126         OSCL_COND_IMPORT_REF NTPTime operator-(const NTPTime &ntpt) const;
00127 
00129 
00135         void set_from_system_time(const uint32 systemtime);
00136 
00138         /* \return This method returns the middle 32 bits of the 32.32 representation. */
00139         OSCL_COND_IMPORT_REF uint32 get_middle32() const;
00140 
00142         OSCL_COND_IMPORT_REF uint32 get_upper32() const;
00143 
00145         OSCL_COND_IMPORT_REF uint32 get_lower32() const;
00146 
00148 
00152         int32 to_system_time() const;
00153 
00155         OSCL_COND_IMPORT_REF uint64 get_value() const;
00156 
00158         OSCL_IMPORT_REF int set_to_current_time();
00159 
00160 };
00161 
00162 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00164 
00177 class TimeValue
00178 {
00179 
00180     public:
00182         OSCL_COND_IMPORT_REF TimeValue();
00183 
00185         OSCL_COND_IMPORT_REF TimeValue(const TimeValue& Tv);
00186 
00188 
00192         OSCL_COND_IMPORT_REF TimeValue(long tv, TimeUnits units);
00193 
00195 
00197         OSCL_COND_IMPORT_REF TimeValue(const OsclBasicTimeStruct& in_tv);
00198 
00199         OSCL_COND_IMPORT_REF TimeValue(const ISO8601timeStrBuf time_strbuf);
00202 
00214         OSCL_COND_IMPORT_REF TimeValue(uint16 aYear, uint16 aMonth, uint16 aDay, uint16 aHour,
00215                                        uint16 aMinute, uint16 aSecond,  uint16 aMilliseconds);
00216 
00218 
00222         OSCL_COND_IMPORT_REF TimeValue(OsclBasicDateTimeStruct in_ts);
00223 
00225 
00228         OSCL_COND_IMPORT_REF int32 get_local_time();
00229 
00230 
00231         friend class NTPTime;
00232 
00234         OSCL_COND_IMPORT_REF void set_to_zero();
00235 
00237         OSCL_COND_IMPORT_REF void set_to_current_time();
00238 
00240 
00244         OSCL_COND_IMPORT_REF void set_from_ntp_time(const uint32 ntp_offset);
00245 
00247 
00254         OSCL_COND_IMPORT_REF uint32 get_sec() const ;
00255 
00256         OSCL_COND_IMPORT_REF int32 to_msec() const;
00257 
00259 
00262         OSCL_COND_IMPORT_REF uint32 get_usec() const ;
00264 
00270         OSCL_COND_IMPORT_REF uint64 get_timevalue_in_usec() const ;
00271 
00273 
00278         OSCL_IMPORT_REF char *get_str_ctime(CtimeStrBuf ctime_strbuf);
00279 
00281 
00285         OSCL_IMPORT_REF int get_pv8601_str_time(PV8601timeStrBuf time_strbuf);
00286 
00288 
00292         OSCL_IMPORT_REF int get_ISO8601_str_time(ISO8601timeStrBuf time_strbuf);
00293 
00295 
00301         OSCL_IMPORT_REF char *get_rfc822_gmtime_str(int max_time_strlen,
00302                 char *time_str);
00303 
00305         OSCL_COND_IMPORT_REF bool is_zero();
00306 
00308 
00309         OSCL_COND_IMPORT_REF bool is_zulu() const;
00310         OSCL_COND_IMPORT_REF void set_zulu(bool is_zulu);
00311 
00312         // comparison operators
00313         OSCL_COND_IMPORT_REF friend bool operator ==(const TimeValue& a, const TimeValue& b);
00314         OSCL_COND_IMPORT_REF friend bool operator !=(const TimeValue& a, const TimeValue& b);
00315         OSCL_COND_IMPORT_REF friend bool operator <=(const TimeValue& a, const TimeValue& b);
00316         OSCL_COND_IMPORT_REF friend bool operator >=(const TimeValue& a, const TimeValue& b);
00317         OSCL_COND_IMPORT_REF friend bool operator <(const TimeValue& a, const TimeValue& b);
00318         OSCL_COND_IMPORT_REF friend bool operator >(const TimeValue& a, const TimeValue& b);
00319 
00321         OSCL_COND_IMPORT_REF TimeValue& operator =(const TimeValue& a);
00322 
00323         // arithmetic operators
00325         OSCL_COND_IMPORT_REF TimeValue& operator +=(const TimeValue& a);
00327         OSCL_COND_IMPORT_REF TimeValue& operator -=(const TimeValue& a);
00329         OSCL_COND_IMPORT_REF TimeValue& operator *=(const int scale);
00330 
00331         OSCL_COND_IMPORT_REF OsclBasicTimeStruct * get_timeval_ptr();
00332 
00333         OSCL_COND_IMPORT_REF TimeValue& operator+=(const int32 aSeconds);
00334         OSCL_COND_IMPORT_REF TimeValue& operator-=(const int32 aSeconds);
00335     private:
00336 
00337         bool zulu;
00338         OsclBasicTimeStruct ts;
00339         const OsclBasicTimeStruct *getBasicTimeStruct() const
00340         {
00341             return &ts;
00342         };
00343 
00344 };
00345 
00346 OSCL_COND_IMPORT_REF TimeValue operator -(const TimeValue& a, const TimeValue& b);
00347 OSCL_COND_IMPORT_REF TimeValue operator+(const TimeValue& a, const int32 bSeconds);
00348 OSCL_COND_IMPORT_REF TimeValue operator+(const int32 aSeconds, const TimeValue& b);
00349 OSCL_COND_IMPORT_REF TimeValue operator-(const TimeValue& a, const int32 bSeconds);
00350 OSCL_COND_IMPORT_REF TimeValue operator-(const int32 aSeconds, const TimeValue& b);
00351 
00352 #if (!OSCL_DISABLE_INLINES)
00353 #include "oscl_time.inl"
00354 #endif
00355 
00356 
00357 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00358 
00362 #endif // OSCL_TIME_H_INCLUDED

OSCL API
Posting Version: CORE_8.000.1.1_RC4