Send CaptureThread error into app-local message queue.

This commit is contained in:
Jared Boone 2016-06-21 11:04:10 -07:00
parent 76c5fe96af
commit cfaa44b02a
5 changed files with 42 additions and 17 deletions

View File

@ -77,9 +77,11 @@ Thread* CaptureThread::thread = nullptr;
CaptureThread::CaptureThread(
std::unique_ptr<Writer> writer,
size_t write_size,
size_t buffer_count
size_t buffer_count,
std::function<void(File::Error)>&& error_callback
) : config { write_size, buffer_count },
writer { std::move(writer) }
writer { std::move(writer) },
error_callback { std::move(error_callback) }
{
// Need significant stack for FATFS
thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, CaptureThread::static_fn, this);
@ -94,10 +96,6 @@ CaptureThread::~CaptureThread() {
}
}
const Optional<File::Error>& CaptureThread::error() const {
return last_error;
}
void CaptureThread::check_fifo_isr() {
// TODO: Prevent over-signalling by transmitting a set of
// flags from the baseband core.

View File

@ -44,7 +44,8 @@ public:
CaptureThread(
std::unique_ptr<Writer> writer,
size_t write_size,
size_t buffer_count
size_t buffer_count,
std::function<void(File::Error)>&& error_callback
);
~CaptureThread();
@ -52,8 +53,6 @@ public:
return config;
}
const Optional<File::Error>& error() const;
static void check_fifo_isr();
private:
@ -61,12 +60,15 @@ private:
CaptureConfig config;
std::unique_ptr<Writer> writer;
Optional<File::Error> last_error;
std::function<void(File::Error)> error_callback;
static Thread* thread;
static msg_t static_fn(void* arg) {
auto obj = static_cast<CaptureThread*>(arg);
obj->last_error = obj->run();
const auto error = obj->run();
if( error.is_valid() && obj->error_callback ) {
obj->error_callback(error.value());
}
return 0;
}

View File

@ -269,7 +269,11 @@ void RecordView::start() {
button_record.set_bitmap(&bitmap_stop);
capture_thread = std::make_unique<CaptureThread>(
std::move(writer),
write_size, buffer_count
write_size, buffer_count,
[](File::Error error) {
CaptureThreadErrorMessage message { error.code() };
EventDispatcher::send_message(message);
}
);
}
}
@ -301,11 +305,6 @@ Optional<File::Error> RecordView::write_metadata_file(const std::string& filenam
void RecordView::on_tick_second() {
if( is_active() ) {
const auto error = capture_thread->error();
if( error.is_valid() ) {
stop();
report_error(error.value().what());
}
const auto dropped_percent = std::min(99U, capture_thread->state().dropped_percent());
const auto s = to_string_dec_uint(dropped_percent, 2, ' ') + "\%";
text_record_dropped.set(s);
@ -328,6 +327,7 @@ void RecordView::on_tick_second() {
}
void RecordView::report_error(const std::string& message) {
stop();
if( on_error ) {
on_error(message);
}

View File

@ -115,6 +115,18 @@ private:
};
std::unique_ptr<CaptureThread> capture_thread;
MessageHandlerRegistration message_handler_capture_thread_error {
Message::ID::CaptureThreadError,
[this](const Message* const p) {
const auto message = *reinterpret_cast<const CaptureThreadErrorMessage*>(p);
this->on_capture_thread_error(message.error);
}
};
void on_capture_thread_error(File::Error error) {
report_error(error.what());
}
};
} /* namespace ui */

View File

@ -64,6 +64,7 @@ public:
SpectrumStreamingConfig = 15,
DisplaySleep = 16,
CaptureConfig = 17,
CaptureThreadError = 18,
MAX
};
@ -494,4 +495,16 @@ public:
CaptureConfig* const config;
};
class CaptureThreadErrorMessage : public Message {
public:
constexpr CaptureThreadErrorMessage(
uint32_t error
) : Message { ID::CaptureThreadError },
error { error }
{
}
uint32_t error;
};
#endif/*__MESSAGE_H__*/