Add CaptureThread success_callback.

This commit is contained in:
Jared Boone 2016-06-21 11:53:07 -07:00
parent 4ffb05212e
commit 81d4e59aeb
4 changed files with 13 additions and 1 deletions

View File

@ -78,9 +78,11 @@ CaptureThread::CaptureThread(
std::unique_ptr<Writer> writer,
size_t write_size,
size_t buffer_count,
std::function<void()> success_callback,
std::function<void(File::Error)> error_callback
) : config { write_size, buffer_count },
writer { std::move(writer) },
success_callback { std::move(success_callback) },
error_callback { std::move(error_callback) }
{
// Need significant stack for FATFS

View File

@ -45,6 +45,7 @@ public:
std::unique_ptr<Writer> writer,
size_t write_size,
size_t buffer_count,
std::function<void()> success_callback,
std::function<void(File::Error)> error_callback
);
~CaptureThread();
@ -60,6 +61,7 @@ private:
CaptureConfig config;
std::unique_ptr<Writer> writer;
std::function<void()> success_callback;
std::function<void(File::Error)> error_callback;
static Thread* thread;
@ -68,6 +70,10 @@ private:
const auto error = obj->run();
if( error.is_valid() && obj->error_callback ) {
obj->error_callback(error.value());
} else {
if( obj->success_callback ) {
obj->success_callback();
}
}
return 0;
}

View File

@ -285,6 +285,10 @@ void RecordView::start() {
capture_thread = std::make_unique<CaptureThread>(
std::move(writer),
write_size, buffer_count,
[]() {
CaptureThreadErrorMessage message { };
EventDispatcher::send_message(message);
},
[](File::Error error) {
CaptureThreadErrorMessage message { error.code() };
EventDispatcher::send_message(message);

View File

@ -498,7 +498,7 @@ public:
class CaptureThreadErrorMessage : public Message {
public:
constexpr CaptureThreadErrorMessage(
uint32_t error
uint32_t error = 0
) : Message { ID::CaptureThreadError },
error { error }
{