swift
Loading...
Searching...
No Matches
swift::misc::CValueCache Class Reference

Manages a map of { QString, CVariant } pairs, which can be distributed among multiple processes. More...

#include <valuecache.h>

Inheritance diagram for swift::misc::CValueCache:
[legend]

Classes

class  BatchGuard
 RAII object returned by CValueCache::batchChanges. 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.

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.
swift::misc::CVariantMap getAllValues (const QStringList &keys) const
 Return map containing all given values in the cache.
swift::misc::CValueCachePacket getAllValuesWithTimestamps (const QString &keyPrefix={}) const
 Return map containing all values in the cache, and timestamps when they were modified.
QStringList getAllUnsavedKeys (const QString &keyPrefix={}) const
 Return keys of all values which have been changed but not saved.
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.
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.
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.
CStatusMessageList loadFromJsonNoThrow (const QJsonObject &json, const CLogCategoryList &categories, const QString &prefix)
 Call loadFromJson, catch any CJsonException that are thrown and return them as CStatusMessage.
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.
CStatusMessage saveToFiles (const QString &directory, const QStringList &keys)
 Save values to Json files in a given directory.
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.
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).
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).
void clearAllValues (const QString &keyPrefix={})
 Clear all values from the cache.
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.
Public Member Functions inherited from QObject
QBindable< QString > bindableObjectName ()
 QObject (QObject *parent)
 QT_NO_CONTEXTLESS_CONNECT QT_NO_CONTEXTLESS_CONNECT
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 Q_CLASSINFO (Name, Value)
 Q_EMIT Q_EMIT
 Q_ENUM (...)
 Q_ENUMS (...)
 Q_ENUM_NS (...)
 Q_FLAG (...)
 Q_FLAGS (...)
 Q_FLAG_NS (...)
 Q_GADGET Q_GADGET
 Q_GADGET_EXPORT (EXPORT_MACRO)
 Q_INTERFACES (...)
 Q_INVOKABLE Q_INVOKABLE
 Q_MOC_INCLUDE Q_MOC_INCLUDE
 Q_NAMESPACE Q_NAMESPACE
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 Q_OBJECT Q_OBJECT
 Q_PROPERTY (...)
 Q_REVISION Q_REVISION
 Q_SET_OBJECT_NAME (Object)
 Q_SIGNAL Q_SIGNAL
 Q_SIGNALS Q_SIGNALS
 Q_SLOT Q_SLOT
 Q_SLOTS Q_SLOTS
T qobject_cast (QObject *object)
T qobject_cast (const QObject *object)
bool blockSignals (bool block)
virtual bool event (QEvent *e)
virtual bool eventFilter (QObject *watched, QEvent *event)
bool moveToThread (QThread *targetThread)
bool setProperty (const char *name, QVariant &&value)
bool setProperty (const char *name, const QVariant &value)
int startTimer (int interval, Qt::TimerType timerType)
int startTimer (std::chrono::nanoseconds interval, Qt::TimerType timerType)
void deleteLater ()
void destroyed (QObject *obj)
void installEventFilter (QObject *filterObj)
void killTimer (Qt::TimerId id)
void killTimer (int id)
void objectNameChanged (const QString &objectName)
void removeEventFilter (QObject *obj)
void setObjectName (QAnyStringView name)
void setObjectName (const QString &name)
void setParent (QObject *parent)
QList< QByteArray > dynamicPropertyNames () const const
QList< T > findChildren (QAnyStringView name, Qt::FindChildOptions options) const const
QList< T > findChildren (Qt::FindChildOptions options) const const
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
QObject * parent () const const
QString objectName () const const
QThread * thread () const const
QVariant property (const char *name) const const
T findChild (QAnyStringView name, Qt::FindChildOptions options) const const
T findChild (Qt::FindChildOptions options) const const
bool disconnect (const QObject *receiver, const char *method) const const
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
bool inherits (const char *className) const const
bool isQmlExposed () const const
bool isQuickItemType () const const
bool isWidgetType () const const
bool isWindowType () const const
bool signalsBlocked () const const
virtual const QMetaObject * metaObject () const const
const QObjectList & children () const const
void dumpObjectInfo () const const
void dumpObjectTree () const const

Static Public Member Functions

static const QStringList & getLogCategories ()
 Log categories.
Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString tr (const char *sourceText, const char *disambiguation, int n)
bool disconnect (const QMetaObject::Connection &connection)
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)

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.
CStatusMessage loadFromFiles (const QString &directory, const QSet< QString > &keys, const CVariantMap &current, 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.
void markAllAsSaved (const QString &keyPrefix)
 Mark all values with keys that start with the given prefix as having been saved.
void markAllAsSaved (const QStringList &keys)
 Mark all values with given keys as having been saved.
CVariant getValueSync (const QString &key)
 Synchronously return a current value.
qint64 getTimestampSync (const QString &key)
 Synchronously return a current timestamp.
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 Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
virtual void connectNotify (const QMetaMethod &signal)
virtual void customEvent (QEvent *event)
virtual void disconnectNotify (const QMetaMethod &signal)
virtual void timerEvent (QTimerEvent *event)
QObject * sender () const const
bool isSignalConnected (const QMetaMethod &signal) const const
int receivers (const char *signal) const const
int senderSignalIndex () const const

Protected Attributes

QRecursiveMutex m_mutex
 Mutex protecting operations which are critical on m_elements.

Friends

class private_ns::CValuePage

Additional Inherited Members

Public Types inherited from QObject
enum  TimerId
Public Attributes inherited from QObject
typedef QObjectList
 Invalid
Properties inherited from QObject
 objectName

Detailed Description

Manages a map of { QString, CVariant } pairs, which can be distributed among multiple processes.

Definition at line 153 of file valuecache.h.

Member Function Documentation

◆ batchChanges()

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.

Note
Must be called in the thread where owner lives.

◆ changeValuesFromRemote

void swift::misc::CValueCache::changeValuesFromRemote ( const swift::misc::CValueCachePacket & values,
const swift::misc::CIdentifier & originator )
slot

Notify this cache that values have been changed by one of the duplicate caches in the multi-process environment.

See also
swift::misc::CValueCache::valuesChangedByLocal.
Parameters
valuesThe values that were changed.
originatorIdentifier of the process which made the change. Can be this very process, or a different one.

◆ clearAllValues()

void swift::misc::CValueCache::clearAllValues ( const QString & keyPrefix = {})

Clear all values from the cache.

Remarks
This function is thread safe.

◆ elementsStartingWith() [1/2]

auto swift::misc::CValueCache::elementsStartingWith ( const QString & keyPrefix)
inlineprotected

Returns a range referring to all elements which start with the given prefix.

Definition at line 272 of file valuecache.h.

◆ elementsStartingWith() [2/2]

auto swift::misc::CValueCache::elementsStartingWith ( const QString & keyPrefix) const
inlineprotected

Returns a range referring to all elements which start with the given prefix.

Definition at line 277 of file valuecache.h.

◆ enumerateFiles()

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).

Remarks
This function is thread safe.

◆ filenameForKey()

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).

Remarks
This function is thread safe.

◆ getAllUnsavedKeys()

QStringList swift::misc::CValueCache::getAllUnsavedKeys ( const QString & keyPrefix = {}) const

Return keys of all values which have been changed but not saved.

Remarks
This function is thread safe.

◆ getAllValues() [1/2]

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.

Remarks
This function is thread safe.

◆ getAllValues() [2/2]

swift::misc::CVariantMap swift::misc::CValueCache::getAllValues ( const QStringList & keys) const

Return map containing all given values in the cache.

Remarks
This function is thread safe.

◆ getAllValuesWithTimestamps()

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.

Remarks
This function is thread safe.

◆ getTimestampSync()

qint64 swift::misc::CValueCache::getTimestampSync ( const QString & key)
inlineprotected

Synchronously return a current timestamp.

Remarks
This function is thread safe.

Definition at line 312 of file valuecache.h.

◆ getValueSync()

CVariant swift::misc::CValueCache::getValueSync ( const QString & key)
inlineprotected

Synchronously return a current value.

Remarks
This function is thread safe.

Definition at line 308 of file valuecache.h.

◆ insertValues()

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.

Remarks
This function is thread safe.

◆ loadFromFiles() [1/2]

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.

Remarks
This function is thread safe.

◆ loadFromFiles() [2/2]

CStatusMessage swift::misc::CValueCache::loadFromFiles ( const QString & directory,
const QSet< QString > & keys,
const CVariantMap & current,
CValueCachePacket & o_values,
const QString & keysMessage = {},
bool keysOnly = false ) const
protected

Load from Json files in a given directory any values which differ from the current ones, and insert them in o_values.

Remarks
This function is thread safe.

◆ loadFromJson()

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.

Exceptions
swift::misc::CJsonExceptionif JSON schema validation fails.
Remarks
This function is thread safe.

◆ loadFromJsonNoThrow()

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.

Remarks
This function is thread safe.

◆ markAllAsSaved() [1/2]

void swift::misc::CValueCache::markAllAsSaved ( const QString & keyPrefix)
protected

Mark all values with keys that start with the given prefix as having been saved.

Remarks
This function is thread safe.

◆ markAllAsSaved() [2/2]

void swift::misc::CValueCache::markAllAsSaved ( const QStringList & keys)
protected

Mark all values with given keys as having been saved.

Remarks
This function is thread safe.

◆ saveToFiles() [1/3]

CStatusMessage swift::misc::CValueCache::saveToFiles ( const QString & directory,
const CVariantMap & values,
const QString & keysMessage = {} ) const
protected

Save specific values to Json files in a given directory.

Remarks
This function is thread safe.

◆ saveToFiles() [2/3]

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.

Remarks
This function is thread safe.

◆ saveToFiles() [3/3]

CStatusMessage swift::misc::CValueCache::saveToFiles ( const QString & directory,
const QStringList & keys )

Save values to Json files in a given directory.

Remarks
This function is thread safe.

◆ saveToJson()

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.

Remarks
This function is thread safe.

◆ private_ns::CValuePage

friend class private_ns::CValuePage
friend

Definition at line 318 of file valuecache.h.

Member Data Documentation

◆ m_mutex

QRecursiveMutex swift::misc::CValueCache::m_mutex
mutableprotected

Mutex protecting operations which are critical on m_elements.

Definition at line 304 of file valuecache.h.


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