|
Motion Master
|
#include "od_cache.h"#include <cctype>#include <string_view>#include <system_error>#include <utility>#include "util.h"
Functions | |
| std::string | sanitizeFirmwareVersion (std::string_view version) |
| Reduces a firmware version to the characters a file name may hold. | |
| std::string | trimObjectString (std::string_view raw) |
| Removes the padding of a string read from the object dictionary. | |
| std::filesystem::path | odCacheDirectory (const std::filesystem::path &data_dir) |
| The folder of the object dictionary cache: <data-dir>/od-cache. | |
| 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. | |
| nlohmann::json | makeOdCacheDocument (const OdCacheIdentity &identity, nlohmann::json entries) |
| Builds the content of a cache file. | |
| bool | odCacheDocumentMatches (const nlohmann::json &document, const OdCacheIdentity &identity) |
| Tells whether a cache file applies to a device. | |
| OdCacheClearResult | clearOdCache (const std::filesystem::path &data_dir) |
| Deletes every object dictionary cache file in the data directory. | |
| OdCacheClearResult clearOdCache | ( | const std::filesystem::path & | data_dir | ) |
Deletes every object dictionary cache file in the data directory.
Deleted are the files in <data-dir>/od-cache whose names have the layout of odCacheFilePath(), and the files of the earlier layout <data-dir>/0x<vendor>/0x<product>/0x<revision>.json. Other files are not touched. A folder that is empty afterwards is deleted as well.
| data_dir | The data directory, see –data-dir. A directory that does not exist holds no cache, and the result is empty. |
| nlohmann::json makeOdCacheDocument | ( | const OdCacheIdentity & | identity, |
| nlohmann::json | entries ) |
Builds the content of a cache file.
| identity | What the dictionary was read from. |
| entries | The dictionary entries, as serialized. |
| std::filesystem::path odCacheDirectory | ( | const std::filesystem::path & | data_dir | ) |
The folder of the object dictionary cache: <data-dir>/od-cache.
| bool odCacheDocumentMatches | ( | const nlohmann::json & | document, |
| const OdCacheIdentity & | identity ) |
Tells whether a cache file applies to a device.
It applies when it has the current format version and the same vendor ID, product code and full firmware version. A file in an older format, such as a bare list of entries, does not apply.
| document | The parsed cache file. |
| identity | The identity of the device. |
| 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.
The file is <data-dir>/od-cache/0x<vendor>0x<product><version>.json, with the vendor ID and the product code written as 8 lowercase hex digits and the version reduced by sanitizeFirmwareVersion(). The SII revision is not part of the name, because on Jasper firmware it does not follow the dictionary.
| data_dir | The data directory, see –data-dir. |
| identity | The device identity and the firmware version. |
| std::string sanitizeFirmwareVersion | ( | std::string_view | version | ) |
Reduces a firmware version to the characters a file name may hold.
Every character other than A-Z, a-z, 0-9, '.', '' and '-' becomes '', and the result is at most 64 characters long. Two versions can reduce to the same name, for example "v10.0.4+41" and "v10.0.4_41", so the cache file also stores the full version, see odCacheDocumentMatches().
| version | The firmware version, as read from 0x100A. |
| std::string trimObjectString | ( | std::string_view | raw | ) |
Removes the padding of a string read from the object dictionary.
A device can pad a visible string with null bytes or spaces. The string ends at the first null byte, and trailing white space is removed.
| raw | The bytes of the string as read. |