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

Method SaveQueue

lib/mdflib/mdflib/src/writer4samplequeue.cpp:36–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36void Writer4SampleQueue::SaveQueue(std::unique_lock<std::mutex>& lock) {
37 if (writer_.CompressData()) {
38 SaveQueueCompressed(lock);
39 return;
40 }
41
42 // Save uncompressed data in last DG/DT block
43 auto* dg4 = dynamic_cast<Dg4Block*>(&data_group_);
44 if (dg4 == nullptr) {
45 return;
46 }
47
48 lock.unlock();
49
50 writer_.Open( std::ios_base::in | std::ios_base::out | std::ios_base::binary);
51 if (!writer_.IsOpen()) {
52 lock.lock();
53 return;
54 }
55 auto* dt4 = dg4->CreateOrGetDt4(*writer_.file_);
56 if (dt4 == nullptr) {
57 return;
58 }
59 const auto data_position = dt4->DataPosition();
60 if (data_position <= 0) {
61 return;
62 }
63
64 SetLastPosition(*writer_.file_);
65
66 lock.lock();
67
68 TrimQueue();
69
70 const auto id_size = dg4->RecordIdSize();
71 const auto stop_time = writer_.StopTime();
72 while (!IsEmpty()) {
73 // Write a sample last to file
74 SampleRecord sample = GetSample();
75 if (stop_time > 0 && sample.timestamp > stop_time) {
76 break;
77 }
78 auto* cg4 = dg4->FindCgRecordId(sample.record_id);
79 if (cg4 == nullptr) {
80 continue;
81 }
82 lock.unlock();
83
84
85 auto* vlsd_group = sample.vlsd_data ?
86 dg4->FindCgRecordId(sample.record_id + 1) : nullptr;
87 // The next group must have the VLSD flag set otherwise it's not a VLSD group.
88 if (vlsd_group != nullptr && (vlsd_group->Flags() & CgFlag::VlsdChannel) == 0) {
89 vlsd_group = nullptr;
90 }
91 auto* cn4 = sample.vlsd_data && vlsd_group == nullptr ?
92 cg4->FindSdChannel() : nullptr;
93 // If the sample holds VLSD data, save this data first and then update

Callers

nothing calls this directly

Calls 15

GetLastFilePositionFunction · 0.85
CompressDataMethod · 0.80
CreateOrGetDt4Method · 0.80
DataPositionMethod · 0.80
StopTimeMethod · 0.80
FindSdChannelMethod · 0.80
WriteVlsdSampleMethod · 0.80
cbeginMethod · 0.80
cendMethod · 0.80
beginMethod · 0.80
WriteSdSampleMethod · 0.80
WriteSampleMethod · 0.80

Tested by

no test coverage detected