MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / open

Method open

Tactility/Source/file/ObjectFileReader.cpp:11–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9static const auto LOGGER = Logger("ObjectFileReader");
10
11bool ObjectFileReader::open() {
12 auto opening_file = std::unique_ptr<FILE, FileCloser>(fopen(filePath.c_str(), "r"));
13 if (opening_file == nullptr) {
14 LOGGER.error("Failed to open file {}", filePath.c_str());
15 return false;
16 }
17
18 FileHeader file_header;
19 if (fread(&file_header, sizeof(FileHeader), 1, opening_file.get()) != 1) {
20 LOGGER.error("Failed to read file header from {}", filePath);
21 return false;
22 }
23
24 if (file_header.identifier != OBJECT_FILE_IDENTIFIER) {
25 LOGGER.error("Invalid file type for {}", filePath);
26 return false;
27 }
28
29 if (file_header.version != OBJECT_FILE_VERSION) {
30 LOGGER.error("Unknown version for {}: {}", filePath, file_header.identifier);
31 return false;
32 }
33
34 ContentHeader content_header;
35 if (fread(&content_header, sizeof(ContentHeader), 1, opening_file.get()) != 1) {
36 LOGGER.error("Failed to read content header from {}", filePath);
37 return false;
38 }
39
40 if (recordSize != content_header.recordSize) {
41 LOGGER.error("Record size mismatch for {}: expected {}, got {}", filePath, recordSize, content_header.recordSize);
42 return false;
43 }
44
45 recordCount = content_header.recordCount;
46 recordVersion = content_header.recordVersion;
47
48 file = std::move(opening_file);
49
50 LOGGER.debug("File version: {}", file_header.version);
51 LOGGER.debug("Content: version = {}, size = {} bytes, count = {}", content_header.recordVersion, content_header.recordSize, content_header.recordCount);
52
53 return true;
54}
55
56void ObjectFileReader::close() {
57 recordCount = 0;

Callers 8

package_allFunction · 0.45
runMethod · 0.45
ObjectFileTest.cppFile · 0.45
uart_controller_openFunction · 0.45
downloadFunction · 0.45
getGpsConfigurationsMethod · 0.45
addGpsConfigurationMethod · 0.45

Calls 3

errorMethod · 0.80
debugMethod · 0.80
getMethod · 0.45

Tested by 1

runMethod · 0.36