Skip to content

Commit 8fcb333

Browse files
committed
AP_Logger: tidy running of LoggerMessageWriter sub-writers
... use the fact these all have a common base class to reduce effectively duplicate code. Also un-virtualise and const a function which wasn't overridden and can be const
1 parent 247f5e5 commit 8fcb333

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

libraries/AP_Logger/LoggerMessageWriter.cpp

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -177,40 +177,30 @@ void LoggerMessageWriter_DFLogStart::process()
177177
stage = Stage::RUNNING_SUBWRITERS;
178178
FALLTHROUGH;
179179

180-
case Stage::RUNNING_SUBWRITERS:
181-
if (!_writesysinfo.finished()) {
182-
_writesysinfo.process();
183-
if (!_writesysinfo.finished()) {
184-
return;
185-
}
186-
}
180+
case Stage::RUNNING_SUBWRITERS: {
181+
LoggerMessageWriter *subwriters[] {
182+
&_writesysinfo,
187183
#if AP_MISSION_ENABLED
188-
if (!_writeentiremission.finished()) {
189-
_writeentiremission.process();
190-
if (!_writeentiremission.finished()) {
191-
return;
192-
}
193-
}
184+
&_writeentiremission,
194185
#endif
195186
#if HAL_LOGGER_RALLY_ENABLED
196-
if (!_writeallrallypoints.finished()) {
197-
_writeallrallypoints.process();
198-
if (!_writeallrallypoints.finished()) {
199-
return;
200-
}
201-
}
187+
&_writeallrallypoints,
202188
#endif
203189
#if HAL_LOGGER_FENCE_ENABLED
204-
if (!_writeallpolyfence.finished()) {
205-
_writeallpolyfence.process();
206-
if (!_writeallpolyfence.finished()) {
207-
return;
190+
&_writeallpolyfence,
191+
#endif
192+
};
193+
for (auto *sw : subwriters) {
194+
if (!sw->finished()) {
195+
sw->process();
196+
if (!sw->finished()) {
197+
return;
198+
}
208199
}
209200
}
210-
#endif
211201
stage = Stage::VEHICLE_MESSAGES;
212202
FALLTHROUGH;
213-
203+
}
214204
case Stage::VEHICLE_MESSAGES:
215205
// we guarantee 200 bytes of space for the vehicle startup
216206
// messages. This allows them to be simple functions rather

libraries/AP_Logger/LoggerMessageWriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class LoggerMessageWriter {
88

99
virtual void reset() = 0;
1010
virtual void process() = 0;
11-
virtual bool finished() { return _finished; }
11+
bool finished() const { return _finished; }
1212

1313
virtual void set_logger_backend(class AP_Logger_Backend *backend) {
1414
_logger_backend = backend;

0 commit comments

Comments
 (0)