swift
|
Manages a map of { QString, CVariant } pairs, which can be distributed among multiple processes. More...
Public Slots | |
void | changeValuesFromRemote (const swift::misc::CValueCachePacket &values, const swift::misc::CIdentifier &originator) |
Notify this cache that values have been changed by one of the duplicate caches in the multi-process environment. More... | |
Signals | |
void | valuesChangedByLocal (const swift::misc::CValueCachePacket &values) |
Emitted when values in the cache are changed by an object in this very process. The interprocess communication (e.g. DBus) should arrange for this signal to call the slot changeValueFromRemote of CValueCache instances in all processes including this one. The slot will do its own round-trip detection. | |
void | valuesSaveRequested (const swift::misc::CValueCachePacket &values) |
Emitted when this cache has ratified a change which included a request to save (i.e. via CCaches::setAndSave). If the derived class does not handle such requests, the signal can be ignored. | |
Public Member Functions | |
CValueCache (int fileSplitDepth, QObject *parent=nullptr) | |
Constructor. | |
swift::misc::CVariantMap | getAllValues (const QString &keyPrefix={}) const |
Return map containing all values in the cache. If prefix is provided then only those values whose keys start with that prefix. More... | |
swift::misc::CVariantMap | getAllValues (const QStringList &keys) const |
Return map containing all given values in the cache. More... | |
swift::misc::CValueCachePacket | getAllValuesWithTimestamps (const QString &keyPrefix={}) const |
Return map containing all values in the cache, and timestamps when they were modified. More... | |
QStringList | getAllUnsavedKeys (const QString &keyPrefix={}) const |
Return keys of all values which have been changed but not saved. More... | |
void | insertValues (const swift::misc::CValueCachePacket &values) |
Add some values to the cache. Values already in the cache will remain in the cache unless they are overwritten. More... | |
QJsonObject | saveToJson (const QString &keyPrefix={}) const |
Save values in Json format. If prefix is provided then only those values whose keys start with that prefix. More... | |
void | loadFromJson (const QJsonObject &json) |
Load all values in Json format. Values already in the cache will remain in the cache unless they are overwritten. More... | |
CStatusMessageList | loadFromJsonNoThrow (const QJsonObject &json, const CLogCategoryList &categories, const QString &prefix) |
Call loadFromJson, catch any CJsonException that are thrown and return them as CStatusMessage. More... | |
CStatusMessage | saveToFiles (const QString &directory, const QString &keyPrefix={}) |
Save values to Json files in a given directory. If prefix is provided then only those values whose keys start with that prefix. More... | |
CStatusMessage | saveToFiles (const QString &directory, const QStringList &keys) |
Save values to Json files in a given directory. More... | |
CStatusMessage | loadFromFiles (const QString &directory) |
Load all values from Json files in a given directory. Values already in the cache will remain in the cache unless they are overwritten. More... | |
QString | filenameForKey (const QString &key) const |
Return the (relative) filename that may is (or would be) used to save the value with the given key. The file may or may not exist (because it might not have been saved yet). More... | |
QStringList | enumerateFiles (const QString &directory) const |
List the Json files which are (or would be) used to save the current values. The files may or may not exist (because they might not have been saved yet). More... | |
void | clearAllValues (const QString &keyPrefix={}) |
Clear all values from the cache. More... | |
QString | getHumanReadableName (const QString &key) const |
Return the human readable name of the given key, or the raw key string if there is none. | |
QString | getHumanReadableWithKey (const QString &key) const |
Return the human readable name of the given key, with the raw key string appended. | |
BatchGuard | batchChanges (QObject *owner) |
Begins a batch of changes to be made through CCached instances owned by owner. More... | |
~BatchGuard () | |
Destructor. Applies deferred changes. | |
BatchGuard (const BatchGuard &)=delete | |
Deleted copy constructor. Class is move-only. | |
BatchGuard & | operator= (const BatchGuard &)=delete |
Deleted copy assignment operator. Class is move-only. | |
BatchGuard (BatchGuard &&other) noexcept | |
Move constructor. | |
BatchGuard & | operator= (BatchGuard &&other) noexcept |
Move assignment operator. | |
Static Public Member Functions | |
static const QStringList & | getLogCategories () |
Log categories. | |
Protected Member Functions | |
CStatusMessage | saveToFiles (const QString &directory, const CVariantMap &values, const QString &keysMessage={}) const |
Save specific values to Json files in a given directory. More... | |
CStatusMessage | loadFromFiles (const QString &directory, const QSet< QString > &keys, const CVariantMap ¤t, CValueCachePacket &o_values, const QString &keysMessage={}, bool keysOnly=false) const |
Load from Json files in a given directory any values which differ from the current ones, and insert them in o_values. More... | |
void | markAllAsSaved (const QString &keyPrefix) |
Mark all values with keys that start with the given prefix as having been saved. More... | |
void | markAllAsSaved (const QStringList &keys) |
Mark all values with given keys as having been saved. More... | |
CVariant | getValueSync (const QString &key) |
Synchronously return a current value. More... | |
qint64 | getTimestampSync (const QString &key) |
Synchronously return a current timestamp. More... | |
auto | elementsStartingWith (const QString &keyPrefix) |
Returns a range referring to all elements which start with the given prefix. | |
auto | elementsStartingWith (const QString &keyPrefix) const |
Returns a range referring to all elements which start with the given prefix. | |
Protected Attributes | |
QRecursiveMutex | m_mutex |
Mutex protecting operations which are critical on m_elements. | |
Friends | |
class | private_ns::CValuePage |
Manages a map of { QString, CVariant } pairs, which can be distributed among multiple processes.
RAII object returned by CValueCache::batchChanges.
Applies deferred changes when it is destroyed.
Definition at line 153 of file valuecache.h.
BatchGuard swift::misc::CValueCache::batchChanges | ( | QObject * | owner | ) |
Begins a batch of changes to be made through CCached instances owned by owner.
All changes made through those CCached instances will be deferred until the returned RAII object is destroyed. If the destruction happens during stack unwinding due to an exception being thrown, the changes are abandoned, otherwise they are applied in one single change signal instead of lots of individual ones. Can be called multiple times; the batch will be applied (or abandoned) when the last RAII object is destroyed. CCached::getValue will continue to return the old value until the batched changes are applied.
|
slot |
Notify this cache that values have been changed by one of the duplicate caches in the multi-process environment.
values | The values that were changed. |
originator | Identifier of the process which made the change. Can be this very process, or a different one. |
void swift::misc::CValueCache::clearAllValues | ( | const QString & | keyPrefix = {} | ) |
Clear all values from the cache.
QStringList swift::misc::CValueCache::enumerateFiles | ( | const QString & | directory | ) | const |
List the Json files which are (or would be) used to save the current values. The files may or may not exist (because they might not have been saved yet).
QString swift::misc::CValueCache::filenameForKey | ( | const QString & | key | ) | const |
Return the (relative) filename that may is (or would be) used to save the value with the given key. The file may or may not exist (because it might not have been saved yet).
QStringList swift::misc::CValueCache::getAllUnsavedKeys | ( | const QString & | keyPrefix = {} | ) | const |
Return keys of all values which have been changed but not saved.
swift::misc::CVariantMap swift::misc::CValueCache::getAllValues | ( | const QString & | keyPrefix = {} | ) | const |
Return map containing all values in the cache. If prefix is provided then only those values whose keys start with that prefix.
swift::misc::CVariantMap swift::misc::CValueCache::getAllValues | ( | const QStringList & | keys | ) | const |
Return map containing all given values in the cache.
swift::misc::CValueCachePacket swift::misc::CValueCache::getAllValuesWithTimestamps | ( | const QString & | keyPrefix = {} | ) | const |
Return map containing all values in the cache, and timestamps when they were modified.
|
inlineprotected |
Synchronously return a current timestamp.
Definition at line 312 of file valuecache.h.
|
inlineprotected |
Synchronously return a current value.
Definition at line 308 of file valuecache.h.
void swift::misc::CValueCache::insertValues | ( | const swift::misc::CValueCachePacket & | values | ) |
Add some values to the cache. Values already in the cache will remain in the cache unless they are overwritten.
CStatusMessage swift::misc::CValueCache::loadFromFiles | ( | const QString & | directory | ) |
Load all values from Json files in a given directory. Values already in the cache will remain in the cache unless they are overwritten.
|
protected |
Load from Json files in a given directory any values which differ from the current ones, and insert them in o_values.
void swift::misc::CValueCache::loadFromJson | ( | const QJsonObject & | json | ) |
Load all values in Json format. Values already in the cache will remain in the cache unless they are overwritten.
swift::misc::CJsonException | if JSON schema validation fails. |
CStatusMessageList swift::misc::CValueCache::loadFromJsonNoThrow | ( | const QJsonObject & | json, |
const CLogCategoryList & | categories, | ||
const QString & | prefix | ||
) |
Call loadFromJson, catch any CJsonException that are thrown and return them as CStatusMessage.
|
protected |
Mark all values with keys that start with the given prefix as having been saved.
|
protected |
Mark all values with given keys as having been saved.
|
protected |
Save specific values to Json files in a given directory.
CStatusMessage swift::misc::CValueCache::saveToFiles | ( | const QString & | directory, |
const QString & | keyPrefix = {} |
||
) |
Save values to Json files in a given directory. If prefix is provided then only those values whose keys start with that prefix.
CStatusMessage swift::misc::CValueCache::saveToFiles | ( | const QString & | directory, |
const QStringList & | keys | ||
) |
Save values to Json files in a given directory.
QJsonObject swift::misc::CValueCache::saveToJson | ( | const QString & | keyPrefix = {} | ) | const |
Save values in Json format. If prefix is provided then only those values whose keys start with that prefix.