/** * Read a log mask from a configuration object. * * @param conf Log mask JSON configuration object. * @param pmask Location for the read mask. * * @return Global return code. */ static tlog_grc get_log_mask(struct json_object *conf, unsigned int *pmask) { unsigned int mask = 0; struct json_object *obj; assert(conf != NULL); assert(pmask != NULL); #define READ_ITEM(_NAME, _Name, _name) \ do { \ if (!json_object_object_get_ex(conf, #_name, &obj)) { \ fprintf(stderr, #_Name " logging flag is not specified\n"); \ return TLOG_RC_FAILURE; \ } \ mask |= json_object_get_boolean(obj) << TLOG_LOG_ITEM_##_NAME; \ } while (0) READ_ITEM(INPUT, Input, input); READ_ITEM(OUTPUT, Output, output); READ_ITEM(WINDOW, Window, window); #undef READ_ITEM *pmask = mask; return TLOG_RC_OK; }
/* Reads the appropriate size of block from input. */ static bool read_timestamp_block(FILE *stream) { struct extended_timestamp_id0 *block = get_timestamp_block(); if (save_id0) return READ_ITEM(stream, *block); else return READ_ITEM(stream, *(struct extended_timestamp *) block); }
/* Captures open data stream to configured output file. */ static bool capture_and_save(FILE *stream) { return IF_(!continuous_capture, TEST_OK(READ_ITEM(stream, sample_count))) && IF_ELSE(matlab_format, capture_matlab_data(stream), capture_raw_data(stream)); }
/* Coordination of matlab data capture. */ static bool capture_matlab_data(FILE *stream) { uint64_t frames_written; time_t local_offset = offset_matlab_times ? local_time_offset() : 0; return TEST_OK(READ_ITEM(stream, timestamp_header)) && TEST_OK_(timestamp_header.offset < timestamp_header.block_size, "Invalid response from server") && write_header((uint32_t) sample_count) && capture_data(stream, &frames_written) && write_footer((uint32_t) frames_written, local_offset) && IF_(frames_written != sample_count, /* For an incomplete capture, probably an interrupted continuous * capture, we need to rewrite the header with the correct * capture count. */ TEST_IO_(fseek(output_file, 0, SEEK_SET), "Cannot update matlab file, file not seekable") && write_header((uint32_t) frames_written)); }