summaryrefslogtreecommitdiff
path: root/ACE/ace/System_Time.h
blob: e40b21299f51152487522bcae7dbedff65e59b4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// -*- C++ -*-

//=============================================================================
/**
 *  @file    System_Time.h
 *
 *  $Id$
 *
 *  @author Prashant Jain
 *  @author Tim H. Harrison
 *  @author Douglas C. Schmidt
 */
//=============================================================================

#ifndef ACE_SYSTEM_TIME_H
#define ACE_SYSTEM_TIME_H
#include /**/ "ace/pre.h"

#include /**/ "ace/config-all.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Global_Macros.h"
#include "ace/os_include/os_time.h"  /* For time_t. */
#include "ace/os_include/os_limits.h"  /* For MAXPATHLEN. */
#include "ace/MMAP_Memory_Pool.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

template<ACE_MEM_POOL_1, class ACE_LOCK> class ACE_Malloc;
template<class MALLOC> class ACE_Allocator_Adapter;

class ACE_Null_Mutex;
class ACE_Time_Value;
class ACE_MMAP_Memory_Pool;

/**
 * @class ACE_System_Time
 *
 * @brief 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.
 */
class ACE_Export ACE_System_Time
{
public:
  /**
   * 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.
   */
  enum Sync_Mode { Jump, Adjust };

  /// Default constructor.
  ACE_System_Time (const ACE_TCHAR *poolname = 0);

  /// Default destructor.
  ~ACE_System_Time (void);

  /// Get the local system time, i.e., the value returned by
  /// ACE_OS::time().
  static int get_local_system_time (time_t & time_out);

  /// Get the local system time, i.e., the value returned by
  /// ACE_OS::time().
  static int get_local_system_time (ACE_Time_Value &time_out);

  /// Get the system time of the central time server.
  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);

  /// Synchronize local system time with the central time server using
  /// specified mode.
  int sync_local_system_time (ACE_System_Time::Sync_Mode mode);

private:
  typedef ACE_Malloc<ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex> MALLOC;
  typedef ACE_Allocator_Adapter<MALLOC> ALLOCATOR;

  /// Our allocator (used for obtaining system time from shared memory).
  ALLOCATOR * shmem_;

  /// The name of the pool used by the allocator.
  ACE_TCHAR poolname_[MAXPATHLEN + 1];

  /// Pointer to delta time kept in shared memory.
  long * delta_time_;
};

ACE_END_VERSIONED_NAMESPACE_DECL

#include /**/ "ace/post.h"
#endif /* ACE_SYSTEM_TIME_H */