System_Time.cpp

Go to the documentation of this file.
00001 // System_Time.cpp,v 4.24 2006/04/19 19:13:09 jwillemsen Exp
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   // Only create a new unique filename for the memory pool file
00018   // if the user didn't supply one...
00019   if (poolname == 0)
00020     {
00021 #if defined (ACE_DEFAULT_BACKING_STORE)
00022       // Create a temporary file.
00023       ACE_OS::strcpy (this->poolname_,
00024                       ACE_DEFAULT_BACKING_STORE);
00025 #else /* ACE_DEFAULT_BACKING_STORE */
00026       if (ACE::get_temp_dir (this->poolname_,
00027                                       MAXPATHLEN - 17) == -1)
00028         // -17 for ace-malloc-XXXXXX
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       // Add the filename to the end
00037       ACE_OS::strcat (this->poolname_, ACE_LIB_TEXT ("ace-malloc-XXXXXX"));
00038 
00039 #endif /* ACE_DEFAULT_BACKING_STORE */
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 // Get the local system time.
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 // Get the system time of the central time server.
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       // Try to find it
00084       void * temp;
00085       if (this->shmem_->find (ACE_DEFAULT_TIME_SERVER_STR, temp) ==  -1)
00086         {
00087           // No time entry in shared memory (meaning no Clerk exists)
00088           // so return the local time of the host.
00089           return this->get_local_system_time (time_out);
00090         }
00091       else
00092         // Extract the delta time.
00093         this->delta_time_ = (long *) temp;
00094     }
00095 
00096   ACE_UINT32 local_time;
00097 
00098   // If delta_time is positive, it means that the system clock is
00099   // ahead of our local clock so add delta to the local time to get an
00100   // approximation of the system time. Else if delta time is negative,
00101   // it means that our local clock is ahead of the system clock, so
00102   // return the last local time stored (to avoid time conflicts).
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     // Return the last local time. Note that this is stored as the
00110     // second field in shared memory.
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 // Synchronize local system time with the central time server using
00127 // specified mode (currently unimplemented).
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

Generated on Thu Nov 9 09:42:06 2006 for ACE by doxygen 1.3.6