MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / StartReadTask

Method StartReadTask

cpp/src/platform/winRT/SerialControllerImpl.cpp:175–219  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Start a background task which reads available data and passes it along to SerialController -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

173// Start a background task which reads available data and passes it along to SerialController
174//-----------------------------------------------------------------------------
175void SerialControllerImpl::StartReadTask()
176{
177 // Read serial data on background task
178 cancellation_token token = m_readTaskCancelationTokenSource.get_token();
179
180 create_task([token, this]()
181 {
182 uint32 readBufferLength = 512;
183 Buffer ^ buffer = ref new Buffer(readBufferLength);
184
185 for (;;)
186 {
187 try
188 {
189 create_task(m_serialDevice->InputStream->ReadAsync(buffer, readBufferLength, InputStreamOptions::None))
190 .then([&, this](IBuffer ^ outBuffer)
191 {
192 if (token.is_canceled())
193 return;
194 auto reader = DataReader::FromBuffer(outBuffer);
195 auto bytesRead = reader->UnconsumedBufferLength;
196
197 std::vector<uint8> byteVector(bytesRead);
198 if (!byteVector.empty())
199 {
200 reader->ReadBytes(::Platform::ArrayReference<uint8>(byteVector.data(), bytesRead));
201 m_owner->Put(byteVector.data(), bytesRead);
202 }
203 }).wait();
204 }
205 catch (Platform::Exception^ ex)
206 {
207 if (ex->HResult == HRESULT_FROM_WIN32(ERROR_OPERATION_ABORTED))
208 {
209 m_owner->Close();
210 }
211 }
212
213 if (token.is_canceled())
214 {
215 cancel_current_task();
216 }
217 }
218 }, token);
219}
220
221//-----------------------------------------------------------------------------
222// <SerialControllerImpl::Write>

Callers

nothing calls this directly

Calls 4

dataMethod · 0.80
PutMethod · 0.80
emptyMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected