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
11 * Szabo, Janos Zoltan – initial implementation
13 ******************************************************************************/
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).
28 // linked list of running timers
29 static TIMER *list_head, *list_tail, *backup_head, *backup_tail;
30 static boolean control_timers_saved;
32 const char *timer_name;
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;
41 void remove_from_list();
43 /// Copy constructor disabled.
44 TIMER(const TIMER& other_timer);
45 /// Assignment disabled.
46 TIMER& operator=(const TIMER& other_timer);
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);
58 /// Change the name of the timer.
59 void set_name(const char * name);
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);
67 /// Start the timer with its default duration.
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);
76 /// Return the number of seconds until the timer expires.
78 /** Is the timer running.
79 * @return \c TRUE if is_started and not yet expired, \c FALSE otherwise.
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
87 * If the answer is ALT_YES, a TIMEROP_TIMEOUT message is written to the log
88 * and \p is_started becomes FALSE.
94 /// Stop all running timers (empties the list).
95 static void all_stop();
96 static boolean any_running();
97 static alt_status any_timeout();
99 /** Get the earliest expiration time for a running timer.
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.
105 static boolean get_min_expiration(double& min_val);
107 static void save_control_timers();
108 static void restore_control_timers();
111 extern TIMER testcase_timer;