From patchwork Tue Dec 4 22:11:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 23 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E74BF60B13 for ; Tue, 4 Dec 2018 23:10:52 +0100 (CET) Received: from avalon.bb.dnainternet.fi (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 50644553 for ; Tue, 4 Dec 2018 23:10:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1543961452; bh=kvJlXRmY8v8mS0YDVtbi5VpKQgTATPdxMfZN3JyM3t4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Llg3xT7eVd7FRE1rRIr6aMT09iZFLHzhK/+aS0m2cF+KPdUbD6c76qDovmgQZJ/mL NMjCpr7FflYIl9myzo0ROAUnF7aaBwxkCsVcDPWGIdE3CdWnnazffazeH2CH+gopuj 5mCEoNarh6kZTUf+hQksg/MYn+ItPA8Jowjrx0Yg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 5 Dec 2018 00:11:21 +0200 Message-Id: <20181204221123.571-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204221123.571-1-laurent.pinchart@ideasonboard.com> References: <20181204221123.571-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/3] Overhaul the directory structure X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Dec 2018 22:10:53 -0000 In order to match the directory structure of traditional projects, rename the top-level lib/ directory to src/libcamera/. Other libraries developed as part of the project will later find a home in src/. Split the libcamera header files in three categories: public headers describing the public API in include/libcamera/, internal headers describing the internal API in src/libcamera/include/, and private headers local to one or a small number of compilation units along the corresponding .cpp files. As no internal header exists yet the src/libcamera/include/ directory is created empty as the build system would fail otherwise. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- meson.build | 4 ++-- src/libcamera/include/.keep_empty | 0 {lib => src/libcamera}/main.cpp | 0 {lib => src/libcamera}/meson.build | 7 ++++++- src/meson.build | 1 + test/meson.build | 2 +- 6 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 src/libcamera/include/.keep_empty rename {lib => src/libcamera}/main.cpp (100%) rename {lib => src/libcamera}/meson.build (50%) create mode 100644 src/meson.build diff --git a/meson.build b/meson.build index e0aeefa30330..e6ed03f951c7 100644 --- a/meson.build +++ b/meson.build @@ -21,11 +21,11 @@ cpp_arguments = common_arguments add_project_arguments(c_arguments, language: 'c') add_project_arguments(cpp_arguments, language: 'cpp') -inc = include_directories('include') +libcamera_includes = include_directories('include') subdir('Documentation') subdir('include') -subdir('lib') +subdir('src') subdir('test') subdir('utils') diff --git a/src/libcamera/include/.keep_empty b/src/libcamera/include/.keep_empty new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/main.cpp b/src/libcamera/main.cpp similarity index 100% rename from lib/main.cpp rename to src/libcamera/main.cpp diff --git a/lib/meson.build b/src/libcamera/meson.build similarity index 50% rename from lib/meson.build rename to src/libcamera/meson.build index fcd738cc86d8..07d9cd448342 100644 --- a/lib/meson.build +++ b/src/libcamera/meson.build @@ -1,6 +1,11 @@ sources = ['main.cpp'] +includes = [ + libcamera_includes, + include_directories('include'), +] + libcamera = shared_library('camera', sources, install : true, - include_directories : inc) + include_directories : includes) diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 000000000000..4ce9668caa7b --- /dev/null +++ b/src/meson.build @@ -0,0 +1 @@ +subdir('libcamera') diff --git a/test/meson.build b/test/meson.build index afe9bd9a741c..924a26f1ca66 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,5 +1,5 @@ test_init = executable('test_init', 'init.cpp', link_with : libcamera, - include_directories : inc) + include_directories : libcamera_includes) test('Initialisation test', test_init) From patchwork Tue Dec 4 22:11:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 24 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7721360A71 for ; Tue, 4 Dec 2018 23:10:53 +0100 (CET) Received: from avalon.bb.dnainternet.fi (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E62CA546 for ; Tue, 4 Dec 2018 23:10:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1543961453; bh=/W1F+eov4TJl0wJgwzn2U/cPNmmYJ4Z5ysxNHxNk0/U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ulJWhvxv3noLR/4tW1i2b/maOUq8AS11sFNiPzefpGi0ZwjwWFnxOaGx7yUhmGyAD zEOoxxvU2KfbzpVwZ9lE4byFmtWEPRDQjSVUqbL0oJH4YFPwJYV8bABgPwHpPG4GUn gR7luAZ0gRF43ijKQjm2Ux+hzTQid/SfGOOE6n3M= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 5 Dec 2018 00:11:22 +0200 Message-Id: <20181204221123.571-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204221123.571-1-laurent.pinchart@ideasonboard.com> References: <20181204221123.571-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] libcamera: Add initial logger X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Dec 2018 22:10:53 -0000 The logger is based on the ostream API, allowing code to log messages in a native way. It automatically logs the time stamp, severity level, file name and line number. Many important features are missing, such as logging to file, logging classes, and log filtering based on the severity level, file name and class. Signed-off-by: Laurent Pinchart Acked-by: Kieran Bingham --- src/libcamera/include/.keep_empty | 0 src/libcamera/include/log.h | 38 +++++++++++++++ src/libcamera/include/utils.h | 12 +++++ src/libcamera/log.cpp | 81 +++++++++++++++++++++++++++++++ src/libcamera/meson.build | 5 +- 5 files changed, 135 insertions(+), 1 deletion(-) delete mode 100644 src/libcamera/include/.keep_empty create mode 100644 src/libcamera/include/log.h create mode 100644 src/libcamera/include/utils.h create mode 100644 src/libcamera/log.cpp diff --git a/src/libcamera/include/.keep_empty b/src/libcamera/include/.keep_empty deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/src/libcamera/include/log.h b/src/libcamera/include/log.h new file mode 100644 index 000000000000..76acd1520868 --- /dev/null +++ b/src/libcamera/include/log.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2018, Google Inc. + * + * log.h - Logging infrastructure + */ +#ifndef __LIBCAMERA_LOG_H__ +#define __LIBCAMERA_LOG_H__ + +#include + +namespace libcamera { + +enum LogSeverity { + LogInfo, + LogWarning, + LogError, +}; + +class LogMessage +{ +public: + LogMessage(const char *fileName, unsigned int line, + LogSeverity severity); + LogMessage(const LogMessage&) = delete; + ~LogMessage(); + + std::ostream& stream() { return msgStream; } + +private: + std::ostringstream msgStream; +}; + +#define LOG(severity) LogMessage(__FILE__, __LINE__, Log##severity).stream() + +}; + +#endif /* __LIBCAMERA_LOG_H__ */ diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h new file mode 100644 index 000000000000..3ffa6f4ea591 --- /dev/null +++ b/src/libcamera/include/utils.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2018, Google Inc. + * + * utils.h - Miscellaneous utility functions + */ +#ifndef __LIBCAMERA_UTILS_H__ +#define __LIBCAMERA_UTILS_H__ + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) + +#endif /* __LIBCAMERA_UTILS_H__ */ diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp new file mode 100644 index 000000000000..18ccfa32d8b4 --- /dev/null +++ b/src/libcamera/log.cpp @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2018, Google Inc. + * + * log.h - Logging infrastructure + */ + +#include +#include +#include +#include + +#include "log.h" +#include "utils.h" + +/** + * \file log.h + * \brief Logging infrastructure + */ + +namespace libcamera { + +/** + * \enum LogSeverity + * Log message severity + * \var Info + * Informational message + * \var Warning + * Warning message, signals a potential issue + * \var Error + * Error message, signals an unrecoverable issue + */ + +/** + * \def LOG(severity) + * \brief Log a message + * + * Return an std::ostream reference to which a message can be logged using the + * iostream API. The \a severity controls whether the message is printed or + * dropped, depending on the global log level. + */ + +static const char *log_severity_name(LogSeverity severity) +{ + static const char * const names[] = { + "INFO", + "WARN", + " ERR", + }; + + if ((unsigned int)severity < ARRAY_SIZE(names)) + return names[severity]; + else + return "UNKN"; +} + +LogMessage::LogMessage(const char *fileName, unsigned int line, + LogSeverity severity) +{ + /* Log the timestamp, severity and file information. */ + struct timespec timestamp; + clock_gettime(CLOCK_MONOTONIC, ×tamp); + msgStream << "[" << 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 << "]"; + + msgStream << " " << log_severity_name(severity); + msgStream << " " << basename(fileName) << ":" << line << " "; +} + +LogMessage::~LogMessage() +{ + msgStream << std::endl; + + std::string msg(msgStream.str()); + fwrite(msg.data(), msg.size(), 1, stderr); + fflush(stderr); +} + +}; diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 07d9cd448342..fe38f8b2b5b4 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -1,4 +1,7 @@ -sources = ['main.cpp'] +sources = files([ + 'log.cpp', + 'main.cpp', +]) includes = [ libcamera_includes, From patchwork Tue Dec 4 22:11:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 25 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F2D4D600CC for ; Tue, 4 Dec 2018 23:10:53 +0100 (CET) Received: from avalon.bb.dnainternet.fi (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 774C8591 for ; Tue, 4 Dec 2018 23:10:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1543961453; bh=5CqUjiDVKX4h7W8J0vG8BzWTIMAq2CPRuez/NSGND1w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=R2af1enrf97TiiNVa8D8fFc7OC5AWiNmsRipw4quqeZvbMfDu8bEgjbRyuj+fBmx1 gycc8K4VtE1o5dpVEY2XoeG9BZjFI/N/rkt31xfvcJ4JkTMvhPHIEtUyZi86AaJexF 1PyDsLnknOuR4ZN7OTWMo0toryhV3FnY3FUVFIwA= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 5 Dec 2018 00:11:23 +0200 Message-Id: <20181204221123.571-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204221123.571-1-laurent.pinchart@ideasonboard.com> References: <20181204221123.571-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] libcamera: Use the logger instead of cout X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Dec 2018 22:10:54 -0000 Signed-off-by: Laurent Pinchart Acked-by: Kieran Bingham --- include/libcamera/libcamera.h | 4 ++++ src/libcamera/main.cpp | 10 ++++++---- test/init.cpp | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/libcamera/libcamera.h b/include/libcamera/libcamera.h index 64857326a0b0..790771b61e41 100644 --- a/include/libcamera/libcamera.h +++ b/include/libcamera/libcamera.h @@ -7,10 +7,14 @@ #ifndef __LIBCAMERA_LIBCAMERA_H__ #define __LIBCAMERA_LIBCAMERA_H__ +namespace libcamera { + class libcamera { public: void init_lib(void); }; +}; + #endif /* __LIBCAMERA_LIBCAMERA_H__ */ diff --git a/src/libcamera/main.cpp b/src/libcamera/main.cpp index 0059e0c91571..7ed37dfcfd5b 100644 --- a/src/libcamera/main.cpp +++ b/src/libcamera/main.cpp @@ -5,13 +5,15 @@ * main.cpp - libcamera main class */ -#include #include -using std::cout; -using std::endl; +#include "log.h" + +namespace libcamera { void libcamera::init_lib(void) { - cout << "Lib Camera Init" << endl; + LOG(Info) << "Lib Camera Init"; } + +}; diff --git a/test/init.cpp b/test/init.cpp index 8c8ec9adfb83..278169cdbf1e 100644 --- a/test/init.cpp +++ b/test/init.cpp @@ -2,7 +2,7 @@ int main(void) { - libcamera l = libcamera(); + libcamera::libcamera l = libcamera::libcamera(); l.init_lib(); return 0;