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