libcamera: Switch to the std::chrono API

Replace the clock_gettime()-based API with durations expressed as
integers with the std::chrono API.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
Laurent Pinchart
2019-09-14 15:05:45 +03:00
parent 98dff063f2
commit cecfeed61e
9 changed files with 67 additions and 75 deletions
+4 -16
View File
@@ -11,7 +11,6 @@
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <string.h>
@@ -78,17 +77,6 @@ static int log_severity_to_syslog(LogSeverity severity)
}
}
static std::string log_timespec_to_string(const struct timespec &timestamp)
{
std::ostringstream ossTimestamp;
ossTimestamp.fill('0');
ossTimestamp << "[" << timestamp.tv_sec / (60 * 60) << ":"
<< std::setw(2) << (timestamp.tv_sec / 60) % 60 << ":"
<< std::setw(2) << timestamp.tv_sec % 60 << "."
<< std::setw(9) << timestamp.tv_nsec << "]";
return ossTimestamp.str();
}
static const char *log_severity_name(LogSeverity severity)
{
static const char *const names[] = {
@@ -216,10 +204,10 @@ void LogOutput::writeSyslog(const LogMessage &msg)
void LogOutput::writeStream(const LogMessage &msg)
{
std::string str = std::string(log_timespec_to_string(msg.timestamp()) +
log_severity_name(msg.severity()) + " " +
std::string str = "[" + utils::time_point_to_string(msg.timestamp()) +
"]" + log_severity_name(msg.severity()) + " " +
msg.category().name() + " " + msg.fileInfo() + " " +
msg.msg());
msg.msg();
stream_->write(str.c_str(), str.size());
stream_->flush();
}
@@ -777,7 +765,7 @@ LogMessage::LogMessage(LogMessage &&other)
void LogMessage::init(const char *fileName, unsigned int line)
{
/* Log the timestamp, severity and file information. */
clock_gettime(CLOCK_MONOTONIC, &timestamp_);
timestamp_ = utils::clock::now();
std::ostringstream ossFileInfo;
ossFileInfo << utils::basename(fileName) << ":" << line;