Commit | Line | Data |
---|---|---|
d44e3c4f | 1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 Ericsson Telecom AB | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Raduly, Csaba | |
11 | * Szabo, Janos Zoltan – initial implementation | |
12 | * | |
13 | ******************************************************************************/ | |
970ed795 EL |
14 | #ifndef TIMER_HH |
15 | #define TIMER_HH | |
16 | ||
17 | #include <stdlib.h> | |
18 | ||
19 | #include "Types.h" | |
20 | ||
21 | class FLOAT; | |
22 | ||
23 | /** Runtime class for TTCN-3 timers. | |
24 | * All durations are in seconds with fractional values, | |
25 | * all times are counted from the Unix epoch (1970). | |
26 | */ | |
27 | class TIMER { | |
28 | // linked list of running timers | |
29 | static TIMER *list_head, *list_tail, *backup_head, *backup_tail; | |
30 | static boolean control_timers_saved; | |
31 | ||
32 | const char *timer_name; | |
33 | boolean has_default; | |
34 | boolean is_started; | |
35 | double default_val; ///< default timeout duration | |
36 | double t_started; ///< time when the timer started running | |
37 | double t_expires; ///< time when the timer expires | |
38 | TIMER *list_prev, *list_next; | |
39 | ||
40 | void add_to_list(); | |
41 | void remove_from_list(); | |
42 | ||
43 | /// Copy constructor disabled. | |
44 | TIMER(const TIMER& other_timer); | |
45 | /// Assignment disabled. | |
46 | TIMER& operator=(const TIMER& other_timer); | |
47 | ||
48 | public: | |
49 | /// Create a timer with no default duration. | |
50 | TIMER(const char *par_timer_name = NULL); | |
51 | /// Create a timer with a default timeout value. | |
52 | TIMER(const char *par_timer_name, double def_val); | |
53 | /// Create a timer with a default timeout value. | |
54 | /// @pre \p def_val must be bound | |
55 | TIMER(const char *par_timer_name, const FLOAT& def_val); | |
56 | ~TIMER(); | |
57 | ||
58 | /// Change the name of the timer. | |
59 | void set_name(const char * name); | |
60 | ||
61 | /// Change the default duration. | |
62 | void set_default_duration(double def_val); | |
63 | /// Change the default duration. | |
64 | /// @pre \p def_val must be bound | |
65 | void set_default_duration(const FLOAT& def_val); | |
66 | ||
67 | /// Start the timer with its default duration. | |
68 | void start(); | |
69 | /// Start the timer with the specified duration. | |
70 | void start(double start_val); | |
71 | /// Start the timer with the specified duration. | |
72 | /// @pre \p start_val must be bound | |
73 | void start(const FLOAT& start_val); | |
74 | /// Stop the timer. | |
75 | void stop(); | |
76 | /// Return the number of seconds until the timer expires. | |
77 | double read() const; | |
78 | /** Is the timer running. | |
79 | * @return \c TRUE if is_started and not yet expired, \c FALSE otherwise. | |
80 | */ | |
81 | boolean running() const; | |
82 | /** Return the alt status. | |
83 | * @return ALT_NO if the timer is not started. | |
84 | * @return ALT_MAYBE if it's started and the snapshot was taken before the expiration time | |
85 | * @return ALT_YES if it's started and the snapshot is past the expiration time | |
86 | * | |
87 | * If the answer is ALT_YES, a TIMEROP_TIMEOUT message is written to the log | |
88 | * and \p is_started becomes FALSE. | |
89 | */ | |
90 | alt_status timeout(); | |
91 | ||
92 | void log() const; | |
93 | ||
94 | /// Stop all running timers (empties the list). | |
95 | static void all_stop(); | |
96 | static boolean any_running(); | |
97 | static alt_status any_timeout(); | |
98 | ||
99 | /** Get the earliest expiration time for a running timer. | |
100 | * | |
101 | * This includes the testcase guard timer. | |
102 | * @param[out] min_val set to the earliest expiration time. | |
103 | * @return \c TRUE if an active timer was found, \c FALSE otherwise. | |
104 | */ | |
105 | static boolean get_min_expiration(double& min_val); | |
106 | ||
107 | static void save_control_timers(); | |
108 | static void restore_control_timers(); | |
109 | }; | |
110 | ||
111 | extern TIMER testcase_timer; | |
112 | ||
113 | #endif |