24 #include "bblogreplay_plugin.h" 25 #include "logreplay_thread.h" 26 #include "logreplay_bt_thread.h" 28 #include <utils/time/time.h> 35 #include <sys/types.h> 55 std::set<std::string> logs;
57 std::string prefix =
"/fawkes/bblogreplay/";
59 std::string scenario =
"";
61 scenario = config->
get_string((prefix +
"scenario").c_str());
63 e.
append(
"No scenario defined, configure %sscenario", prefix.c_str());
67 std::string scenario_prefix = prefix + scenario +
"/";
68 std::string logs_prefix = scenario_prefix +
"logs/";
70 std::string logdir = LOGDIR;
72 logdir = config->
get_string((scenario_prefix +
"logdir").c_str());
75 int err = stat(logdir.c_str(), &s);
78 Exception se (
"Cannot access logdir %s (%s)",
79 logdir.c_str(), strerror_r(errno, buf, 1024));
80 }
else if ( ! S_ISDIR(s.st_mode) ) {
81 throw Exception(
"Logdir path %s is not a directory", logdir.c_str());
84 bool scenario_loop_replay =
false;
85 bool scenario_non_blocking =
false;
86 float scenario_grace_period = 0.001;
88 scenario_loop_replay = config->
get_bool((prefix +
"loop").c_str());
91 scenario_loop_replay = config->
get_bool((scenario_prefix +
"loop").c_str());
94 scenario_non_blocking = config->
get_bool((prefix +
"non_blocking").c_str());
97 scenario_non_blocking = config->
get_bool((scenario_prefix +
"non_blocking").c_str());
100 scenario_grace_period = config->
get_float((prefix +
"grace_period").c_str());
103 scenario_grace_period = config->
get_float((scenario_prefix +
"grace_period").c_str());
106 #if __cplusplus >= 201103L 107 std::unique_ptr<Configuration::ValueIterator> i(config->
search(logs_prefix.c_str()));
109 std::auto_ptr<Configuration::ValueIterator> i(config->
search(logs_prefix.c_str()));
112 std::string log_name = std::string(i->
path()).substr(logs_prefix.length());
113 log_name = log_name.substr(0, log_name.find(
"/"));
115 if ( logs.find(log_name) == logs.end() ) {
116 std::string log_prefix = logs_prefix + log_name +
"/";
118 printf(
"Log name: %s log_prefix: %s\n", log_name.c_str(), log_prefix.c_str());
120 std::string log_file =
"";
121 bool loop_replay = scenario_loop_replay;
122 bool non_blocking = scenario_non_blocking;
123 float grace_period = scenario_grace_period;
124 std::string hook_str =
"";
127 log_file = config->
get_string((log_prefix +
"file").c_str());
133 loop_replay = config->
get_bool((log_prefix +
"loop").c_str());
136 non_blocking = config->
get_bool((log_prefix +
"non_blocking").c_str());
139 hook_str = config->
get_string((log_prefix +
"hook").c_str());
142 grace_period = config->
get_float((log_prefix +
"grace_period").c_str());
146 if (hook_str !=
"") {
148 hook = BlockedTimingAspect::WAKEUP_HOOK_PRE_LOOP;
150 if (hook_str ==
"pre_loop") {
151 hook = BlockedTimingAspect::WAKEUP_HOOK_PRE_LOOP;
152 }
else if (hook_str ==
"sensor_acquire") {
153 hook = BlockedTimingAspect::WAKEUP_HOOK_SENSOR_ACQUIRE;
154 }
else if (hook_str ==
"sensor_prepare") {
155 hook = BlockedTimingAspect::WAKEUP_HOOK_SENSOR_PREPARE;
156 }
else if (hook_str ==
"sensor_process") {
157 hook = BlockedTimingAspect::WAKEUP_HOOK_SENSOR_PROCESS;
158 }
else if (hook_str ==
"worldstate") {
159 hook = BlockedTimingAspect::WAKEUP_HOOK_WORLDSTATE;
160 }
else if (hook_str ==
"think") {
161 hook = BlockedTimingAspect::WAKEUP_HOOK_THINK;
162 }
else if (hook_str ==
"skill") {
163 hook = BlockedTimingAspect::WAKEUP_HOOK_SKILL;
164 }
else if (hook_str ==
"act") {
165 hook = BlockedTimingAspect::WAKEUP_HOOK_ACT;
166 }
else if (hook_str ==
"act_exec") {
167 hook = BlockedTimingAspect::WAKEUP_HOOK_ACT_EXEC;
168 }
else if (hook_str ==
"post_loop") {
169 hook = BlockedTimingAspect::WAKEUP_HOOK_POST_LOOP;
171 throw Exception(
"Invalid hook '%s' for %s",
193 logs.insert(log_name);
198 throw Exception(
"No interfaces configured for log replay, aborting");
202 PLUGIN_DESCRIPTION(
"Replay BlackBoard log files")
BlackBoardLogReplayPlugin(fawkes::Configuration *config)
Constructor.
Fawkes library namespace.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
BlackBoard log replay blocked timing thread.
BlackBoard log replay plugin.
virtual ValueIterator * search(const char *path)=0
Iterator with search results.
virtual bool next()=0
Check if there is another element and advance to this if possible.
WakeupHook
Type to define at which hook the thread is woken up.
Base class for exceptions in Fawkes.
ThreadList thread_list
Thread list member.
virtual std::string get_string() const =0
Get string value.
virtual const char * path() const =0
Path of value.
void push_back(Thread *thread)
Add thread to the end.
Interface for configuration handling.
virtual float get_float(const char *path)=0
Get value from configuration which is of type float.
void append(const char *format,...)
Append messages to the message list.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
BlackBoard log Replay thread.