00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file System_Time.h 00006 * 00007 * $Id: System_Time.h 76055 2006-12-17 19:34:12Z johnnyw $ 00008 * 00009 * @author Prashant Jain 00010 * @author Tim H. Harrison 00011 * @author Douglas C. Schmidt 00012 */ 00013 //============================================================================= 00014 00015 #ifndef ACE_SYSTEM_TIME_H 00016 #define ACE_SYSTEM_TIME_H 00017 #include /**/ "ace/pre.h" 00018 00019 #include /**/ "ace/config-all.h" 00020 00021 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00022 # pragma once 00023 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00024 00025 #include "ace/Global_Macros.h" 00026 #include "ace/os_include/os_time.h" /* For time_t. */ 00027 #include "ace/os_include/os_limits.h" /* For MAXPATHLEN. */ 00028 #include "ace/MMAP_Memory_Pool.h" 00029 00030 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00031 00032 template<ACE_MEM_POOL_1, class ACE_LOCK> class ACE_Malloc; 00033 template<class MALLOC> class ACE_Allocator_Adapter; 00034 00035 class ACE_Null_Mutex; 00036 class ACE_Time_Value; 00037 class ACE_MMAP_Memory_Pool; 00038 00039 /** 00040 * @class ACE_System_Time 00041 * 00042 * @brief Defines the timer services of the OS interface to access the 00043 * system time either on the local host or on the central time 00044 * server in the network. 00045 */ 00046 class ACE_Export ACE_System_Time 00047 { 00048 public: 00049 /** 00050 * Enumeration types to specify mode of synchronization with master 00051 * clock. Jump will set local system time directly (thus possibly 00052 * producing time gaps or ambiguous local system times. Adjust will 00053 * smoothly slow down or speed up the local system clock to reach 00054 * the system time of the master clock. 00055 */ 00056 enum Sync_Mode { Jump, Adjust }; 00057 00058 /// Default constructor. 00059 ACE_System_Time (const ACE_TCHAR *poolname = 0); 00060 00061 /// Default destructor. 00062 ~ACE_System_Time (void); 00063 00064 /// Get the local system time, i.e., the value returned by 00065 /// ACE_OS::time(). 00066 static int get_local_system_time (time_t & time_out); 00067 00068 /// Get the local system time, i.e., the value returned by 00069 /// ACE_OS::time(). 00070 static int get_local_system_time (ACE_Time_Value &time_out); 00071 00072 /// Get the system time of the central time server. 00073 int get_master_system_time (time_t & time_out); 00074 00075 /// Get the system time of the central time server. 00076 int get_master_system_time (ACE_Time_Value &time_out); 00077 00078 /// Synchronize local system time with the central time server using 00079 /// specified mode. 00080 int sync_local_system_time (ACE_System_Time::Sync_Mode mode); 00081 00082 private: 00083 typedef ACE_Malloc<ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex> MALLOC; 00084 typedef ACE_Allocator_Adapter<MALLOC> ALLOCATOR; 00085 00086 /// Our allocator (used for obtaining system time from shared memory). 00087 ALLOCATOR * shmem_; 00088 00089 /// The name of the pool used by the allocator. 00090 ACE_TCHAR poolname_[MAXPATHLEN + 1]; 00091 00092 /// Pointer to delta time kept in shared memory. 00093 long * delta_time_; 00094 }; 00095 00096 ACE_END_VERSIONED_NAMESPACE_DECL 00097 00098 #include /**/ "ace/post.h" 00099 #endif /* ACE_SYSTEM_TIME_H */