MCPcopy Index your code
hub / github.com/DreamSourceLab/DSView / save_analog

Method save_analog

DSView/pv/storesession.cpp:369–454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367}
368
369void StoreSession::save_analog(pv::data::AnalogSnapshot *analog_snapshot)
370{
371 char chunk_name[20] = {0};
372 int num = 0;
373 int ret = SR_ERR;
374
375 int ch_type = -1;
376 for(auto s : _session->get_signals()) {
377 ch_type = s->get_type();
378 break;
379 }
380
381 if (ch_type != -1) {
382 num = analog_snapshot->get_block_num();
383 _unit_count = analog_snapshot->get_sample_count() *
384 analog_snapshot->get_unit_bytes() *
385 analog_snapshot->get_channel_num();
386 uint8_t *buf = NULL;
387 uint8_t *buf_start = NULL;
388
389 buf = (uint8_t *)analog_snapshot->get_data() +
390 (analog_snapshot->get_ring_start() * analog_snapshot->get_unit_bytes()
391 * analog_snapshot->get_channel_num());
392
393 buf_start = (uint8_t *)analog_snapshot->get_data();
394
395 const uint8_t *buf_end = buf_start + _unit_count;
396
397 for (int i = 0; !_canceled && i < num; i++) {
398 const uint64_t size = analog_snapshot->get_block_size(i);
399 if ((buf + size) > buf_end) {
400 uint8_t *tmp = (uint8_t *)malloc(size);
401 if (tmp == NULL) {
402 _has_error = true;
403 _error = L_S(STR_PAGE_DLG, S_ID(IDS_MSG_STORESESS_SAVEPROC_ERROR1),
404 "Failed to create zip file. Malloc error.");
405 } else {
406 memcpy(tmp, buf, buf_end-buf);
407 memcpy(tmp+(buf_end-buf), buf_start, buf+size-buf_end);
408 }
409
410 MakeChunkName(chunk_name, i, 0, ch_type, HEADER_FORMAT_VERSION);
411 ret = m_zipDoc.AddFromBuffer(chunk_name, (const char*)tmp, size) ? SR_OK : -1;
412
413 buf += (size - _unit_count);
414 if (tmp)
415 free(tmp);
416 }
417 else {
418 MakeChunkName(chunk_name, i, 0, ch_type, HEADER_FORMAT_VERSION);
419 ret = m_zipDoc.AddFromBuffer(chunk_name, (const char*)buf, size) ? SR_OK : -1;
420
421 buf += size;
422 }
423
424 if (ret != SR_OK) {
425 if (!_has_error) {
426 _has_error = true;

Callers

nothing calls this directly

Calls 12

get_sample_countMethod · 0.80
get_unit_bytesMethod · 0.80
get_channel_numMethod · 0.80
get_ring_startMethod · 0.80
AddFromBufferMethod · 0.80
GetErrorMethod · 0.80
get_typeMethod · 0.45
get_block_numMethod · 0.45
get_dataMethod · 0.45
get_block_sizeMethod · 0.45
CloseMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected