2012-03-02 01:33:57 +01:00
|
|
|
/*
|
|
|
|
|
REAL-CLOCK.hpp - convenience front-end to access the system clock
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2012, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** @file real-clock.hpp
|
|
|
|
|
** Front-end for simplified access to the current wall clock time.
|
2018-11-15 21:13:52 +01:00
|
|
|
** The implementation relies on Lumiera vault functions to access the
|
2012-03-02 01:33:57 +01:00
|
|
|
** system clock with a sufficient level of precision. The result is
|
2023-04-21 05:29:10 +02:00
|
|
|
** delivered in lumiera's [internal time format](\ref lib::time::Time)
|
|
|
|
|
**
|
2012-03-02 01:33:57 +01:00
|
|
|
** @todo this might be a good candidate also to provide some kind of
|
|
|
|
|
** translation service, i.e. a grid to anchor a logical time value
|
2012-03-19 01:03:14 +01:00
|
|
|
** with actual running wall clock time.
|
2012-03-02 01:33:57 +01:00
|
|
|
**
|
|
|
|
|
** @see lib/time/timevalue.hpp
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:52:02 +01:00
|
|
|
#ifndef VAULT_REAL_CLOCK_H
|
|
|
|
|
#define VAULT_REAL_CLOCK_H
|
2012-03-02 01:33:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/error.hpp"
|
|
|
|
|
#include "lib/time/timevalue.hpp"
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
namespace vault {
|
2012-03-02 01:33:57 +01:00
|
|
|
|
|
|
|
|
using lib::time::Time;
|
|
|
|
|
using lib::time::TimeValue;
|
2023-04-21 05:29:10 +02:00
|
|
|
using lib::time::Offset;
|
2012-03-02 01:33:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-10-28 20:55:28 +02:00
|
|
|
* Convenience frontend to access the current raw system time
|
2012-03-02 01:33:57 +01:00
|
|
|
*/
|
|
|
|
|
class RealClock
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
static Time
|
|
|
|
|
now()
|
|
|
|
|
{
|
2023-10-28 20:55:28 +02:00
|
|
|
return Time{_readSystemTime()};
|
2012-03-02 01:33:57 +01:00
|
|
|
}
|
|
|
|
|
|
2023-04-21 05:29:10 +02:00
|
|
|
static bool
|
|
|
|
|
wasRecently (Time event)
|
|
|
|
|
{
|
|
|
|
|
Offset past{event, now()};
|
|
|
|
|
return Time::ZERO <= past
|
|
|
|
|
and past < CONSIDERED_RECENT;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-02 01:33:57 +01:00
|
|
|
|
|
|
|
|
private:
|
2012-03-19 01:03:14 +01:00
|
|
|
static TimeValue _readSystemTime();
|
2023-04-21 05:29:10 +02:00
|
|
|
static const Offset CONSIDERED_RECENT;
|
2012-03-02 01:33:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
} // namespace vault
|
2012-03-02 01:33:57 +01:00
|
|
|
#endif
|