summaryrefslogtreecommitdiff
path: root/ACE/ace/Time_Policy.h
blob: 0d8858f400971b740f961d5e8ca97bde6e0cf3f2 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#ifndef ACE_TIME_POLICY_H
#define ACE_TIME_POLICY_H
// -*- C++ -*-
/**
 *  @file Time_Policy.h
 *
 *  $Id$
 *
 *  @author Carlos O'Ryan <coryan@atdesk.com>
 *  @author Martin Corino <mcorino@remedy.nl>
 */
#include /**/ "ace/pre.h"

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

#include /**/ "ace/Time_Value.h"

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

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

/**
 * @class ACE_Default_Time_Policy
 *
 * @brief Implement the default time policy for ACE.
 *
 * The most common time policy is to simply use
 * ACE_OS::gettimeofday(), this class implements that policy, i.e., it
 * simply calls that function.
 */
class ACE_Export ACE_Default_Time_Policy
{
public:
  /// Return the current time according to this policy
  ACE_Time_Value operator() () const;
};

/**
 * @class ACE_HR_Time_Policy
 *
 * @brief Implement a time policy based on the ACE Highres timer.
 *
 */
class ACE_Export ACE_HR_Time_Policy
{
public:
  /// Return the current time according to this policy
  ACE_Time_Value operator() () const;
};

/**
 * @class ACE_FPointer_Timer_Policy
 *
 * @brief Implement a time policy based on a function pointer.
 *
 * This time policy allows dynamic changes to the source of time by
 * using a function pointer.
 */
class ACE_Export ACE_FPointer_Time_Policy
{
public:
  /**
   * @brief Default constructor uses ACE_OS::gettimeofday()
   *
   * ACE_T requires a default constructor that leaves the
   * policy in a functional state.  Therefore, a null pointer would
   * not be desirable, in other words, we need a non-trivial default
   * constructor.
   */
  ACE_FPointer_Time_Policy();

  /**
   * @typedef FPtr
   *
   * Short-hand for the right type of pointer to function.
   */
  typedef ACE_Time_Value (*FPtr)();

  /**
   * @brief Constructor from a pointer to function.
   *
   * Construct from a pointer to function.
   */
  ACE_FPointer_Time_Policy(FPtr f);

  /// Return the current time according to this policy
  ACE_Time_Value operator()() const;


private:
  FPtr function_;
};

/**
 * @class ACE_Dynamic_Time_Policy_base
 *
 * @brief Abstract base class for dynamically loaded and/or shared
 *        time policies.
 *
 */
class ACE_Export ACE_Dynamic_Time_Policy_Base
{
public:
  virtual ~ACE_Dynamic_Time_Policy_Base ();

  /// Return the current time according to this policy
  ACE_Time_Value operator()() const;

protected:
  /// Return the current time according to policy implementation.
  virtual ACE_Time_Value gettimeofday () const = 0;
};

/**
 * @class ACE_Delegating_Time_Policy
 *
 * @brief Implement a time policy that delegates to a dynamic
 *        time policy.
 *
 */
class ACE_Export ACE_Delegating_Time_Policy
{
public:
  ACE_Delegating_Time_Policy (ACE_Dynamic_Time_Policy_Base const * delegate = 0);

  /// Return the current time according to this policy
  ACE_Time_Value operator()() const;

  /// Set delegate
  void set_delegate (ACE_Dynamic_Time_Policy_Base const * delegate);

  /// Copy policy
  ACE_Delegating_Time_Policy& operator =(ACE_Delegating_Time_Policy const & pol);

private:
  ACE_Dynamic_Time_Policy_Base const * delegate_;

  class NULL_Time_Policy : public ACE_Dynamic_Time_Policy_Base
  {
  protected:
    virtual ACE_Time_Value gettimeofday () const;
  };

  static NULL_Time_Policy null_policy_;
};

ACE_END_VERSIONED_NAMESPACE_DECL

#if defined (__ACE_INLINE__)
#include "ace/Time_Policy.inl"
#endif /* __ACE_INLINE__ */

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