blob: b50d0594a4de8119f1eed56d07e807609903ab79 (
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
#ifndef ACE_TIME_POLICY_H
#define ACE_TIME_POLICY_H
// -*- C++ -*-
/**
* @file Time_Policy.h
*
* @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_T.h"
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
/**
* @class ACE_System_Time_Policy
*
* @brief Implement the system 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_System_Time_Policy
{
public:
/// Return the current time according to this policy
ACE_Time_Value_T<ACE_System_Time_Policy> operator() () const;
/// Noop. Just here to satisfy backwards compatibility demands.
void set_gettimeofday (ACE_Time_Value (*gettimeofday)());
};
/**
* @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_T<ACE_HR_Time_Policy> operator() () const;
/// Noop. Just here to satisfy backwards compatibility demands.
void set_gettimeofday (ACE_Time_Value (*gettimeofday)());
};
/**
* @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_T<ACE_FPointer_Time_Policy> operator()() const;
/// Satisfy backwards compatibility demands.
void set_gettimeofday (ACE_Time_Value (*gettimeofday)());
private:
FPtr function_;
};
class ACE_Dynamic_Time_Policy_Base; // forward decl
/**
* @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_T<ACE_Delegating_Time_Policy> operator()() const;
/// Set delegate
void set_delegate (ACE_Dynamic_Time_Policy_Base const * delegate);
ACE_Delegating_Time_Policy (const ACE_Delegating_Time_Policy&) = default;
ACE_Delegating_Time_Policy (ACE_Delegating_Time_Policy&&) = default;
ACE_Delegating_Time_Policy& operator = (ACE_Delegating_Time_Policy const &) = default;
ACE_Delegating_Time_Policy &operator = (ACE_Delegating_Time_Policy&&) = default;
/// Noop. Just here to satisfy backwards compatibility demands.
void set_gettimeofday (ACE_Time_Value (*gettimeofday)());
private:
ACE_Dynamic_Time_Policy_Base const * delegate_;
};
/**
* @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_T<ACE_Delegating_Time_Policy> operator()() const;
/// Noop. Just here to satisfy backwards compatibility demands.
void set_gettimeofday (ACE_Time_Value (*gettimeofday)());
protected:
/// Return the current time according to policy implementation.
virtual ACE_Time_Value_T<ACE_Delegating_Time_Policy> gettimeofday () const = 0;
};
/// Temporarily, for backwards compatibility reasons, this will
/// be the default time policy. In time to be replaced by
/// ACE_System_Time_Policy.
typedef ACE_FPointer_Time_Policy ACE_Default_Time_Policy;
#if defined ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT
template class ACE_Export ACE_Time_Value_T<ACE_System_Time_Policy>;
template class ACE_Export ACE_Time_Value_T<ACE_HR_Time_Policy>;
template class ACE_Export ACE_Time_Value_T<ACE_FPointer_Time_Policy>;
template class ACE_Export ACE_Time_Value_T<ACE_Delegating_Time_Policy>;
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT */
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 */
|