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

Method FinalizeFile

lib/mdflib/mdflib/src/mdf4file.cpp:198–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196}
197
198bool Mdf4File::FinalizeFile(std::streambuf& buffer) {
199
200 uint16_t standard_flags = 0;
201 uint16_t custom_flags = 0;
202 const auto finalized = IsFinalized(standard_flags, custom_flags);
203 if (finalized || standard_flags == 0 || !hd_block_) {
204 MDF_DEBUG()
205 << "The files standard flags are OK. Cannot finalize the file. File: "
206 << Name();
207 return false;
208 }
209
210 // 1. Update DL block
211 // 2. Update DT block
212 // 3. Update RD block
213 // 4. Update CG (CA) block
214 const bool update_cg_blocks = (standard_flags & 0x01) != 0;
215 const bool update_sr_blocks = (standard_flags & 0x02) != 0;
216 const bool update_dt_blocks = (standard_flags & 0x04) != 0;
217 const bool update_rd_blocks = (standard_flags & 0x08) != 0;
218 const bool update_dl_blocks = (standard_flags & 0x10) != 0;
219 const bool update_vlsd_bytes = (standard_flags & 0x20) != 0;
220 const bool update_vlsd_offset = (standard_flags & 0x40) != 0;
221 bool updated = true;
222 if (update_dl_blocks) {
223 MDF_ERROR() << "Finalizing DL block is not supported. File: " << Name();
224 updated = false;
225 }
226 if (update_dt_blocks) {
227 // Update the number of bytes in the DT block.
228 const bool update_dt = hd_block_->FinalizeDtBlocks(buffer);
229 if (!update_dt) {
230 MDF_ERROR() << "Fail to finalize last DT block. File: " << Name();
231 updated = false;
232 }
233 }
234 if (update_rd_blocks) {
235 MDF_ERROR() << "Finalizing RD block is not supported. File: " << Name();
236 updated = false;
237 }
238
239 if (update_cg_blocks || update_vlsd_bytes || update_vlsd_offset ) {
240 const bool update_nof_samples = hd_block_->FinalizeCgAndVlsdBlocks(
241 buffer, update_cg_blocks, update_vlsd_bytes || update_vlsd_offset);
242 if (!update_nof_samples) {
243 MDF_ERROR() << "Failed to update number of samples and VLSD block sizes. File: " << Name();
244 updated = false;
245 }
246 }
247 if (update_sr_blocks) {
248 MDF_ERROR() << "Finalizing SR block is not supported. File: " << Name();
249 updated = false;
250 }
251 return updated;
252}
253
254IDataGroup *Mdf4File::FindParentDataGroup(const IChannel &channel) const {
255 const auto channel_index = channel.Index();

Callers

nothing calls this directly

Calls 2

FinalizeDtBlocksMethod · 0.45

Tested by

no test coverage detected