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"
13 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
15 ACE_System_Time::ACE_System_Time (const ACE_TCHAR
*poolname
)
19 ACE_TRACE ("ACE_System_Time::ACE_System_Time");
21 // Only create a new unique filename for the memory pool file
22 // if the user didn't supply one...
25 #if defined (ACE_DEFAULT_BACKING_STORE)
26 // Create a temporary file.
27 ACE_OS::strcpy (this->poolname_
,
28 ACE_DEFAULT_BACKING_STORE
);
29 #else /* ACE_DEFAULT_BACKING_STORE */
30 if (ACE::get_temp_dir (this->poolname_
,
31 MAXPATHLEN
- 17) == -1)
32 // -17 for ace-malloc-XXXXXX
34 ACELIB_ERROR ((LM_ERROR
,
35 ACE_TEXT ("Temporary path too long, ")
36 ACE_TEXT ("defaulting to current directory\n")));
37 this->poolname_
[0] = 0;
40 // Add the filename to the end
41 ACE_OS::strcat (this->poolname_
, ACE_TEXT ("ace-malloc-XXXXXX"));
43 #endif /* ACE_DEFAULT_BACKING_STORE */
46 ACE_OS::strsncpy (this->poolname_
,
48 (sizeof this->poolname_
/ sizeof (ACE_TCHAR
)));
50 ACE_NEW (this->shmem_
,
51 ALLOCATOR (this->poolname_
));
54 ACE_System_Time::~ACE_System_Time (void)
56 ACE_TRACE ("ACE_System_Time::~ACE_System_Time");
60 // Get the local system time.
63 ACE_System_Time::get_local_system_time (time_t & time_out
)
65 ACE_TRACE ("ACE_System_Time::get_local_system_time");
66 time_out
= ACE_OS::time (0);
71 ACE_System_Time::get_local_system_time (ACE_Time_Value
&time_out
)
73 ACE_TRACE ("ACE_System_Time::get_local_system_time");
74 time_out
.set (ACE_OS::time (0), 0);
78 // Get the system time of the central time server.
81 ACE_System_Time::get_master_system_time (time_t &time_out
)
83 ACE_TRACE ("ACE_System_Time::get_master_system_time");
85 if (this->delta_time_
== 0)
89 if (this->shmem_
->find (ACE_DEFAULT_TIME_SERVER_STR
, temp
) == -1)
91 // No time entry in shared memory (meaning no Clerk exists)
92 // so return the local time of the host.
93 return this->get_local_system_time (time_out
);
96 // Extract the delta time.
97 this->delta_time_
= static_cast<long *> (temp
);
102 // If delta_time is positive, it means that the system clock is
103 // ahead of our local clock so add delta to the local time to get an
104 // approximation of the system time. Else if delta time is negative,
105 // it means that our local clock is ahead of the system clock, so
106 // return the last local time stored (to avoid time conflicts).
107 if (*this->delta_time_
>= 0 )
109 this->get_local_system_time (local_time
);
110 time_out
= local_time
+ static_cast<ACE_UINT32
> (*this->delta_time_
);
113 // Return the last local time. Note that this is stored as the
114 // second field in shared memory.
115 time_out
= *(this->delta_time_
+ 1);
120 ACE_System_Time::get_master_system_time (ACE_Time_Value
&time_out
)
122 ACE_TRACE ("ACE_System_Time::get_master_system_time");
124 if (this->get_master_system_time (to
) == -1)
130 // Synchronize local system time with the central time server using
131 // specified mode (currently unimplemented).
134 ACE_System_Time::sync_local_system_time (ACE_System_Time::Sync_Mode
)
136 ACE_TRACE ("ACE_System_Time::sync_local_system_time");
137 ACE_NOTSUP_RETURN (-1);
140 ACE_END_VERSIONED_NAMESPACE_DECL