logger: remove _enabled attribute and add LogWriter::is_started() instead

This commit is contained in:
Beat Küng
2016-10-07 14:48:03 +02:00
committed by Lorenz Meier
parent c26e29d11c
commit 4e1a4440ca
3 changed files with 11 additions and 8 deletions
+5
View File
@@ -65,6 +65,11 @@ public:
void stop_log(); void stop_log();
/**
* whether logging is currently active or not.
*/
bool is_started() const { return _should_run; }
/** /**
* Write data to be logged. The caller must call lock() before calling this. * Write data to be logged. The caller must call lock() before calling this.
* @param dropout_start timestamp when lastest dropout occured. 0 if no dropout at the moment. * @param dropout_start timestamp when lastest dropout occured. 0 if no dropout at the moment.
+6 -7
View File
@@ -215,7 +215,7 @@ int Logger::start(char *const *argv)
void Logger::status() void Logger::status()
{ {
if (!_enabled) { if (!_writer.is_started()) {
PX4_INFO("Running, but not logging"); PX4_INFO("Running, but not logging");
} else { } else {
@@ -225,7 +225,7 @@ void Logger::status()
} }
void Logger::print_statistics() void Logger::print_statistics()
{ {
if (!_enabled) { if (!_writer.is_started()) {
return; return;
} }
@@ -637,6 +637,7 @@ void Logger::run()
PX4_ERR("init of writer failed (alloc failed)"); PX4_ERR("init of writer failed (alloc failed)");
return; return;
} }
pthread_t writer_thread; pthread_t writer_thread;
int ret = _writer.thread_start(writer_thread); int ret = _writer.thread_start(writer_thread);
@@ -693,7 +694,7 @@ void Logger::run()
} }
} }
if (_enabled) { if (_writer.is_started()) {
bool data_written = false; bool data_written = false;
@@ -1048,7 +1049,7 @@ bool Logger::get_log_time(struct tm *tt, bool boot_time)
void Logger::start_log() void Logger::start_log()
{ {
if (_enabled) { if (_writer.is_started()) {
return; return;
} }
@@ -1072,17 +1073,15 @@ void Logger::start_log()
write_parameters(); write_parameters();
write_all_add_logged_msg(); write_all_add_logged_msg();
_writer.notify(); _writer.notify();
_enabled = true;
_start_time = hrt_absolute_time(); _start_time = hrt_absolute_time();
} }
void Logger::stop_log() void Logger::stop_log()
{ {
if (!_enabled) { if (!_writer.is_started()) {
return; return;
} }
_enabled = false;
_writer.stop_log(); _writer.stop_log();
} }
-1
View File
@@ -219,7 +219,6 @@ private:
char _log_dir[LOG_DIR_LEN]; char _log_dir[LOG_DIR_LEN];
char _log_file_name[32]; char _log_file_name[32];
bool _has_log_dir = false; bool _has_log_dir = false;
bool _enabled = false;
bool _was_armed = false; bool _was_armed = false;
bool _arm_override; bool _arm_override;