IBR-DTNSuite  0.10
Clock.h
Go to the documentation of this file.
1 /*
2  * Clock.h
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #ifndef CLOCK_H_
23 #define CLOCK_H_
24 
25 #include <sys/time.h>
26 
27 #include "ibrdtn/data/Number.h"
28 #include "ibrdtn/data/Bundle.h"
29 #include "ibrdtn/data/BundleID.h"
30 
31 namespace dtn
32 {
33  namespace utils
34  {
35  class Clock
36  {
37  public:
43 
49 
54  static bool isExpired(const dtn::data::Bundle &b);
55 
60  static bool isExpired(const dtn::data::Timestamp &timestamp, const dtn::data::Number &lifetime = 0) __attribute__ ((deprecated));
61 
66 
71  static dtn::data::Timestamp getExpireTime(const dtn::data::Timestamp &timestamp, const dtn::data::Number &lifetime) __attribute__ ((deprecated));
72 
80 
85  static dtn::data::Number getLifetime(const dtn::data::BundleID &id, const dtn::data::Timestamp &expiretime);
86 
90  static void settimeofday(struct timeval *tv);
91 
97  static void gettimeofday(struct timeval *tv);
98 
103  static void setOffset(const struct timeval &tv);
104 
109  static const struct timeval& getOffset();
110 
112 
118  static bool isBad();
119 
123  static void setBad(bool val);
124 
128  static int getTimezone();
129 
133  static void setTimezone(int val);
134 
140  static double getRating();
141 
145  static void setRating(double val);
146 
151  static bool shouldModifyClock();
152 
156  static void setModifyClock(bool val);
157 
161  static double toDouble(const timeval &val);
162 
167 
168  private:
172  static int _timezone;
173 
179  static double _rating;
180 
185  static bool _badclock;
186 
191  static bool _modify_clock;
192 
193  Clock();
194  virtual ~Clock();
195 
196  static bool __isExpired(const dtn::data::Timestamp &timestamp, const dtn::data::Number &lifetime = 0);
197  static dtn::data::Timestamp __getExpireTime(const dtn::data::Timestamp &timestamp, const dtn::data::Number &lifetime);
198 
199  static struct timeval _offset;
200  static bool _offset_init;
201 
202  static const dtn::data::Timestamp _boot_timestamp;
203  };
204  }
205 }
206 
207 #endif /* CLOCK_H_ */