Motion Master
Loading...
Searching...
No Matches
od_cache.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <filesystem>
5#include <nlohmann/json.hpp>
6#include <string>
7#include <string_view>
8#include <vector>
9
12inline constexpr int kOdCacheFormatVersion = 2;
13
18 uint32_t vendor_id = 0;
19 uint32_t product_code = 0;
20 std::string firmware_version;
21};
22
34std::string sanitizeFirmwareVersion(std::string_view version);
35
45std::string trimObjectString(std::string_view raw);
46
48std::filesystem::path odCacheDirectory(const std::filesystem::path& data_dir);
49
62std::filesystem::path odCacheFilePath(const std::filesystem::path& data_dir,
63 const OdCacheIdentity& identity);
64
72nlohmann::json makeOdCacheDocument(const OdCacheIdentity& identity,
73 nlohmann::json entries);
74
86bool odCacheDocumentMatches(const nlohmann::json& document,
87 const OdCacheIdentity& identity);
88
92 std::vector<std::filesystem::path> deleted;
94 std::vector<std::pair<std::filesystem::path, std::string>> failed;
95};
96
109OdCacheClearResult clearOdCache(const std::filesystem::path& data_dir);
std::string sanitizeFirmwareVersion(std::string_view version)
Reduces a firmware version to the characters a file name may hold.
Definition od_cache.cc:62
std::string trimObjectString(std::string_view raw)
Removes the padding of a string read from the object dictionary.
Definition od_cache.cc:74
constexpr int kOdCacheFormatVersion
Definition od_cache.h:12
std::filesystem::path odCacheDirectory(const std::filesystem::path &data_dir)
The folder of the object dictionary cache: <data-dir>/od-cache.
Definition od_cache.cc:83
std::filesystem::path odCacheFilePath(const std::filesystem::path &data_dir, const OdCacheIdentity &identity)
Returns the path of the object dictionary cache file of a device.
Definition od_cache.cc:87
nlohmann::json makeOdCacheDocument(const OdCacheIdentity &identity, nlohmann::json entries)
Builds the content of a cache file.
Definition od_cache.cc:95
OdCacheClearResult clearOdCache(const std::filesystem::path &data_dir)
Deletes every object dictionary cache file in the data directory.
Definition od_cache.cc:117
bool odCacheDocumentMatches(const nlohmann::json &document, const OdCacheIdentity &identity)
Tells whether a cache file applies to a device.
Definition od_cache.cc:104
The outcome of clearOdCache().
Definition od_cache.h:90
std::vector< std::pair< std::filesystem::path, std::string > > failed
The cache files that could not be deleted, each with the reason.
Definition od_cache.h:94
std::vector< std::filesystem::path > deleted
The cache files that were deleted.
Definition od_cache.h:92
Definition od_cache.h:17
uint32_t product_code
Definition od_cache.h:19
uint32_t vendor_id
Definition od_cache.h:18
std::string firmware_version
Definition od_cache.h:20