Prefix LOG and CHECK with AOS_
This prepares us for introducing glog more widely and transitioning
things over where they make sense.
Change-Id: Ic6c208882407bc2153fe875ffc736d66f5c8ade5
diff --git a/aos/logging/binary_log_file.cc b/aos/logging/binary_log_file.cc
index ca62b73..9ea5c82 100644
--- a/aos/logging/binary_log_file.cc
+++ b/aos/logging/binary_log_file.cc
@@ -24,8 +24,8 @@
: fd_(fd), writable_(writable), offset_(0), current_(0), position_(0) {
// Check to make sure that mmap will allow mmaping in chunks of kPageSize.
if (SystemPageSize() > kPageSize || (kPageSize % SystemPageSize()) != 0) {
- LOG(FATAL, "system page size (%lu) not factor of kPageSize (%zd).\n",
- SystemPageSize(), kPageSize);
+ AOS_LOG(FATAL, "system page size (%lu) not factor of kPageSize (%zd).\n",
+ SystemPageSize(), kPageSize);
}
MapNextPage();
@@ -36,14 +36,14 @@
}
void LogFileAccessor::SkipToLastSeekablePage() {
- CHECK(definitely_use_mmap());
+ AOS_CHECK(definitely_use_mmap());
struct stat info;
if (fstat(fd_, &info) == -1) {
- PLOG(FATAL, "fstat(%d, %p) failed", fd_, &info);
+ AOS_PLOG(FATAL, "fstat(%d, %p) failed", fd_, &info);
}
- CHECK((info.st_size % kPageSize) == 0);
+ AOS_CHECK((info.st_size % kPageSize) == 0);
const auto last_readable_page_number = (info.st_size / kPageSize) - 1;
const auto last_seekable_page_number =
last_readable_page_number / kSeekPages * kSeekPages;
@@ -66,7 +66,7 @@
struct stat info;
if (fstat(fd_, &info) == -1) {
- PLOG(FATAL, "fstat(%d, %p) failed", fd_, &info);
+ AOS_PLOG(FATAL, "fstat(%d, %p) failed", fd_, &info);
}
bool r = offset_ == static_cast<off_t>(info.st_size - kPageSize);
is_last_page_ = r ? Maybe::kYes : Maybe::kNo;
@@ -76,7 +76,7 @@
void LogFileAccessor::MapNextPage() {
if (writable_) {
if (ftruncate(fd_, offset_ + kPageSize) == -1) {
- PLOG(FATAL, "ftruncate(%d, %zd) failed", fd_, kPageSize);
+ AOS_PLOG(FATAL, "ftruncate(%d, %zd) failed", fd_, kPageSize);
}
}
@@ -85,49 +85,51 @@
while (todo > 0) {
ssize_t result = read(fd_, current_ + (kPageSize - todo), todo);
if (result == -1) {
- PLOG(FATAL, "read(%d, %p, %zu) failed", fd_,
- current_ + (kPageSize - todo), todo);
+ AOS_PLOG(FATAL, "read(%d, %p, %zu) failed", fd_,
+ current_ + (kPageSize - todo), todo);
} else if (result == 0) {
memset(current_, 0, todo);
result = todo;
}
todo -= result;
}
- CHECK_EQ(0, todo);
+ AOS_CHECK_EQ(0, todo);
} else {
current_ = static_cast<char *>(
mmap(NULL, kPageSize, PROT_READ | (writable_ ? PROT_WRITE : 0),
MAP_SHARED, fd_, offset_));
if (current_ == MAP_FAILED) {
if (!writable_ && use_read_ == Maybe::kUnknown && errno == ENODEV) {
- LOG(INFO, "Falling back to reading the file using read(2).\n");
+ AOS_LOG(INFO, "Falling back to reading the file using read(2).\n");
use_read_ = Maybe::kYes;
current_ = new char[kPageSize];
MapNextPage();
return;
} else {
- PLOG(FATAL,
- "mmap(NULL, %zd, PROT_READ [ | PROT_WRITE], MAP_SHARED, %d, %jd)"
- " failed",
- kPageSize, fd_, static_cast<intmax_t>(offset_));
+ AOS_PLOG(
+ FATAL,
+ "mmap(NULL, %zd, PROT_READ [ | PROT_WRITE], MAP_SHARED, %d, %jd)"
+ " failed",
+ kPageSize, fd_, static_cast<intmax_t>(offset_));
}
} else {
use_read_ = Maybe::kNo;
}
if (madvise(current_, kPageSize, MADV_SEQUENTIAL | MADV_WILLNEED) == -1) {
- PLOG(WARNING, "madvise(%p, %zd, MADV_SEQUENTIAL | MADV_WILLNEED) failed",
- current_, kPageSize);
+ AOS_PLOG(WARNING,
+ "madvise(%p, %zd, MADV_SEQUENTIAL | MADV_WILLNEED) failed",
+ current_, kPageSize);
}
}
offset_ += kPageSize;
}
void LogFileAccessor::Unmap(void *location) {
- CHECK_NE(Maybe::kUnknown, use_read_);
+ AOS_CHECK_NE(Maybe::kUnknown, use_read_);
if (use_read_ == Maybe::kNo) {
if (munmap(location, kPageSize) == -1) {
- PLOG(FATAL, "munmap(%p, %zd) failed", location, kPageSize);
+ AOS_PLOG(FATAL, "munmap(%p, %zd) failed", location, kPageSize);
}
}
is_last_page_ = Maybe::kUnknown;
@@ -140,7 +142,7 @@
r = static_cast<LogFileMessageHeader *>(
static_cast<void *>(¤t()[position()]));
if (wait) {
- CHECK(definitely_use_mmap());
+ AOS_CHECK(definitely_use_mmap());
if (futex_wait(&r->marker) != 0) continue;
}
if (r->marker == 2) {
@@ -158,7 +160,7 @@
if (position() >= kPageSize) {
// It's a lot better to blow up here rather than getting SIGBUS errors the
// next time we try to read...
- LOG(FATAL, "corrupt log file running over page size\n");
+ AOS_LOG(FATAL, "corrupt log file running over page size\n");
}
return r;
}
@@ -189,31 +191,31 @@
action.sa_flags = SA_RESETHAND | SA_SIGINFO;
struct sigaction previous_bus, previous_segv;
if (sigaction(SIGBUS, &action, &previous_bus) == -1) {
- PLOG(FATAL, "sigaction(SIGBUS(=%d), %p, %p) failed",
- SIGBUS, &action, &previous_bus);
+ AOS_PLOG(FATAL, "sigaction(SIGBUS(=%d), %p, %p) failed", SIGBUS, &action,
+ &previous_bus);
}
if (sigaction(SIGSEGV, &action, &previous_segv) == -1) {
- PLOG(FATAL, "sigaction(SIGSEGV(=%d), %p, %p) failed",
- SIGSEGV, &action, &previous_segv);
+ AOS_PLOG(FATAL, "sigaction(SIGSEGV(=%d), %p, %p) failed", SIGSEGV,
+ &action, &previous_segv);
}
char __attribute__((unused)) c = current()[0];
if (sigaction(SIGBUS, &previous_bus, NULL) == -1) {
- PLOG(FATAL, "sigaction(SIGBUS(=%d), %p, NULL) failed",
- SIGBUS, &previous_bus);
+ AOS_PLOG(FATAL, "sigaction(SIGBUS(=%d), %p, NULL) failed", SIGBUS,
+ &previous_bus);
}
if (sigaction(SIGSEGV, &previous_segv, NULL) == -1) {
- PLOG(FATAL, "sigaction(SIGSEGV(=%d), %p, NULL) failed",
- SIGSEGV, &previous_segv);
+ AOS_PLOG(FATAL, "sigaction(SIGSEGV(=%d), %p, NULL) failed", SIGSEGV,
+ &previous_segv);
}
} else {
if (fault_address == current()) {
- LOG(FATAL, "could not read 1 byte at offset 0x%jx into log file\n",
- static_cast<uintmax_t>(offset()));
+ AOS_LOG(FATAL, "could not read 1 byte at offset 0x%jx into log file\n",
+ static_cast<uintmax_t>(offset()));
} else {
- LOG(FATAL, "faulted at %p, not %p like we were (maybe) supposed to\n",
- fault_address, current());
+ AOS_LOG(FATAL, "faulted at %p, not %p like we were (maybe) supposed to\n",
+ fault_address, current());
}
}
}
@@ -234,7 +236,7 @@
++next_message_page;
}
const off_t current_seekable_page = next_message_page / kSeekPages;
- CHECK_LE(*cookie, current_seekable_page);
+ AOS_CHECK_LE(*cookie, current_seekable_page);
const bool r = *cookie != current_seekable_page;
*cookie = current_seekable_page;
return r;
@@ -252,8 +254,8 @@
if (futex_set_value(
static_cast<aos_futex *>(static_cast<void *>(&temp[position()])),
2) == -1) {
- PLOG(WARNING, "readers will hang because futex_set_value(%p, 2) failed",
- &temp[position()]);
+ AOS_PLOG(WARNING, "readers will hang because futex_set_value(%p, 2) failed",
+ &temp[position()]);
}
Unmap(temp);
}
diff --git a/aos/logging/binary_log_writer.cc b/aos/logging/binary_log_writer.cc
index e335b53..be19d45 100644
--- a/aos/logging/binary_log_writer.cc
+++ b/aos/logging/binary_log_writer.cc
@@ -42,8 +42,8 @@
char buffer[1024];
ssize_t size = type.Serialize(buffer, sizeof(buffer));
if (size == -1) {
- LOG(WARNING, "%zu-byte buffer is too small to serialize type %s\n",
- sizeof(buffer), type.name.c_str());
+ AOS_LOG(WARNING, "%zu-byte buffer is too small to serialize type %s\n",
+ sizeof(buffer), type.name.c_str());
return;
}
LogFileMessageHeader *const output =
@@ -78,7 +78,7 @@
if (errno == 0) {
break;
} else {
- PLOG(FATAL, "readdir(%p) failed", d);
+ AOS_PLOG(FATAL, "readdir(%p) failed", d);
}
} else {
if (sscanf(dir->d_name, "aos_log-%d", &index) == 1) {
@@ -97,15 +97,16 @@
previous[len] = '\0';
} else {
previous[0] = '\0';
- LOG(INFO, "Could not find aos_log-current\n");
+ AOS_LOG(INFO, "Could not find aos_log-current\n");
printf("Could not find aos_log-current\n");
}
if (asprintf(filename, "%s/aos_log-%03d", directory, fileindex) == -1) {
PDie("couldn't create final name");
}
- LOG(INFO, "Created log file (aos_log-%d) in directory (%s). Previous file "
- "was (%s).\n",
- fileindex, directory, previous);
+ AOS_LOG(INFO,
+ "Created log file (aos_log-%d) in directory (%s). Previous file "
+ "was (%s).\n",
+ fileindex, directory, previous);
printf("Created log file (aos_log-%d) in directory (%s). Previous file was "
"(%s).\n",
fileindex, directory, previous);
@@ -138,7 +139,7 @@
char test_device[10];
for (char i = 'a'; i < 'z'; ++i) {
snprintf(test_device, sizeof(test_device), "/dev/sd%c", i);
- LOG(INFO, "Trying to access %s\n", test_device);
+ AOS_LOG(INFO, "Trying to access %s\n", test_device);
if (access(test_device, F_OK) != -1) {
snprintf(device, device_size, "sd%c", i);
return true;
@@ -157,13 +158,13 @@
{
char dev_name[8];
while (!FindDevice(dev_name, sizeof(dev_name))) {
- LOG(INFO, "Waiting for a device\n");
+ AOS_LOG(INFO, "Waiting for a device\n");
printf("Waiting for a device\n");
sleep(5);
}
snprintf(folder, sizeof(folder), "/media/%s1", dev_name);
while (!FoundThumbDrive(folder)) {
- LOG(INFO, "Waiting for %s\n", folder);
+ AOS_LOG(INFO, "Waiting for %s\n", folder);
printf("Waiting for %s\n", folder);
sleep(1);
}
@@ -175,21 +176,21 @@
const char *folder = configuration::GetLoggingDirectory();
if (access(folder, R_OK | W_OK) == -1) {
#endif
- LOG(FATAL, "folder '%s' does not exist. please create it\n", folder);
+ AOS_LOG(FATAL, "folder '%s' does not exist. please create it\n", folder);
}
- LOG(INFO, "logging to folder '%s'\n", folder);
+ AOS_LOG(INFO, "logging to folder '%s'\n", folder);
char *tmp;
AllocateLogName(&tmp, folder);
char *tmp2;
if (asprintf(&tmp2, "%s/aos_log-current", folder) == -1) {
- PLOG(WARNING, "couldn't create current symlink name");
+ AOS_PLOG(WARNING, "couldn't create current symlink name");
} else {
if (unlink(tmp2) == -1 && (errno != EROFS && errno != ENOENT)) {
- LOG(WARNING, "unlink('%s') failed", tmp2);
+ AOS_LOG(WARNING, "unlink('%s') failed", tmp2);
}
if (symlink(tmp, tmp2) == -1) {
- PLOG(WARNING, "symlink('%s', '%s') failed", tmp, tmp2);
+ AOS_PLOG(WARNING, "symlink('%s', '%s') failed", tmp, tmp2);
}
free(tmp2);
}
@@ -197,7 +198,7 @@
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
free(tmp);
if (fd == -1) {
- PLOG(FATAL, "opening file '%s' failed", tmp);
+ AOS_PLOG(FATAL, "opening file '%s' failed", tmp);
}
LogFileWriter writer(fd);
@@ -234,7 +235,7 @@
output_length +=
sizeof(msg->matrix.type) + sizeof(uint32_t) + sizeof(uint16_t) +
sizeof(uint16_t) + msg->matrix.string_length;
- CHECK(MessageType::IsPrimitive(msg->matrix.type));
+ AOS_CHECK(MessageType::IsPrimitive(msg->matrix.type));
}
LogFileMessageHeader *const output = writer.GetWritePosition(output_length);
char *output_strings = reinterpret_cast<char *>(output) + sizeof(*output);
@@ -289,8 +290,8 @@
memcpy(position, &cols, sizeof(cols));
position += sizeof(cols);
output->message_size += sizeof(rows) + sizeof(cols);
- CHECK_EQ(msg->message_length,
- MessageType::Sizeof(msg->matrix.type) * rows * cols);
+ AOS_CHECK_EQ(msg->message_length,
+ MessageType::Sizeof(msg->matrix.type) * rows * cols);
memcpy(position, msg->matrix.data, msg->message_length + length);
output->message_size += length;
@@ -301,8 +302,8 @@
if (output->message_size - msg->message_length !=
output_length - raw_output_length) {
- LOG(FATAL, "%zu != %zu\n", output->message_size - msg->message_length,
- output_length - raw_output_length);
+ AOS_LOG(FATAL, "%zu != %zu\n", output->message_size - msg->message_length,
+ output_length - raw_output_length);
}
futex_set(&output->marker);
diff --git a/aos/logging/implementations.cc b/aos/logging/implementations.cc
index 273c583..632d90b 100644
--- a/aos/logging/implementations.cc
+++ b/aos/logging/implementations.cc
@@ -21,15 +21,15 @@
// The root LogImplementation. It only logs to stderr/stdout.
// Some of the things specified in the LogImplementation documentation doesn't
-// apply here (mostly the parts about being able to use LOG) because this is the
-// root one.
+// apply here (mostly the parts about being able to use AOS_LOG) because this is
+// the root one.
class RootLogImplementation : public SimpleLogImplementation {
public:
void have_other_implementation() { only_implementation_ = false; }
private:
void set_next(LogImplementation *) override {
- LOG(FATAL, "can't have a next logger from here\n");
+ AOS_LOG(FATAL, "can't have a next logger from here\n");
}
__attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0)))
@@ -68,8 +68,7 @@
if (pthread_atfork(NULL /*prepare*/, NULL /*parent*/,
NewContext /*child*/) != 0) {
- LOG(FATAL, "pthread_atfork(NULL, NULL, %p) failed\n",
- NewContext);
+ AOS_LOG(FATAL, "pthread_atfork(NULL, NULL, %p) failed\n", NewContext);
}
return NULL;
@@ -116,7 +115,8 @@
FillInMessageBase(level, monotonic_now, message);
if (message_string.size() + size > sizeof(message->structure.serialized)) {
- LOG(FATAL,
+ AOS_LOG(
+ FATAL,
"serialized struct %s (size %zd + %zd > %zd) and message %s too big\n",
type->name.c_str(), message_string.size(), size,
sizeof(message->structure.serialized), message_string.c_str());
@@ -135,7 +135,7 @@
const ::std::string &message_string, uint32_t type_id,
int rows, int cols, const void *data,
LogMessage *message) {
- CHECK(MessageType::IsPrimitive(type_id));
+ AOS_CHECK(MessageType::IsPrimitive(type_id));
message->matrix.type = type_id;
const auto element_size = MessageType::Sizeof(type_id);
@@ -145,9 +145,10 @@
message->message_length = rows * cols * element_size;
if (message_string.size() + message->message_length >
sizeof(message->matrix.data)) {
- LOG(FATAL, "%dx%d matrix of type %" PRIu32
- " (size %u) and message %s is too big\n",
- rows, cols, type_id, element_size, message_string.c_str());
+ AOS_LOG(FATAL,
+ "%dx%d matrix of type %" PRIu32
+ " (size %u) and message %s is too big\n",
+ rows, cols, type_id, element_size, message_string.c_str());
}
message->matrix.string_length = message_string.size();
memcpy(message->matrix.data, message_string.data(),
@@ -187,15 +188,17 @@
buffer, &output_length,
message.structure.serialized + message.structure.string_length,
&input_length, type_cache::Get(message.structure.type_id))) {
- LOG(FATAL,
+ AOS_LOG(
+ FATAL,
"printing message (%.*s) of type %s into %zu-byte buffer failed\n",
static_cast<int>(message.message_length), message.message,
type_cache::Get(message.structure.type_id).name.c_str(),
sizeof(buffer));
}
if (input_length > 0) {
- LOG(WARNING, "%zu extra bytes on message of type %s\n", input_length,
- type_cache::Get(message.structure.type_id).name.c_str());
+ AOS_LOG(WARNING, "%zu extra bytes on message of type %s\n",
+ input_length,
+ type_cache::Get(message.structure.type_id).name.c_str());
}
fprintf(output, AOS_LOGGING_BASE_FORMAT "%.*s: %.*s\n", BASE_ARGS,
static_cast<int>(message.structure.string_length),
@@ -208,17 +211,17 @@
if (message.message_length !=
static_cast<size_t>(message.matrix.rows * message.matrix.cols *
MessageType::Sizeof(message.matrix.type))) {
- LOG(FATAL, "expected %d bytes of matrix data but have %zu\n",
- message.matrix.rows * message.matrix.cols *
- MessageType::Sizeof(message.matrix.type),
- message.message_length);
+ AOS_LOG(FATAL, "expected %d bytes of matrix data but have %zu\n",
+ message.matrix.rows * message.matrix.cols *
+ MessageType::Sizeof(message.matrix.type),
+ message.message_length);
}
if (!PrintMatrix(buffer, &output_length,
message.matrix.data + message.matrix.string_length,
message.matrix.type, message.matrix.rows,
message.matrix.cols)) {
- LOG(FATAL, "printing %dx%d matrix of type %" PRIu32 " failed\n",
- message.matrix.rows, message.matrix.cols, message.matrix.type);
+ AOS_LOG(FATAL, "printing %dx%d matrix of type %" PRIu32 " failed\n",
+ message.matrix.rows, message.matrix.cols, message.matrix.type);
}
fprintf(output, AOS_LOGGING_BASE_FORMAT "%.*s: %.*s\n", BASE_ARGS,
static_cast<int>(message.matrix.string_length),
@@ -236,16 +239,17 @@
const MessageType *type, const ::std::function<size_t(char *)> &serialize) {
char serialized[1024];
if (size > sizeof(serialized)) {
- LOG(FATAL, "structure of type %s too big to serialize\n",
- type->name.c_str());
+ AOS_LOG(FATAL, "structure of type %s too big to serialize\n",
+ type->name.c_str());
}
size_t used = serialize(serialized);
char printed[1024];
size_t printed_bytes = sizeof(printed);
if (!PrintMessage(printed, &printed_bytes, serialized, &used, *type)) {
- LOG(FATAL, "PrintMessage(%p, %p(=%zd), %p, %p(=%zd), %p(name=%s)) failed\n",
- printed, &printed_bytes, printed_bytes, serialized, &used, used, type,
- type->name.c_str());
+ AOS_LOG(FATAL,
+ "PrintMessage(%p, %p(=%zd), %p, %p(=%zd), %p(name=%s)) failed\n",
+ printed, &printed_bytes, printed_bytes, serialized, &used, used,
+ type, type->name.c_str());
}
DoLogVariadic(level, "%.*s: %.*s\n", static_cast<int>(message.size()),
message.data(),
@@ -258,16 +262,17 @@
char serialized[1024];
if (static_cast<size_t>(rows * cols * MessageType::Sizeof(type_id)) >
sizeof(serialized)) {
- LOG(FATAL, "matrix of size %u too big to serialize\n",
- rows * cols * MessageType::Sizeof(type_id));
+ AOS_LOG(FATAL, "matrix of size %u too big to serialize\n",
+ rows * cols * MessageType::Sizeof(type_id));
}
SerializeMatrix(type_id, serialized, data, rows, cols);
char printed[1024];
size_t printed_bytes = sizeof(printed);
if (!PrintMatrix(printed, &printed_bytes, serialized, type_id, rows, cols)) {
- LOG(FATAL, "PrintMatrix(%p, %p(=%zd), %p, %" PRIu32 ", %d, %d) failed\n",
- printed, &printed_bytes, printed_bytes, serialized, type_id, rows,
- cols);
+ AOS_LOG(FATAL,
+ "PrintMatrix(%p, %p(=%zd), %p, %" PRIu32 ", %d, %d) failed\n",
+ printed, &printed_bytes, printed_bytes, serialized, type_id, rows,
+ cols);
}
DoLogVariadic(level, "%.*s: %.*s\n", static_cast<int>(message.size()),
message.data(),
@@ -311,8 +316,10 @@
internal::Context *context = internal::Context::Get();
if (implementation->next() != NULL) {
- LOG(FATAL, "%p already has a next implementation, but it's not"
- " being used yet\n", implementation);
+ AOS_LOG(FATAL,
+ "%p already has a next implementation, but it's not"
+ " being used yet\n",
+ implementation);
}
LogImplementation *old = context->implementation;
@@ -348,7 +355,7 @@
LogMessage *GetMessageOrDie() {
LogMessage *message = static_cast<LogMessage *>(queue->GetMessage());
if (message == NULL) {
- LOG(FATAL, "%p->GetMessage() failed\n", queue);
+ AOS_LOG(FATAL, "%p->GetMessage() failed\n", queue);
} else {
return message;
}
diff --git a/aos/logging/implementations_test.cc b/aos/logging/implementations_test.cc
index ecf66e9..2accf35 100644
--- a/aos/logging/implementations_test.cc
+++ b/aos/logging/implementations_test.cc
@@ -63,17 +63,17 @@
}
internal::Context *context = internal::Context::Get();
if (log_implementation->message().source != context->source) {
- LOG(FATAL, "got a message from %" PRIu32 ", but we're %" PRIu32 "\n",
- static_cast<uint32_t>(log_implementation->message().source),
- static_cast<uint32_t>(context->source));
+ AOS_LOG(FATAL, "got a message from %" PRIu32 ", but we're %" PRIu32 "\n",
+ static_cast<uint32_t>(log_implementation->message().source),
+ static_cast<uint32_t>(context->source));
}
if (log_implementation->message().name_length != context->name_size ||
memcmp(log_implementation->message().name, context->name,
context->name_size) !=
0) {
- LOG(FATAL, "got a message from %.*s, but we're %s\n",
- static_cast<int>(log_implementation->message().name_length),
- log_implementation->message().name, context->name);
+ AOS_LOG(FATAL, "got a message from %.*s, but we're %s\n",
+ static_cast<int>(log_implementation->message().name_length),
+ log_implementation->message().name, context->name);
}
if (strstr(log_implementation->message().message, message.c_str())
== NULL) {
@@ -110,26 +110,26 @@
// correctly.
TEST_F(LoggingTest, Basic) {
EXPECT_FALSE(WasAnythingLogged());
- LOG(INFO, "test log 1\n");
+ AOS_LOG(INFO, "test log 1\n");
EXPECT_TRUE(WasLogged(INFO, "test log 1\n"));
- LOG(INFO, "test log 1.5\n");
+ AOS_LOG(INFO, "test log 1.5\n");
// there's a subtle typo on purpose...
EXPECT_FALSE(WasLogged(INFO, "test log 15\n"));
- LOG(ERROR, "test log 2=%d\n", 55);
+ AOS_LOG(ERROR, "test log 2=%d\n", 55);
EXPECT_TRUE(WasLogged(ERROR, "test log 2=55\n"));
- LOG(ERROR, "test log 3\n");
+ AOS_LOG(ERROR, "test log 3\n");
EXPECT_FALSE(WasLogged(WARNING, "test log 3\n"));
- LOG(WARNING, "test log 4\n");
+ AOS_LOG(WARNING, "test log 4\n");
EXPECT_TRUE(WasAnythingLogged());
}
TEST_F(LoggingTest, Cork) {
static const int begin_line = __LINE__;
- LOG_CORK("first part ");
- LOG_CORK("second part (=%d) ", 19);
+ AOS_LOG_CORK("first part ");
+ AOS_LOG_CORK("second part (=%d) ", 19);
EXPECT_FALSE(WasAnythingLogged());
- LOG_CORK("third part ");
+ AOS_LOG_CORK("third part ");
static const int end_line = __LINE__;
- LOG_UNCORK(WARNING, "last part %d\n", 5);
+ AOS_LOG_UNCORK(WARNING, "last part %d\n", 5);
std::stringstream expected;
expected << "implementations_test.cc: ";
expected << (begin_line + 1);
@@ -142,27 +142,24 @@
}
TEST_F(LoggingDeathTest, Fatal) {
- ASSERT_EXIT(LOG(FATAL, "this should crash it\n"),
- ::testing::KilledBySignal(SIGABRT),
- "this should crash it");
+ ASSERT_EXIT(AOS_LOG(FATAL, "this should crash it\n"),
+ ::testing::KilledBySignal(SIGABRT), "this should crash it");
}
TEST_F(LoggingDeathTest, PCHECK) {
- EXPECT_DEATH(PCHECK(fprintf(stdin, "nope")),
+ EXPECT_DEATH(AOS_PCHECK(fprintf(stdin, "nope")),
".*fprintf\\(stdin, \"nope\"\\).*failed.*");
}
-TEST_F(LoggingTest, PCHECK) {
- EXPECT_EQ(7, PCHECK(printf("abc123\n")));
-}
+TEST_F(LoggingTest, PCHECK) { EXPECT_EQ(7, AOS_PCHECK(printf("abc123\n"))); }
TEST_F(LoggingTest, PrintfDirectives) {
- LOG(INFO, "test log %%1 %%d\n");
+ AOS_LOG(INFO, "test log %%1 %%d\n");
EXPECT_TRUE(WasLogged(INFO, "test log %1 %d\n"));
- LOG_DYNAMIC(WARNING, "test log %%2 %%f\n");
+ AOS_LOG_DYNAMIC(WARNING, "test log %%2 %%f\n");
EXPECT_TRUE(WasLogged(WARNING, "test log %2 %f\n"));
- LOG_CORK("log 3 part %%1 %%d ");
- LOG_UNCORK(DEBUG, "log 3 part %%2 %%f\n");
+ AOS_LOG_CORK("log 3 part %%1 %%d ");
+ AOS_LOG_UNCORK(DEBUG, "log 3 part %%2 %%f\n");
EXPECT_TRUE(WasLogged(DEBUG, "log 3 part %1 %d log 3 part %2 %f\n"));
}
@@ -173,7 +170,7 @@
monotonic_clock::time_point start = monotonic_clock::now();
for (long i = 0; i < kTimingCycles; ++i) {
- LOG(INFO, "a\n");
+ AOS_LOG(INFO, "a\n");
}
monotonic_clock::time_point end = monotonic_clock::now();
auto diff = end - start;
@@ -183,7 +180,7 @@
start = monotonic_clock::now();
for (long i = 0; i < kTimingCycles; ++i) {
- LOG(INFO, "something longer than just \"a\" to log to test timing\n");
+ AOS_LOG(INFO, "something longer than just \"a\" to log to test timing\n");
}
end = monotonic_clock::now();
diff = end - start;
diff --git a/aos/logging/interface.cc b/aos/logging/interface.cc
index fb3b60e..bcd8470 100644
--- a/aos/logging/interface.cc
+++ b/aos/logging/interface.cc
@@ -21,7 +21,7 @@
const int ret = vsnprintf(output, size, format, ap);
typedef ::std::common_type<typeof(ret), typeof(size)>::type RetType;
if (ret < 0) {
- PLOG(FATAL, "vsnprintf(%p, %zd, %s, args) failed",
+ AOS_PLOG(FATAL, "vsnprintf(%p, %zd, %s, args) failed",
output, size, format);
} else if (static_cast<RetType>(ret) >= static_cast<RetType>(size)) {
// Overwrite the '\0' at the end of the existing data and
@@ -84,8 +84,9 @@
context->cork_data.function = function;
} else {
if (strcmp(context->cork_data.function, function) != 0) {
- LOG(FATAL, "started corking data in function %s but then moved to %s\n",
- context->cork_data.function, function);
+ AOS_LOG(FATAL,
+ "started corking data in function %s but then moved to %s\n",
+ context->cork_data.function, function);
}
}
diff --git a/aos/logging/log_displayer.cc b/aos/logging/log_displayer.cc
index 0480b4b..e63bdc3 100644
--- a/aos/logging/log_displayer.cc
+++ b/aos/logging/log_displayer.cc
@@ -75,28 +75,28 @@
"possible arguments for the -n option cannot be shown. log_displayer\n"
"looks for start_list.txt in the current working directory and in\n"
"%s.\n\n", ::aos::configuration::GetRootDirectory());
- PLOG(FATAL, "Unable to open start_list.txt");
+ AOS_PLOG(FATAL, "Unable to open start_list.txt");
}
}
// Get file size.
if (fseek(start_list, 0, SEEK_END)) {
- PLOG(FATAL, "fseek() failed while reading start_list.txt");
+ AOS_PLOG(FATAL, "fseek() failed while reading start_list.txt");
}
int size = ftell(start_list);
if (size < 0) {
- PLOG(FATAL, "ftell() failed while reading start_list.txt");
+ AOS_PLOG(FATAL, "ftell() failed while reading start_list.txt");
}
rewind(start_list);
::std::unique_ptr<char[]> contents(new char[size + 1]);
if (contents == NULL) {
- LOG(FATAL, "malloc() failed while reading start_list.txt.\n");
+ AOS_LOG(FATAL, "malloc() failed while reading start_list.txt.\n");
}
size_t bytes_read = fread(contents.get(), 1, size, start_list);
if (bytes_read < static_cast<size_t>(size)) {
- LOG(FATAL, "Read %zu bytes from start_list.txt, expected %d.\n",
- bytes_read, size);
+ AOS_LOG(FATAL, "Read %zu bytes from start_list.txt, expected %d.\n",
+ bytes_read, size);
}
// printf doesn't like strings without the \0.
@@ -104,7 +104,7 @@
fprintf(stderr, "\nPossible arguments for the -n option:\n%s", contents.get());
if (fclose(start_list)) {
- LOG(FATAL, "fclose() failed.\n");
+ AOS_LOG(FATAL, "fclose() failed.\n");
}
exit(EXIT_SUCCESS);
@@ -249,7 +249,7 @@
::aos::logging::log_str(filter_level), filename);
if (fd == -1) {
- PLOG(FATAL, "couldn't open file '%s' for reading", filename);
+ AOS_PLOG(FATAL, "couldn't open file '%s' for reading", filename);
}
::aos::logging::linux_code::LogFileReader reader(fd);
@@ -272,16 +272,17 @@
::aos::MessageType *type = ::aos::MessageType::Deserialize(
reinterpret_cast<const char *>(msg + 1), &bytes);
if (type == nullptr) {
- LOG(INFO, "Trying old version of type decoding.\n");
+ AOS_LOG(INFO, "Trying old version of type decoding.\n");
bytes = msg->message_size;
type = ::aos::MessageType::Deserialize(
reinterpret_cast<const char *>(msg + 1), &bytes, false);
}
if (type == nullptr) {
- LOG(WARNING, "Error deserializing MessageType of size %" PRIx32
- " starting at %zx.\n",
- msg->message_size, reader.file_offset(msg + 1));
+ AOS_LOG(WARNING,
+ "Error deserializing MessageType of size %" PRIx32
+ " starting at %zx.\n",
+ msg->message_size, reader.file_offset(msg + 1));
} else {
::aos::type_cache::Add(*type);
}
@@ -357,14 +358,15 @@
(sizeof(type_id) + sizeof(uint32_t) + string_length);
if (!PrintMessage(buffer, &output_length, position + string_length,
&input_length, ::aos::type_cache::Get(type_id))) {
- LOG(FATAL, "printing message (%.*s) of type %s into %zu-byte buffer "
- "failed\n",
- static_cast<int>(string_length), position,
- ::aos::type_cache::Get(type_id).name.c_str(), sizeof(buffer));
+ AOS_LOG(FATAL,
+ "printing message (%.*s) of type %s into %zu-byte buffer "
+ "failed\n",
+ static_cast<int>(string_length), position,
+ ::aos::type_cache::Get(type_id).name.c_str(), sizeof(buffer));
}
if (input_length > 0) {
- LOG(WARNING, "%zu extra bytes on message of type %s\n",
- input_length, ::aos::type_cache::Get(type_id).name.c_str());
+ AOS_LOG(WARNING, "%zu extra bytes on message of type %s\n",
+ input_length, ::aos::type_cache::Get(type_id).name.c_str());
}
fprintf(stdout, AOS_LOGGING_BASE_FORMAT "%.*s: %.*s\n", BASE_ARGS,
static_cast<int>(string_length), position,
@@ -390,20 +392,21 @@
msg->message_size -
(sizeof(type) + sizeof(uint32_t) + sizeof(uint16_t) +
sizeof(uint16_t) + string_length);
- CHECK_EQ(matrix_bytes, ::aos::MessageType::Sizeof(type) * rows * cols);
+ AOS_CHECK_EQ(matrix_bytes,
+ ::aos::MessageType::Sizeof(type) * rows * cols);
char buffer[4096];
size_t output_length = sizeof(buffer);
if (!::aos::PrintMatrix(buffer, &output_length,
position + string_length, type, rows, cols)) {
- LOG(FATAL, "printing %dx%d matrix of type %" PRIu32 " failed\n", rows,
- cols, type);
+ AOS_LOG(FATAL, "printing %dx%d matrix of type %" PRIu32 " failed\n",
+ rows, cols, type);
}
fprintf(stdout, AOS_LOGGING_BASE_FORMAT "%.*s: %.*s\n", BASE_ARGS,
static_cast<int>(string_length), position,
static_cast<int>(sizeof(buffer) - output_length), buffer);
} break;
case LogFileMessageHeader::MessageType::kStructType:
- LOG(FATAL, "shouldn't get here\n");
+ AOS_LOG(FATAL, "shouldn't get here\n");
break;
}
#undef BASE_ARGS
diff --git a/aos/logging/logging.h b/aos/logging/logging.h
index 6682098..bd9b103 100644
--- a/aos/logging/logging.h
+++ b/aos/logging/logging.h
@@ -4,14 +4,14 @@
// This file contains the logging client interface. It works with both C and C++
// code.
-#include <stdio.h>
+#include <errno.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <errno.h>
-#include "aos/macros.h"
#include "aos/libc/aos_strerror.h"
+#include "aos/macros.h"
#ifdef __cplusplus
extern "C" {
@@ -19,16 +19,16 @@
typedef uint8_t log_level;
-#define DECL_LEVELS \
-DECL_LEVEL(DEBUG, 0); /* stuff that gets printed out every cycle */ \
-DECL_LEVEL(INFO, 1); /* things like PosEdge/NegEdge */ \
-/* things that might still work if they happen occasionally */ \
-DECL_LEVEL(WARNING, 2); \
-/*-1 so that vxworks macro of same name will have same effect if used*/ \
-DECL_LEVEL(ERROR, -1); /* errors */ \
-/* serious errors. the logging code will terminate the process/task */ \
-DECL_LEVEL(FATAL, 4); \
-DECL_LEVEL(LOG_UNKNOWN, 5); /* unknown logging level */
+#define DECL_LEVELS \
+ DECL_LEVEL(DEBUG, 0); /* stuff that gets printed out every cycle */ \
+ DECL_LEVEL(INFO, 1); /* things like PosEdge/NegEdge */ \
+ /* things that might still work if they happen occasionally */ \
+ DECL_LEVEL(WARNING, 2); \
+ /*-1 so that vxworks macro of same name will have same effect if used*/ \
+ DECL_LEVEL(ERROR, -1); /* errors */ \
+ /* serious errors. the logging code will terminate the process/task */ \
+ DECL_LEVEL(FATAL, 4); \
+ DECL_LEVEL(LOG_UNKNOWN, 5); /* unknown logging level */
#define DECL_LEVEL(name, value) static const log_level name = value;
DECL_LEVELS;
#undef DECL_LEVEL
@@ -40,14 +40,14 @@
// Actually implements the basic logging call.
// Does not check that level is valid.
void log_do(log_level level, const char *format, ...)
- __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 2, 3)));
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 2, 3)));
void log_cork(int line, const char *function, const char *format, ...)
- __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 4)));
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 4)));
// Implements the uncork logging call.
void log_uncork(int line, const char *function, log_level level,
const char *file, const char *format, ...)
- __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 5, 6)));
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 5, 6)));
#ifdef __cplusplus
}
@@ -64,7 +64,7 @@
#define LOG_SOURCENAME __FILE__
// The basic logging call.
-#define LOG(level, format, args...) \
+#define AOS_LOG(level, format, args...) \
do { \
log_do(level, LOG_SOURCENAME ": " STRINGIFY(__LINE__) ": %s: " format, \
LOG_CURRENT_FUNCTION, ##args); \
@@ -78,39 +78,39 @@
// Same as LOG except appends " due to %d (%s)\n" (formatted with errno and
// aos_strerror(errno)) to the message.
-#define PLOG(level, format, args...) PELOG(level, errno, format, ##args)
+#define AOS_PLOG(level, format, args...) AOS_PELOG(level, errno, format, ##args)
// Like PLOG except allows specifying an error other than errno.
-#define PELOG(level, error_in, format, args...) \
- do { \
- const int error = error_in; \
- LOG(level, format " due to %d (%s)\n", ##args, error, \
- aos_strerror(error)); \
+#define AOS_PELOG(level, error_in, format, args...) \
+ do { \
+ const int error = error_in; \
+ AOS_LOG(level, format " due to %d (%s)\n", ##args, error, \
+ aos_strerror(error)); \
} while (0);
// Allows format to not be a string constant.
-#define LOG_DYNAMIC(level, format, args...) \
- do { \
- static char log_buf[LOG_MESSAGE_LEN]; \
- int ret = snprintf(log_buf, sizeof(log_buf), format, ##args); \
- if (ret < 0 || (uintmax_t)ret >= LOG_MESSAGE_LEN) { \
- LOG(ERROR, "next message was too long so not subbing in args\n"); \
- LOG(level, "%s", format); \
- } else { \
- LOG(level, "%s", log_buf); \
- } \
+#define AOS_LOG_DYNAMIC(level, format, args...) \
+ do { \
+ static char log_buf[LOG_MESSAGE_LEN]; \
+ int ret = snprintf(log_buf, sizeof(log_buf), format, ##args); \
+ if (ret < 0 || (uintmax_t)ret >= LOG_MESSAGE_LEN) { \
+ AOS_LOG(ERROR, "next message was too long so not subbing in args\n"); \
+ AOS_LOG(level, "%s", format); \
+ } else { \
+ AOS_LOG(level, "%s", log_buf); \
+ } \
} while (0)
// Allows "bottling up" multiple log fragments which can then all be logged in
// one message with LOG_UNCORK.
// Calls from a given thread/task will be grouped together.
-#define LOG_CORK(format, args...) \
+#define AOS_LOG_CORK(format, args...) \
do { \
log_cork(__LINE__, LOG_CURRENT_FUNCTION, format, ##args); \
} while (0)
// Actually logs all of the saved up log fragments (including format and args on
// the end).
-#define LOG_UNCORK(level, format, args...) \
+#define AOS_LOG_UNCORK(level, format, args...) \
do { \
log_uncork(__LINE__, LOG_CURRENT_FUNCTION, level, LOG_SOURCENAME, format, \
##args); \
@@ -162,16 +162,16 @@
// controlled by NDEBUG, so the check will be executed regardless of
// compilation mode. Therefore, it is safe to do things like:
// CHECK(fp->Write(x) == 4)
-#define CHECK(condition) \
- if (__builtin_expect(!(condition), 0)) { \
- LOG(FATAL, "CHECK(%s) failed\n", #condition); \
+#define AOS_CHECK(condition) \
+ if (__builtin_expect(!(condition), 0)) { \
+ AOS_LOG(FATAL, "CHECK(%s) failed\n", #condition); \
}
// Helper functions for CHECK_OP macro.
// The (int, int) specialization works around the issue that the compiler
// will not instantiate the template version of the function on values of
// unnamed enum type.
-#define DEFINE_CHECK_OP_IMPL(name, op) \
+#define AOS_DEFINE_CHECK_OP_IMPL(name, op) \
template <typename T1, typename T2> \
inline void LogImpl##name(const T1 &v1, const T2 &v2, \
const char *exprtext) { \
@@ -192,47 +192,47 @@
// base/logging.h provides its own #defines for the simpler names EQ, NE, etc.
// This happens if, for example, those are used as token names in a
// yacc grammar.
-DEFINE_CHECK_OP_IMPL(Check_EQ, ==) // Compilation error with CHECK_EQ(NULL, x)?
-DEFINE_CHECK_OP_IMPL(Check_NE, !=) // Use CHECK(x == NULL) instead.
-DEFINE_CHECK_OP_IMPL(Check_LE, <=)
-DEFINE_CHECK_OP_IMPL(Check_LT, < )
-DEFINE_CHECK_OP_IMPL(Check_GE, >=)
-DEFINE_CHECK_OP_IMPL(Check_GT, > )
+AOS_DEFINE_CHECK_OP_IMPL(Check_EQ, ==) // Compilation error with CHECK_EQ(NULL, x)?
+AOS_DEFINE_CHECK_OP_IMPL(Check_NE, !=) // Use CHECK(x == NULL) instead.
+AOS_DEFINE_CHECK_OP_IMPL(Check_LE, <=)
+AOS_DEFINE_CHECK_OP_IMPL(Check_LT, <)
+AOS_DEFINE_CHECK_OP_IMPL(Check_GE, >=)
+AOS_DEFINE_CHECK_OP_IMPL(Check_GT, >)
-#define CHECK_OP(name, op, val1, val2) \
- ::aos::LogImplCheck##name(val1, val2, \
+#define AOS_CHECK_OP(name, op, val1, val2) \
+ ::aos::LogImplCheck##name(val1, val2, \
STRINGIFY(val1) STRINGIFY(op) STRINGIFY(val2))
-#define CHECK_EQ(val1, val2) CHECK_OP(_EQ, ==, val1, val2)
-#define CHECK_NE(val1, val2) CHECK_OP(_NE, !=, val1, val2)
-#define CHECK_LE(val1, val2) CHECK_OP(_LE, <=, val1, val2)
-#define CHECK_LT(val1, val2) CHECK_OP(_LT, < , val1, val2)
-#define CHECK_GE(val1, val2) CHECK_OP(_GE, >=, val1, val2)
-#define CHECK_GT(val1, val2) CHECK_OP(_GT, > , val1, val2)
+#define AOS_CHECK_EQ(val1, val2) AOS_CHECK_OP(_EQ, ==, val1, val2)
+#define AOS_CHECK_NE(val1, val2) AOS_CHECK_OP(_NE, !=, val1, val2)
+#define AOS_CHECK_LE(val1, val2) AOS_CHECK_OP(_LE, <=, val1, val2)
+#define AOS_CHECK_LT(val1, val2) AOS_CHECK_OP(_LT, <, val1, val2)
+#define AOS_CHECK_GE(val1, val2) AOS_CHECK_OP(_GE, >=, val1, val2)
+#define AOS_CHECK_GT(val1, val2) AOS_CHECK_OP(_GT, >, val1, val2)
// A small helper for CHECK_NOTNULL().
template <typename T>
-inline T* CheckNotNull(const char *value_name, T *t) {
+inline T *CheckNotNull(const char *value_name, T *t) {
if (t == NULL) {
- LOG(FATAL, "'%s' must not be NULL\n", value_name);
+ AOS_LOG(FATAL, "'%s' must not be NULL\n", value_name);
}
return t;
}
// Check that the input is non NULL. This very useful in constructor
// initializer lists.
-#define CHECK_NOTNULL(val) ::aos::CheckNotNull(STRINGIFY(val), val)
+#define AOS_CHECK_NOTNULL(val) ::aos::CheckNotNull(STRINGIFY(val), val)
inline int CheckSyscall(const char *syscall_string, int value) {
if (__builtin_expect(value == -1, false)) {
- PLOG(FATAL, "%s failed", syscall_string);
+ AOS_PLOG(FATAL, "%s failed", syscall_string);
}
return value;
}
inline void CheckSyscallReturn(const char *syscall_string, int value) {
if (__builtin_expect(value != 0, false)) {
- PELOG(FATAL, value, "%s failed", syscall_string);
+ AOS_PELOG(FATAL, value, "%s failed", syscall_string);
}
}
@@ -240,16 +240,17 @@
// useful for quickly checking syscalls where it's not very useful to print out
// the values of any of the arguments. Returns the result otherwise.
//
-// Example: const int fd = PCHECK(open("/tmp/whatever", O_WRONLY))
-#define PCHECK(syscall) ::aos::CheckSyscall(STRINGIFY(syscall), syscall)
+// Example: const int fd = AOS_PCHECK(open("/tmp/whatever", O_WRONLY))
+#define AOS_PCHECK(syscall) ::aos::CheckSyscall(STRINGIFY(syscall), syscall)
// PELOG(FATAL)s with the result of syscall if it returns anything other than 0.
// This is useful for quickly checking things like many of the pthreads
// functions where it's not very useful to print out the values of any of the
// arguments.
//
-// Example: PRCHECK(munmap(address, length))
-#define PRCHECK(syscall) ::aos::CheckSyscallReturn(STRINGIFY(syscall), syscall)
+// Example: AOS_PRCHECK(munmap(address, length))
+#define AOS_PRCHECK(syscall) \
+ ::aos::CheckSyscallReturn(STRINGIFY(syscall), syscall)
} // namespace aos
diff --git a/aos/logging/matrix_logging.h b/aos/logging/matrix_logging.h
index 630e85e..ef51d56 100644
--- a/aos/logging/matrix_logging.h
+++ b/aos/logging/matrix_logging.h
@@ -15,7 +15,7 @@
// Logs the contents of a matrix and a constant string.
// matrix must be an instance of an Eigen matrix (or something similar).
-#define LOG_MATRIX(level, message, matrix) \
+#define AOS_LOG_MATRIX(level, message, matrix) \
do { \
static const ::std::string kAosLoggingMessage( \
LOG_SOURCENAME ": " STRINGIFY(__LINE__) ": " message); \
diff --git a/aos/logging/queue_logging.h b/aos/logging/queue_logging.h
index a390412..fdebcc3 100644
--- a/aos/logging/queue_logging.h
+++ b/aos/logging/queue_logging.h
@@ -15,7 +15,7 @@
// Logs the contents of a structure (or Queue message) and a constant string.
// structure must be an instance of one of the generated queue types.
-#define LOG_STRUCT(level, message, structure) \
+#define AOS_LOG_STRUCT(level, message, structure) \
do { \
static const ::std::string kAosLoggingMessage( \
LOG_SOURCENAME ": " STRINGIFY(__LINE__) ": " message); \
diff --git a/aos/logging/replay.h b/aos/logging/replay.h
index 45a4cd2..6604591 100644
--- a/aos/logging/replay.h
+++ b/aos/logging/replay.h
@@ -57,11 +57,13 @@
void AddHandler(const ::std::string &process_name,
const ::std::string &log_message,
::std::function<void(const T &message)> handler) {
- CHECK(handlers_.emplace(
- ::std::piecewise_construct,
- ::std::forward_as_tuple(process_name, log_message),
- ::std::forward_as_tuple(::std::unique_ptr<StructHandlerInterface>(
- new TypedStructHandler<T>(handler)))).second);
+ AOS_CHECK(handlers_
+ .emplace(::std::piecewise_construct,
+ ::std::forward_as_tuple(process_name, log_message),
+ ::std::forward_as_tuple(
+ ::std::unique_ptr<StructHandlerInterface>(
+ new TypedStructHandler<T>(handler))))
+ .second);
}
// Adds a handler which takes messages and places them directly on a queue.
@@ -98,10 +100,11 @@
void HandleStruct(::aos::monotonic_clock::time_point log_time,
uint32_t type_id, const void *data,
size_t data_size) override {
- CHECK_EQ(type_id, T::GetType()->id);
+ AOS_CHECK_EQ(type_id, T::GetType()->id);
T message;
- CHECK_EQ(data_size, T::Size());
- CHECK_EQ(data_size, message.Deserialize(static_cast<const char *>(data)));
+ AOS_CHECK_EQ(data_size, T::Size());
+ AOS_CHECK_EQ(data_size,
+ message.Deserialize(static_cast<const char *>(data)));
message.sent_time = log_time;
handler_(message);
}
@@ -119,11 +122,11 @@
T::kQueueLength)) {}
void operator()(const T &message) {
- LOG_STRUCT(DEBUG, "re-sending", message);
+ AOS_LOG_STRUCT(DEBUG, "re-sending", message);
void *raw_message = queue_->GetMessage();
- CHECK_NOTNULL(raw_message);
+ AOS_CHECK_NOTNULL(raw_message);
memcpy(raw_message, &message, sizeof(message));
- CHECK(queue_->WriteMessage(raw_message, RawQueue::kOverride));
+ AOS_CHECK(queue_->WriteMessage(raw_message, RawQueue::kOverride));
}
private: