MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / SaveQueue

Method SaveQueue

lib/mdflib/mdflib/src/convertersamplequeue.cpp:31–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29}
30
31void ConverterSampleQueue::SaveQueue(std::unique_lock<std::mutex>& lock) {
32 if (writer_.CompressData()) {
33 SaveQueueCompressed(lock);
34 return;
35 }
36 auto* dg4 = dynamic_cast<Dg4Block*>(&data_group_);
37 if (dg4 == nullptr) {
38 return;
39 }
40
41 lock.unlock(); // OK to add samples to the queue
42 // Save uncompressed data in last DG/DT block
43
44 // File should be open at this point
45 if (!IsOpen()) {
46 lock.lock();
47 return;
48 }
49 if (dg4->FilePosition() <= 0) {
50 dg4->Write(*writer_.file_); // Flush out data
51 }
52
53 auto* dt4 = dg4->CreateOrGetDt4(*writer_.file_);
54 if (dt4 == nullptr) {
55 return;
56 }
57
58 SetLastPosition(*writer_.file_);
59
60 const auto id_size = dg4->RecordIdSize();
61
62 lock.lock(); // Lock the sample queue while flushing out to file
63
64 while (!IsEmpty() ) {
65 // Write all samples last to file
66 SampleRecord sample = GetSample();
67
68 auto* cg4 = dg4->FindCgRecordId(sample.record_id);
69 if (cg4 == nullptr) {
70 continue;
71 }
72 lock.unlock();
73
74 auto* vlsd_group = sample.vlsd_data ?
75 dg4->FindCgRecordId(sample.record_id + 1) : nullptr;
76 // The next group must have the VLSD flag set otherwise it's not a VLSD group.
77 if (vlsd_group != nullptr && (vlsd_group->Flags() & CgFlag::VlsdChannel) == 0) {
78 vlsd_group = nullptr;
79 }
80 auto* cn4 = sample.vlsd_data && vlsd_group == nullptr ?
81 cg4->FindSdChannel() : nullptr;
82 // If the sample holds VLSD data, save this data first and then update
83 // the data index. VLSD data is stored in SD or CG. A dirty trick is that
84 // the VLSD CG must have the next record_id
85 if (vlsd_group != nullptr) {
86 // Store as a VLSD record
87 const auto vlsd_index = vlsd_group->WriteVlsdSample(*writer_.file_, id_size,
88 sample.vlsd_buffer);

Callers

nothing calls this directly

Calls 15

GetFilePositionFunction · 0.85
CompressDataMethod · 0.80
CreateOrGetDt4Method · 0.80
FindSdChannelMethod · 0.80
WriteVlsdSampleMethod · 0.80
cbeginMethod · 0.80
cendMethod · 0.80
beginMethod · 0.80
WriteSdSampleMethod · 0.80
WriteSampleMethod · 0.80
UpdateBlockSizeMethod · 0.80
FilePositionMethod · 0.45

Tested by

no test coverage detected