Motion Master 6.0.0-alpha.53
Next-generation motion control software
Loading...
Searching...
No Matches
mm::node::ParameterCache Class Reference

On-disk cache of CoE parameter definitions, keyed by device identity. More...

#include <parameter_cache.h>

Classes

struct  CacheEntry
 Summary of one cache file on disk, for the management UI. More...
 

Public Member Functions

 ParameterCache ()=default
 
 ParameterCache (ParameterCacheConfig config)
 
void configure (ParameterCacheConfig config)
 Replaces the active policy/location. Called by DeviceManager::init.
 
bool enabledForVendor (uint32_t vendorId) const
 Whether the cache is active for vendorId under the current policy.
 
std::optional< std::vector< DeviceParameter > > load (uint32_t vendorId, uint32_t productCode, uint32_t revisionNumber) const
 Loads the cached parameter definitions for an identity.
 
void store (uint32_t vendorId, uint32_t productCode, uint32_t revisionNumber, const std::vector< DeviceParameter > &parameters) const
 Persists parameter definitions for an identity (atomic temp-file + rename).
 
std::vector< CacheEntrylist () const
 Lists every valid cache file in the cache directory.
 
std::expected< std::vector< uint8_t >, std::string > readRaw (std::string_view id) const
 Reads the raw JSON bytes of one cache file, addressed by its id (for download).
 
std::expected< void, std::string > remove (std::string_view id) const
 Deletes one cache file addressed by its id. Policy-independent.
 

Static Public Member Functions

static std::string makeId (uint32_t vendorId, uint32_t productCode, uint32_t revisionNumber)
 Builds the opaque id a client uses to address one cache file, from an identity triple. The single place the id encoding lives; list reports it and readRaw / remove parse it back, so neither the HTTP layer nor the UI ever formats the key itself.
 

Static Public Attributes

static constexpr int kFormatVersion = 1
 Bumped when the on-disk field set / meaning changes in a way that invalidates older files. Adding a new optional field does not require a bump (missing keys default and unknown keys are ignored); changing a field's meaning does.
 

Detailed Description

On-disk cache of CoE parameter definitions, keyed by device identity.

Enumerating a drive's object dictionary over the SDO-Information service is hundreds of mailbox round-trips and takes seconds; the result — the set of DeviceParameter definitions (index, subindex, name, data type, bit length, access, unit, and the static default/min/max bounds) — is identical for every device of the same (vendorId, productCode, revisionNumber) and, for a vendor with stable revision discipline, stays valid across power cycles. This cache persists those definitions to a human-readable JSON file per identity so a later scan of the same hardware skips the round-trips.

Only the definition is cached — never the live value or syncState. On load each parameter's value is reset to the type-appropriate default and read live from the device, so a stale cache can at most cost a re-enumeration, never show a stale value as if current. The cached file is a definition/schema snapshot, intended to be readable and (in future) enriched with ESI-derived metadata such as descriptions and enum option labels.

All operations are best-effort and never throw: a missing, unreadable, corrupt, or wrong-format-version file is a miss (the caller falls back to a live enumeration); a write failure is logged, not propagated. Owned by DeviceManager (it outlives the Device set, which is rebuilt on every scan) and handed to each Device by pointer.

Constructor & Destructor Documentation

◆ ParameterCache() [1/2]

mm::node::ParameterCache::ParameterCache ( )
default

◆ ParameterCache() [2/2]

mm::node::ParameterCache::ParameterCache ( ParameterCacheConfig  config)
explicit

Member Function Documentation

◆ configure()

void mm::node::ParameterCache::configure ( ParameterCacheConfig  config)

Replaces the active policy/location. Called by DeviceManager::init.

◆ enabledForVendor()

bool mm::node::ParameterCache::enabledForVendor ( uint32_t  vendorId) const

Whether the cache is active for vendorId under the current policy.

True when the master switch is on and either cacheAllVendors is set or vendorId is Synapticon's. The single gate consulted by both load and store.

◆ list()

std::vector< ParameterCache::CacheEntry > mm::node::ParameterCache::list ( ) const

Lists every valid cache file in the cache directory.

Unlike load / store, listing/management ignores the enabled/vendor policy — you must be able to inspect and clean up files even with caching disabled or after turning it off. Files that do not parse or carry a different formatVersion are skipped. Returns an empty list when the directory does not exist.

◆ load()

std::optional< std::vector< DeviceParameter > > mm::node::ParameterCache::load ( uint32_t  vendorId,
uint32_t  productCode,
uint32_t  revisionNumber 
) const

Loads the cached parameter definitions for an identity.

Each returned DeviceParameter has its definition fields populated, its value set to the type-appropriate default, and its syncState left Unknown (the caller reads live values).

Returns
The cached definitions on a hit, or std::nullopt when the cache is disabled for the vendor, no file exists, or the file is unreadable / corrupt / for a different identity or format version (all treated as a miss).

◆ makeId()

std::string mm::node::ParameterCache::makeId ( uint32_t  vendorId,
uint32_t  productCode,
uint32_t  revisionNumber 
)
static

Builds the opaque id a client uses to address one cache file, from an identity triple. The single place the id encoding lives; list reports it and readRaw / remove parse it back, so neither the HTTP layer nor the UI ever formats the key itself.

◆ readRaw()

std::expected< std::vector< uint8_t >, std::string > mm::node::ParameterCache::readRaw ( std::string_view  id) const

Reads the raw JSON bytes of one cache file, addressed by its id (for download).

Parses id and reads the file; policy-independent. The HTTP layer passes the path parameter straight through — the id encoding and its validation live here, not in the server.

Returns
The file bytes, or an error string if id is malformed or the file does not exist.

◆ remove()

std::expected< void, std::string > mm::node::ParameterCache::remove ( std::string_view  id) const

Deletes one cache file addressed by its id. Policy-independent.

Returns
Void on success, or an error string if id is malformed or the file does not exist.

◆ store()

void mm::node::ParameterCache::store ( uint32_t  vendorId,
uint32_t  productCode,
uint32_t  revisionNumber,
const std::vector< DeviceParameter > &  parameters 
) const

Persists parameter definitions for an identity (atomic temp-file + rename).

The live value and syncState of each parameter are intentionally not written. No-op when the cache is disabled for the vendor. Best-effort: directory-creation or write failures are logged at warn level and otherwise ignored.

Member Data Documentation

◆ kFormatVersion

constexpr int mm::node::ParameterCache::kFormatVersion = 1
staticconstexpr

Bumped when the on-disk field set / meaning changes in a way that invalidates older files. Adding a new optional field does not require a bump (missing keys default and unknown keys are ignored); changing a field's meaning does.


The documentation for this class was generated from the following files: