From 6479678a82a7d57b83d84f3ce92a36c058f5ef73 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 16 Jun 2018 10:08:13 -1000 Subject: [PATCH] Add public waitForCompletion method --- include/kabufuda/Card.hpp | 5 +++++ lib/kabufuda/Card.cpp | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/kabufuda/Card.hpp b/include/kabufuda/Card.hpp index cb10079..c88714d 100644 --- a/include/kabufuda/Card.hpp +++ b/include/kabufuda/Card.hpp @@ -429,6 +429,11 @@ public: */ ECardResult getError() const; + /** + * @brief Block caller until any asynchronous I/O operations have completed + */ + void waitForCompletion() const; + operator bool() const { return getError() == ECardResult::READY; } }; } diff --git a/lib/kabufuda/Card.cpp b/lib/kabufuda/Card.cpp index 7b7cc4d..472365f 100644 --- a/lib/kabufuda/Card.cpp +++ b/lib/kabufuda/Card.cpp @@ -862,8 +862,11 @@ void Card::format(ECardSlot id, ECardSize size, EEncoding encoding) if (m_fileHandle) { + uint32_t blockCount = (uint32_t(size) * MbitToBlocks) - 5; + m_tmpCh = m_ch; m_tmpCh._swapEndian(); + m_fileHandle.resizeQueue(5 + blockCount); m_fileHandle.asyncWrite(0, &m_tmpCh, BlockSize, 0); m_tmpDirs[0] = m_dirs[0]; m_tmpDirs[0].swapEndian(); @@ -882,7 +885,6 @@ void Card::format(ECardSlot id, ECardSize size, EEncoding encoding) DummyBlock.reset(new uint8_t[BlockSize]); memset(DummyBlock.get(), 0xFF, BlockSize); } - uint32_t blockCount = (uint32_t(size) * MbitToBlocks) - 5; for (uint32_t i=0 ; i