Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / System_Time.cpp
blobaf0f79c5264203bb72e58624e3c6a06df8491582
1 #include "ace/System_Time.h"
2 #include "ace/MMAP_Memory_Pool.h"
3 #include "ace/Malloc_T.h"
4 #include "ace/Null_Mutex.h"
5 #include "ace/Time_Value.h"
6 #include "ace/Lib_Find.h"
8 #include "ace/OS_NS_string.h"
9 #include "ace/OS_NS_time.h"
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 ACE_System_Time::ACE_System_Time (const ACE_TCHAR *poolname)
15 : shmem_ (0)
16 , delta_time_ (0)
18 ACE_TRACE ("ACE_System_Time::ACE_System_Time");
20 // Only create a new unique filename for the memory pool file
21 // if the user didn't supply one...
22 if (poolname == 0)
24 #if defined (ACE_DEFAULT_BACKING_STORE)
25 // Create a temporary file.
26 ACE_OS::strcpy (this->poolname_,
27 ACE_DEFAULT_BACKING_STORE);
28 #else /* ACE_DEFAULT_BACKING_STORE */
29 if (ACE::get_temp_dir (this->poolname_,
30 MAXPATHLEN - 17) == -1)
31 // -17 for ace-malloc-XXXXXX
33 ACELIB_ERROR ((LM_ERROR,
34 ACE_TEXT ("Temporary path too long, ")
35 ACE_TEXT ("defaulting to current directory\n")));
36 this->poolname_[0] = 0;
39 // Add the filename to the end
40 ACE_OS::strcat (this->poolname_, ACE_TEXT ("ace-malloc-XXXXXX"));
42 #endif /* ACE_DEFAULT_BACKING_STORE */
44 else
45 ACE_OS::strsncpy (this->poolname_,
46 poolname,
47 (sizeof this->poolname_ / sizeof (ACE_TCHAR)));
49 ACE_NEW (this->shmem_,
50 ALLOCATOR (this->poolname_));
53 ACE_System_Time::~ACE_System_Time ()
55 ACE_TRACE ("ACE_System_Time::~ACE_System_Time");
56 delete this->shmem_;
59 // Get the local system time.
61 int
62 ACE_System_Time::get_local_system_time (time_t & time_out)
64 ACE_TRACE ("ACE_System_Time::get_local_system_time");
65 time_out = ACE_OS::time (0);
66 return 0;
69 int
70 ACE_System_Time::get_local_system_time (ACE_Time_Value &time_out)
72 ACE_TRACE ("ACE_System_Time::get_local_system_time");
73 time_out.set (ACE_OS::time (0), 0);
74 return 0;
77 // Get the system time of the central time server.
79 int
80 ACE_System_Time::get_master_system_time (time_t &time_out)
82 ACE_TRACE ("ACE_System_Time::get_master_system_time");
84 if (this->delta_time_ == 0)
86 // Try to find it
87 void * temp = 0;
88 if (this->shmem_->find (ACE_DEFAULT_TIME_SERVER_STR, temp) == -1)
90 // No time entry in shared memory (meaning no Clerk exists)
91 // so return the local time of the host.
92 return this->get_local_system_time (time_out);
94 else
95 // Extract the delta time.
96 this->delta_time_ = static_cast<long *> (temp);
99 time_t local_time;
101 // If delta_time is positive, it means that the system clock is
102 // ahead of our local clock so add delta to the local time to get an
103 // approximation of the system time. Else if delta time is negative,
104 // it means that our local clock is ahead of the system clock, so
105 // return the last local time stored (to avoid time conflicts).
106 if (*this->delta_time_ >= 0 )
108 this->get_local_system_time (local_time);
109 time_out = local_time + static_cast<ACE_UINT32> (*this->delta_time_);
111 else
112 // Return the last local time. Note that this is stored as the
113 // second field in shared memory.
114 time_out = *(this->delta_time_ + 1);
115 return 0;
119 ACE_System_Time::get_master_system_time (ACE_Time_Value &time_out)
121 ACE_TRACE ("ACE_System_Time::get_master_system_time");
122 time_t to;
123 if (this->get_master_system_time (to) == -1)
124 return -1;
125 time_out.sec (to);
126 return 0;
129 // Synchronize local system time with the central time server using
130 // specified mode (currently unimplemented).
133 ACE_System_Time::sync_local_system_time (ACE_System_Time::Sync_Mode)
135 ACE_TRACE ("ACE_System_Time::sync_local_system_time");
136 ACE_NOTSUP_RETURN (-1);
139 ACE_END_VERSIONED_NAMESPACE_DECL