libcamera: base: timer: Drop start() overload with int argument
The start(unsigned int msec) overload is error-prone, as the argument unit can easily be mistaken in callers. Drop it and update all callers to use the start(std::chrono::milliseconds) overload instead. The callers now need to use std::chrono_literals. The using statement could be added to timer.h for convenience, but "using" is discouraged in header files to avoid namespace pollution. Update the callers instead, and while at it, sort the "using" statements alphabetically in tests. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
This commit is contained in:
parent
074fa98ac4
commit
54398c1583
19 changed files with 67 additions and 61 deletions
|
@ -25,7 +25,6 @@ public:
|
|||
Timer(Object *parent = nullptr);
|
||||
~Timer();
|
||||
|
||||
void start(unsigned int msec) { start(std::chrono::milliseconds(msec)); }
|
||||
void start(std::chrono::milliseconds duration);
|
||||
void start(std::chrono::steady_clock::time_point deadline);
|
||||
void stop();
|
||||
|
|
|
@ -62,16 +62,6 @@ Timer::~Timer()
|
|||
stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn Timer::start(unsigned int msec)
|
||||
* \brief Start or restart the timer with a timeout of \a msec
|
||||
* \param[in] msec The timer duration in milliseconds
|
||||
*
|
||||
* If the timer is already running it will be stopped and restarted.
|
||||
*
|
||||
* \context This function is \threadbound.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Start or restart the timer with a timeout of \a duration
|
||||
* \param[in] duration The timer duration in milliseconds
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include "libcamera/internal/ipc_unixsocket.h"
|
||||
#include "libcamera/internal/process.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
LOG_DECLARE_CATEGORY(IPCPipe)
|
||||
|
@ -126,7 +128,7 @@ int IPCPipeUnixSocket::call(const IPCUnixSocket::Payload &message,
|
|||
}
|
||||
|
||||
/* \todo Make this less dangerous, see IPCPipe::sendSync() */
|
||||
timeout.start(2000);
|
||||
timeout.start(2000ms);
|
||||
while (!iter->second.done) {
|
||||
if (!timeout.isRunning()) {
|
||||
LOG(IPCPipe, Error) << "Call timeout!";
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "test.h"
|
||||
|
||||
using namespace libcamera;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -135,7 +136,7 @@ protected:
|
|||
EventDispatcher *dispatcher = Thread::current()->eventDispatcher();
|
||||
|
||||
Timer timer;
|
||||
timer.start(1000);
|
||||
timer.start(1000ms);
|
||||
while (timer.isRunning())
|
||||
dispatcher->processEvents();
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
using namespace libcamera;
|
||||
using namespace std;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -117,7 +118,7 @@ private:
|
|||
EventDispatcher *dispatcher = Thread::current()->eventDispatcher();
|
||||
|
||||
Timer timer;
|
||||
timer.start(100);
|
||||
timer.start(100ms);
|
||||
while (timer.isRunning())
|
||||
dispatcher->processEvents();
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
using namespace libcamera;
|
||||
using namespace std;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -137,7 +138,7 @@ protected:
|
|||
EventDispatcher *dispatcher = Thread::current()->eventDispatcher();
|
||||
|
||||
Timer timer;
|
||||
timer.start(1000);
|
||||
timer.start(1000ms);
|
||||
while (timer.isRunning())
|
||||
dispatcher->processEvents();
|
||||
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
|
||||
#include "test.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace libcamera;
|
||||
using namespace std;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
static EventDispatcher *dispatcher;
|
||||
static bool interrupt;
|
||||
|
@ -50,7 +51,7 @@ protected:
|
|||
/* Event processing interruption by signal. */
|
||||
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
||||
|
||||
timer.start(1000);
|
||||
timer.start(1000ms);
|
||||
|
||||
struct itimerval itimer = {};
|
||||
itimer.it_value.tv_usec = 500000;
|
||||
|
@ -69,7 +70,7 @@ protected:
|
|||
}
|
||||
|
||||
/* Event processing interruption. */
|
||||
timer.start(1000);
|
||||
timer.start(1000ms);
|
||||
dispatcher->interrupt();
|
||||
|
||||
dispatcher->processEvents();
|
||||
|
@ -79,7 +80,7 @@ protected:
|
|||
return TestFail;
|
||||
}
|
||||
|
||||
timer.start(1000);
|
||||
timer.start(1000ms);
|
||||
itimer.it_value.tv_usec = 500000;
|
||||
interrupt = true;
|
||||
setitimer(ITIMER_REAL, &itimer, nullptr);
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
|
||||
#include "test.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace libcamera;
|
||||
using namespace std;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class EventTest : public Test
|
||||
{
|
||||
|
@ -55,7 +56,7 @@ protected:
|
|||
return TestFail;
|
||||
}
|
||||
|
||||
timeout.start(100);
|
||||
timeout.start(100ms);
|
||||
dispatcher->processEvents();
|
||||
timeout.stop();
|
||||
|
||||
|
@ -67,7 +68,7 @@ protected:
|
|||
/* Test read notification without data. */
|
||||
notified_ = false;
|
||||
|
||||
timeout.start(100);
|
||||
timeout.start(100ms);
|
||||
dispatcher->processEvents();
|
||||
timeout.stop();
|
||||
|
||||
|
@ -86,7 +87,7 @@ protected:
|
|||
return TestFail;
|
||||
}
|
||||
|
||||
timeout.start(100);
|
||||
timeout.start(100ms);
|
||||
dispatcher->processEvents();
|
||||
timeout.stop();
|
||||
|
||||
|
@ -99,7 +100,7 @@ protected:
|
|||
notified_ = false;
|
||||
notifier_->setEnabled(true);
|
||||
|
||||
timeout.start(100);
|
||||
timeout.start(100ms);
|
||||
dispatcher->processEvents();
|
||||
timeout.stop();
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
#include "camera_test.h"
|
||||
#include "test.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using namespace libcamera;
|
||||
using namespace std;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class FenceTest : public CameraTest, public Test
|
||||
{
|
||||
|
@ -316,7 +316,7 @@ int FenceTest::run()
|
|||
|
||||
/* Loop for one second. */
|
||||
Timer timer;
|
||||
timer.start(1000);
|
||||
timer.start(1000ms);
|
||||
while (timer.isRunning() && expectedCompletionResult_) {
|
||||
if (completedRequest_ == signalledRequestId_ && setFence_)
|
||||
/*
|
||||
|
@ -324,7 +324,7 @@ int FenceTest::run()
|
|||
* been re-queued with a fence. Start the timer to
|
||||
* signal the fence in 10 msec.
|
||||
*/
|
||||
fenceTimer.start(10);
|
||||
fenceTimer.start(10ms);
|
||||
|
||||
dispatcher_->processEvents();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "test.h"
|
||||
|
||||
using namespace libcamera;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class HotplugTest : public Test
|
||||
{
|
||||
|
@ -88,7 +89,7 @@ protected:
|
|||
std::ofstream(uvcDriverDir_ + "unbind", std::ios::binary)
|
||||
<< uvcDeviceDir;
|
||||
Timer timer;
|
||||
timer.start(1000);
|
||||
timer.start(1000ms);
|
||||
while (timer.isRunning() && !cameraRemoved_)
|
||||
Thread::current()->eventDispatcher()->processEvents();
|
||||
if (!cameraRemoved_) {
|
||||
|
@ -99,7 +100,7 @@ protected:
|
|||
/* Bind the camera again and process events. */
|
||||
std::ofstream(uvcDriverDir_ + "bind", std::ios::binary)
|
||||
<< uvcDeviceDir;
|
||||
timer.start(1000);
|
||||
timer.start(1000ms);
|
||||
while (timer.isRunning() && !cameraAdded_)
|
||||
Thread::current()->eventDispatcher()->processEvents();
|
||||
if (!cameraAdded_) {
|
||||
|
|
|
@ -27,8 +27,9 @@
|
|||
|
||||
#include "test.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace libcamera;
|
||||
using namespace std;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class IPAInterfaceTest : public Test, public Object
|
||||
{
|
||||
|
@ -111,7 +112,7 @@ protected:
|
|||
return TestFail;
|
||||
}
|
||||
|
||||
timer.start(1000);
|
||||
timer.start(1000ms);
|
||||
while (timer.isRunning() && trace_ != ipa::vimc::IPAOperationInit)
|
||||
dispatcher->processEvents();
|
||||
|
||||
|
@ -123,7 +124,7 @@ protected:
|
|||
|
||||
/* Test start of IPA module. */
|
||||
ipa_->start();
|
||||
timer.start(1000);
|
||||
timer.start(1000ms);
|
||||
while (timer.isRunning() && trace_ != ipa::vimc::IPAOperationStart)
|
||||
dispatcher->processEvents();
|
||||
|
||||
|
@ -134,7 +135,7 @@ protected:
|
|||
|
||||
/* Test stop of IPA module. */
|
||||
ipa_->stop();
|
||||
timer.start(1000);
|
||||
timer.start(1000ms);
|
||||
while (timer.isRunning() && trace_ != ipa::vimc::IPAOperationStop)
|
||||
dispatcher->processEvents();
|
||||
|
||||
|
|
|
@ -30,8 +30,9 @@
|
|||
#define CMD_LEN_CMP 3
|
||||
#define CMD_JOIN 4
|
||||
|
||||
using namespace std;
|
||||
using namespace libcamera;
|
||||
using namespace std;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
int calculateLength(int fd)
|
||||
{
|
||||
|
@ -430,7 +431,7 @@ private:
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
timeout.start(200);
|
||||
timeout.start(200ms);
|
||||
while (!callDone_) {
|
||||
if (!timeout.isRunning()) {
|
||||
cerr << "Call timeout!" << endl;
|
||||
|
|
|
@ -26,8 +26,9 @@
|
|||
|
||||
#include "test.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace libcamera;
|
||||
using namespace std;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
static const string message("hello from the child");
|
||||
|
||||
|
@ -80,7 +81,7 @@ protected:
|
|||
return TestFail;
|
||||
}
|
||||
|
||||
timeout.start(200);
|
||||
timeout.start(200ms);
|
||||
while (timeout.isRunning())
|
||||
dispatcher->processEvents();
|
||||
|
||||
|
|
|
@ -18,8 +18,9 @@
|
|||
|
||||
#include "test.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace libcamera;
|
||||
using namespace std;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class ProcessTestChild
|
||||
{
|
||||
|
@ -61,7 +62,7 @@ protected:
|
|||
return TestFail;
|
||||
}
|
||||
|
||||
timeout.start(2000);
|
||||
timeout.start(2000ms);
|
||||
while (timeout.isRunning() && exitStatus_ == Process::NotExited)
|
||||
dispatcher->processEvents();
|
||||
|
||||
|
|
|
@ -14,8 +14,9 @@
|
|||
|
||||
#include "test.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace libcamera;
|
||||
using namespace std;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class TimeoutHandler : public Object
|
||||
{
|
||||
|
@ -24,13 +25,13 @@ public:
|
|||
: timer_(this), timeout_(false)
|
||||
{
|
||||
timer_.timeout.connect(this, &TimeoutHandler::timeoutHandler);
|
||||
timer_.start(100);
|
||||
timer_.start(100ms);
|
||||
}
|
||||
|
||||
void restart()
|
||||
{
|
||||
timeout_ = false;
|
||||
timer_.start(100);
|
||||
timer_.start(100ms);
|
||||
}
|
||||
|
||||
bool timeout() const
|
||||
|
|
|
@ -14,8 +14,9 @@
|
|||
|
||||
#include "test.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace libcamera;
|
||||
using namespace std;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class ManagedTimer : public Timer
|
||||
{
|
||||
|
@ -26,7 +27,7 @@ public:
|
|||
timeout.connect(this, &ManagedTimer::timeoutHandler);
|
||||
}
|
||||
|
||||
void start(int msec)
|
||||
void start(std::chrono::milliseconds msec)
|
||||
{
|
||||
count_ = 0;
|
||||
start_ = std::chrono::steady_clock::now();
|
||||
|
@ -82,7 +83,7 @@ protected:
|
|||
ManagedTimer timer2;
|
||||
|
||||
/* Timer expiration. */
|
||||
timer.start(1000);
|
||||
timer.start(1000ms);
|
||||
|
||||
if (!timer.isRunning()) {
|
||||
cout << "Timer expiration test failed" << endl;
|
||||
|
@ -101,7 +102,7 @@ protected:
|
|||
* Nanosecond resolution in a 32 bit value wraps at 4.294967
|
||||
* seconds (0xFFFFFFFF / 1000000)
|
||||
*/
|
||||
timer.start(4295);
|
||||
timer.start(4295ms);
|
||||
dispatcher->processEvents();
|
||||
|
||||
if (timer.hasFailed()) {
|
||||
|
@ -110,7 +111,7 @@ protected:
|
|||
}
|
||||
|
||||
/* Timer restart. */
|
||||
timer.start(500);
|
||||
timer.start(500ms);
|
||||
|
||||
if (!timer.isRunning()) {
|
||||
cout << "Timer restart test failed" << endl;
|
||||
|
@ -125,9 +126,9 @@ protected:
|
|||
}
|
||||
|
||||
/* Timer restart before expiration. */
|
||||
timer.start(50);
|
||||
timer.start(100);
|
||||
timer.start(150);
|
||||
timer.start(50ms);
|
||||
timer.start(100ms);
|
||||
timer.start(150ms);
|
||||
|
||||
dispatcher->processEvents();
|
||||
|
||||
|
@ -147,8 +148,8 @@ protected:
|
|||
}
|
||||
|
||||
/* Two timers. */
|
||||
timer.start(1000);
|
||||
timer2.start(300);
|
||||
timer.start(1000ms);
|
||||
timer2.start(300ms);
|
||||
|
||||
dispatcher->processEvents();
|
||||
|
||||
|
@ -170,8 +171,8 @@ protected:
|
|||
}
|
||||
|
||||
/* Restart timer before expiration. */
|
||||
timer.start(1000);
|
||||
timer2.start(300);
|
||||
timer.start(1000ms);
|
||||
timer2.start(300ms);
|
||||
|
||||
dispatcher->processEvents();
|
||||
|
||||
|
@ -180,7 +181,7 @@ protected:
|
|||
return TestFail;
|
||||
}
|
||||
|
||||
timer.start(1000);
|
||||
timer.start(1000ms);
|
||||
|
||||
dispatcher->processEvents();
|
||||
|
||||
|
@ -194,10 +195,10 @@ protected:
|
|||
* deleted. This will result in a crash on failure.
|
||||
*/
|
||||
ManagedTimer *dyntimer = new ManagedTimer();
|
||||
dyntimer->start(100);
|
||||
dyntimer->start(100ms);
|
||||
delete dyntimer;
|
||||
|
||||
timer.start(200);
|
||||
timer.start(200ms);
|
||||
dispatcher->processEvents();
|
||||
|
||||
return TestPass;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "v4l2_videodevice_test.h"
|
||||
|
||||
using namespace libcamera;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class BufferSharingTest : public V4L2VideoDeviceTest
|
||||
{
|
||||
|
@ -145,7 +146,7 @@ protected:
|
|||
return TestFail;
|
||||
}
|
||||
|
||||
timeout.start(10000);
|
||||
timeout.start(10000ms);
|
||||
while (timeout.isRunning()) {
|
||||
dispatcher->processEvents();
|
||||
if (framesCaptured_ > 30 && framesOutput_ > 30)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "v4l2_videodevice_test.h"
|
||||
|
||||
using namespace libcamera;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class CaptureAsyncTest : public V4L2VideoDeviceTest
|
||||
{
|
||||
|
@ -60,7 +61,7 @@ protected:
|
|||
if (ret)
|
||||
return TestFail;
|
||||
|
||||
timeout.start(10000);
|
||||
timeout.start(10000ms);
|
||||
while (timeout.isRunning()) {
|
||||
dispatcher->processEvents();
|
||||
if (frames > 30)
|
||||
|
|
|
@ -19,8 +19,9 @@
|
|||
|
||||
#include "test.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace libcamera;
|
||||
using namespace std;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class V4L2M2MDeviceTest : public Test
|
||||
{
|
||||
|
@ -155,7 +156,7 @@ protected:
|
|||
}
|
||||
|
||||
Timer timeout;
|
||||
timeout.start(5000);
|
||||
timeout.start(5000ms);
|
||||
while (timeout.isRunning()) {
|
||||
dispatcher->processEvents();
|
||||
if (captureFrames_ > 30)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue