ACE_System_Time Class Reference

Defines the timer services of the OS interface to access the system time either on the local host or on the central time server in the network. More...

#include <System_Time.h>

Collaboration diagram for ACE_System_Time:

Collaboration graph
[legend]
List of all members.

Public Types

 Jump
 Adjust
enum  Sync_Mode { Jump, Adjust }

Public Member Functions

 ACE_System_Time (const ACE_TCHAR *poolname=0)
 Default constructor.
 ~ACE_System_Time (void)
 Default destructor.
int get_master_system_time (time_t &time_out)
 Get the system time of the central time server.
int get_master_system_time (ACE_Time_Value &time_out)
 Get the system time of the central time server.
int sync_local_system_time (ACE_System_Time::Sync_Mode mode)

Static Public Member Functions

static int get_local_system_time (time_t &time_out)
static int get_local_system_time (ACE_Time_Value &time_out)

Private Types

typedef ACE_Malloc< ACE_MMAP_MEMORY_POOL,
ACE_Null_Mutex
MALLOC
typedef ACE_Allocator_Adapter<
MALLOC
ALLOCATOR

Private Attributes

ALLOCATORshmem_
 Our allocator (used for obtaining system time from shared memory).
ACE_TCHAR poolname_ [MAXPATHLEN+1]
 The name of the pool used by the allocator.
long * delta_time_
 Pointer to delta time kept in shared memory.

Detailed Description

Defines the timer services of the OS interface to access the system time either on the local host or on the central time server in the network.

Definition at line 46 of file System_Time.h.


Member Typedef Documentation

typedef ACE_Allocator_Adapter<MALLOC> ACE_System_Time::ALLOCATOR [private]

Definition at line 84 of file System_Time.h.

typedef ACE_Malloc<ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex> ACE_System_Time::MALLOC [private]

Definition at line 83 of file System_Time.h.


Member Enumeration Documentation

enum ACE_System_Time::Sync_Mode

Enumeration types to specify mode of synchronization with master clock. Jump will set local system time directly (thus possibly producing time gaps or ambiguous local system times. Adjust will smoothly slow down or speed up the local system clock to reach the system time of the master clock.

Enumerator:
Jump 
Adjust 

Definition at line 56 of file System_Time.h.

00056 { Jump, Adjust };


Constructor & Destructor Documentation

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_System_Time::ACE_System_Time ( const ACE_TCHAR poolname = 0  ) 

Default constructor.

Definition at line 15 of file System_Time.cpp.

References ACE_ERROR, ACE_NEW, ACE_TEXT, ACE_TRACE, ACE::get_temp_dir(), LM_ERROR, MAXPATHLEN, ACE_OS::strcat(), ACE_OS::strcpy(), and ACE_OS::strsncpy().

00016   : shmem_ (0)
00017   , delta_time_ (0)
00018 {
00019   ACE_TRACE ("ACE_System_Time::ACE_System_Time");
00020 
00021   // Only create a new unique filename for the memory pool file
00022   // if the user didn't supply one...
00023   if (poolname == 0)
00024     {
00025 #if defined (ACE_DEFAULT_BACKING_STORE)
00026       // Create a temporary file.
00027       ACE_OS::strcpy (this->poolname_,
00028                       ACE_DEFAULT_BACKING_STORE);
00029 #else /* ACE_DEFAULT_BACKING_STORE */
00030       if (ACE::get_temp_dir (this->poolname_,
00031                                       MAXPATHLEN - 17) == -1)
00032         // -17 for ace-malloc-XXXXXX
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       // Add the filename to the end
00041       ACE_OS::strcat (this->poolname_, ACE_TEXT ("ace-malloc-XXXXXX"));
00042 
00043 #endif /* ACE_DEFAULT_BACKING_STORE */
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 }

ACE_System_Time::~ACE_System_Time ( void   ) 

Default destructor.

Definition at line 54 of file System_Time.cpp.

References ACE_TRACE, and shmem_.

00055 {
00056   ACE_TRACE ("ACE_System_Time::~ACE_System_Time");
00057   delete this->shmem_;
00058 }


Member Function Documentation

int ACE_System_Time::get_local_system_time ( ACE_Time_Value time_out  )  [static]

Get the local system time, i.e., the value returned by ACE_OS::time().

Definition at line 71 of file System_Time.cpp.

References ACE_TRACE, ACE_Time_Value::set(), and ACE_OS::time().

00072 {
00073   ACE_TRACE ("ACE_System_Time::get_local_system_time");
00074   time_out.set (ACE_OS::time (0), 0);
00075   return 0;
00076 }

int ACE_System_Time::get_local_system_time ( time_t &  time_out  )  [static]

Get the local system time, i.e., the value returned by ACE_OS::time().

Definition at line 63 of file System_Time.cpp.

References ACE_TRACE, and ACE_OS::time().

Referenced by get_master_system_time().

00064 {
00065   ACE_TRACE ("ACE_System_Time::get_local_system_time");
00066   time_out = ACE_OS::time (0);
00067   return 0;
00068 }

int ACE_System_Time::get_master_system_time ( ACE_Time_Value time_out  ) 

Get the system time of the central time server.

Definition at line 120 of file System_Time.cpp.

References ACE_TRACE, and ACE_Time_Value::sec().

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 }

int ACE_System_Time::get_master_system_time ( time_t &  time_out  ) 

Get the system time of the central time server.

Definition at line 81 of file System_Time.cpp.

References ACE_DEFAULT_TIME_SERVER_STR, ACE_TRACE, delta_time_, and get_local_system_time().

00082 {
00083   ACE_TRACE ("ACE_System_Time::get_master_system_time");
00084 
00085   if (this->delta_time_ == 0)
00086     {
00087       // Try to find it
00088       void * temp;
00089       if (this->shmem_->find (ACE_DEFAULT_TIME_SERVER_STR, temp) == -1)
00090         {
00091           // No time entry in shared memory (meaning no Clerk exists)
00092           // so return the local time of the host.
00093           return this->get_local_system_time (time_out);
00094         }
00095       else
00096         // Extract the delta time.
00097         this->delta_time_ = static_cast<long *> (temp);
00098     }
00099 
00100   time_t local_time;
00101 
00102   // If delta_time is positive, it means that the system clock is
00103   // ahead of our local clock so add delta to the local time to get an
00104   // approximation of the system time. Else if delta time is negative,
00105   // it means that our local clock is ahead of the system clock, so
00106   // return the last local time stored (to avoid time conflicts).
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     // Return the last local time. Note that this is stored as the
00114     // second field in shared memory.
00115     time_out = *(this->delta_time_ + 1);
00116   return 0;
00117 }

int ACE_System_Time::sync_local_system_time ( ACE_System_Time::Sync_Mode  mode  ) 

Synchronize local system time with the central time server using specified mode.

Definition at line 134 of file System_Time.cpp.

References ACE_NOTSUP_RETURN, and ACE_TRACE.

00135 {
00136   ACE_TRACE ("ACE_System_Time::sync_local_system_time");
00137   ACE_NOTSUP_RETURN (-1);
00138 }


Member Data Documentation

long* ACE_System_Time::delta_time_ [private]

Pointer to delta time kept in shared memory.

Definition at line 93 of file System_Time.h.

Referenced by get_master_system_time().

ACE_TCHAR ACE_System_Time::poolname_[MAXPATHLEN+1] [private]

The name of the pool used by the allocator.

Definition at line 90 of file System_Time.h.

ALLOCATOR* ACE_System_Time::shmem_ [private]

Our allocator (used for obtaining system time from shared memory).

Definition at line 87 of file System_Time.h.

Referenced by ~ACE_System_Time().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:43 2010 for ACE by  doxygen 1.4.7