A convenience class for responding to changes in a databaseState, potentially fired from other processes. Watches a given property's field corresponding to type T for changes, and fires a callback on change. Note that callback will run on a background timer thread, so if you need thread safety, be sure to utilise ISharedState::callOnMessageThread from your callback lambda.
More...
#include <mostlyharmless_DatabasePropertyWatcher.h>
|
| static auto | tryCreate (const DatabaseState &databaseState, std::string_view propertyName, int pollFrequencyMs, std::function< void(const T &)> &&callback) -> std::unique_ptr< DatabasePropertyWatcher > |
template<DatabaseStorageType T>
class mostly_harmless::data::DatabasePropertyWatcher< T >
A convenience class for responding to changes in a databaseState, potentially fired from other processes. Watches a given property's field corresponding to type T for changes, and fires a callback on change. Note that callback will run on a background timer thread, so if you need thread safety, be sure to utilise ISharedState::callOnMessageThread from your callback lambda.
- Template Parameters
-
| T | Any type satisfying DatabaseStorageType |
◆ DatabasePropertyWatcher() [1/2]
template<DatabaseStorageType T>
◆ DatabasePropertyWatcher() [2/2]
template<DatabaseStorageType T>
◆ operator=() [1/2]
template<DatabaseStorageType T>
◆ operator=() [2/2]
template<DatabaseStorageType T>
◆ tryCreate()
template<DatabaseStorageType T>
| auto mostly_harmless::data::DatabasePropertyWatcher< T >::tryCreate |
( |
const DatabaseState & | databaseState, |
|
|
std::string_view | propertyName, |
|
|
int | pollFrequencyMs, |
|
|
std::function< void(const T &)> && | callback ) -> std::unique_ptr< DatabasePropertyWatcher > |
|
inlinestatic |
Attempts to create a DatabasePropertyWatcher for the given property name. As sqlite requires database access across different processes to each have their own unique connection, we first call DatabaseState::duplicate to create a new connection specifically for this thread.
- Parameters
-
| databaseState | A const reference to the database connection to duplicate for this PropertyWatcher. |
| propertyName | The name of the property to watch. |
| pollFrequencyMs | The interval in milliseconds to poll the database for changes at. |
| callback | A lambda to be invoked from a background timer thread on property value change. |
- Returns
- A DatabasePropertyWatcher for the given property name if successful, nullptr otherwise.
The documentation for this class was generated from the following file: