lots of formatting/naming fixes and changed Context::name to std::string
diff --git a/aos/atom_code/core/BinaryLogReader.cpp b/aos/atom_code/core/BinaryLogReader.cpp
index 7027d21..e266f24 100644
--- a/aos/atom_code/core/BinaryLogReader.cpp
+++ b/aos/atom_code/core/BinaryLogReader.cpp
@@ -21,7 +21,7 @@
namespace atom {
namespace {
-int binary_log_reader_main() {
+int BinaryLogReaderMain() {
InitNRT();
const char *folder = configuration::GetLoggingDirectory();
@@ -112,5 +112,5 @@
} // namespace aos
int main() {
- return aos::logging::atom::binary_log_reader_main();
+ return ::aos::logging::atom::BinaryLogReaderMain();
}
diff --git a/aos/atom_code/core/CRIOLogReader.cpp b/aos/atom_code/core/CRIOLogReader.cpp
index 2aa216c..73a5350 100644
--- a/aos/atom_code/core/CRIOLogReader.cpp
+++ b/aos/atom_code/core/CRIOLogReader.cpp
@@ -55,7 +55,7 @@
}
};
-int crio_log_reader_main() {
+int CRIOLogReaderMain() {
InitNRT();
const int sock = socket(AF_INET, SOCK_STREAM, 0);
@@ -150,5 +150,5 @@
} // namespace aos
int main() {
- return aos::logging::atom::crio_log_reader_main();
+ return ::aos::logging::atom::CRIOLogReaderMain();
}
diff --git a/aos/atom_code/core/LogDisplayer.cpp b/aos/atom_code/core/LogDisplayer.cpp
index 8f15535..d106119 100644
--- a/aos/atom_code/core/LogDisplayer.cpp
+++ b/aos/atom_code/core/LogDisplayer.cpp
@@ -83,7 +83,7 @@
filter_name = optarg;
break;
case 'l':
- filter_level = aos::logging::str_log(optarg);
+ filter_level = ::aos::logging::str_log(optarg);
if (filter_level == LOG_UNKNOWN) {
fprintf(stderr, "LogDisplayer: unknown log level '%s'\n", optarg);
exit(EXIT_FAILURE);
@@ -117,13 +117,14 @@
case '?':
break;
default:
- fprintf(stderr, "LogDisplayer: in a bad spot (%s: %d)\n", __FILE__, __LINE__);
+ fprintf(stderr, "LogDisplayer: in a bad spot (%s: %d)\n",
+ __FILE__, __LINE__);
abort();
}
}
fprintf(stderr, "displaying down to level %s from file '%s'\n",
- aos::logging::log_str(filter_level), filename);
+ ::aos::logging::log_str(filter_level), filename);
if (optind < argc) {
fprintf(stderr, "non-option ARGV-elements: ");
while (optind < argc) {
@@ -137,18 +138,19 @@
filename, strerror(errno));
exit(EXIT_FAILURE);
}
- aos::logging::LogFileAccessor accessor(fd, false);
+ ::aos::logging::LogFileAccessor accessor(fd, false);
if (!start_at_beginning) {
accessor.MoveToEnd();
}
- const aos::logging::LogFileMessageHeader *msg;
- aos::logging::LogMessage log_message;
+ const ::aos::logging::LogFileMessageHeader *msg;
+ ::aos::logging::LogMessage log_message;
do {
msg = accessor.ReadNextMessage(follow);
if (msg == NULL) continue;
- if (aos::logging::log_gt_important(filter_level, msg->level)) continue;
+ if (::aos::logging::log_gt_important(filter_level, msg->level)) continue;
if (filter_name != NULL &&
- strcmp(filter_name, reinterpret_cast<const char *>(msg) + sizeof(*msg)) != 0) {
+ strcmp(filter_name,
+ reinterpret_cast<const char *>(msg) + sizeof(*msg)) != 0) {
continue;
}
@@ -164,6 +166,6 @@
reinterpret_cast<const char *>(msg) + sizeof(*msg) +
msg->name_size,
sizeof(log_message.message));
- aos::logging::internal::PrintMessage(stdout, log_message);
+ ::aos::logging::internal::PrintMessage(stdout, log_message);
} while (msg != NULL);
}
diff --git a/aos/atom_code/core/LogStreamer.cpp b/aos/atom_code/core/LogStreamer.cpp
index ffecac8..a7151ad 100644
--- a/aos/atom_code/core/LogStreamer.cpp
+++ b/aos/atom_code/core/LogStreamer.cpp
@@ -15,18 +15,19 @@
#include "aos/atom_code/init.h"
#include "aos/atom_code/ipc_lib/queue.h"
#include "aos/common/logging/logging_impl.h"
+#include "aos/common/time.h"
namespace aos {
namespace logging {
namespace atom {
namespace {
-int log_streamer_main() {
+int LogStreamerMain() {
InitNRT();
- const time_t t = time(NULL);
- printf("starting at %jd----------------------------------\n",
- static_cast<uintmax_t>(t));
+ const time::Time now = time::Time::Now();
+ printf("starting at %"PRId32"s%"PRId32"ns---------------------------------\n",
+ now.sec(), now.nsec());
int index = 0;
while (true) {
@@ -48,5 +49,5 @@
} // namespace aos
int main() {
- return aos::logging::atom::log_streamer_main();
+ return ::aos::logging::atom::LogStreamerMain();
}
diff --git a/aos/atom_code/core/core.gyp b/aos/atom_code/core/core.gyp
index 4e13e51..3b327da 100644
--- a/aos/atom_code/core/core.gyp
+++ b/aos/atom_code/core/core.gyp
@@ -31,6 +31,7 @@
'dependencies': [
'<(AOS)/build/aos.gyp:logging',
'<(AOS)/atom_code/atom_code.gyp:init',
+ '<(AOS)/common/common.gyp:time',
],
},
{
diff --git a/aos/atom_code/logging/atom_logging.cc b/aos/atom_code/logging/atom_logging.cc
index c9b1195..08a65cb 100644
--- a/aos/atom_code/logging/atom_logging.cc
+++ b/aos/atom_code/logging/atom_logging.cc
@@ -25,13 +25,13 @@
AOS_THREAD_LOCAL Context *my_context(NULL);
-std::string GetMyName() {
+::std::string GetMyName() {
// The maximum number of characters that can make up a thread name.
// The docs are unclear if it can be 16 characters with no '\0', so we'll be
// safe by adding our own where necessary.
static const size_t kThreadNameLength = 16;
- std::string process_name(program_invocation_short_name);
+ ::std::string process_name(program_invocation_short_name);
char thread_name_array[kThreadNameLength + 1];
if (prctl(PR_GET_NAME, thread_name_array) != 0) {
@@ -39,13 +39,13 @@
thread_name_array, errno, strerror(errno));
}
thread_name_array[sizeof(thread_name_array) - 1] = '\0';
- std::string thread_name(thread_name_array);
+ ::std::string thread_name(thread_name_array);
// If the first bunch of characters are the same.
// We cut off comparing at the shorter of the 2 strings because one or the
// other often ends up cut off.
if (strncmp(thread_name.c_str(), process_name.c_str(),
- std::min(thread_name.length(), process_name.length())) == 0) {
+ ::std::min(thread_name.length(), process_name.length())) == 0) {
// This thread doesn't have an actual name.
return process_name;
}
@@ -53,7 +53,7 @@
return process_name + '.' + thread_name;
}
-static const aos_type_sig message_sig = {sizeof(LogMessage), 1234, 1500};
+static const aos_type_sig message_sig = {sizeof(LogMessage), 1323, 1500};
static aos_queue *queue;
} // namespace
@@ -62,12 +62,11 @@
Context *Context::Get() {
if (my_context == NULL) {
my_context = new Context();
- std::string name = GetMyName();
- char *name_chars = new char[name.size() + 1];
- my_context->name_size = std::min(name.size() + 1, sizeof(LogMessage::name));
- memcpy(name_chars, name.c_str(), my_context->name_size);
- name_chars[my_context->name_size - 1] = '\0';
- my_context->name = name_chars;
+ my_context->name = GetMyName();
+ if (my_context->name.size() + 1 > sizeof(LogMessage::name)) {
+ Die("logging: process/thread name '%s' is too long\n",
+ my_context->name.c_str());
+ }
my_context->source = getpid();
}
return my_context;
@@ -82,7 +81,7 @@
namespace atom {
namespace {
-class AtomLogImplementation : public LogImplementation {
+class AtomQueueLogImplementation : public LogImplementation {
virtual void DoLog(log_level level, const char *format, va_list ap) {
LogMessage *message = static_cast<LogMessage *>(aos_queue_get_msg(queue));
if (message == NULL) {
@@ -105,7 +104,7 @@
Die("logging: couldn't fetch queue\n");
}
- AddImplementation(new AtomLogImplementation());
+ AddImplementation(new AtomQueueLogImplementation());
}
const LogMessage *ReadNext(int flags, int *index) {
diff --git a/aos/common/logging/logging_impl.cc b/aos/common/logging/logging_impl.cc
index 7b49f7b..64696dc 100644
--- a/aos/common/logging/logging_impl.cc
+++ b/aos/common/logging/logging_impl.cc
@@ -101,7 +101,7 @@
message->level = level;
message->source = context->source;
- memcpy(message->name, context->name, context->name_size);
+ memcpy(message->name, context->name.c_str(), context->name.size() + 1);
time::Time now = time::Time::Now();
message->seconds = now.sec();
diff --git a/aos/common/logging/logging_impl.h b/aos/common/logging/logging_impl.h
index 28ffd99..1416fe1 100644
--- a/aos/common/logging/logging_impl.h
+++ b/aos/common/logging/logging_impl.h
@@ -161,11 +161,9 @@
// Will be NULL if there is no logging implementation to use right now.
LogImplementation *implementation;
- // A string representing this task/(process and thread).
- const char *name;
- // The number of bytes in name (including the terminating '\0').
- // Must be <= sizeof(LogMessage::name).
- size_t name_size;
+ // A name representing this task/(process and thread).
+ // strlen(name.c_str()) must be <= sizeof(LogMessage::name).
+ ::std::string name;
// What to assign LogMessage::source to in this task/thread.
pid_t source;
diff --git a/aos/common/logging/logging_impl_test.cc b/aos/common/logging/logging_impl_test.cc
index bc411ce..f64f3d6 100644
--- a/aos/common/logging/logging_impl_test.cc
+++ b/aos/common/logging/logging_impl_test.cc
@@ -57,9 +57,10 @@
static_cast<uint32_t>(log_implementation->message().source),
static_cast<uint32_t>(context->source));
}
- if (strcmp(log_implementation->message().name, context->name) != 0) {
+ if (strcmp(log_implementation->message().name,
+ context->name.c_str()) != 0) {
Die("got a message from %s, but we're %s\n",
- log_implementation->message().name, context->name);
+ log_implementation->message().name, context->name.c_str());
}
if (strstr(log_implementation->message().message, message.c_str())
== NULL) {
diff --git a/aos/crio/logging/crio_logging.cc b/aos/crio/logging/crio_logging.cc
index af55e88..2d643c3 100644
--- a/aos/crio/logging/crio_logging.cc
+++ b/aos/crio/logging/crio_logging.cc
@@ -120,22 +120,16 @@
holder = new ContextHolder();
errno = 0; // in case taskName decides not to set it
- // We're going to make a copy of it because vxworks might allocate the
- // memory for it from some funky place or something.
const char *my_name = taskName(0);
if (my_name == NULL) {
Die("logging: taskName(0) failed with %d: %s\n",
errno, strerror(errno));
}
- holder->context.name_size = strlen(my_name);
- if (holder->context.name_size > sizeof(LogMessage::name)) {
+ holder->context.name = std::string(my_name);
+ if (holder->context.name.size() + 1 > sizeof(LogMessage::name)) {
Die("logging: somebody chose a task name ('%s') that's too long\n",
my_name);
}
- char *name_chars = new char[holder->context.name_size];
- memcpy(name_chars, my_name, holder->context.name_size);
- name_chars[holder->context.name_size - 1] = '\0';
- holder->context.name = name_chars;
holder->context.source = taskIdSelf();
}