File-backed ISurfaceStore — one JSON document on disk. More...
#include <phosphor-layer/include/PhosphorLayer/defaults/JsonSurfaceStore.h>
Public Member Functions | |
| JsonSurfaceStore (QString filePath) | |
| ~JsonSurfaceStore () override | |
| bool | save (const QString &key, const QJsonObject &data) override |
Persist data under key. | |
| QJsonObject | load (const QString &key) const override |
Load the JSON object previously stored under key. | |
| bool | has (const QString &key) const override |
True if key exists in the store. | |
| void | remove (const QString &key) override |
Remove the entry for key (no-op if absent). | |
| QString | filePath () const |
| File path this store reads from / writes to. | |
Public Member Functions inherited from PhosphorLayer::ISurfaceStore | |
| ISurfaceStore ()=default | |
| virtual | ~ISurfaceStore ()=default |
File-backed ISurfaceStore — one JSON document on disk.
The entire store is serialised as a single JSON object keyed by key-name. Loads happen lazily on first access; saves use QSaveFile for atomicity (write-to-temp + rename). Suitable for modest amounts of state (hundreds of keys); for heavier workloads wrap KConfig or a database.
The file path is consumer-chosen. Typical usage:
save() and load() share a single in-memory QJsonObject without locks. All calls must originate from the same thread (typically the GUI thread). Consumers that need cross-thread access must serialise calls externally, or wrap the store in their own mutex. Every save() also rewrites the full file; batching on the caller side is recommended if many keys are mutated together.
|
explicit |
|
override |
| QString PhosphorLayer::JsonSurfaceStore::filePath | ( | ) | const |
File path this store reads from / writes to.
|
overridevirtual |
True if key exists in the store.
Implements PhosphorLayer::ISurfaceStore.
|
overridevirtual |
Load the JSON object previously stored under key.
Returns an empty object if the key does not exist or the stored data cannot be parsed.
Implements PhosphorLayer::ISurfaceStore.
|
overridevirtual |
Remove the entry for key (no-op if absent).
Implements PhosphorLayer::ISurfaceStore.
|
overridevirtual |
Persist data under key.
Overwrites any existing entry. Returns false on I/O failure (the implementation logs the reason).
Implements PhosphorLayer::ISurfaceStore.