00001
00002
00003
00004
00005
00006
00007
00022 #ifndef OSCL_TIME_H_INCLUDED
00023 #define OSCL_TIME_H_INCLUDED
00024
00025
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
00043 typedef char CtimeStrBuf[CTIME_BUFFER_SIZE];
00044 typedef char PV8601timeStrBuf[PV8601TIME_BUFFER_SIZE];
00045
00046 class TimeValue;
00047
00048 OSCL_IMPORT_REF void PV8601ToRFC822(PV8601timeStrBuf pv8601_buffer, CtimeStrBuf ctime_buffer);
00049 OSCL_IMPORT_REF void RFC822ToPV8601(CtimeStrBuf ctime_buffer, PV8601timeStrBuf);
00050
00051
00053
00054
00055 const long USEC_PER_SEC = 1000000;
00056 const long MSEC_PER_SEC = 1000;
00057
00059 static const long MapToSeconds[] = {1, 1000, 1000000};
00060 static const long MapToUSeconds[] = {1000000, 1000, 1};
00061 static const long MapTo100NanoSeconds[] = {10000000, 10000, 10};
00062 const uint32 unix_ntp_offset = 2208988800U;
00063
00064
00065
00067
00076 class NTPTime
00077 {
00078
00079 private:
00080 uint64 timevalue;
00081
00082 public:
00084 OSCL_COND_IMPORT_REF NTPTime();
00085
00087 OSCL_COND_IMPORT_REF NTPTime(const NTPTime& src);
00088
00090
00091 OSCL_COND_IMPORT_REF NTPTime(const uint32 seconds);
00092
00094
00095 OSCL_COND_IMPORT_REF NTPTime(const int32 seconds);
00096
00098
00102 OSCL_COND_IMPORT_REF NTPTime(const TimeValue& t);
00103
00105
00106 OSCL_COND_IMPORT_REF NTPTime(const uint64 value);
00107
00108
00110
00111 OSCL_COND_IMPORT_REF NTPTime& operator=(uint32 newval);
00112
00114
00115 OSCL_COND_IMPORT_REF NTPTime& operator=(uint64 newval);
00116
00118
00119 OSCL_COND_IMPORT_REF NTPTime& operator+=(uint64 val);
00120
00122
00123 OSCL_COND_IMPORT_REF NTPTime operator-(const NTPTime &ntpt) const;
00124
00126
00132 void set_from_system_time(const uint32 systemtime);
00133
00135
00136 OSCL_COND_IMPORT_REF uint32 get_middle32() const;
00137
00139 OSCL_COND_IMPORT_REF uint32 get_upper32() const;
00140
00142 OSCL_COND_IMPORT_REF uint32 get_lower32() const;
00143
00145
00149 int32 to_system_time() const;
00150
00152 OSCL_COND_IMPORT_REF uint64 get_value() const;
00153
00155 OSCL_IMPORT_REF int set_to_current_time();
00156
00157 };
00158
00159
00161
00174 class TimeValue
00175 {
00176
00177 public:
00179 OSCL_COND_IMPORT_REF TimeValue();
00180
00182 OSCL_COND_IMPORT_REF TimeValue(const TimeValue& Tv);
00183
00185
00189 OSCL_COND_IMPORT_REF TimeValue(long tv, TimeUnits units);
00190
00192
00194 OSCL_COND_IMPORT_REF TimeValue(const OsclBasicTimeStruct& in_tv);
00195
00197
00201 OSCL_COND_IMPORT_REF TimeValue(OsclBasicDateTimeStruct in_ts);
00202
00204
00207 OSCL_COND_IMPORT_REF int32 get_local_time();
00208
00209
00210 friend class NTPTime;
00211
00213 OSCL_COND_IMPORT_REF void set_to_zero();
00214
00216 OSCL_COND_IMPORT_REF void set_to_current_time();
00217
00219
00223 OSCL_COND_IMPORT_REF void set_from_ntp_time(const uint32 ntp_offset);
00224
00226
00233 OSCL_COND_IMPORT_REF uint32 get_sec() const ;
00234
00235 OSCL_COND_IMPORT_REF int32 to_msec() const;
00236
00238
00241 OSCL_COND_IMPORT_REF uint32 get_usec() const ;
00242
00244
00249 OSCL_IMPORT_REF char *get_str_ctime(CtimeStrBuf ctime_strbuf);
00250
00252
00256 OSCL_IMPORT_REF int get_pv8601_str_time(PV8601timeStrBuf time_strbuf);
00257
00259
00265 OSCL_IMPORT_REF char *get_rfc822_gmtime_str(int max_time_strlen,
00266 char *time_str);
00267
00269 OSCL_COND_IMPORT_REF bool is_zero();
00270
00271
00272
00273 OSCL_COND_IMPORT_REF friend bool operator ==(const TimeValue& a, const TimeValue& b);
00274 OSCL_COND_IMPORT_REF friend bool operator !=(const TimeValue& a, const TimeValue& b);
00275 OSCL_COND_IMPORT_REF friend bool operator <=(const TimeValue& a, const TimeValue& b);
00276 OSCL_COND_IMPORT_REF friend bool operator >=(const TimeValue& a, const TimeValue& b);
00277 OSCL_COND_IMPORT_REF friend bool operator <(const TimeValue& a, const TimeValue& b);
00278 OSCL_COND_IMPORT_REF friend bool operator >(const TimeValue& a, const TimeValue& b);
00279
00281 OSCL_COND_IMPORT_REF TimeValue& operator =(const TimeValue& a);
00282
00283
00285
00287
00289
00290
00291 OSCL_COND_IMPORT_REF OsclBasicTimeStruct * get_timeval_ptr();
00292
00293 private:
00294
00295 OsclBasicTimeStruct ts;
00296 const OsclBasicTimeStruct *getBasicTimeStruct() const
00297 {
00298 return &ts;
00299 };
00300
00301 };
00302
00303 OSCL_COND_IMPORT_REF TimeValue operator -(const TimeValue& a, const TimeValue& b);
00304
00305 #if (!OSCL_DISABLE_INLINES)
00306 #include "oscl_time.inl"
00307 #endif
00308
00309
00310
00311
00315 #endif // OSCL_TIME_H_INCLUDED