00001
00002
00003 #include "ace/System_Time.h"
00004 #include "ace/MMAP_Memory_Pool.h"
00005 #include "ace/Malloc_T.h"
00006 #include "ace/Null_Mutex.h"
00007 #include "ace/Time_Value.h"
00008 #include "ace/OS_NS_string.h"
00009 #include "ace/OS_NS_time.h"
00010
00011 ACE_RCSID(ace, System_Time, "$Id: System_Time.cpp 79134 2007-07-31 18:23:50Z johnnyw $")
00012
00013 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00014
00015 ACE_System_Time::ACE_System_Time (const ACE_TCHAR *poolname)
00016 : shmem_ (0)
00017 , delta_time_ (0)
00018 {
00019 ACE_TRACE ("ACE_System_Time::ACE_System_Time");
00020
00021
00022
00023 if (poolname == 0)
00024 {
00025 #if defined (ACE_DEFAULT_BACKING_STORE)
00026
00027 ACE_OS::strcpy (this->poolname_,
00028 ACE_DEFAULT_BACKING_STORE);
00029 #else
00030 if (ACE::get_temp_dir (this->poolname_,
00031 MAXPATHLEN - 17) == -1)
00032
00033 {
00034 ACE_ERROR ((LM_ERROR,
00035 ACE_TEXT ("Temporary path too long, ")
00036 ACE_TEXT ("defaulting to current directory\n")));
00037 this->poolname_[0] = 0;
00038 }
00039
00040
00041 ACE_OS::strcat (this->poolname_, ACE_TEXT ("ace-malloc-XXXXXX"));
00042
00043 #endif
00044 }
00045 else
00046 ACE_OS::strsncpy (this->poolname_,
00047 poolname,
00048 (sizeof this->poolname_ / sizeof (ACE_TCHAR)));
00049
00050 ACE_NEW (this->shmem_,
00051 ALLOCATOR (this->poolname_));
00052 }
00053
00054 ACE_System_Time::~ACE_System_Time (void)
00055 {
00056 ACE_TRACE ("ACE_System_Time::~ACE_System_Time");
00057 delete this->shmem_;
00058 }
00059
00060
00061
00062 int
00063 ACE_System_Time::get_local_system_time (time_t & time_out)
00064 {
00065 ACE_TRACE ("ACE_System_Time::get_local_system_time");
00066 time_out = ACE_OS::time (0);
00067 return 0;
00068 }
00069
00070 int
00071 ACE_System_Time::get_local_system_time (ACE_Time_Value &time_out)
00072 {
00073 ACE_TRACE ("ACE_System_Time::get_local_system_time");
00074 time_out.set (ACE_OS::time (0), 0);
00075 return 0;
00076 }
00077
00078
00079
00080 int
00081 ACE_System_Time::get_master_system_time (time_t &time_out)
00082 {
00083 ACE_TRACE ("ACE_System_Time::get_master_system_time");
00084
00085 if (this->delta_time_ == 0)
00086 {
00087
00088 void * temp;
00089 if (this->shmem_->find (ACE_DEFAULT_TIME_SERVER_STR, temp) == -1)
00090 {
00091
00092
00093 return this->get_local_system_time (time_out);
00094 }
00095 else
00096
00097 this->delta_time_ = static_cast<long *> (temp);
00098 }
00099
00100 time_t local_time;
00101
00102
00103
00104
00105
00106
00107 if (*this->delta_time_ >= 0 )
00108 {
00109 this->get_local_system_time (local_time);
00110 time_out = local_time + static_cast<ACE_UINT32> (*this->delta_time_);
00111 }
00112 else
00113
00114
00115 time_out = *(this->delta_time_ + 1);
00116 return 0;
00117 }
00118
00119 int
00120 ACE_System_Time::get_master_system_time (ACE_Time_Value &time_out)
00121 {
00122 ACE_TRACE ("ACE_System_Time::get_master_system_time");
00123 time_t to;
00124 if (this->get_master_system_time (to) == -1)
00125 return -1;
00126 time_out.sec (to);
00127 return 0;
00128 }
00129
00130
00131
00132
00133 int
00134 ACE_System_Time::sync_local_system_time (ACE_System_Time::Sync_Mode)
00135 {
00136 ACE_TRACE ("ACE_System_Time::sync_local_system_time");
00137 ACE_NOTSUP_RETURN (-1);
00138 }
00139
00140 ACE_END_VERSIONED_NAMESPACE_DECL