TimeService.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Wed Apr 17 16:01:31 CEST 2002 TimeService.cpp
3 
4  TimeService.cpp - description
5  -------------------
6  begin : Wed April 17 2002
7  copyright : (C) 2002 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 #include "os/fosi.h"
39 #include "TimeService.hpp"
40 
41 namespace RTT {
42  using namespace os;
43 
44  TimeService* TimeService::_instance = 0;
45 
49 
51  {
52  return nano2ticks( m );
53  }
54 
56  {
57  return ticks2nano( t );
58  }
59 
61  {
62  if ( _instance == 0 )
63  {
64  _instance = new TimeService();
65  }
66 
67  return _instance;
68  }
69 
70 
72  {
73  if ( _instance != 0 )
74  {
75  delete _instance;
76  _instance = 0;
77  return true;
78  }
79 
80  return false;
81  }
82 
83 
85  : offset(0), use_clock(true)
86  {
87  //os::cout << "HeartBeat Created\n";
88  }
89 
91  {
92  //os::cout << "HB DESTRUCTOR\n";
93  }
94 
95  void TimeService::enableSystemClock( bool yes_no )
96  {
97  // guarantee monotonous time increase :
98  if ( yes_no == use_clock )
99  return;
100  // we switched from one time domain to the other
101  use_clock=yes_no;
102  if ( use_clock == true )
103  {
104  // if offset is X, then start counting from X.
106  }
107  else
108  {
109  // start counting from _now_ + old offset
111  }
112  }
113 
115  {
116  return use_clock;
117  }
118 
121  {
122  return use_clock ? rtos_get_time_ticks() + offset : 0 + offset;
123  }
124 
127  {
128  if ( relativeTime == 0 )
129  {
130  relativeTime = getTicks();
131  return 0;
132  }
133  return ( getTicks() - relativeTime );
134  }
135 
138  {
139  return ( getTicks() - relativeTime );
140  }
141 
142 
145  {
146  return nsecs_to_Seconds( ticks2nsecs( getTicks( relativeTime ) ) ) ;
147  }
148 
151  {
152  return nsecs_to_Seconds( ticks2nsecs( ticksSince( relativeTime ) ) ) ;
153  }
154 
157  {
158  offset += nsecs2ticks( Seconds_to_nsecs( delta ) );
159  return nsecs_to_Seconds( ticks2nsecs( ticksSince( 0 ) ) ) ;
160  }
161 
164  {
165  offset += delta;
166  return ticksSince( 0 );
167  }
168 
171  {
172  return rtos_get_time_ns();
173  }
174 
177  {
178  if ( relativeTime == 0 )
179  {
180  relativeTime = getNSecs();
181  return 0;
182  }
183  return ( getNSecs() - relativeTime );
184  }
185 }
const double InfiniteSeconds
Definition: ecos/fosi.h:72
static TimeService * _instance
const TICK_TIME InfiniteTicks
Definition: ecos/fosi.h:70
static nsecs ticks2nsecs(const ticks t)
Definition: TimeService.cpp:55
nsecs getNSecs() const
Seconds nsecs_to_Seconds(const nsecs ns)
Definition: os/Time.hpp:108
NANO_TIME rtos_get_time_ns(void)
Definition: ecos/fosi.h:125
const NANO_TIME InfiniteNSecs
Definition: ecos/fosi.h:71
static bool Release()
Definition: TimeService.cpp:71
Seconds secondsSince(ticks relativeTime) const
ticks ticksChange(ticks delta)
static const ticks InfiniteTicks
static TimeService * Instance()
Definition: TimeService.cpp:60
Seconds getSeconds(ticks &relativeTime) const
bool systemClockEnabled() const
static const nsecs InfiniteNSecs
static ticks nsecs2ticks(const nsecs m)
Definition: TimeService.cpp:50
static const Seconds InfiniteSeconds
void enableSystemClock(bool yes_no)
Definition: TimeService.cpp:95
ticks ticksSince(ticks relativeTime) const
TICK_TIME rtos_get_time_ticks(void)
Definition: ecos/fosi.h:130
NANO_TIME ticks2nano(TICK_TIME count)
Definition: ecos/fosi.h:119
nsecs Seconds_to_nsecs(const Seconds s)
Definition: os/Time.hpp:107
TICK_TIME nano2ticks(NANO_TIME nano)
Definition: ecos/fosi.h:112
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
Seconds secondsChange(Seconds delta)
ticks getTicks() const


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:44