libcamera: timer: Remove the interval() method
The libcamera timers are single-shot timers. They are started with a duration, but fire once only, not based on an interval. Remove the interval concept by removing the interval() method, and rename other occurences of interval to duration. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
parent
ecf1c2e57b
commit
e85f42110f
3 changed files with 13 additions and 17 deletions
|
@ -24,11 +24,10 @@ public:
|
||||||
~Timer();
|
~Timer();
|
||||||
|
|
||||||
void start(unsigned int msec) { start(std::chrono::milliseconds(msec)); }
|
void start(unsigned int msec) { start(std::chrono::milliseconds(msec)); }
|
||||||
void start(std::chrono::milliseconds interval);
|
void start(std::chrono::milliseconds duration);
|
||||||
void stop();
|
void stop();
|
||||||
bool isRunning() const;
|
bool isRunning() const;
|
||||||
|
|
||||||
std::chrono::milliseconds interval() const { return interval_; }
|
|
||||||
std::chrono::steady_clock::time_point deadline() const { return deadline_; }
|
std::chrono::steady_clock::time_point deadline() const { return deadline_; }
|
||||||
|
|
||||||
Signal<Timer *> timeout;
|
Signal<Timer *> timeout;
|
||||||
|
@ -40,7 +39,6 @@ private:
|
||||||
void registerTimer();
|
void registerTimer();
|
||||||
void unregisterTimer();
|
void unregisterTimer();
|
||||||
|
|
||||||
std::chrono::milliseconds interval_;
|
|
||||||
std::chrono::steady_clock::time_point deadline_;
|
std::chrono::steady_clock::time_point deadline_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -61,19 +61,18 @@ Timer::~Timer()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Start or restart the timer with a timeout of \a interval
|
* \brief Start or restart the timer with a timeout of \a duration
|
||||||
* \param[in] interval The timer duration in milliseconds
|
* \param[in] duration The timer duration in milliseconds
|
||||||
*
|
*
|
||||||
* If the timer is already running it will be stopped and restarted.
|
* If the timer is already running it will be stopped and restarted.
|
||||||
*/
|
*/
|
||||||
void Timer::start(std::chrono::milliseconds interval)
|
void Timer::start(std::chrono::milliseconds duration)
|
||||||
{
|
{
|
||||||
interval_ = interval;
|
deadline_ = utils::clock::now() + duration;
|
||||||
deadline_ = utils::clock::now() + interval;
|
|
||||||
|
|
||||||
LOG(Timer, Debug)
|
LOG(Timer, Debug)
|
||||||
<< "Starting timer " << this << " with interval "
|
<< "Starting timer " << this << " with duration "
|
||||||
<< interval.count() << ": deadline "
|
<< duration.count() << ": deadline "
|
||||||
<< utils::time_point_to_string(deadline_);
|
<< utils::time_point_to_string(deadline_);
|
||||||
|
|
||||||
registerTimer();
|
registerTimer();
|
||||||
|
@ -113,12 +112,6 @@ bool Timer::isRunning() const
|
||||||
return deadline_ != utils::time_point();
|
return deadline_ != utils::time_point();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* \fn Timer::interval()
|
|
||||||
* \brief Retrieve the timer interval
|
|
||||||
* \return The timer interval in milliseconds
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn Timer::deadline()
|
* \fn Timer::deadline()
|
||||||
* \brief Retrieve the timer deadline
|
* \brief Retrieve the timer deadline
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* qt_event_dispatcher.cpp - qcam - Qt-based event dispatcher
|
* qt_event_dispatcher.cpp - qcam - Qt-based event dispatcher
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <QAbstractEventDispatcher>
|
#include <QAbstractEventDispatcher>
|
||||||
|
@ -112,7 +113,11 @@ void QtEventDispatcher::exceptionNotifierActivated(int socket)
|
||||||
|
|
||||||
void QtEventDispatcher::registerTimer(Timer *timer)
|
void QtEventDispatcher::registerTimer(Timer *timer)
|
||||||
{
|
{
|
||||||
int timerId = startTimer(timer->interval());
|
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
||||||
|
std::chrono::steady_clock::duration duration = timer->deadline() - now;
|
||||||
|
std::chrono::milliseconds msec =
|
||||||
|
std::chrono::duration_cast<std::chrono::milliseconds>(duration);
|
||||||
|
int timerId = startTimer(msec);
|
||||||
timers_[timerId] = timer;
|
timers_[timerId] = timer;
|
||||||
timerIds_[timer] = timerId;
|
timerIds_[timer] = timerId;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue