Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET | Apache Qpid Documentation |
00001 #ifndef _sys_Time_h 00002 #define _sys_Time_h 00003 00004 /* 00005 * 00006 * Licensed to the Apache Software Foundation (ASF) under one 00007 * or more contributor license agreements. See the NOTICE file 00008 * distributed with this work for additional information 00009 * regarding copyright ownership. The ASF licenses this file 00010 * to you under the Apache License, Version 2.0 (the 00011 * "License"); you may not use this file except in compliance 00012 * with the License. You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, 00017 * software distributed under the License is distributed on an 00018 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 00019 * KIND, either express or implied. See the License for the 00020 * specific language governing permissions and limitations 00021 * under the License. 00022 * 00023 */ 00024 00025 #include "qpid/sys/IntegerTypes.h" 00026 /* 00027 * The platform defines its notion of time as a TimePrivate type. The 00028 * platform's implementation knows how to handle this type. 00029 */ 00030 #if defined (_WIN32) 00031 # include "windows/Time.h" 00032 #else 00033 # include "posix/Time.h" 00034 #endif 00035 00036 #include "qpid/CommonImportExport.h" 00037 00038 #include <limits> 00039 #include <iosfwd> 00040 00041 namespace qpid { 00042 namespace sys { 00043 00044 class Duration; 00045 00085 class AbsTime { 00086 friend class Duration; 00087 00088 TimePrivate timepoint; 00089 00090 public: 00091 QPID_COMMON_EXTERN inline AbsTime() {} 00092 QPID_COMMON_EXTERN AbsTime(const AbsTime& time0, const Duration& duration); 00093 // Default assignment operation fine 00094 // Default copy constructor fine 00095 00096 QPID_COMMON_EXTERN static AbsTime now(); 00097 QPID_COMMON_EXTERN static AbsTime FarFuture(); 00098 const TimePrivate& getPrivate(void) const { return timepoint; } 00099 bool operator==(const AbsTime& t) const { return t.timepoint == timepoint; } 00100 template <class S> void serialize(S& s) { s(timepoint); } 00101 00102 friend bool operator<(const AbsTime& a, const AbsTime& b); 00103 friend bool operator>(const AbsTime& a, const AbsTime& b); 00104 QPID_COMMON_EXTERN friend std::ostream& operator << (std::ostream&, const AbsTime&); 00105 }; 00106 00107 QPID_COMMON_EXTERN std::ostream& operator << (std::ostream&, const AbsTime&); 00108 00118 class Duration { 00119 static int64_t max() { return std::numeric_limits<int64_t>::max(); } 00120 int64_t nanosecs; 00121 00122 friend class AbsTime; 00123 00124 public: 00125 QPID_COMMON_EXTERN inline Duration(int64_t time0); 00126 QPID_COMMON_EXTERN explicit Duration(const AbsTime& time0); 00127 QPID_COMMON_EXTERN explicit Duration(const AbsTime& start, const AbsTime& finish); 00128 inline operator int64_t() const; 00129 }; 00130 00131 std::ostream& operator << (std::ostream&, const Duration&); 00132 00133 inline AbsTime now() { return AbsTime::now(); } 00134 00135 inline bool operator<(const AbsTime& a, const AbsTime& b) 00136 { return a.timepoint < b.timepoint; } 00137 inline bool operator>(const AbsTime& a, const AbsTime& b) 00138 { return a.timepoint > b.timepoint; } 00139 00140 Duration::Duration(int64_t time0) : 00141 nanosecs(time0) 00142 {} 00143 00144 Duration::operator int64_t() const 00145 { return nanosecs; } 00146 00148 const Duration TIME_SEC = 1000*1000*1000; 00150 const Duration TIME_MSEC = 1000*1000; 00152 const Duration TIME_USEC = 1000; 00154 const Duration TIME_NSEC = 1; 00155 00157 const Duration TIME_INFINITE = std::numeric_limits<int64_t>::max(); 00158 00160 const AbsTime FAR_FUTURE = AbsTime::FarFuture(); 00161 00163 QPID_COMMON_EXTERN void sleep(int secs); 00164 00166 QPID_COMMON_EXTERN void usleep(uint64_t usecs); 00167 00169 void outputFormattedNow(std::ostream&); 00170 00171 }} 00172 00173 #endif