Fixed building with a bazel with hdrs_check fixed again.
Change-Id: I015f66cd6e02e07efa367b96edd775015ac0abca
diff --git a/aos/common/logging/BUILD b/aos/common/logging/BUILD
index 8bd59b9..9223c44 100644
--- a/aos/common/logging/BUILD
+++ b/aos/common/logging/BUILD
@@ -15,6 +15,7 @@
name = 'queue_logging',
srcs = [
'queue_logging.cc',
+ 'queue_logging-tmpl.h',
],
hdrs = [
'queue_logging.h',
@@ -27,9 +28,17 @@
)
cc_library(
+ name = 'sizes',
+ hdrs = [
+ 'sizes.h',
+ ],
+)
+
+cc_library(
name = 'matrix_logging',
srcs = [
'matrix_logging.cc',
+ 'matrix_logging-tmpl.h',
],
hdrs = [
'matrix_logging.h',
@@ -44,14 +53,45 @@
)
cc_library(
+ name = 'logging_printf_formats',
+ hdrs = [
+ 'logging_printf_formats.h',
+ ],
+ deps = [
+ '//aos/common:macros',
+ ],
+)
+
+cc_library(
name = 'logging_interface',
+ hdrs = [
+ 'logging.h',
+ 'logging_interface.h',
+ ],
srcs = [
'logging_interface.cc',
],
+ copts = [
+ # TODO(austin): This is wrong.
+ '-Wno-error=format-nonliteral'
+ ],
deps = [
- '//aos/linux_code/logging:linux_interface',
'//aos/common:die',
'//aos/common/libc:aos_strerror',
+ '//aos/linux_code/logging:linux_interface',
+ ],
+)
+
+cc_library(
+ name = 'context',
+ hdrs = [
+ 'context.h',
+ ],
+ srcs = [
+ 'context.cc',
+ ],
+ deps = [
+ ':sizes',
],
)
@@ -60,11 +100,12 @@
srcs = [
'logging_impl.cc',
],
+ hdrs = [
+ 'logging_impl.h',
+ ],
deps = [
- '//aos/linux_code/logging:linux_logging',
'//aos/common:time',
'//aos/common:once',
- ':logging_interface',
'//aos/common:queue_types',
],
)
diff --git a/aos/common/logging/context.cc b/aos/common/logging/context.cc
new file mode 100644
index 0000000..8874edb
--- /dev/null
+++ b/aos/common/logging/context.cc
@@ -0,0 +1,19 @@
+#include "aos/common/logging/context.h"
+
+#include <string.h>
+
+namespace aos {
+namespace logging {
+namespace internal {
+
+::std::atomic<LogImplementation *> global_top_implementation(NULL);
+
+Context::Context()
+ : implementation(global_top_implementation.load()),
+ sequence(0) {
+ cork_data.Reset();
+}
+
+} // namespace internal
+} // namespace logging
+} // namespace aos
diff --git a/aos/common/logging/context.h b/aos/common/logging/context.h
new file mode 100644
index 0000000..b7fee26
--- /dev/null
+++ b/aos/common/logging/context.h
@@ -0,0 +1,84 @@
+#ifndef AOS_COMMON_LOGGING_CONTEXT_H_
+#define AOS_COMMON_LOGGING_CONTEXT_H_
+
+#include <inttypes.h>
+#include <stddef.h>
+#include <sys/types.h>
+#include <limits.h>
+
+#include <atomic>
+
+#include "aos/common/logging/sizes.h"
+
+namespace aos {
+namespace logging {
+
+class LogImplementation;
+
+// This is where all of the code that is only used by actual LogImplementations
+// goes.
+namespace internal {
+
+extern ::std::atomic<LogImplementation *> global_top_implementation;
+
+// An separate instance of this class is accessible from each task/thread.
+// NOTE: It will get deleted in the child of a fork.
+//
+// Get() and Delete() are implemented in the platform-specific interface.cc
+// file.
+struct Context {
+ Context();
+
+ // Gets the Context object for this task/thread. Will create one the first
+ // time it is called.
+ //
+ // The implementation for each platform will lazily instantiate a new instance
+ // and then initialize name the first time.
+ // IMPORTANT: The implementation of this can not use logging.
+ static Context *Get();
+ // Deletes the Context object for this task/thread so that the next Get() is
+ // called it will create a new one.
+ // It is valid to call this when Get() has never been called.
+ // This also gets called after a fork(2) in the new process, where it should
+ // still work to clean up any state.
+ static void Delete();
+
+ // Which one to log to right now.
+ // Will be NULL if there is no logging implementation to use right now.
+ LogImplementation *implementation;
+
+ // A name representing this task/(process and thread).
+ char name[LOG_MESSAGE_NAME_LEN];
+ size_t name_size;
+
+ // What to assign LogMessage::source to in this task/thread.
+ pid_t source;
+
+ // The sequence value to send out with the next message.
+ uint16_t sequence;
+
+ // Contains all of the information related to implementing LOG_CORK and
+ // LOG_UNCORK.
+ struct {
+ char message[LOG_MESSAGE_LEN];
+ int line_min, line_max;
+ // Sets the data up to record a new series of corked logs.
+ void Reset() {
+ message[0] = '\0'; // make strlen of it 0
+ line_min = INT_MAX;
+ line_max = -1;
+ function = NULL;
+ }
+ // The function that the calls are in.
+ // REMEMBER: While the compiler/linker will probably optimize all of the
+ // identical strings to point to the same data, it might not, so using == to
+ // compare this with another value is a bad idea.
+ const char *function;
+ } cork_data;
+};
+
+} // namespace internal
+} // namespace logging
+} // namespace aos
+
+#endif // AOS_COMMON_LOGGING_CONTEXT_H_
diff --git a/aos/common/logging/logging.h b/aos/common/logging/logging.h
index 66b88c7..3182d1a 100644
--- a/aos/common/logging/logging.h
+++ b/aos/common/logging/logging.h
@@ -33,9 +33,6 @@
DECL_LEVELS;
#undef DECL_LEVEL
-// Not static const size_t for C code.
-#define LOG_MESSAGE_LEN 400
-
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/aos/common/logging/logging_impl.cc b/aos/common/logging/logging_impl.cc
index c776991..34c3816 100644
--- a/aos/common/logging/logging_impl.cc
+++ b/aos/common/logging/logging_impl.cc
@@ -1,10 +1,10 @@
#include "aos/common/logging/logging_impl.h"
#include <stdarg.h>
-
-#include "aos/common/time.h"
#include <inttypes.h>
+
#include "aos/common/once.h"
+#include "aos/common/time.h"
#include "aos/common/queue_types.h"
#include "aos/common/logging/logging_printf_formats.h"
diff --git a/aos/common/logging/logging_impl.h b/aos/common/logging/logging_impl.h
index 367c1a1..ab4b728 100644
--- a/aos/common/logging/logging_impl.h
+++ b/aos/common/logging/logging_impl.h
@@ -17,6 +17,10 @@
#include "aos/common/type_traits.h"
#include "aos/common/mutex.h"
#include "aos/common/macros.h"
+#include "aos/common/logging/sizes.h"
+#include "aos/common/logging/logging_interface.h"
+#include "aos/common/logging/context.h"
+#include "aos/common/once.h"
namespace aos {
@@ -58,7 +62,7 @@
uint16_t sequence;
Type type;
log_level level;
- char name[100];
+ char name[LOG_MESSAGE_NAME_LEN];
union {
char message[LOG_MESSAGE_LEN];
struct {
@@ -125,78 +129,6 @@
template <class T>
void DoLogMatrix(log_level, const ::std::string &, const T &);
-// Represents a system that can actually take log messages and do something
-// useful with them.
-// All of the code (transitively too!) in the DoLog here can make
-// normal LOG and LOG_DYNAMIC calls but can NOT call LOG_CORK/LOG_UNCORK. These
-// calls will not result in DoLog recursing. However, implementations must be
-// safe to call from multiple threads/tasks at the same time. Also, any other
-// overriden methods may end up logging through a given implementation's DoLog.
-class LogImplementation {
- public:
- LogImplementation() : next_(NULL) {}
-
- // The one that this one's implementation logs to.
- // NULL means that there is no next one.
- LogImplementation *next() { return next_; }
- // Virtual in case a subclass wants to perform checks. There will be a valid
- // logger other than this one available while this is called.
- virtual void set_next(LogImplementation *next) { next_ = next; }
-
- private:
- // Actually logs the given message. Implementations should somehow create a
- // LogMessage and then call internal::FillInMessage.
- __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0)))
- virtual void DoLog(log_level level, const char *format, va_list ap) = 0;
- __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 4)))
- void DoLogVariadic(log_level level, const char *format, ...) {
- va_list ap;
- va_start(ap, format);
- DoLog(level, format, ap);
- va_end(ap);
- }
-
- // Logs the contents of an auto-generated structure. The implementation here
- // just converts it to a string with PrintMessage and then calls DoLog with
- // that, however some implementations can be a lot more efficient than that.
- // size and type are the result of calling Size() and Type() on the type of
- // the message.
- // serialize will call Serialize on the message.
- virtual void LogStruct(log_level level, const ::std::string &message,
- size_t size, const MessageType *type,
- const ::std::function<size_t(char *)> &serialize);
- // Similiar to LogStruct, except for matrixes.
- // type_id is the type of the elements of the matrix.
- // data points to rows*cols*type_id.Size() bytes of data in row-major order.
- virtual void LogMatrix(log_level level, const ::std::string &message,
- uint32_t type_id, int rows, int cols,
- const void *data);
-
- // These functions call similar methods on the "current" LogImplementation or
- // Die if they can't find one.
- // levels is how many LogImplementations to not use off the stack.
- static void DoVLog(log_level, const char *format, va_list ap, int levels)
- __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 2, 0)));
- // This one is implemented in queue_logging.cc.
- static void DoLogStruct(log_level level, const ::std::string &message,
- size_t size, const MessageType *type,
- const ::std::function<size_t(char *)> &serialize,
- int levels);
- // This one is implemented in matrix_logging.cc.
- static void DoLogMatrix(log_level level, const ::std::string &message,
- uint32_t type_id, int rows, int cols,
- const void *data, int levels);
-
- // Friends so that they can access the static Do* functions.
- friend void VLog(log_level, const char *, va_list);
- friend void LogNext(log_level, const char *, ...);
- template <class T>
- friend void DoLogStruct(log_level, const ::std::string &, const T &);
- template <class T>
- friend void DoLogMatrix(log_level, const ::std::string &, const T &);
-
- LogImplementation *next_;
-};
// Implements all of the DoLog* methods in terms of a (pure virtual in this
// class) HandleMessage method that takes a pointer to the message.
@@ -252,64 +184,6 @@
// goes.
namespace internal {
-extern ::std::atomic<LogImplementation *> global_top_implementation;
-
-// An separate instance of this class is accessible from each task/thread.
-// NOTE: It will get deleted in the child of a fork.
-//
-// Get() and Delete() are implemented in the platform-specific interface.cc
-// file.
-struct Context {
- Context();
-
- // Gets the Context object for this task/thread. Will create one the first
- // time it is called.
- //
- // The implementation for each platform will lazily instantiate a new instance
- // and then initialize name the first time.
- // IMPORTANT: The implementation of this can not use logging.
- static Context *Get();
- // Deletes the Context object for this task/thread so that the next Get() is
- // called it will create a new one.
- // It is valid to call this when Get() has never been called.
- // This also gets called after a fork(2) in the new process, where it should
- // still work to clean up any state.
- static void Delete();
-
- // Which one to log to right now.
- // Will be NULL if there is no logging implementation to use right now.
- LogImplementation *implementation;
-
- // A name representing this task/(process and thread).
- char name[sizeof(LogMessage::name)];
- size_t name_size;
-
- // What to assign LogMessage::source to in this task/thread.
- pid_t source;
-
- // The sequence value to send out with the next message.
- uint16_t sequence;
-
- // Contains all of the information related to implementing LOG_CORK and
- // LOG_UNCORK.
- struct {
- char message[LOG_MESSAGE_LEN];
- int line_min, line_max;
- // Sets the data up to record a new series of corked logs.
- void Reset() {
- message[0] = '\0'; // make strlen of it 0
- line_min = INT_MAX;
- line_max = -1;
- function = NULL;
- }
- // The function that the calls are in.
- // REMEMBER: While the compiler/linker will probably optimize all of the
- // identical strings to point to the same data, it might not, so using == to
- // compare this with another value is a bad idea.
- const char *function;
- } cork_data;
-};
-
// Fills in all the parts of message according to the given inputs (with type
// kStruct).
void FillInMessageStructure(log_level level,
diff --git a/aos/common/logging/logging_interface.cc b/aos/common/logging/logging_interface.cc
index 0bec52c..0a6c968 100644
--- a/aos/common/logging/logging_interface.cc
+++ b/aos/common/logging/logging_interface.cc
@@ -1,11 +1,14 @@
-#include "aos/common/logging/logging_impl.h"
+#include "aos/common/logging/logging_interface.h"
#include <stdarg.h>
+#include <stdio.h>
#include <string.h>
#include <type_traits>
+#include <functional>
#include "aos/common/die.h"
+#include "aos/common/logging/context.h"
// This file only contains the code necessary to link (ie no implementations).
// See logging_impl.h for why this is necessary.
@@ -14,14 +17,6 @@
namespace logging {
namespace internal {
-::std::atomic<LogImplementation *> global_top_implementation(NULL);
-
-Context::Context()
- : implementation(global_top_implementation.load()),
- sequence(0) {
- cork_data.Reset();
-}
-
size_t ExecuteFormat(char *output, size_t output_size, const char *format,
va_list ap) {
static const char *const continued = "...\n";
diff --git a/aos/common/logging/logging_interface.h b/aos/common/logging/logging_interface.h
new file mode 100644
index 0000000..af591ee
--- /dev/null
+++ b/aos/common/logging/logging_interface.h
@@ -0,0 +1,96 @@
+#ifndef AOS_COMMON_LOGGING_LOGGING_INTERFACE_H_
+#define AOS_COMMON_LOGGING_LOGGING_INTERFACE_H_
+
+#include <stdarg.h>
+
+#include <string>
+#include <functional>
+
+#include "aos/common/logging/logging.h"
+
+namespace aos {
+
+struct MessageType;
+
+} // namespace aos
+
+namespace aos {
+namespace logging {
+
+// Represents a system that can actually take log messages and do something
+// useful with them.
+// All of the code (transitively too!) in the DoLog here can make
+// normal LOG and LOG_DYNAMIC calls but can NOT call LOG_CORK/LOG_UNCORK. These
+// calls will not result in DoLog recursing. However, implementations must be
+// safe to call from multiple threads/tasks at the same time. Also, any other
+// overriden methods may end up logging through a given implementation's DoLog.
+class LogImplementation {
+ public:
+ LogImplementation() : next_(NULL) {}
+
+ // The one that this one's implementation logs to.
+ // NULL means that there is no next one.
+ LogImplementation *next() { return next_; }
+ // Virtual in case a subclass wants to perform checks. There will be a valid
+ // logger other than this one available while this is called.
+ virtual void set_next(LogImplementation *next) { next_ = next; }
+
+ private:
+ // Actually logs the given message. Implementations should somehow create a
+ // LogMessage and then call internal::FillInMessage.
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0)))
+ virtual void DoLog(log_level level, const char *format, va_list ap) = 0;
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 4)))
+ void DoLogVariadic(log_level level, const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ DoLog(level, format, ap);
+ va_end(ap);
+ }
+
+ // Logs the contents of an auto-generated structure. The implementation here
+ // just converts it to a string with PrintMessage and then calls DoLog with
+ // that, however some implementations can be a lot more efficient than that.
+ // size and type are the result of calling Size() and Type() on the type of
+ // the message.
+ // serialize will call Serialize on the message.
+ virtual void LogStruct(log_level level, const ::std::string &message,
+ size_t size, const MessageType *type,
+ const ::std::function<size_t(char *)> &serialize);
+ // Similiar to LogStruct, except for matrixes.
+ // type_id is the type of the elements of the matrix.
+ // data points to rows*cols*type_id.Size() bytes of data in row-major order.
+ virtual void LogMatrix(log_level level, const ::std::string &message,
+ uint32_t type_id, int rows, int cols,
+ const void *data);
+
+ // These functions call similar methods on the "current" LogImplementation or
+ // Die if they can't find one.
+ // levels is how many LogImplementations to not use off the stack.
+ static void DoVLog(log_level, const char *format, va_list ap, int levels)
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 2, 0)));
+ // This one is implemented in queue_logging.cc.
+ static void DoLogStruct(log_level level, const ::std::string &message,
+ size_t size, const MessageType *type,
+ const ::std::function<size_t(char *)> &serialize,
+ int levels);
+ // This one is implemented in matrix_logging.cc.
+ static void DoLogMatrix(log_level level, const ::std::string &message,
+ uint32_t type_id, int rows, int cols,
+ const void *data, int levels);
+
+ // Friends so that they can access the static Do* functions.
+ friend void VLog(log_level, const char *, va_list);
+ friend void LogNext(log_level, const char *, ...);
+ template <class T>
+ friend void DoLogStruct(log_level, const ::std::string &, const T &);
+ template <class T>
+ friend void DoLogMatrix(log_level, const ::std::string &, const T &);
+
+ LogImplementation *next_;
+};
+
+} // namespace logging
+} // namespace aos
+
+#endif // AOS_COMMON_LOGGING_LOGGING_INTERFACE_H_
diff --git a/aos/common/logging/sizes.h b/aos/common/logging/sizes.h
new file mode 100644
index 0000000..6a4c7d5
--- /dev/null
+++ b/aos/common/logging/sizes.h
@@ -0,0 +1,9 @@
+#ifndef AOS_COMMON_LOGGING_SIZES_H_
+#define AOS_COMMON_LOGGING_SIZES_H_
+
+// This file exists so C code and context.h can both get at these constants...
+
+#define LOG_MESSAGE_LEN 400
+#define LOG_MESSAGE_NAME_LEN 100
+
+#endif // AOS_COMMON_LOGGING_SIZES_H_