Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

System_Time.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // System_Time.cpp
00003 // $Id: System_Time.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:22 chad Exp $
00004 
00005 #include "ace/System_Time.h"
00006 
00007 ACE_RCSID(ace, System_Time, "$Id: System_Time.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:22 chad Exp $")
00008 
00009 ACE_System_Time::ACE_System_Time (const ACE_TCHAR *poolname)
00010   : delta_time_ (0)
00011 {
00012   ACE_TRACE ("ACE_System_Time::ACE_System_Time");
00013 
00014   // Only create a new unique filename for the memory pool file
00015   // if the user didn't supply one...
00016   if (poolname == 0)
00017     {
00018 #if defined (ACE_DEFAULT_BACKING_STORE)
00019       // Create a temporary file.
00020       ACE_OS::strcpy (this->poolname_,
00021                       ACE_DEFAULT_BACKING_STORE);
00022 #else /* ACE_DEFAULT_BACKING_STORE */
00023       if (ACE_Lib_Find::get_temp_dir (this->poolname_, 
00024                                       MAXPATHLEN - 17) == -1)
00025         // -17 for ace-malloc-XXXXXX
00026         {
00027           ACE_ERROR ((LM_ERROR, 
00028                       ACE_LIB_TEXT ("Temporary path too long, ")
00029                       ACE_LIB_TEXT ("defaulting to current directory\n")));
00030           this->poolname_[0] = 0;
00031         }
00032 
00033       // Add the filename to the end
00034       ACE_OS::strcat (this->poolname_, ACE_LIB_TEXT ("ace-malloc-XXXXXX"));
00035   
00036 #endif /* ACE_DEFAULT_BACKING_STORE */
00037     }
00038   else
00039     ACE_OS::strsncpy (this->poolname_,
00040                       poolname,
00041                       (sizeof this->poolname_ / sizeof (ACE_TCHAR)));
00042   
00043   ACE_NEW (this->shmem_,
00044            ALLOCATOR (this->poolname_));
00045 }
00046 
00047 ACE_System_Time::~ACE_System_Time (void)
00048 {
00049   ACE_TRACE ("ACE_System_Time::~ACE_System_Time");
00050   delete this->shmem_;
00051 }
00052 
00053 // Get the local system time.
00054 
00055 int
00056 ACE_System_Time::get_local_system_time (ACE_UINT32 &time_out)
00057 {
00058   ACE_TRACE ("ACE_System_Time::get_local_system_time");
00059   time_out = ACE_OS::time (0);
00060   return 0;
00061 }
00062 
00063 int
00064 ACE_System_Time::get_local_system_time (ACE_Time_Value &time_out)
00065 {
00066   ACE_TRACE ("ACE_System_Time::get_local_system_time");
00067   time_out.sec (ACE_OS::time (0));
00068   return 0;
00069 }
00070 
00071 // Get the system time of the central time server.
00072 
00073 int
00074 ACE_System_Time::get_master_system_time (ACE_UINT32 &time_out)
00075 {
00076   ACE_TRACE ("ACE_System_Time::get_master_system_time");
00077 
00078   if (this->delta_time_ == 0)
00079     {
00080       // Try to find it
00081       void * temp;
00082       if (this->shmem_->find (ACE_DEFAULT_TIME_SERVER_STR, temp) ==  -1)
00083         {
00084           // No time entry in shared memory (meaning no Clerk exists)
00085           // so return the local time of the host.
00086           return this->get_local_system_time (time_out);
00087         }
00088       else
00089         // Extract the delta time.
00090         this->delta_time_ = (long *) temp;
00091     }
00092 
00093   ACE_UINT32 local_time;
00094 
00095   // If delta_time is positive, it means that the system clock is
00096   // ahead of our local clock so add delta to the local time to get an
00097   // approximation of the system time. Else if delta time is negative,
00098   // it means that our local clock is ahead of the system clock, so
00099   // return the last local time stored (to avoid time conflicts).
00100   if (*this->delta_time_ >=0 )
00101     {
00102       this->get_local_system_time (local_time);
00103       time_out = local_time + (ACE_UINT32) *this->delta_time_;
00104     }
00105   else
00106     // Return the last local time. Note that this is stored as the
00107     // second field in shared memory.
00108     time_out = *(this->delta_time_ + 1);
00109   return 0;
00110 }
00111 
00112 int
00113 ACE_System_Time::get_master_system_time (ACE_Time_Value &time_out)
00114 {
00115   ACE_TRACE ("ACE_System_Time::get_master_system_time");
00116   ACE_UINT32 to;
00117   if (this->get_master_system_time (to) == -1)
00118     return -1;
00119   time_out.sec (to);
00120   return 0;
00121 }
00122 
00123 // Synchronize local system time with the central time server using
00124 // specified mode (currently unimplemented).
00125 
00126 int
00127 ACE_System_Time::sync_local_system_time (ACE_System_Time::Sync_Mode)
00128 {
00129   ACE_TRACE ("ACE_System_Time::sync_local_system_time");
00130   ACE_NOTSUP_RETURN (-1);
00131 }
00132 
00133 #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
00134 template class ACE_Malloc_T<ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex, ACE_Control_Block>;
00135 template class ACE_Malloc<ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex>;
00136 template class ACE_Allocator_Adapter<ACE_Malloc<ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex> >;
00137 #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
00138 #pragma instantiate ACE_Malloc_T<ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex, ACE_Control_Block>
00139 #pragma instantiate ACE_Malloc<ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex>
00140 #pragma instantiate ACE_Allocator_Adapter<ACE_Malloc<ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex> >
00141 #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
00142 

Generated on Mon Jun 16 11:21:43 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002