diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-03-21 04:51:48 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-03-21 04:51:48 +0100 |
commit | a78a01eaccf4fcbdf34aa994254d7e536040f906 (patch) | |
tree | c9ad194010fef26dd530e025db254001eb54a40a /mmss/context.cpp | |
parent | aaddd2e7cde6d23c26573d7da0ab10398037a954 (diff) | |
download | gmrf-a78a01eaccf4fcbdf34aa994254d7e536040f906.tar gmrf-a78a01eaccf4fcbdf34aa994254d7e536040f906.zip |
Add monitors
Monitors are used to log events from the simulated nodes. So far there are a log
monitor which just logs the nodes' log messages and a SQLite monitor which does
nothing at the moment.
Diffstat (limited to 'mmss/context.cpp')
-rw-r--r-- | mmss/context.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/mmss/context.cpp b/mmss/context.cpp index dd24ae8..4cf5011 100644 --- a/mmss/context.cpp +++ b/mmss/context.cpp @@ -29,6 +29,9 @@ #include "network.hpp" #include "node.hpp" +#include "monitor_log.hpp" +#include "monitor_sqlite.hpp" + #include <algorithm> #include <cassert> #include <cstdio> @@ -65,25 +68,18 @@ static inline const char* get_log_prefix(int log_level) { } -void context_t::vlogf_orig(const node_t *orig, int priority, const char *format, std::va_list ap) { +void context_t::logf(int priority, const char *format, ...) { char buf[1024]; size_t pos; - if (orig) - pos = snprintf_safe(buf, sizeof(buf), "[% 6u.%03u] %s: %s", now()/1000, now()%1000, orig->get_name().c_str(), get_log_prefix(priority)); - else - pos = snprintf_safe(buf, sizeof(buf), "[% 6u.%03u] %s", now()/1000, now()%1000, get_log_prefix(priority)); - - std::vsnprintf(buf+pos, sizeof(buf)-pos, format, ap); - - std::fprintf(stderr, "%s\n", buf); -} + pos = snprintf_safe(buf, sizeof(buf), "[% 6u.%03u] %s", now()/1000, now()%1000, get_log_prefix(priority)); -void context_t::logf(int priority, const char *format, ...) { std::va_list ap; va_start(ap, format); - vlogf_orig(nullptr, priority, format, ap); + std::vsnprintf(buf+pos, sizeof(buf)-pos, format, ap); va_end(ap); + + std::fprintf(stderr, "%s\n", buf); } void context_t::run(int argc, char *argv[]) { @@ -93,6 +89,9 @@ void context_t::run(int argc, char *argv[]) { } + attach_monitor(std::make_shared<monitor_log_t>()); + attach_monitor(std::make_shared<monitor_sqlite_t>()); + std::shared_ptr<const config_t> conf = config_t::read(this, argv[1]); if (!conf) |